liyujie
2025-08-28 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*-------------------------------------------------------------------------
 * drawElements Internal Test Module
 * ---------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief Build information tests.
 *//*--------------------------------------------------------------------*/
 
#include "ditBuildInfoTests.hpp"
#include "tcuTestLog.hpp"
#include "deStringUtil.hpp"
 
using tcu::TestLog;
 
namespace dit
{
 
static const char* getOsName (int os)
{
   switch (os)
   {
       case DE_OS_VANILLA:        return "DE_OS_VANILLA";
       case DE_OS_WIN32:        return "DE_OS_WIN32";
       case DE_OS_UNIX:        return "DE_OS_UNIX";
       case DE_OS_WINCE:        return "DE_OS_WINCE";
       case DE_OS_OSX:            return "DE_OS_OSX";
       case DE_OS_ANDROID:        return "DE_OS_ANDROID";
       case DE_OS_SYMBIAN:        return "DE_OS_SYMBIAN";
       case DE_OS_IOS:            return "DE_OS_IOS";
       default:
           return DE_NULL;
   }
}
 
static const char* getCompilerName (int compiler)
{
   switch (compiler)
   {
       case DE_COMPILER_VANILLA:    return "DE_COMPILER_VANILLA";
       case DE_COMPILER_MSC:        return "DE_COMPILER_MSC";
       case DE_COMPILER_GCC:        return "DE_COMPILER_GCC";
       case DE_COMPILER_CLANG:        return "DE_COMPILER_CLANG";
       default:
           return DE_NULL;
   }
}
 
static const char* getCpuName (int cpu)
{
   switch (cpu)
   {
       case DE_CPU_VANILLA:    return "DE_CPU_VANILLA";
       case DE_CPU_ARM:        return "DE_CPU_ARM";
       case DE_CPU_X86:        return "DE_CPU_X86";
       case DE_CPU_X86_64:        return "DE_CPU_X86_64";
       case DE_CPU_ARM_64:        return "DE_CPU_ARM_64";
       case DE_CPU_MIPS:        return "DE_CPU_MIPS";
       case DE_CPU_MIPS_64:    return "DE_CPU_MIPS_64";
       default:
           return DE_NULL;
   }
}
 
static const char* getEndiannessName (int endianness)
{
   switch (endianness)
   {
       case DE_BIG_ENDIAN:        return "DE_BIG_ENDIAN";
       case DE_LITTLE_ENDIAN:    return "DE_LITTLE_ENDIAN";
       default:
           return DE_NULL;
   }
}
 
class BuildInfoStringCase : public tcu::TestCase
{
public:
   BuildInfoStringCase (tcu::TestContext& testCtx, const char* name, const char* valueName, const char* value)
       : tcu::TestCase    (testCtx, name, valueName)
       , m_valueName    (valueName)
       , m_value        (value)
   {
   }
 
   IterateResult iterate (void)
   {
       m_testCtx.getLog() << TestLog::Message << m_valueName << " = " << m_value << TestLog::EndMessage;
       m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
       return STOP;
   }
 
private:
   std::string    m_valueName;
   std::string    m_value;
};
 
class BuildEnumCase : public tcu::TestCase
{
public:
   typedef const char* (*GetStringFunc) (int value);
 
   BuildEnumCase (tcu::TestContext& testCtx, const char* name, const char* varName, int value, GetStringFunc getString)
       : tcu::TestCase    (testCtx, name, varName)
       , m_varName        (varName)
       , m_value        (value)
       , m_getString    (getString)
   {
   }
 
   IterateResult iterate (void)
   {
       const char*    valueName    = m_getString(m_value);
       const bool    isOk        = valueName != DE_NULL;
       std::string    logValue    = valueName ? std::string(valueName) : de::toString(m_value);
 
       m_testCtx.getLog() << TestLog::Message << m_varName << " = " << logValue << TestLog::EndMessage;
 
       m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS    : QP_TEST_RESULT_FAIL,
                               isOk ? "Pass"                : "No enum name found");
       return STOP;
   }
 
private:
   std::string        m_varName;
   int                m_value;
   GetStringFunc    m_getString;
};
 
class EndiannessConsistencyCase : public tcu::TestCase
{
public:
   EndiannessConsistencyCase (tcu::TestContext& context, const char* name, const char* description)
       : tcu::TestCase(context, name, description)
   {
   }
 
   IterateResult iterate (void)
   {
       const deUint16    multiByte    = (deUint16)0x0102;
 
#if DE_ENDIANNESS == DE_BIG_ENDIAN
       const bool        isOk        = *((const deUint8*)&multiByte) == (deUint8)0x01;
#elif DE_ENDIANNESS == DE_LITTLE_ENDIAN
       const bool        isOk        = *((const deUint8*)&multiByte) == (deUint8)0x02;
#endif
 
       m_testCtx.getLog()
           << TestLog::Message
           << "Verifying DE_ENDIANNESS matches actual behavior"
           << TestLog::EndMessage;
 
       m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS    : QP_TEST_RESULT_FAIL,
                               isOk ? "Pass"                : "Configured endianness inconsistent");
       return STOP;
   }
};
 
BuildInfoTests::BuildInfoTests (tcu::TestContext& testCtx)
   : tcu::TestCaseGroup(testCtx, "build_info", "Build Info Tests")
{
}
 
BuildInfoTests::~BuildInfoTests (void)
{
}
 
void BuildInfoTests::init (void)
{
#if defined(DE_DEBUG)
   const bool isDebug = true;
#else
   const bool isDebug = false;
#endif
 
   addChild(new BuildInfoStringCase        (m_testCtx, "de_debug",                    "DE_DEBUG",            isDebug ? "1" : "not defined"));
   addChild(new BuildEnumCase                (m_testCtx, "de_os",                    "DE_OS",            DE_OS,                                    getOsName));
   addChild(new BuildEnumCase                (m_testCtx, "de_cpu",                    "DE_CPU",            DE_CPU,                                    getCpuName));
   addChild(new BuildEnumCase                (m_testCtx, "de_compiler",                "DE_COMPILER",        DE_COMPILER,                            getCompilerName));
   addChild(new BuildInfoStringCase        (m_testCtx, "de_ptr_size",                "DE_PTR_SIZE",        de::toString(DE_PTR_SIZE).c_str()));
   addChild(new BuildEnumCase                (m_testCtx, "de_endianness",            "DE_ENDIANNESS",    DE_ENDIANNESS,                            getEndiannessName));
   addChild(new EndiannessConsistencyCase    (m_testCtx, "de_endianness_consistent", "DE_ENDIANNESS"));
}
 
} // dit