xref: /aosp_15_r20/external/deqp/modules/egl/teglInfoTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL 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 EGL Implementation Information Tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglInfoTests.hpp"
25 #include "teglConfigList.hpp"
26 #include "tcuTestLog.hpp"
27 #include "deStringUtil.hpp"
28 #include "egluUtil.hpp"
29 #include "eglwLibrary.hpp"
30 #include "eglwEnums.hpp"
31 
32 #include <vector>
33 #include <string>
34 #include <sstream>
35 
36 namespace deqp
37 {
38 namespace egl
39 {
40 
41 using std::string;
42 using std::vector;
43 using tcu::TestLog;
44 using namespace eglw;
45 
toInt(std::string str)46 static int toInt(std::string str)
47 {
48     std::istringstream strStream(str);
49 
50     int out;
51     strStream >> out;
52     return out;
53 }
54 
55 class InfoCase : public TestCase
56 {
57 public:
InfoCase(EglTestContext & eglTestCtx,const char * name,const char * description)58     InfoCase(EglTestContext &eglTestCtx, const char *name, const char *description)
59         : TestCase(eglTestCtx, name, description)
60         , m_display(EGL_NO_DISPLAY)
61         , m_version(0, 0)
62     {
63     }
64 
init(void)65     void init(void)
66     {
67         DE_ASSERT(m_display == EGL_NO_DISPLAY);
68         m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay(), &m_version);
69     }
70 
deinit(void)71     void deinit(void)
72     {
73         m_eglTestCtx.getLibrary().terminate(m_display);
74         m_display = EGL_NO_DISPLAY;
75     }
76 
77 protected:
78     EGLDisplay m_display;
79     eglu::Version m_version;
80 };
81 
82 class QueryStringCase : public InfoCase
83 {
84 public:
QueryStringCase(EglTestContext & eglTestCtx,const char * name,const char * description,EGLint query)85     QueryStringCase(EglTestContext &eglTestCtx, const char *name, const char *description, EGLint query)
86         : InfoCase(eglTestCtx, name, description)
87         , m_query(query)
88     {
89     }
90 
validateString(const std::string & result)91     void validateString(const std::string &result)
92     {
93         tcu::TestLog &log               = m_testCtx.getLog();
94         std::vector<std::string> tokens = de::splitString(result, ' ');
95 
96         if (m_query == EGL_VERSION)
97         {
98             const int dispMajor = m_version.getMajor();
99             const int dispMinor = m_version.getMinor();
100 
101             const std::vector<std::string> versionTokens = de::splitString(tokens[0], '.');
102 
103             if (versionTokens.size() < 2)
104             {
105                 log << TestLog::Message
106                     << "  Fail, first part of the string must be in the format <major_version.minor_version>"
107                     << TestLog::EndMessage;
108                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid version string");
109             }
110             else
111             {
112                 const int stringMajor = toInt(versionTokens[0]);
113                 const int stringMinor = toInt(versionTokens[1]);
114 
115                 if (stringMajor != dispMajor || stringMinor != dispMinor)
116                 {
117                     log << TestLog::Message << "  Fail, version numer (" << stringMajor << "." << stringMinor
118                         << ") does not match the one reported by eglInitialize (" << dispMajor << "." << dispMinor
119                         << ")" << TestLog::EndMessage;
120                     m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Version number mismatch");
121                 }
122             }
123         }
124     }
125 
iterate(void)126     IterateResult iterate(void)
127     {
128         const Library &egl = m_eglTestCtx.getLibrary();
129         const char *result = egl.queryString(m_display, m_query);
130         EGLU_CHECK_MSG(egl, "eglQueryString() failed");
131 
132         m_testCtx.getLog() << tcu::TestLog::Message << result << tcu::TestLog::EndMessage;
133         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
134 
135         validateString(result);
136 
137         return STOP;
138     }
139 
140 private:
141     EGLint m_query;
142 };
143 
144 class QueryExtensionsCase : public InfoCase
145 {
146 public:
QueryExtensionsCase(EglTestContext & eglTestCtx)147     QueryExtensionsCase(EglTestContext &eglTestCtx) : InfoCase(eglTestCtx, "extensions", "Supported Extensions")
148     {
149     }
150 
iterate(void)151     IterateResult iterate(void)
152     {
153         const Library &egl        = m_eglTestCtx.getLibrary();
154         vector<string> extensions = eglu::getDisplayExtensions(egl, m_display);
155 
156         for (vector<string>::const_iterator i = extensions.begin(); i != extensions.end(); i++)
157             m_testCtx.getLog() << tcu::TestLog::Message << *i << tcu::TestLog::EndMessage;
158 
159         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
160 
161         return STOP;
162     }
163 };
164 
InfoTests(EglTestContext & eglTestCtx)165 InfoTests::InfoTests(EglTestContext &eglTestCtx) : TestCaseGroup(eglTestCtx, "info", "Platform Information")
166 {
167 }
168 
~InfoTests(void)169 InfoTests::~InfoTests(void)
170 {
171 }
172 
init(void)173 void InfoTests::init(void)
174 {
175     addChild(new QueryStringCase(m_eglTestCtx, "version", "EGL Version", EGL_VERSION));
176     addChild(new QueryStringCase(m_eglTestCtx, "vendor", "EGL Vendor", EGL_VENDOR));
177     addChild(new QueryStringCase(m_eglTestCtx, "client_apis", "Supported client APIs", EGL_CLIENT_APIS));
178     addChild(new QueryExtensionsCase(m_eglTestCtx));
179     addChild(new ConfigList(m_eglTestCtx));
180 }
181 
182 } // namespace egl
183 } // namespace deqp
184