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";
74 case DE_CPU_RISCV_32: return "DE_CPU_RISCV_32";
75 case DE_CPU_RISCV_64: return "DE_CPU_RISCV_64";
81 static const char* getEndiannessName (int endianness)
85 case DE_BIG_ENDIAN: return "DE_BIG_ENDIAN";
86 case DE_LITTLE_ENDIAN: return "DE_LITTLE_ENDIAN";
92 class BuildInfoStringCase : public tcu::TestCase
95 BuildInfoStringCase (tcu::TestContext& testCtx, const char* name, const char* valueName, const char* value)
96 : tcu::TestCase (testCtx, name, valueName)
97 , m_valueName (valueName)
102 IterateResult iterate (void)
104 m_testCtx.getLog() << TestLog::Message << m_valueName << " = " << m_value << TestLog::EndMessage;
105 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
110 std::string m_valueName;
114 class BuildEnumCase : public tcu::TestCase
117 typedef const char* (*GetStringFunc) (int value);
119 BuildEnumCase (tcu::TestContext& testCtx, const char* name, const char* varName, int value, GetStringFunc getString)
120 : tcu::TestCase (testCtx, name, varName)
121 , m_varName (varName)
123 , m_getString (getString)
127 IterateResult iterate (void)
129 const char* valueName = m_getString(m_value);
130 const bool isOk = valueName != DE_NULL;
131 std::string logValue = valueName ? std::string(valueName) : de::toString(m_value);
133 m_testCtx.getLog() << TestLog::Message << m_varName << " = " << logValue << TestLog::EndMessage;
135 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
136 isOk ? "Pass" : "No enum name found");
141 std::string m_varName;
143 GetStringFunc m_getString;
146 class EndiannessConsistencyCase : public tcu::TestCase
149 EndiannessConsistencyCase (tcu::TestContext& context, const char* name, const char* description)
150 : tcu::TestCase(context, name, description)
154 IterateResult iterate (void)
156 const deUint16 multiByte = (deUint16)0x0102;
158 #if DE_ENDIANNESS == DE_BIG_ENDIAN
159 const bool isOk = *((const deUint8*)&multiByte) == (deUint8)0x01;
160 #elif DE_ENDIANNESS == DE_LITTLE_ENDIAN
161 const bool isOk = *((const deUint8*)&multiByte) == (deUint8)0x02;
166 << "Verifying DE_ENDIANNESS matches actual behavior"
167 << TestLog::EndMessage;
169 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
170 isOk ? "Pass" : "Configured endianness inconsistent");
175 BuildInfoTests::BuildInfoTests (tcu::TestContext& testCtx)
176 : tcu::TestCaseGroup(testCtx, "build_info", "Build Info Tests")
180 BuildInfoTests::~BuildInfoTests (void)
184 void BuildInfoTests::init (void)
186 #if defined(DE_DEBUG)
187 const bool isDebug = true;
189 const bool isDebug = false;
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_consistent", "DE_ENDIANNESS"));