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