Home | History | Annotate | Download | only in internal
      1 /*-------------------------------------------------------------------------
      2  * drawElements Internal Test Module
      3  * ---------------------------------
      4  *
      5  * Copyright 2014 The Android Open Source Project
      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 information tests.
     22  *//*--------------------------------------------------------------------*/
     23 
     24 #include "ditBuildInfoTests.hpp"
     25 #include "tcuTestLog.hpp"
     26 #include "deStringUtil.hpp"
     27 
     28 using tcu::TestLog;
     29 
     30 namespace dit
     31 {
     32 
     33 static const char* getOsName (int os)
     34 {
     35 	switch (os)
     36 	{
     37 		case DE_OS_VANILLA:		return "DE_OS_VANILLA";
     38 		case DE_OS_WIN32:		return "DE_OS_WIN32";
     39 		case DE_OS_UNIX:		return "DE_OS_UNIX";
     40 		case DE_OS_WINCE:		return "DE_OS_WINCE";
     41 		case DE_OS_OSX:			return "DE_OS_OSX";
     42 		case DE_OS_ANDROID:		return "DE_OS_ANDROID";
     43 		case DE_OS_SYMBIAN:		return "DE_OS_SYMBIAN";
     44 		case DE_OS_IOS:			return "DE_OS_IOS";
     45 		default:
     46 			return DE_NULL;
     47 	}
     48 }
     49 
     50 static const char* getCompilerName (int compiler)
     51 {
     52 	switch (compiler)
     53 	{
     54 		case DE_COMPILER_VANILLA:	return "DE_COMPILER_VANILLA";
     55 		case DE_COMPILER_MSC:		return "DE_COMPILER_MSC";
     56 		case DE_COMPILER_GCC:		return "DE_COMPILER_GCC";
     57 		case DE_COMPILER_CLANG:		return "DE_COMPILER_CLANG";
     58 		default:
     59 			return DE_NULL;
     60 	}
     61 }
     62 
     63 static const char* getCpuName (int cpu)
     64 {
     65 	switch (cpu)
     66 	{
     67 		case DE_CPU_VANILLA:	return "DE_CPU_VANILLA";
     68 		case DE_CPU_ARM:		return "DE_CPU_ARM";
     69 		case DE_CPU_X86:		return "DE_CPU_X86";
     70 		case DE_CPU_X86_64:		return "DE_CPU_X86_64";
     71 		case DE_CPU_ARM_64:		return "DE_CPU_ARM_64";
     72 		case DE_CPU_MIPS:		return "DE_CPU_MIPS";
     73 		case DE_CPU_MIPS_64:	return "DE_CPU_MIPS_64";
     74 		default:
     75 			return DE_NULL;
     76 	}
     77 }
     78 
     79 static const char* getEndiannessName (int endianness)
     80 {
     81 	switch (endianness)
     82 	{
     83 		case DE_BIG_ENDIAN:		return "DE_BIG_ENDIAN";
     84 		case DE_LITTLE_ENDIAN:	return "DE_LITTLE_ENDIAN";
     85 		default:
     86 			return DE_NULL;
     87 	}
     88 }
     89 
     90 class BuildInfoStringCase : public tcu::TestCase
     91 {
     92 public:
     93 	BuildInfoStringCase (tcu::TestContext& testCtx, const char* name, const char* valueName, const char* value)
     94 		: tcu::TestCase	(testCtx, name, valueName)
     95 		, m_valueName	(valueName)
     96 		, m_value		(value)
     97 	{
     98 	}
     99 
    100 	IterateResult iterate (void)
    101 	{
    102 		m_testCtx.getLog() << TestLog::Message << m_valueName << " = " << m_value << TestLog::EndMessage;
    103 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
    104 		return STOP;
    105 	}
    106 
    107 private:
    108 	std::string	m_valueName;
    109 	std::string	m_value;
    110 };
    111 
    112 class BuildEnumCase : public tcu::TestCase
    113 {
    114 public:
    115 	typedef const char* (*GetStringFunc) (int value);
    116 
    117 	BuildEnumCase (tcu::TestContext& testCtx, const char* name, const char* varName, int value, GetStringFunc getString)
    118 		: tcu::TestCase	(testCtx, name, varName)
    119 		, m_varName		(varName)
    120 		, m_value		(value)
    121 		, m_getString	(getString)
    122 	{
    123 	}
    124 
    125 	IterateResult iterate (void)
    126 	{
    127 		const char*	valueName	= m_getString(m_value);
    128 		const bool	isOk		= valueName != DE_NULL;
    129 		std::string	logValue	= valueName ? std::string(valueName) : de::toString(m_value);
    130 
    131 		m_testCtx.getLog() << TestLog::Message << m_varName << " = " << logValue << TestLog::EndMessage;
    132 
    133 		m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
    134 								isOk ? "Pass"				: "No enum name found");
    135 		return STOP;
    136 	}
    137 
    138 private:
    139 	std::string		m_varName;
    140 	int				m_value;
    141 	GetStringFunc	m_getString;
    142 };
    143 
    144 class EndiannessConsistencyCase : public tcu::TestCase
    145 {
    146 public:
    147 	EndiannessConsistencyCase (tcu::TestContext& context, const char* name, const char* description)
    148 		: tcu::TestCase(context, name, description)
    149 	{
    150 	}
    151 
    152 	IterateResult iterate (void)
    153 	{
    154 		const deUint16	multiByte	= (deUint16)0x0102;
    155 
    156 #if DE_ENDIANNESS == DE_BIG_ENDIAN
    157 		const bool		isOk		= *((const deUint8*)&multiByte) == (deUint8)0x01;
    158 #elif DE_ENDIANNESS == DE_LITTLE_ENDIAN
    159 		const bool		isOk		= *((const deUint8*)&multiByte) == (deUint8)0x02;
    160 #endif
    161 
    162 		m_testCtx.getLog()
    163 			<< TestLog::Message
    164 			<< "Verifying DE_ENDIANNESS matches actual behavior"
    165 			<< TestLog::EndMessage;
    166 
    167 		m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
    168 								isOk ? "Pass"				: "Configured endianness inconsistent");
    169 		return STOP;
    170 	}
    171 };
    172 
    173 BuildInfoTests::BuildInfoTests (tcu::TestContext& testCtx)
    174 	: tcu::TestCaseGroup(testCtx, "build_info", "Build Info Tests")
    175 {
    176 }
    177 
    178 BuildInfoTests::~BuildInfoTests (void)
    179 {
    180 }
    181 
    182 void BuildInfoTests::init (void)
    183 {
    184 #if defined(DE_DEBUG)
    185 	const bool isDebug = true;
    186 #else
    187 	const bool isDebug = false;
    188 #endif
    189 
    190 	addChild(new BuildInfoStringCase		(m_testCtx, "de_debug",					"DE_DEBUG",			isDebug ? "1" : "not defined"));
    191 	addChild(new BuildEnumCase				(m_testCtx, "de_os",					"DE_OS",			DE_OS,									getOsName));
    192 	addChild(new BuildEnumCase				(m_testCtx, "de_cpu",					"DE_CPU",			DE_CPU,									getCpuName));
    193 	addChild(new BuildEnumCase				(m_testCtx, "de_compiler",				"DE_COMPILER",		DE_COMPILER,							getCompilerName));
    194 	addChild(new BuildInfoStringCase		(m_testCtx, "de_ptr_size",				"DE_PTR_SIZE",		de::toString(DE_PTR_SIZE).c_str()));
    195 	addChild(new BuildEnumCase				(m_testCtx, "de_endianness",			"DE_ENDIANNESS",	DE_ENDIANNESS,							getEndiannessName));
    196 	addChild(new EndiannessConsistencyCase	(m_testCtx, "de_endianness_consistent", "DE_ENDIANNESS"));
    197 }
    198 
    199 } // dit
    200