xref: /aosp_15_r20/external/deqp/modules/egl/teglApiCase.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 API test case.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglApiCase.hpp"
25 #include "egluUtil.hpp"
26 #include "egluStrUtil.hpp"
27 #include "eglwLibrary.hpp"
28 #include "eglwEnums.hpp"
29 #include "deSTLUtil.hpp"
30 
31 namespace deqp
32 {
33 namespace egl
34 {
35 
36 using std::vector;
37 using tcu::TestLog;
38 using namespace eglw;
39 
ApiCase(EglTestContext & eglTestCtx,const char * name,const char * description)40 ApiCase::ApiCase(EglTestContext &eglTestCtx, const char *name, const char *description)
41     : TestCase(eglTestCtx, name, description)
42     , CallLogWrapper(eglTestCtx.getLibrary(), eglTestCtx.getTestContext().getLog())
43     , m_display(EGL_NO_DISPLAY)
44 {
45 }
46 
~ApiCase(void)47 ApiCase::~ApiCase(void)
48 {
49 }
50 
init(void)51 void ApiCase::init(void)
52 {
53     m_display             = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
54     m_supportedClientAPIs = eglu::getClientAPIs(m_eglTestCtx.getLibrary(), m_display);
55 }
56 
deinit(void)57 void ApiCase::deinit(void)
58 {
59     const Library &egl = m_eglTestCtx.getLibrary();
60     egl.terminate(m_display);
61 
62     m_display = EGL_NO_DISPLAY;
63     m_supportedClientAPIs.clear();
64 }
65 
iterate(void)66 ApiCase::IterateResult ApiCase::iterate(void)
67 {
68     // Initialize result to pass.
69     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
70 
71     // Enable call logging.
72     enableLogging(true);
73 
74     // Run test.
75     test();
76 
77     return STOP;
78 }
79 
isAPISupported(eglw::EGLenum api) const80 bool ApiCase::isAPISupported(eglw::EGLenum api) const
81 {
82     return de::contains(m_supportedClientAPIs.begin(), m_supportedClientAPIs.end(), api);
83 }
84 
expectError(EGLenum expected)85 void ApiCase::expectError(EGLenum expected)
86 {
87     EGLenum err = m_eglTestCtx.getLibrary().getError();
88     if (err != expected)
89     {
90         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getErrorStr(expected)
91                            << ", Got: " << eglu::getErrorStr(err) << TestLog::EndMessage;
92         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
93             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
94     }
95 }
96 
expectEitherError(EGLenum expectedA,EGLenum expectedB)97 void ApiCase::expectEitherError(EGLenum expectedA, EGLenum expectedB)
98 {
99     EGLenum err = m_eglTestCtx.getLibrary().getError();
100     if (err != expectedA && err != expectedB)
101     {
102         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getErrorStr(expectedA) << " or "
103                            << eglu::getErrorStr(expectedB) << ", Got: " << eglu::getErrorStr(err)
104                            << TestLog::EndMessage;
105         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
106             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
107     }
108 }
109 
expectBoolean(EGLBoolean expected,EGLBoolean got)110 void ApiCase::expectBoolean(EGLBoolean expected, EGLBoolean got)
111 {
112     if (expected != got)
113     {
114         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: " << eglu::getBooleanStr(expected)
115                            << ", Got: " << eglu::getBooleanStr(got) << TestLog::EndMessage;
116         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
117             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
118     }
119 }
120 
expectNoContext(EGLContext got)121 void ApiCase::expectNoContext(EGLContext got)
122 {
123     if (got != EGL_NO_CONTEXT)
124     {
125         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_CONTEXT" << TestLog::EndMessage;
126         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
127             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
128         eglDestroyContext(getDisplay(), got);
129     }
130 }
131 
expectNoSurface(EGLSurface got)132 void ApiCase::expectNoSurface(EGLSurface got)
133 {
134     if (got != EGL_NO_SURFACE)
135     {
136         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_SURFACE" << TestLog::EndMessage;
137         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
138             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
139         eglDestroySurface(getDisplay(), got);
140     }
141 }
142 
expectNoDisplay(EGLDisplay got)143 void ApiCase::expectNoDisplay(EGLDisplay got)
144 {
145     if (got != EGL_NO_DISPLAY)
146     {
147         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: EGL_NO_DISPLAY" << TestLog::EndMessage;
148         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
149             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
150     }
151 }
152 
expectNull(const void * got)153 void ApiCase::expectNull(const void *got)
154 {
155     if (got != DE_NULL)
156     {
157         m_testCtx.getLog() << TestLog::Message << "// ERROR expected: NULL" << TestLog::EndMessage;
158         if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
159             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid value");
160     }
161 }
162 
getConfig(EGLConfig * config,const eglu::FilterList & filters)163 bool ApiCase::getConfig(EGLConfig *config, const eglu::FilterList &filters)
164 {
165     try
166     {
167         *config = eglu::chooseSingleConfig(m_eglTestCtx.getLibrary(), m_display, filters);
168         return true;
169     }
170     catch (const tcu::NotSupportedError &)
171     {
172         return false;
173     }
174 }
175 
176 } // namespace egl
177 } // namespace deqp
178