xref: /aosp_15_r20/external/deqp/modules/egl/teglApiCase.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program EGL Module
3*35238bceSAndroid Build Coastguard Worker  * ---------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief API test case.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "teglApiCase.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "egluUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "egluStrUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "eglwLibrary.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "eglwEnums.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "deSTLUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker namespace deqp
32*35238bceSAndroid Build Coastguard Worker {
33*35238bceSAndroid Build Coastguard Worker namespace egl
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker using std::vector;
37*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
38*35238bceSAndroid Build Coastguard Worker using namespace eglw;
39*35238bceSAndroid Build Coastguard Worker 
ApiCase(EglTestContext & eglTestCtx,const char * name,const char * description)40*35238bceSAndroid Build Coastguard Worker ApiCase::ApiCase(EglTestContext &eglTestCtx, const char *name, const char *description)
41*35238bceSAndroid Build Coastguard Worker     : TestCase(eglTestCtx, name, description)
42*35238bceSAndroid Build Coastguard Worker     , CallLogWrapper(eglTestCtx.getLibrary(), eglTestCtx.getTestContext().getLog())
43*35238bceSAndroid Build Coastguard Worker     , m_display(EGL_NO_DISPLAY)
44*35238bceSAndroid Build Coastguard Worker {
45*35238bceSAndroid Build Coastguard Worker }
46*35238bceSAndroid Build Coastguard Worker 
~ApiCase(void)47*35238bceSAndroid Build Coastguard Worker ApiCase::~ApiCase(void)
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker }
50*35238bceSAndroid Build Coastguard Worker 
init(void)51*35238bceSAndroid Build Coastguard Worker void ApiCase::init(void)
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker     m_display             = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
54*35238bceSAndroid Build Coastguard Worker     m_supportedClientAPIs = eglu::getClientAPIs(m_eglTestCtx.getLibrary(), m_display);
55*35238bceSAndroid Build Coastguard Worker }
56*35238bceSAndroid Build Coastguard Worker 
deinit(void)57*35238bceSAndroid Build Coastguard Worker void ApiCase::deinit(void)
58*35238bceSAndroid Build Coastguard Worker {
59*35238bceSAndroid Build Coastguard Worker     const Library &egl = m_eglTestCtx.getLibrary();
60*35238bceSAndroid Build Coastguard Worker     egl.terminate(m_display);
61*35238bceSAndroid Build Coastguard Worker 
62*35238bceSAndroid Build Coastguard Worker     m_display = EGL_NO_DISPLAY;
63*35238bceSAndroid Build Coastguard Worker     m_supportedClientAPIs.clear();
64*35238bceSAndroid Build Coastguard Worker }
65*35238bceSAndroid Build Coastguard Worker 
iterate(void)66*35238bceSAndroid Build Coastguard Worker ApiCase::IterateResult ApiCase::iterate(void)
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker     // Initialize result to pass.
69*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker     // Enable call logging.
72*35238bceSAndroid Build Coastguard Worker     enableLogging(true);
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker     // Run test.
75*35238bceSAndroid Build Coastguard Worker     test();
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker     return STOP;
78*35238bceSAndroid Build Coastguard Worker }
79*35238bceSAndroid Build Coastguard Worker 
isAPISupported(eglw::EGLenum api) const80*35238bceSAndroid Build Coastguard Worker bool ApiCase::isAPISupported(eglw::EGLenum api) const
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker     return de::contains(m_supportedClientAPIs.begin(), m_supportedClientAPIs.end(), api);
83*35238bceSAndroid Build Coastguard Worker }
84*35238bceSAndroid Build Coastguard Worker 
expectError(EGLenum expected)85*35238bceSAndroid Build Coastguard Worker void ApiCase::expectError(EGLenum expected)
86*35238bceSAndroid Build Coastguard Worker {
87*35238bceSAndroid Build Coastguard Worker     EGLenum err = m_eglTestCtx.getLibrary().getError();
88*35238bceSAndroid Build Coastguard Worker     if (err != expected)
89*35238bceSAndroid Build Coastguard Worker     {
90*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getErrorStr(expected)
91*35238bceSAndroid Build Coastguard Worker                            << ", Got: " << eglu::getErrorStr(err) << TestLog::EndMessage;
92*35238bceSAndroid Build Coastguard Worker         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
93*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
94*35238bceSAndroid Build Coastguard Worker     }
95*35238bceSAndroid Build Coastguard Worker }
96*35238bceSAndroid Build Coastguard Worker 
expectEitherError(EGLenum expectedA,EGLenum expectedB)97*35238bceSAndroid Build Coastguard Worker void ApiCase::expectEitherError(EGLenum expectedA, EGLenum expectedB)
98*35238bceSAndroid Build Coastguard Worker {
99*35238bceSAndroid Build Coastguard Worker     EGLenum err = m_eglTestCtx.getLibrary().getError();
100*35238bceSAndroid Build Coastguard Worker     if (err != expectedA && err != expectedB)
101*35238bceSAndroid Build Coastguard Worker     {
102*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getErrorStr(expectedA) << " or "
103*35238bceSAndroid Build Coastguard Worker                            << eglu::getErrorStr(expectedB) << ", Got: " << eglu::getErrorStr(err)
104*35238bceSAndroid Build Coastguard Worker                            << TestLog::EndMessage;
105*35238bceSAndroid Build Coastguard Worker         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
106*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
107*35238bceSAndroid Build Coastguard Worker     }
108*35238bceSAndroid Build Coastguard Worker }
109*35238bceSAndroid Build Coastguard Worker 
expectBoolean(EGLBoolean expected,EGLBoolean got)110*35238bceSAndroid Build Coastguard Worker void ApiCase::expectBoolean(EGLBoolean expected, EGLBoolean got)
111*35238bceSAndroid Build Coastguard Worker {
112*35238bceSAndroid Build Coastguard Worker     if (expected != got)
113*35238bceSAndroid Build Coastguard Worker     {
114*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getBooleanStr(expected)
115*35238bceSAndroid Build Coastguard Worker                            << ", Got: " << eglu::getBooleanStr(got) << TestLog::EndMessage;
116*35238bceSAndroid Build Coastguard Worker         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
117*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
118*35238bceSAndroid Build Coastguard Worker     }
119*35238bceSAndroid Build Coastguard Worker }
120*35238bceSAndroid Build Coastguard Worker 
expectNoContext(EGLContext got)121*35238bceSAndroid Build Coastguard Worker void ApiCase::expectNoContext(EGLContext got)
122*35238bceSAndroid Build Coastguard Worker {
123*35238bceSAndroid Build Coastguard Worker     if (got != EGL_NO_CONTEXT)
124*35238bceSAndroid Build Coastguard Worker     {
125*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_CONTEXT" << TestLog::EndMessage;
126*35238bceSAndroid Build Coastguard Worker         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
127*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
128*35238bceSAndroid Build Coastguard Worker         eglDestroyContext(getDisplay(), got);
129*35238bceSAndroid Build Coastguard Worker     }
130*35238bceSAndroid Build Coastguard Worker }
131*35238bceSAndroid Build Coastguard Worker 
expectNoSurface(EGLSurface got)132*35238bceSAndroid Build Coastguard Worker void ApiCase::expectNoSurface(EGLSurface got)
133*35238bceSAndroid Build Coastguard Worker {
134*35238bceSAndroid Build Coastguard Worker     if (got != EGL_NO_SURFACE)
135*35238bceSAndroid Build Coastguard Worker     {
136*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_SURFACE" << TestLog::EndMessage;
137*35238bceSAndroid Build Coastguard Worker         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
138*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
139*35238bceSAndroid Build Coastguard Worker         eglDestroySurface(getDisplay(), got);
140*35238bceSAndroid Build Coastguard Worker     }
141*35238bceSAndroid Build Coastguard Worker }
142*35238bceSAndroid Build Coastguard Worker 
expectNoDisplay(EGLDisplay got)143*35238bceSAndroid Build Coastguard Worker void ApiCase::expectNoDisplay(EGLDisplay got)
144*35238bceSAndroid Build Coastguard Worker {
145*35238bceSAndroid Build Coastguard Worker     if (got != EGL_NO_DISPLAY)
146*35238bceSAndroid Build Coastguard Worker     {
147*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_DISPLAY" << TestLog::EndMessage;
148*35238bceSAndroid Build Coastguard Worker         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
149*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
150*35238bceSAndroid Build Coastguard Worker     }
151*35238bceSAndroid Build Coastguard Worker }
152*35238bceSAndroid Build Coastguard Worker 
expectNull(const void * got)153*35238bceSAndroid Build Coastguard Worker void ApiCase::expectNull(const void *got)
154*35238bceSAndroid Build Coastguard Worker {
155*35238bceSAndroid Build Coastguard Worker     if (got != DE_NULL)
156*35238bceSAndroid Build Coastguard Worker     {
157*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: NULL" << TestLog::EndMessage;
158*35238bceSAndroid Build Coastguard Worker         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
159*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
160*35238bceSAndroid Build Coastguard Worker     }
161*35238bceSAndroid Build Coastguard Worker }
162*35238bceSAndroid Build Coastguard Worker 
getConfig(EGLConfig * config,const eglu::FilterList & filters)163*35238bceSAndroid Build Coastguard Worker bool ApiCase::getConfig(EGLConfig *config, const eglu::FilterList &filters)
164*35238bceSAndroid Build Coastguard Worker {
165*35238bceSAndroid Build Coastguard Worker     try
166*35238bceSAndroid Build Coastguard Worker     {
167*35238bceSAndroid Build Coastguard Worker         *config = eglu::chooseSingleConfig(m_eglTestCtx.getLibrary(), m_display, filters);
168*35238bceSAndroid Build Coastguard Worker         return true;
169*35238bceSAndroid Build Coastguard Worker     }
170*35238bceSAndroid Build Coastguard Worker     catch (const tcu::NotSupportedError &)
171*35238bceSAndroid Build Coastguard Worker     {
172*35238bceSAndroid Build Coastguard Worker         return false;
173*35238bceSAndroid Build Coastguard Worker     }
174*35238bceSAndroid Build Coastguard Worker }
175*35238bceSAndroid Build Coastguard Worker 
176*35238bceSAndroid Build Coastguard Worker } // namespace egl
177*35238bceSAndroid Build Coastguard Worker } // namespace deqp
178