1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
# Copyright (c) 2014 Intel Corporation
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
""" Provides tests for the shader_test module """
from __future__ import print_function, absolute_import
import os
import textwrap
import nose.tools as nt
from framework import exceptions
import framework.test.glsl_parser_test as glsl
import framework.tests.utils as utils
from framework.test import TEST_BIN_DIR
# pylint: disable=line-too-long,invalid-name
def _check_config(content):
""" This is the test that actually checks the glsl config section """
with utils.tempfile(content) as tfile:
return glsl.GLSLParserTest(tfile), tfile
def test_no_config_start():
"""test.glsl_parser_test.GLSLParserTest: exception is raised if [config] section is missing
"""
content = ('// expect_result: pass\n'
'// glsl_version: 1.10\n'
'// [end config]\n')
with utils.tempfile(content) as tfile:
with nt.assert_raises(glsl.GLSLParserNoConfigError) as exc:
glsl.GLSLParserTest(tfile)
nt.assert_equal(
exc.exception, 'No [config] section found!',
msg="No config section was found and no exception raised")
@nt.raises(exceptions.PiglitFatalError)
def test_find_config_start():
"""test.glsl_parser_test.GLSLParserTest: successfully finds [config] section
"""
content = ('// [config]\n'
'// glsl_version: 1.10\n'
'//\n')
with utils.tempfile(content) as tfile:
glsl.GLSLParserTest(tfile)
@nt.raises(exceptions.PiglitFatalError)
def test_no_config_end():
"""test.glsl_parser_test.GLSLParserTest: exception is raised if [end config] section is missing
"""
with utils.tempfile('// [config]\n') as tfile:
glsl.GLSLParserTest(tfile)
@nt.raises(exceptions.PiglitFatalError)
def test_no_expect_result():
"""test.glsl_parser_test.GLSLParserTest: exception is raised if "expect_result" key is missing
"""
content = ('// [config]\n'
'// glsl_version: 1.10\n'
'//\n')
with utils.tempfile(content) as tfile:
glsl.GLSLParserTest(tfile)
@nt.raises(exceptions.PiglitFatalError)
def test_no_glsl_version():
"""test.glsl_parser_test.GLSLParserTest: exception is raised if "glsl_version" key is missing
"""
content = ('// [config]\n'
'// expect_result: pass\n'
'// [end config]\n')
with utils.tempfile(content) as tfile:
glsl.GLSLParserTest(tfile)
def test_cpp_comments():
"""test.glsl_parser_test.GLSLParserTest: parses C++ style comments ('//')
"""
content = ('// [config]\n'
'// expect_result: pass\n'
'// glsl_version: 1.10\n'
'// [end config]\n')
test, name = _check_config(content)
nt.assert_equal(
test.command,
[os.path.join(TEST_BIN_DIR, 'glslparsertest'), name, 'pass', '1.10'])
def test_c_comments():
"""test.glsl_parser_test.GLSLParserTest: parses C++ style comments ('/* */')
"""
content = ('/*\n'
' * [config]\n'
' * expect_result: pass\n'
' * glsl_version: 1.10\n'
' * [end config]\n'
' */\n')
test, name = _check_config(content)
nt.assert_equal(test.command, [os.path.join(TEST_BIN_DIR, 'glslparsertest'),
name, 'pass', '1.10'],
msg="C style (/* */) comments were not properly parsed")
def test_blank_in_config():
"""test.glsl_parser_test.GLSLParserTest: C++ style comments can have uncommented newlines
"""
content = ('// [config]\n'
'\n'
'// expect_result: pass\n'
'// glsl_version: 1.10\n'
'// [end config]\n')
test, name = _check_config(content)
nt.assert_equal(test.command, [os.path.join(TEST_BIN_DIR, 'glslparsertest'),
name, 'pass', '1.10'],
msg="A newline in a C++ style comment (//) was not "
"properly parsed.")
def test_empty_in_config():
"""test.glsl_parser_test.GLSLParserTest: C style comments can have blank newlines
"""
content = ('// [config]\n'
'//\n'
'// expect_result: pass\n'
'// glsl_version: 1.10\n'
'// [end config]\n')
test, name = _check_config(content)
nt.assert_equal(test.command, [os.path.join(TEST_BIN_DIR, 'glslparsertest'),
name, 'pass', '1.10'],
msg="A blank commented line in a C++ style comment was not"
" properly parsed.")
def test_glslparser_initializer():
"""test.glsl_parser_test.GLSLParserTest: clas initializes correctly"""
content = textwrap.dedent("""\
/*
* [config]
* expect_result: pass
* glsl_version: 1.10
* [end config]
*/
""")
with utils.tempfile(content) as f:
glsl.GLSLParserTest(f)
def check_config_to_command(config, result):
""" Check that the config is correctly converted """
inst, f = _check_config(config)
result.insert(1, f) # Add the file name
nt.eq_(inst.command, result)
@utils.nose_generator
def test_config_to_command():
""" Generate tests that confirm the config file is correctly parsed """
content = [
('// [config]\n// expect_result: pass\n// glsl_version: 1.10\n// [end config]\n',
[os.path.join(TEST_BIN_DIR, 'glslparsertest'), 'pass', '1.10'],
'all required options'),
('// [config]\n// expect_result: pass\n// glsl_version: 1.10\n//check_link: true\n// [end config]\n',
[os.path.join(TEST_BIN_DIR, 'glslparsertest'), 'pass', '1.10', '--check-link'],
'check_link true'),
('// [config]\n// expect_result: pass\n// glsl_version: 1.10\n//check_link: false\n// [end config]\n',
[os.path.join(TEST_BIN_DIR, 'glslparsertest'), 'pass', '1.10'],
'check_link false'),
('// [config]\n// expect_result: pass\n// glsl_version: 1.10\n//require_extensions: ARB_foo\n// [end config]\n',
[os.path.join(TEST_BIN_DIR, 'glslparsertest'), 'pass', '1.10', 'ARB_foo'],
'one required_extension'),
('// [config]\n// expect_result: pass\n// glsl_version: 1.10\n//require_extensions: ARB_foo ARB_bar\n// [end config]\n',
[os.path.join(TEST_BIN_DIR, 'glslparsertest'), 'pass', '1.10', 'ARB_foo', 'ARB_bar'],
'multiple required_extensions'),
]
for config, result, desc in content:
check_config_to_command.description = (
'test.glsl_parser_test.GLSLParserTest.command: '
'correctly generated for {}'.format(desc))
yield check_config_to_command, config, result
@nt.raises(exceptions.PiglitFatalError)
def test_bad_section_name():
"""test.glsl_parser_test.GLSLParserTest: A section name not in the _CONFIG_KEYS name raises an error"""
content = ('// [config]\n'
'// expect_result: pass\n'
'// glsl_version: 1.10\n'
'// new_awesome_key: foo\n'
'// [end config]\n')
with utils.tempfile(content) as tfile:
glsl.GLSLParserTest(tfile)
@utils.not_raises(exceptions.PiglitFatalError)
def test_good_section_names():
"""test.glsl_parser_test.GLSLParserTest: A section name in the _CONFIG_KEYS does not raise an error"""
content = ('// [config]\n'
'// expect_result: pass\n'
'// glsl_version: 1.10\n'
'// require_extensions: EXT_foo\n'
'// check_link: True\n'
'// [end config]\n')
_check_config(content)
@utils.nose_generator
def test_duplicate_entries():
""" Generate tests for duplicate keys in the config block """
@nt.raises(exceptions.PiglitFatalError)
def check_no_duplicates(content):
""" Ensure that duplicate entries raise an error """
with utils.tempfile(content) as tfile:
glsl.GLSLParserTest(tfile)
content = [
('expect_result', '// expect_result: pass\n'),
('glsl_version', '// glsl_version: 1.10\n'),
('require_extensions', '// require_extensions: ARB_ham_sandwhich\n')
]
for name, value in content:
check_no_duplicates.description = (
"test.glsl_parser_test.GLSLParserTest: duplicate values of "
"{0} raise an exception".format(name))
test = '// [config]\n{0}{1}// [end config]'.format(
''.join(x[1] for x in content), value)
yield check_no_duplicates, test
@utils.nose_generator
def glslparser_exetensions_seperators():
""" GlslParserTest() can only have [A-Za-z_] as characters
This test generates a number of tests that should catch the majority of
errors relating to seperating extensions in the config block of a
glslparser test
"""
@nt.raises(exceptions.PiglitFatalError)
def check_bad_character(tfile):
""" Check for bad characters """
glsl.GLSLParserTest(tfile)
problems = [
('comma seperator', '// require_extensions: ARB_ham, ARB_turkey\n'),
('semi-colon seperator', '// require_extensions: ARB_ham; ARB_turkey\n'),
('trailing semi-colon', '// require_extensions: ARB_ham ARB_turkey\n;'),
('Non-alpha character', '// require_extensions: ARB_$$$\n'),
]
content = ('// [config]\n'
'// expect_result: pass\n'
'// glsl_version: 1.10\n'
'{}'
'// [end config]\n')
for name, value in problems:
test = content.format(value)
with utils.tempfile(test) as tfile:
check_bad_character.description = (
'test.glsl_parser_test.GLSLParserTest: require_extensions {0} '
'should raise an error'.format(name))
yield check_bad_character, tfile
@utils.nose_generator
def test_good_extensions():
""" Generates tests with good extensions which shouldn't raise errors """
@utils.not_raises(exceptions.PiglitFatalError)
def check_good_extension(file_):
""" A good extension should not raise a GLSLParserException """
glsl.GLSLParserTest(file_)
content = ('// [config]\n'
'// expect_result: pass\n'
'// glsl_version: 1.10\n'
'// require_extensions: {}\n'
'// [end config]\n')
options = [
'GL_EXT_texture_array',
'GL_EXT_texture_array ARB_example',
'!GL_ARB_ham_sandwhich',
]
for x in options:
test = content.format(x)
check_good_extension.description = (
'test.glsl_parser_test.GLSLParserTest: '
'require_extension {} is valid'.format(x))
with utils.tempfile(test) as tfile:
yield check_good_extension, tfile
@utils.nose_generator
def test_get_glslparsertest_gles2():
"""GLSLParserTest: gets gles2 binary if glsl is 1.00 or 3.00"""
@utils.no_error
def test(content):
with utils.tempfile(content) as f:
t = glsl.GLSLParserTest(f)
nt.eq_(os.path.basename(t.command[0]), 'glslparsertest_gles2')
content = textwrap.dedent("""\
/*
* [config]
* expect_result: pass
* glsl_version: {}
* [end config]
*/
""")
description = ("test.glsl_parser_test.GLSLParserTest: "
"gets gles2 binary if glsl is {}")
for version in ['1.00', '3.00']:
test.description = description.format(version)
yield test, content.format(version)
|