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