• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2017 The Khronos Group Inc.
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
22  */ /*-------------------------------------------------------------------*/
23 
24 /**
25  */ /*!
26  * \file  gl4cSpirvExtensionsTests.cpp
27  * \brief Conformance tests for the GL_ARB_spirv_extensions functionality.
28  */ /*-------------------------------------------------------------------*/
29 
30 #include "gl4cSpirvExtensionsTests.hpp"
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "gluStrUtil.hpp"
34 #include "glwEnums.hpp"
35 #include "glwFunctions.hpp"
36 #include "tcuTestLog.hpp"
37 
38 using namespace glw;
39 using namespace glu;
40 
41 namespace gl4cts
42 {
43 
44 /** Constructor.
45  *
46  *  @param context     Rendering context
47  */
SpirvExtensionsQueriesTestCase(deqp::Context & context)48 SpirvExtensionsQueriesTestCase::SpirvExtensionsQueriesTestCase(deqp::Context& context)
49 	: TestCase(context, "spirv_extensions_queries",
50 			   "Verifies if queries for GL_ARB_spirv_extension tokens works as expected")
51 {
52 	/* Left blank intentionally */
53 }
54 
55 /** Stub init method */
init()56 void SpirvExtensionsQueriesTestCase::init()
57 {
58 	glu::ContextType contextType = m_context.getRenderContext().getType();
59 	if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
60 		!m_context.getContextInfo().isExtensionSupported("GL_ARB_spirv_extensions"))
61 	{
62 		TCU_THROW(NotSupportedError, "GL_ARB_spirv_extensions not supported");
63 	}
64 
65 	if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
66 		!m_context.getContextInfo().isExtensionSupported("GL_ARB_gl_spirv"))
67 	{
68 		TCU_THROW(NotSupportedError, "GL_ARB_gl_spirv not supported");
69 	}
70 }
71 
72 /** Executes test iteration.
73  *
74  *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
75  */
iterate()76 tcu::TestNode::IterateResult SpirvExtensionsQueriesTestCase::iterate()
77 {
78 	const Functions& gl = m_context.getRenderContext().getFunctions();
79 
80 	GLint numSpirvExtensions;
81 	gl.getIntegerv(GL_NUM_SPIR_V_EXTENSIONS, &numSpirvExtensions);
82 	GLU_EXPECT_NO_ERROR(gl.getError(), "getIntegerv");
83 
84 	m_testCtx.getLog() << tcu::TestLog::Message << "GL_NUM_SPIR_V_EXTENSIONS = " << numSpirvExtensions << "\n"
85 					   << tcu::TestLog::EndMessage;
86 	for (GLint i = 0; i < numSpirvExtensions; ++i)
87 	{
88 		const GLubyte* spirvExtension = DE_NULL;
89 
90 		spirvExtension = gl.getStringi(GL_SPIR_V_EXTENSIONS, i);
91 		GLU_EXPECT_NO_ERROR(gl.getError(), "getStringi");
92 
93 		if (!spirvExtension || strlen((const char*)spirvExtension) == 0)
94 		{
95 			m_testCtx.getLog() << tcu::TestLog::Message << "Failed to fetch GL_SPIRV_EXTENSIONS string for index: " << i
96 							   << "\n"
97 							   << tcu::TestLog::EndMessage;
98 
99 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
100 			return STOP;
101 		}
102 		else
103 		{
104 			m_testCtx.getLog() << tcu::TestLog::Message << "GL_SPIR_V_EXTENSION " << i << ": " << spirvExtension << "\n"
105 							   << tcu::TestLog::EndMessage;
106 		}
107 	}
108 
109 	// Test out of bound query
110 	gl.getStringi(GL_SPIR_V_EXTENSIONS, numSpirvExtensions);
111 	GLenum err = gl.getError();
112 	if (err != GL_INVALID_VALUE)
113 	{
114 		m_testCtx.getLog() << tcu::TestLog::Message
115 						   << "GetStringi query for GL_SPIRV_EXTENSIONS with index: " << numSpirvExtensions
116 						   << " should generate INVALID_VALUE error instead of " << glu::getErrorName(err) << "\n"
117 						   << tcu::TestLog::EndMessage;
118 
119 		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
120 		return STOP;
121 	}
122 
123 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
124 	return STOP;
125 }
126 
127 /** Constructor.
128  *
129  *  @param context Rendering context.
130  */
SpirvExtensionsTests(deqp::Context & context)131 SpirvExtensionsTests::SpirvExtensionsTests(deqp::Context& context)
132 	: TestCaseGroup(context, "spirv_extensions", "Verify conformance of GL_ARB_spirv_extensions implementation")
133 {
134 }
135 
136 /** Initializes the test group contents. */
init()137 void SpirvExtensionsTests::init()
138 {
139 	addChild(new SpirvExtensionsQueriesTestCase(m_context));
140 }
141 
142 } /* gl4cts namespace */
143