Home | History | Annotate | Download | only in egl
      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 
     28 #include <vector>
     29 #include <string>
     30 #include <sstream>
     31 
     32 #include <EGL/egl.h>
     33 
     34 using std::vector;
     35 using std::string;
     36 
     37 using tcu::TestLog;
     38 
     39 namespace deqp
     40 {
     41 namespace egl
     42 {
     43 
     44 static std::vector<std::string> split(const std::string& str, const std::string& delim = " ")
     45 {
     46 	std::vector<std::string>	out;
     47 	if (str.length() == 0) return out;
     48 
     49 	size_t	start	= 0;
     50 	size_t	end		= string::npos;
     51 
     52 	while ((end = str.find(delim, start)) != string::npos)
     53 	{
     54 		out.push_back(str.substr(start, end-start));
     55 		start = end + delim.length();
     56 	}
     57 
     58 	if (start < end)
     59 		out.push_back(str.substr(start, end-start));
     60 
     61 	return out;
     62 }
     63 
     64 static int toInt(std::string str)
     65 {
     66 	std::istringstream strStream(str);
     67 
     68 	int out;
     69 	strStream >> out;
     70 	return out;
     71 }
     72 
     73 class QueryStringCase : public TestCase
     74 {
     75 public:
     76 	QueryStringCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint query)
     77 		: TestCase	(eglTestCtx, name, description)
     78 		, m_query	(query)
     79 	{
     80 	}
     81 
     82 	void validateString (const std::string& result)
     83 	{
     84 		tcu::TestLog&				log		= m_testCtx.getLog();
     85 		std::vector<std::string>	tokens	= split(result);
     86 
     87 		if (m_query == EGL_VERSION)
     88 		{
     89 			const tcu::egl::Display&		display			= m_eglTestCtx.getDisplay();
     90 			const int						dispMajor		= display.getEGLMajorVersion();
     91 			const int						dispMinor		= display.getEGLMinorVersion();
     92 
     93 			const std::vector<std::string>	versionTokens	= split(tokens[0], ".");
     94 
     95 			if (versionTokens.size() < 2)
     96 			{
     97 				log << TestLog::Message << "  Fail, first part of the string must be in the format <major_version.minor_version>" << TestLog::EndMessage;
     98 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid version string");
     99 			}
    100 			else
    101 			{
    102 				const	int	stringMajor	= toInt(versionTokens[0]);
    103 				const	int	stringMinor	= toInt(versionTokens[1]);
    104 
    105 				if (stringMajor != dispMajor || stringMinor != dispMinor)
    106 				{
    107 					log << TestLog::Message << "  Fail, version numer (" << stringMajor << "." << stringMinor
    108 						<< ") does not match the one reported by eglInitialize (" << dispMajor << "." << dispMinor << ")" << TestLog::EndMessage;
    109 					m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Version number mismatch");
    110 				}
    111 			}
    112 		}
    113 	}
    114 
    115 	IterateResult iterate (void)
    116 	{
    117 		const char* result = eglQueryString(m_eglTestCtx.getDisplay().getEGLDisplay(), m_query);
    118 		TCU_CHECK_EGL_MSG("eglQueryString() failed");
    119 
    120 		m_testCtx.getLog() << tcu::TestLog::Message << result << tcu::TestLog::EndMessage;
    121 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
    122 
    123 		validateString(result);
    124 
    125 		return STOP;
    126 	}
    127 
    128 private:
    129 	EGLint m_query;
    130 };
    131 
    132 class QueryExtensionsCase : public TestCase
    133 {
    134 public:
    135 	QueryExtensionsCase (EglTestContext& eglTestCtx)
    136 		: TestCase	(eglTestCtx, "extensions", "Supported Extensions")
    137 	{
    138 	}
    139 
    140 	IterateResult iterate (void)
    141 	{
    142 		vector<string> extensions;
    143 		m_eglTestCtx.getDisplay().getExtensions(extensions);
    144 
    145 		for (vector<string>::const_iterator i = extensions.begin(); i != extensions.end(); i++)
    146 			m_testCtx.getLog() << tcu::TestLog::Message << *i << tcu::TestLog::EndMessage;
    147 
    148 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
    149 
    150 		return STOP;
    151 	}
    152 };
    153 
    154 InfoTests::InfoTests (EglTestContext& eglTestCtx)
    155 	: TestCaseGroup(eglTestCtx, "info", "Platform Information")
    156 {
    157 }
    158 
    159 InfoTests::~InfoTests (void)
    160 {
    161 }
    162 
    163 void InfoTests::init (void)
    164 {
    165 	addChild(new QueryStringCase(m_eglTestCtx, "version",		"EGL Version",				EGL_VERSION));
    166 	addChild(new QueryStringCase(m_eglTestCtx, "vendor",		"EGL Vendor",				EGL_VENDOR));
    167 	addChild(new QueryStringCase(m_eglTestCtx, "client_apis",	"Supported client APIs",	EGL_CLIENT_APIS));
    168 	addChild(new QueryExtensionsCase(m_eglTestCtx));
    169 	addChild(new ConfigList(m_eglTestCtx));
    170 }
    171 
    172 } // egl
    173 } // deqp
    174