Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / modules / internal / ditBuildInfoTests.cpp
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                 case DE_CPU_RISCV_32:   return "DE_CPU_RISCV_32";
75                 case DE_CPU_RISCV_64:   return "DE_CPU_RISCV_64";
76                 default:
77                         return DE_NULL;
78         }
79 }
80
81 static const char* getEndiannessName (int endianness)
82 {
83         switch (endianness)
84         {
85                 case DE_BIG_ENDIAN:             return "DE_BIG_ENDIAN";
86                 case DE_LITTLE_ENDIAN:  return "DE_LITTLE_ENDIAN";
87                 default:
88                         return DE_NULL;
89         }
90 }
91
92 class BuildInfoStringCase : public tcu::TestCase
93 {
94 public:
95         BuildInfoStringCase (tcu::TestContext& testCtx, const char* name, const char* valueName, const char* value)
96                 : tcu::TestCase (testCtx, name, valueName)
97                 , m_valueName   (valueName)
98                 , m_value               (value)
99         {
100         }
101
102         IterateResult iterate (void)
103         {
104                 m_testCtx.getLog() << TestLog::Message << m_valueName << " = " << m_value << TestLog::EndMessage;
105                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
106                 return STOP;
107         }
108
109 private:
110         std::string     m_valueName;
111         std::string     m_value;
112 };
113
114 class BuildEnumCase : public tcu::TestCase
115 {
116 public:
117         typedef const char* (*GetStringFunc) (int value);
118
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)
122                 , m_value               (value)
123                 , m_getString   (getString)
124         {
125         }
126
127         IterateResult iterate (void)
128         {
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);
132
133                 m_testCtx.getLog() << TestLog::Message << m_varName << " = " << logValue << TestLog::EndMessage;
134
135                 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS      : QP_TEST_RESULT_FAIL,
136                                                                 isOk ? "Pass"                           : "No enum name found");
137                 return STOP;
138         }
139
140 private:
141         std::string             m_varName;
142         int                             m_value;
143         GetStringFunc   m_getString;
144 };
145
146 class EndiannessConsistencyCase : public tcu::TestCase
147 {
148 public:
149         EndiannessConsistencyCase (tcu::TestContext& context, const char* name, const char* description)
150                 : tcu::TestCase(context, name, description)
151         {
152         }
153
154         IterateResult iterate (void)
155         {
156                 const deUint16  multiByte       = (deUint16)0x0102;
157
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;
162 #endif
163
164                 m_testCtx.getLog()
165                         << TestLog::Message
166                         << "Verifying DE_ENDIANNESS matches actual behavior"
167                         << TestLog::EndMessage;
168
169                 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS      : QP_TEST_RESULT_FAIL,
170                                                                 isOk ? "Pass"                           : "Configured endianness inconsistent");
171                 return STOP;
172         }
173 };
174
175 BuildInfoTests::BuildInfoTests (tcu::TestContext& testCtx)
176         : tcu::TestCaseGroup(testCtx, "build_info", "Build Info Tests")
177 {
178 }
179
180 BuildInfoTests::~BuildInfoTests (void)
181 {
182 }
183
184 void BuildInfoTests::init (void)
185 {
186 #if defined(DE_DEBUG)
187         const bool isDebug = true;
188 #else
189         const bool isDebug = false;
190 #endif
191
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"));
199 }
200
201 } // dit