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 Simple Context construction test.
22 *//*--------------------------------------------------------------------*/
23
24 #include "teglCreateContextTests.hpp"
25 #include "teglSimpleConfigCase.hpp"
26 #include "egluStrUtil.hpp"
27 #include "egluUtil.hpp"
28 #include "eglwLibrary.hpp"
29 #include "eglwEnums.hpp"
30 #include "tcuTestLog.hpp"
31
32 namespace deqp
33 {
34 namespace egl
35 {
36
37 using std::vector;
38 using tcu::TestLog;
39 using namespace eglw;
40
41 class CreateContextCase : public SimpleConfigCase
42 {
43 public:
44 CreateContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const eglu::FilterList& filters);
45 ~CreateContextCase (void);
46
47 void executeForConfig (EGLDisplay display, EGLConfig config);
48 };
49
CreateContextCase(EglTestContext & eglTestCtx,const char * name,const char * description,const eglu::FilterList & filters)50 CreateContextCase::CreateContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const eglu::FilterList& filters)
51 : SimpleConfigCase(eglTestCtx, name, description, filters)
52 {
53 }
54
~CreateContextCase(void)55 CreateContextCase::~CreateContextCase (void)
56 {
57 }
58
executeForConfig(EGLDisplay display,EGLConfig config)59 void CreateContextCase::executeForConfig (EGLDisplay display, EGLConfig config)
60 {
61 const Library& egl = m_eglTestCtx.getLibrary();
62 TestLog& log = m_testCtx.getLog();
63 EGLint id = eglu::getConfigAttribInt(egl, display, config, EGL_CONFIG_ID);
64 EGLint apiBits = eglu::getConfigAttribInt(egl, display, config, EGL_RENDERABLE_TYPE);
65
66 static const EGLint es1Attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE };
67 static const EGLint es2Attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
68 static const EGLint es3Attrs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE };
69
70 static const struct
71 {
72 const char* name;
73 EGLenum api;
74 EGLint apiBit;
75 const EGLint* ctxAttrs;
76 } apis[] =
77 {
78 { "OpenGL", EGL_OPENGL_API, EGL_OPENGL_BIT, DE_NULL },
79 { "OpenGL ES 1", EGL_OPENGL_ES_API, EGL_OPENGL_ES_BIT, es1Attrs },
80 { "OpenGL ES 2", EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT, es2Attrs },
81 { "OpenGL ES 3", EGL_OPENGL_ES_API, EGL_OPENGL_ES3_BIT_KHR, es3Attrs },
82 { "OpenVG", EGL_OPENVG_API, EGL_OPENVG_BIT, DE_NULL }
83 };
84
85 for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(apis); apiNdx++)
86 {
87 if ((apiBits & apis[apiNdx].apiBit) == 0)
88 continue; // Not supported API
89
90 log << TestLog::Message << "Creating " << apis[apiNdx].name << " context with config ID " << id << TestLog::EndMessage;
91 EGLU_CHECK_MSG(egl, "init");
92
93 EGLU_CHECK_CALL(egl, bindAPI(apis[apiNdx].api));
94
95 EGLContext context = egl.createContext(display, config, EGL_NO_CONTEXT, apis[apiNdx].ctxAttrs);
96 EGLenum err = egl.getError();
97
98 if (context == EGL_NO_CONTEXT || err != EGL_SUCCESS)
99 {
100 log << TestLog::Message << " Fail, context: " << tcu::toHex(context) << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
101 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to create context");
102 }
103 else
104 {
105 // Destroy
106 EGLU_CHECK_CALL(egl, destroyContext(display, context));
107 log << TestLog::Message << " Pass" << TestLog::EndMessage;
108 }
109 }
110 }
111
112
CreateContextTests(EglTestContext & eglTestCtx)113 CreateContextTests::CreateContextTests (EglTestContext& eglTestCtx)
114 : TestCaseGroup(eglTestCtx, "create_context", "Basic eglCreateContext() tests")
115 {
116 }
117
~CreateContextTests(void)118 CreateContextTests::~CreateContextTests (void)
119 {
120 }
121
init(void)122 void CreateContextTests::init (void)
123 {
124 vector<NamedFilterList> filterLists;
125 getDefaultFilterLists(filterLists, eglu::FilterList());
126
127 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++)
128 addChild(new CreateContextCase(m_eglTestCtx, i->getName(), i->getDescription(), *i));
129 }
130
131 } // egl
132 } // deqp
133