1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 Google Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Build and Device Tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktInfoTests.hpp"
25 #include "vktTestCaseUtil.hpp"
26 #include "vkPlatform.hpp"
27 #include "vkApiVersion.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuFormatUtil.hpp"
30 #include "tcuCommandLine.hpp"
31 #include "tcuPlatform.hpp"
32 #include "deDefs.h"
33 #include "deStringUtil.hpp"
34 #include "vktApiFeatureInfo.hpp"
35 #include "vktTestGroupUtil.hpp"
36
37 #include <iomanip>
38
39 namespace vkt
40 {
41 namespace info
42 {
43
44 namespace
45 {
46
47 using std::string;
48 using tcu::TestLog;
49
getOsName(int os)50 std::string getOsName(int os)
51 {
52 switch (os)
53 {
54 case DE_OS_VANILLA:
55 return "DE_OS_VANILLA";
56 case DE_OS_WIN32:
57 return "DE_OS_WIN32";
58 case DE_OS_UNIX:
59 return "DE_OS_UNIX";
60 case DE_OS_WINCE:
61 return "DE_OS_WINCE";
62 case DE_OS_OSX:
63 return "DE_OS_OSX";
64 case DE_OS_ANDROID:
65 return "DE_OS_ANDROID";
66 case DE_OS_SYMBIAN:
67 return "DE_OS_SYMBIAN";
68 case DE_OS_IOS:
69 return "DE_OS_IOS";
70 default:
71 return de::toString(os);
72 }
73 }
74
getCompilerName(int compiler)75 std::string getCompilerName(int compiler)
76 {
77 switch (compiler)
78 {
79 case DE_COMPILER_VANILLA:
80 return "DE_COMPILER_VANILLA";
81 case DE_COMPILER_MSC:
82 return "DE_COMPILER_MSC";
83 case DE_COMPILER_GCC:
84 return "DE_COMPILER_GCC";
85 case DE_COMPILER_CLANG:
86 return "DE_COMPILER_CLANG";
87 default:
88 return de::toString(compiler);
89 }
90 }
91
getCpuName(int cpu)92 std::string getCpuName(int cpu)
93 {
94 switch (cpu)
95 {
96 case DE_CPU_VANILLA:
97 return "DE_CPU_VANILLA";
98 case DE_CPU_ARM:
99 return "DE_CPU_ARM";
100 case DE_CPU_X86:
101 return "DE_CPU_X86";
102 case DE_CPU_X86_64:
103 return "DE_CPU_X86_64";
104 case DE_CPU_ARM_64:
105 return "DE_CPU_ARM_64";
106 case DE_CPU_MIPS:
107 return "DE_CPU_MIPS";
108 case DE_CPU_MIPS_64:
109 return "DE_CPU_MIPS_64";
110 case DE_CPU_RISCV_32:
111 return "DE_CPU_RISCV_32";
112 case DE_CPU_RISCV_64:
113 return "DE_CPU_RISCV_64";
114 default:
115 return de::toString(cpu);
116 }
117 }
118
getEndiannessName(int endianness)119 std::string getEndiannessName(int endianness)
120 {
121 switch (endianness)
122 {
123 case DE_BIG_ENDIAN:
124 return "DE_BIG_ENDIAN";
125 case DE_LITTLE_ENDIAN:
126 return "DE_LITTLE_ENDIAN";
127 default:
128 return de::toString(endianness);
129 }
130 }
131
logBuildInfo(Context & context)132 tcu::TestStatus logBuildInfo(Context &context)
133 {
134 #if defined(DE_DEBUG)
135 const bool isDebug = true;
136 #else
137 const bool isDebug = false;
138 #endif
139
140 context.getTestContext().getLog() << TestLog::Message << "DE_OS: " << getOsName(DE_OS) << "\n"
141 << "DE_CPU: " << getCpuName(DE_CPU) << "\n"
142 << "DE_PTR_SIZE: " << DE_PTR_SIZE << "\n"
143 << "DE_ENDIANNESS: " << getEndiannessName(DE_ENDIANNESS) << "\n"
144 << "DE_COMPILER: " << getCompilerName(DE_COMPILER) << "\n"
145 << "DE_DEBUG: " << (isDebug ? "true" : "false") << "\n"
146 << TestLog::EndMessage;
147
148 return tcu::TestStatus::pass("Not validated");
149 }
150
logDeviceInfo(Context & context)151 tcu::TestStatus logDeviceInfo(Context &context)
152 {
153 TestLog &log = context.getTestContext().getLog();
154 const vk::VkPhysicalDeviceProperties &properties = context.getDeviceProperties();
155
156 log << TestLog::Message << "Using --deqp-vk-device-id=" << context.getTestContext().getCommandLine().getVKDeviceId()
157 << TestLog::EndMessage;
158
159 log << TestLog::Message << "apiVersion: " << vk::unpackVersion(properties.apiVersion) << "\n"
160 << "driverVersion: " << tcu::toHex(properties.driverVersion) << "\n"
161 << "deviceName: " << (const char *)properties.deviceName << "\n"
162 << "vendorID: " << tcu::toHex(properties.vendorID) << "\n"
163 << "deviceID: " << tcu::toHex(properties.deviceID) << "\n"
164 << TestLog::EndMessage;
165
166 return tcu::TestStatus::pass("Not validated");
167 }
168
logPlatformInfo(Context & context)169 tcu::TestStatus logPlatformInfo(Context &context)
170 {
171 std::ostringstream details;
172
173 context.getTestContext().getPlatform().getVulkanPlatform().describePlatform(details);
174
175 context.getTestContext().getLog() << TestLog::Message << details.str() << TestLog::EndMessage;
176
177 return tcu::TestStatus::pass("Not validated");
178 }
179
180 template <typename SizeType>
181 struct PrettySize
182 {
183 SizeType value;
184 int precision;
185
PrettySizevkt::info::__anon4a4790090111::PrettySize186 PrettySize(SizeType value_, int precision_) : value(value_), precision(precision_)
187 {
188 }
189 };
190
191 struct SizeUnit
192 {
193 const char *name;
194 uint64_t value;
195 };
196
getBestSizeUnit(uint64_t value)197 const SizeUnit *getBestSizeUnit(uint64_t value)
198 {
199 static const SizeUnit s_units[] = {
200 // \note Must be ordered from largest to smallest
201 {"TiB", 1ull << 40ull},
202 {"GiB", 1ull << 30ull},
203 {"MiB", 1ull << 20ull},
204 {"KiB", 1ull << 10ull},
205 };
206 static const SizeUnit s_defaultUnit = {"B", 1u};
207
208 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_units); ++ndx)
209 {
210 DE_ASSERT(ndx == (DE_LENGTH_OF_ARRAY(s_units) - 1) || s_units[ndx].value > s_units[ndx + 1].value);
211 if (value >= s_units[ndx].value)
212 return &s_units[ndx];
213 }
214
215 return &s_defaultUnit;
216 }
217
218 template <typename SizeType>
operator <<(std::ostream & str,const PrettySize<SizeType> & size)219 std::ostream &operator<<(std::ostream &str, const PrettySize<SizeType> &size)
220 {
221 const SizeUnit *unit = getBestSizeUnit(uint64_t(size.value));
222 std::ostringstream tmp;
223
224 tmp << std::fixed << std::setprecision(size.precision) << (double(size.value) / double(unit->value)) << " "
225 << unit->name;
226
227 return str << tmp.str();
228 }
229
230 template <typename SizeType>
prettySize(SizeType value,int precision=2)231 PrettySize<SizeType> prettySize(SizeType value, int precision = 2)
232 {
233 return PrettySize<SizeType>(value, precision);
234 }
235
logPlatformMemoryLimits(Context & context)236 tcu::TestStatus logPlatformMemoryLimits(Context &context)
237 {
238 TestLog &log = context.getTestContext().getLog();
239 tcu::PlatformMemoryLimits limits;
240
241 context.getTestContext().getPlatform().getMemoryLimits(limits);
242
243 log << TestLog::Message << "totalSystemMemory = " << prettySize(limits.totalSystemMemory) << " ("
244 << limits.totalSystemMemory << ")\n"
245 << "totalDeviceLocalMemory = " << prettySize(limits.totalDeviceLocalMemory) << " ("
246 << limits.totalDeviceLocalMemory << ")\n"
247 << "deviceMemoryAllocationGranularity = " << limits.deviceMemoryAllocationGranularity << "\n"
248 << "devicePageSize = " << limits.devicePageSize << "\n"
249 << "devicePageTableEntrySize = " << limits.devicePageTableEntrySize << "\n"
250 << "devicePageTableHierarchyLevels = " << limits.devicePageTableHierarchyLevels << "\n"
251 << TestLog::EndMessage;
252
253 TCU_CHECK(limits.totalSystemMemory > 0);
254 TCU_CHECK(limits.deviceMemoryAllocationGranularity > 0);
255 TCU_CHECK(deIsPowerOfTwo64(limits.devicePageSize));
256
257 return tcu::TestStatus::pass("Pass");
258 }
259
createInfoTests(tcu::TestCaseGroup * testGroup)260 void createInfoTests(tcu::TestCaseGroup *testGroup)
261 {
262 addFunctionCase(testGroup, "build", logBuildInfo);
263 addFunctionCase(testGroup, "device", logDeviceInfo);
264 addFunctionCase(testGroup, "platform", logPlatformInfo);
265 addFunctionCase(testGroup, "memory_limits", logPlatformMemoryLimits);
266
267 api::createFeatureInfoInstanceTests(testGroup);
268 api::createFeatureInfoDeviceTests(testGroup);
269 api::createFeatureInfoDeviceGroupTests(testGroup);
270 }
271
272 } // namespace
273
createTests(tcu::TestContext & testCtx,const std::string & name)274 tcu::TestCaseGroup *createTests(tcu::TestContext &testCtx, const std::string &name)
275 {
276 return createTestGroup(testCtx, name.c_str(), createInfoTests);
277 }
278
279 } // namespace info
280 } // namespace vkt
281