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 tcu::TestLog;
48 using std::string;
49
getOsName(int os)50 std::string getOsName (int os)
51 {
52 switch (os)
53 {
54 case DE_OS_VANILLA: return "DE_OS_VANILLA";
55 case DE_OS_WIN32: return "DE_OS_WIN32";
56 case DE_OS_UNIX: return "DE_OS_UNIX";
57 case DE_OS_WINCE: return "DE_OS_WINCE";
58 case DE_OS_OSX: return "DE_OS_OSX";
59 case DE_OS_ANDROID: return "DE_OS_ANDROID";
60 case DE_OS_SYMBIAN: return "DE_OS_SYMBIAN";
61 case DE_OS_IOS: return "DE_OS_IOS";
62 default:
63 return de::toString(os);
64 }
65 }
66
getCompilerName(int compiler)67 std::string getCompilerName (int compiler)
68 {
69 switch (compiler)
70 {
71 case DE_COMPILER_VANILLA: return "DE_COMPILER_VANILLA";
72 case DE_COMPILER_MSC: return "DE_COMPILER_MSC";
73 case DE_COMPILER_GCC: return "DE_COMPILER_GCC";
74 case DE_COMPILER_CLANG: return "DE_COMPILER_CLANG";
75 default:
76 return de::toString(compiler);
77 }
78 }
79
getCpuName(int cpu)80 std::string getCpuName (int cpu)
81 {
82 switch (cpu)
83 {
84 case DE_CPU_VANILLA: return "DE_CPU_VANILLA";
85 case DE_CPU_ARM: return "DE_CPU_ARM";
86 case DE_CPU_X86: return "DE_CPU_X86";
87 case DE_CPU_X86_64: return "DE_CPU_X86_64";
88 case DE_CPU_ARM_64: return "DE_CPU_ARM_64";
89 case DE_CPU_MIPS: return "DE_CPU_MIPS";
90 case DE_CPU_MIPS_64: return "DE_CPU_MIPS_64";
91 case DE_CPU_RISCV_32: return "DE_CPU_RISCV_32";
92 case DE_CPU_RISCV_64: return "DE_CPU_RISCV_64";
93 default:
94 return de::toString(cpu);
95 }
96 }
97
getEndiannessName(int endianness)98 std::string getEndiannessName (int endianness)
99 {
100 switch (endianness)
101 {
102 case DE_BIG_ENDIAN: return "DE_BIG_ENDIAN";
103 case DE_LITTLE_ENDIAN: return "DE_LITTLE_ENDIAN";
104 default:
105 return de::toString(endianness);
106 }
107 }
108
logBuildInfo(Context & context)109 tcu::TestStatus logBuildInfo (Context& context)
110 {
111 #if defined(DE_DEBUG)
112 const bool isDebug = true;
113 #else
114 const bool isDebug = false;
115 #endif
116
117 context.getTestContext().getLog()
118 << TestLog::Message
119 << "DE_OS: " << getOsName(DE_OS) << "\n"
120 << "DE_CPU: " << getCpuName(DE_CPU) << "\n"
121 << "DE_PTR_SIZE: " << DE_PTR_SIZE << "\n"
122 << "DE_ENDIANNESS: " << getEndiannessName(DE_ENDIANNESS) << "\n"
123 << "DE_COMPILER: " << getCompilerName(DE_COMPILER) << "\n"
124 << "DE_DEBUG: " << (isDebug ? "true" : "false") << "\n"
125 << TestLog::EndMessage;
126
127 return tcu::TestStatus::pass("Not validated");
128 }
129
logDeviceInfo(Context & context)130 tcu::TestStatus logDeviceInfo (Context& context)
131 {
132 TestLog& log = context.getTestContext().getLog();
133 const vk::VkPhysicalDeviceProperties& properties = context.getDeviceProperties();
134
135 log << TestLog::Message
136 << "Using --deqp-vk-device-id="
137 << context.getTestContext().getCommandLine().getVKDeviceId()
138 << TestLog::EndMessage;
139
140 log << TestLog::Message
141 << "apiVersion: " << vk::unpackVersion(properties.apiVersion) << "\n"
142 << "driverVersion: " << tcu::toHex(properties.driverVersion) << "\n"
143 << "deviceName: " << (const char*)properties.deviceName << "\n"
144 << "vendorID: " << tcu::toHex(properties.vendorID) << "\n"
145 << "deviceID: " << tcu::toHex(properties.deviceID) << "\n"
146 << TestLog::EndMessage;
147
148 return tcu::TestStatus::pass("Not validated");
149 }
150
logPlatformInfo(Context & context)151 tcu::TestStatus logPlatformInfo (Context& context)
152 {
153 std::ostringstream details;
154
155 context.getTestContext().getPlatform().getVulkanPlatform().describePlatform(details);
156
157 context.getTestContext().getLog()
158 << TestLog::Message
159 << details.str()
160 << TestLog::EndMessage;
161
162 return tcu::TestStatus::pass("Not validated");
163 }
164
165 template<typename SizeType>
166 struct PrettySize
167 {
168 SizeType value;
169 int precision;
170
PrettySizevkt::info::__anonec7d0a730111::PrettySize171 PrettySize (SizeType value_, int precision_)
172 : value (value_)
173 , precision (precision_)
174 {}
175 };
176
177 struct SizeUnit
178 {
179 const char* name;
180 deUint64 value;
181 };
182
getBestSizeUnit(deUint64 value)183 const SizeUnit* getBestSizeUnit (deUint64 value)
184 {
185 static const SizeUnit s_units[] =
186 {
187 // \note Must be ordered from largest to smallest
188 { "TiB", 1ull<<40ull },
189 { "GiB", 1ull<<30ull },
190 { "MiB", 1ull<<20ull },
191 { "KiB", 1ull<<10ull },
192 };
193 static const SizeUnit s_defaultUnit = { "B", 1u };
194
195 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_units); ++ndx)
196 {
197 DE_ASSERT(ndx == (DE_LENGTH_OF_ARRAY(s_units) - 1) ||
198 s_units[ndx].value > s_units[ndx + 1].value);
199 if (value >= s_units[ndx].value)
200 return &s_units[ndx];
201 }
202
203 return &s_defaultUnit;
204 }
205
206 template<typename SizeType>
operator <<(std::ostream & str,const PrettySize<SizeType> & size)207 std::ostream& operator<< (std::ostream& str, const PrettySize<SizeType>& size)
208 {
209 const SizeUnit* unit = getBestSizeUnit(deUint64(size.value));
210 std::ostringstream tmp;
211
212 tmp << std::fixed << std::setprecision(size.precision)
213 << (double(size.value) / double(unit->value))
214 << " " << unit->name;
215
216 return str << tmp.str();
217 }
218
219 template<typename SizeType>
prettySize(SizeType value,int precision=2)220 PrettySize<SizeType> prettySize (SizeType value, int precision = 2)
221 {
222 return PrettySize<SizeType>(value, precision);
223 }
224
logPlatformMemoryLimits(Context & context)225 tcu::TestStatus logPlatformMemoryLimits (Context& context)
226 {
227 TestLog& log = context.getTestContext().getLog();
228 tcu::PlatformMemoryLimits limits;
229
230 context.getTestContext().getPlatform().getMemoryLimits(limits);
231
232 log << TestLog::Message << "totalSystemMemory = " << prettySize(limits.totalSystemMemory) << " (" << limits.totalSystemMemory << ")\n"
233 << "totalDeviceLocalMemory = " << prettySize(limits.totalDeviceLocalMemory) << " (" << limits.totalDeviceLocalMemory << ")\n"
234 << "deviceMemoryAllocationGranularity = " << limits.deviceMemoryAllocationGranularity << "\n"
235 << "devicePageSize = " << limits.devicePageSize << "\n"
236 << "devicePageTableEntrySize = " << limits.devicePageTableEntrySize << "\n"
237 << "devicePageTableHierarchyLevels = " << limits.devicePageTableHierarchyLevels << "\n"
238 << TestLog::EndMessage;
239
240 TCU_CHECK(limits.totalSystemMemory > 0);
241 TCU_CHECK(limits.deviceMemoryAllocationGranularity > 0);
242 TCU_CHECK(deIsPowerOfTwo64(limits.devicePageSize));
243
244 return tcu::TestStatus::pass("Pass");
245 }
246
createInfoTests(tcu::TestCaseGroup * testGroup)247 void createInfoTests (tcu::TestCaseGroup* testGroup)
248 {
249 addFunctionCase(testGroup, "build", logBuildInfo);
250 addFunctionCase(testGroup, "device", logDeviceInfo);
251 addFunctionCase(testGroup, "platform", logPlatformInfo);
252 addFunctionCase(testGroup, "memory_limits", logPlatformMemoryLimits);
253
254 api::createFeatureInfoInstanceTests(testGroup);
255 api::createFeatureInfoDeviceTests(testGroup);
256 api::createFeatureInfoDeviceGroupTests(testGroup);
257 }
258
259 } // anonymous
260
createTests(tcu::TestContext & testCtx,const std::string & name)261 tcu::TestCaseGroup* createTests (tcu::TestContext& testCtx, const std::string& name)
262 {
263 return createTestGroup(testCtx, name.c_str(), createInfoTests);
264 }
265
266 } // info
267 } // vkt
268