• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::vector;
42 using std::string;
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 << "  Fail, first part of the string must be in the format <major_version.minor_version>" << TestLog::EndMessage;
106 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid version string");
107 			}
108 			else
109 			{
110 				const	int	stringMajor	= toInt(versionTokens[0]);
111 				const	int	stringMinor	= toInt(versionTokens[1]);
112 
113 				if (stringMajor != dispMajor || stringMinor != dispMinor)
114 				{
115 					log << TestLog::Message << "  Fail, version numer (" << stringMajor << "." << stringMinor
116 						<< ") does not match the one reported by eglInitialize (" << dispMajor << "." << dispMinor << ")" << TestLog::EndMessage;
117 					m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Version number mismatch");
118 				}
119 			}
120 		}
121 	}
122 
iterate(void)123 	IterateResult iterate (void)
124 	{
125 		const Library&	egl		= m_eglTestCtx.getLibrary();
126 		const char*		result	= egl.queryString(m_display, m_query);
127 		EGLU_CHECK_MSG(egl, "eglQueryString() failed");
128 
129 		m_testCtx.getLog() << tcu::TestLog::Message << result << tcu::TestLog::EndMessage;
130 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
131 
132 		validateString(result);
133 
134 		return STOP;
135 	}
136 
137 private:
138 	EGLint m_query;
139 };
140 
141 class QueryExtensionsCase : public InfoCase
142 {
143 public:
QueryExtensionsCase(EglTestContext & eglTestCtx)144 	QueryExtensionsCase (EglTestContext& eglTestCtx)
145 		: InfoCase	(eglTestCtx, "extensions", "Supported Extensions")
146 	{
147 	}
148 
iterate(void)149 	IterateResult iterate (void)
150 	{
151 		const Library&	egl			= m_eglTestCtx.getLibrary();
152 		vector<string>	extensions	= eglu::getDisplayExtensions(egl, m_display);
153 
154 		for (vector<string>::const_iterator i = extensions.begin(); i != extensions.end(); i++)
155 			m_testCtx.getLog() << tcu::TestLog::Message << *i << tcu::TestLog::EndMessage;
156 
157 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
158 
159 		return STOP;
160 	}
161 };
162 
InfoTests(EglTestContext & eglTestCtx)163 InfoTests::InfoTests (EglTestContext& eglTestCtx)
164 	: TestCaseGroup(eglTestCtx, "info", "Platform Information")
165 {
166 }
167 
~InfoTests(void)168 InfoTests::~InfoTests (void)
169 {
170 }
171 
init(void)172 void InfoTests::init (void)
173 {
174 	addChild(new QueryStringCase(m_eglTestCtx, "version",		"EGL Version",				EGL_VERSION));
175 	addChild(new QueryStringCase(m_eglTestCtx, "vendor",		"EGL Vendor",				EGL_VENDOR));
176 	addChild(new QueryStringCase(m_eglTestCtx, "client_apis",	"Supported client APIs",	EGL_CLIENT_APIS));
177 	addChild(new QueryExtensionsCase(m_eglTestCtx));
178 	addChild(new ConfigList(m_eglTestCtx));
179 }
180 
181 } // egl
182 } // deqp
183