1 /*-------------------------------------------------------------------------
2 * drawElements Internal Test Module
3 * ---------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Build information tests.
22 *//*--------------------------------------------------------------------*/
24 #include "ditBuildInfoTests.hpp"
25 #include "tcuTestLog.hpp"
26 #include "deStringUtil.hpp"
33 static const char* getOsName (int os)
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";
50 static const char* getCompilerName (int compiler)
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";
63 static const char* getCpuName (int cpu)
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";
79 static const char* getEndiannessName (int endianness)
83 case DE_BIG_ENDIAN: return "DE_BIG_ENDIAN";
84 case DE_LITTLE_ENDIAN: return "DE_LITTLE_ENDIAN";
90 class BuildInfoStringCase : public tcu::TestCase
93 BuildInfoStringCase (tcu::TestContext& testCtx, const char* name, const char* valueName, const char* value)
94 : tcu::TestCase (testCtx, name, valueName)
95 , m_valueName (valueName)
100 IterateResult iterate (void)
102 m_testCtx.getLog() << TestLog::Message << m_valueName << " = " << m_value << TestLog::EndMessage;
103 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
108 std::string m_valueName;
112 class BuildEnumCase : public tcu::TestCase
115 typedef const char* (*GetStringFunc) (int value);
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)
121 , m_getString (getString)
125 IterateResult iterate (void)
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);
131 m_testCtx.getLog() << TestLog::Message << m_varName << " = " << logValue << TestLog::EndMessage;
133 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
134 isOk ? "Pass" : "No enum name found");
139 std::string m_varName;
141 GetStringFunc m_getString;
144 class EndiannessConsistencyCase : public tcu::TestCase
147 EndiannessConsistencyCase (tcu::TestContext& context, const char* name, const char* description)
148 : tcu::TestCase(context, name, description)
152 IterateResult iterate (void)
154 const deUint16 multiByte = (deUint16)0x0102;
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;
164 << "Verifying DE_ENDIANNESS matches actual behavior"
165 << TestLog::EndMessage;
167 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
168 isOk ? "Pass" : "Configured endianness inconsistent");
173 BuildInfoTests::BuildInfoTests (tcu::TestContext& testCtx)
174 : tcu::TestCaseGroup(testCtx, "build_info", "Build Info Tests")
178 BuildInfoTests::~BuildInfoTests (void)
182 void BuildInfoTests::init (void)
184 #if defined(DE_DEBUG)
185 const bool isDebug = true;
187 const bool isDebug = false;
190 addChild(new BuildInfoStringCase (m_testCtx, "date", "__DATE__", __DATE__));
191 addChild(new BuildInfoStringCase (m_testCtx, "time", "__TIME__", __TIME__));
192 addChild(new BuildInfoStringCase (m_testCtx, "de_debug", "DE_DEBUG", isDebug ? "1" : "not defined"));
193 addChild(new BuildEnumCase (m_testCtx, "de_os", "DE_OS", DE_OS, getOsName));
194 addChild(new BuildEnumCase (m_testCtx, "de_cpu", "DE_CPU", DE_CPU, getCpuName));
195 addChild(new BuildEnumCase (m_testCtx, "de_compiler", "DE_COMPILER", DE_COMPILER, getCompilerName));
196 addChild(new BuildInfoStringCase (m_testCtx, "de_ptr_size", "DE_PTR_SIZE", de::toString(DE_PTR_SIZE).c_str()));
197 addChild(new BuildEnumCase (m_testCtx, "de_endianness", "DE_ENDIANNESS", DE_ENDIANNESS, getEndiannessName));
198 addChild(new EndiannessConsistencyCase (m_testCtx, "de_endianness_consitent", "DE_ENDIANNESS"));