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