[Piglit] [PATCH 18/49] unittests: port tests for glsl_parser_test to py.test

Dylan Baker dylan at pnwbakers.com
Fri Jul 29 18:39:04 UTC 2016


This patch adds a couple of new tests that were not being generated for
some reason, and fixes a test that wasn't testing what it was supposed
to. These tests fail of course, so they've been marked as expected fail
and will be fixed later.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 unittests/framework/test/test_glsl_parser_test.py | 484 ++++++++++++++++++++
 unittests/glsl_parser_test_tests.py               | 525 ----------------------
 2 files changed, 484 insertions(+), 525 deletions(-)
 create mode 100644 unittests/framework/test/test_glsl_parser_test.py
 delete mode 100644 unittests/glsl_parser_test_tests.py

diff --git a/unittests/framework/test/test_glsl_parser_test.py b/unittests/framework/test/test_glsl_parser_test.py
new file mode 100644
index 0000000..69ad5fc
--- /dev/null
+++ b/unittests/framework/test/test_glsl_parser_test.py
@@ -0,0 +1,484 @@
+# Copyright (c) 2014-2016 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.
+
+"""Tests for framework.test.glsl_parser_test."""
+
+from __future__ import (
+    absolute_import, division, print_function, unicode_literals
+)
+import itertools
+import os
+import textwrap
+# pylint: disable=import-error
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+# pylint: enable=import-error
+
+import pytest
+import six
+
+from framework import exceptions
+from framework.test import glsl_parser_test as glsl
+from framework.test.piglit_test import TEST_BIN_DIR as _TEST_BIN_DIR
+from framework.test.base import TestIsSkip as _TestIsSkip
+
+# pylint: disable=invalid-name
+
+
+class _Setup(object):
+    """A class holding setup and teardown methods.
+
+    These methods need to share data, and a class is a nice way to encapsulate
+    that.
+
+    """
+    def __init__(self):
+        self.patchers = [
+            mock.patch('framework.test.glsl_parser_test._HAS_GL_BIN', True),
+            mock.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', True),
+            mock.patch.dict('framework.test.opengl.OPTIONS.env',
+                            {'PIGLIT_PLATFORM': 'foo'}),
+        ]
+
+    def setup(self, _):
+        for p in self.patchers:
+            p.start()
+
+    def teardown(self, _):
+        for p in self.patchers:
+            p.stop()
+
+
+_setup = _Setup()
+setup_module = _setup.setup
+teardown_module = _setup.teardown
+
+
+def test_no_config_start(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: exception is raised if [config]
+    section is missing."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""
+        // expect_result: pass
+        // glsl_version: 1.10
+        // [end config]"""))
+
+    with pytest.raises(glsl.GLSLParserNoConfigError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+def test_find_config_start(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: successfully finds [config]
+    section."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""
+        // [config]
+        // expect_result: pass
+        // glsl_version: 1.10"""))
+
+    with pytest.raises(exceptions.PiglitFatalError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+def test_no_config_end(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: exception is raised if [end
+    config] section is missing."""
+    p = tmpdir.join('test.frag')
+    p.write('// [config]')
+
+    with pytest.raises(exceptions.PiglitFatalError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+def test_no_expect_result(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: exception is raised if
+    "expect_result" key is missing."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        // [config]
+        // glsl_version: 1.10
+        // [end config]"""))
+
+    with pytest.raises(exceptions.PiglitFatalError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+def test_no_glsl_version(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: exception is raised if
+    "glsl_version" key is missing."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        // [config]
+        // expect_result: pass
+        // [end config]"""))
+
+    with pytest.raises(exceptions.PiglitFatalError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+def test_cpp_comments(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: parses C++ style comments ('//').
+    """
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        // [config]
+        // expect_result: pass
+        // glsl_version: 1.10
+        // [end config]"""))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'),
+                            six.text_type(p), 'pass', '1.10']
+
+
+def test_c_comments(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: parses C++ style comments ('/* */')
+    """
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        /* [config]
+         * expect_result: pass
+         * glsl_version: 1.10
+         * [end config]
+         */"""))
+
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'),
+                            six.text_type(p), 'pass', '1.10']
+
+
+def test_blank_in_config_cpp(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: C++ style comments can have
+    uncommented newlines."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        // [config]
+
+        // expect_result: pass
+        // glsl_version: 1.10
+        // [end config]"""))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'),
+                            six.text_type(p), 'pass', '1.10']
+
+
+def test_empty_in_config_cpp(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: C++ style comments can have blank
+    commented lines."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        // [config]
+        //
+        // expect_result: pass
+        // glsl_version: 1.10
+        // [end config]"""))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'),
+                            six.text_type(p), 'pass', '1.10']
+
+
+def test_blank_in_config_c(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: C style comments can have
+    uncommented newlines."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        /* [config]
+
+         * expect_result: pass
+         * glsl_version: 1.10
+         * [end config]
+         */"""))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'),
+                            six.text_type(p), 'pass', '1.10']
+
+
+ at pytest.mark.xfail
+def test_empty_in_config_c(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: C style comments can have blank
+    commented lines."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        /* [config]
+         *
+         * expect_result: pass
+         * glsl_version: 1.10
+         * [end config]
+         */"""))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    assert test.command == [os.path.join(_TEST_BIN_DIR, 'glslparsertest'),
+                            six.text_type(p), 'pass', '1.10']
+
+
+ at pytest.mark.parametrize(
+    "config,expected",
+    # pylint: disable=line-too-long
+    [('// [config]\n// expect_result: pass\n// glsl_version: 1.10\n// [end config]\n',
+      [os.path.join(_TEST_BIN_DIR, 'glslparsertest'), 'pass', '1.10']),
+     ('// [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']),
+     ('// [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']),
+     ('// [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']),
+     ('// [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'])],
+    # pylint: enable=line-too-long
+    ids=['all required options', 'check_link true', 'check_link false',
+         'one required_extension', 'multiple required_exetension'])
+def test_config_to_command(config, expected, tmpdir):
+    """Test that config blocks are converted into the expected commands."""
+    p = tmpdir.join('test.frag')
+    p.write(config)
+    test = glsl.GLSLParserTest(six.text_type(p))
+    # add the filename, which isn't known util now
+    expected.insert(1, six.text_type(p))
+
+    assert test.command == expected
+
+
+def test_bad_section_name(tmpdir):
+    """test.glsl_parser_test.GLSLParserTest: Unknown config keys cause an
+    error."""
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        // [config]
+        // expect_result: pass
+        // glsl_version: 1.10
+        // new_awesome_key: foo
+        // [end config]"""))
+
+    with pytest.raises(exceptions.PiglitFatalError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+ at pytest.mark.parametrize(
+    "extra",
+    ['expect_result: pass', 'glsl_version: 1.10',
+     'require_extensions: ARB_ham_sandwhich', 'check_link: false'],
+    ids=['expect_result', 'glsl_version', 'require_extensions', 'check_link'])
+def test_duplicate_entry(extra, tmpdir):
+    """Test that duplicate entries are an error."""
+    p = tmpdir.join('test.vert')
+    p.write(textwrap.dedent("""\
+        // [config]
+        // expect_result: pass
+        // glsl_version: 1.10
+        // require_extensions: ARB_foobar
+        // check_link: True
+        // {}
+        // [end config]""".format(extra)))
+
+    with pytest.raises(exceptions.PiglitFatalError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+ at pytest.mark.parametrize(
+    "separator",
+    ['ARB_ham, ARB_turkey', 'ARB_pork; ARB_chicken', 'ARB_foo;'],
+    ids=['comma separated', 'semicolon separated', 'trailing semicolon'])
+def test_invalid_extensions_separator(separator, tmpdir):
+    """Test that invalid extension separators are rejected."""
+    p = tmpdir.join('test.vert')
+    p.write(textwrap.dedent("""\
+        // [config]
+        // expect_result: pass
+        // glsl_version: 1.10
+        // require_extensions: ARB_foobar
+        // check_link: True
+        // require_extensions: {}
+        // [end config]""".format(separator)))
+
+    with pytest.raises(exceptions.PiglitFatalError):
+        glsl.GLSLParserTest(six.text_type(p))
+
+
+ at pytest.mark.parametrize(
+    "ext",
+    ['GL_EXT_foo', '!GL_EXT_foo', 'GL_EXT_foo GL_ARB_foo',
+     '!GL_EXT_foo !GL_ARB_foo', '!GL_EXT_foo GL_ARB_foo'],
+    ids=['single require', 'single exclude', 'multiple require',
+         'multiple exclude', 'mixed require and exclude'])
+def test_valid_extensions(ext, tmpdir):
+    """Test that invalid extension separators are rejected."""
+    p = tmpdir.join('test.vert')
+    p.write(textwrap.dedent("""\
+        // [config]
+        // expect_result: pass
+        // glsl_version: 1.10
+        // require_extensions: {}
+        // [end config]""".format(ext)))
+
+    expected = ext.split(' ')
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    assert test.command[-len(expected):] == expected
+
+
+ at pytest.mark.parametrize(
+    "version,has_bin,forced",
+    itertools.product(
+        ['1.00', '3.00', '3.10', '3.20', '3.00 es', '3.10 es', '3.20 es'],
+        [True, False], [True, False]))
+def test_get_glslparsertest_gles2(version, has_bin, forced, tmpdir, mocker):
+    """Tests for assigning the correct binary for GLES tests.
+
+    Tests with and without the gles binary and with and without the force
+    desktop mode.
+    """
+    if not has_bin or forced:
+        expected = 'glslparsertest'
+    else:
+        expected = 'glslparsertest_gles2'
+
+    mocker.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', has_bin)
+    mocker.patch('framework.test.glsl_parser_test._FORCE_DESKTOP_VERSION',
+                 forced)
+
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        /* [config]
+         * expect_result: pass
+         * glsl_version: {}
+         * [end config]
+         */""".format(version)))
+    inst = glsl.GLSLParserTest(six.text_type(p))
+
+    assert os.path.basename(inst.command[0]) == expected
+
+
+class TestGLSLParserTestSkipRequirements(object):
+    """Tests for setting FastSkip parameters."""
+    @staticmethod
+    def write_config(filename, version='4.3', extra=''):
+        filename.write(textwrap.dedent("""\
+            // [config]
+            // expect_result: pass
+            // glsl_version: {}
+            // {}
+            // [end config]""".format(version, extra)))
+
+    def test_glsl_version(self, tmpdir):
+        p = tmpdir.join('test.frag')
+        self.write_config(p)
+        assert glsl.GLSLParserTest(six.text_type(p)).glsl_version == 4.3
+
+    def test_glsl_es_version(self, tmpdir):
+        p = tmpdir.join('test.frag')
+        self.write_config(p, version='3.0')
+        assert glsl.GLSLParserTest(six.text_type(p)).glsl_es_version == 3.0
+
+    def test_gl_required(self, tmpdir):
+        p = tmpdir.join('test.frag')
+        self.write_config(p, extra="require_extensions: GL_ARB_foo GL_ARB_bar")
+        assert glsl.GLSLParserTest(six.text_type(p)).gl_required == \
+            {'GL_ARB_foo', 'GL_ARB_bar'}
+
+    def test_exclude_not_added_to_gl_required(self, tmpdir):
+        p = tmpdir.join('test.frag')
+        self.write_config(p, extra="require_extensions: GL_ARB_foo !GL_ARB_bar")
+        assert glsl.GLSLParserTest(six.text_type(p)).gl_required == \
+            {'GL_ARB_foo'}
+
+
+def test_skip_desktop_without_binary(tmpdir, mocker):
+    """There is no way to run desktop tests with only GLES compiled make sure
+    we don't try.
+    """
+    mocker.patch('framework.test.glsl_parser_test._HAS_GL_BIN', False)
+
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        /* [config]
+         * expect_result: pass
+         * glsl_version: 1.10
+         * [end config]
+         */"""))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    with pytest.raises(_TestIsSkip):
+        test.is_skip()
+
+
+ at pytest.mark.parametrize("version,extension", [
+    ('1.00', 'ARB_ES2_compatibility'),
+    ('3.00', 'ARB_ES3_compatibility'),
+    ('3.10', 'ARB_ES3_1_compatibility'),
+    ('3.20', 'ARB_ES3_2_compatibility'),
+])
+def test_add_compatibility_requirement_fastskip(version, extension, tmpdir,
+                                                mocker):
+    """When running GLES tests using the GL binary ensure that the proper
+    ARB_ES<ver> compatibility extension is added to the requirements.
+
+    This test checks the fast skipping variable
+    """
+    mocker.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', False)
+
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        /* [config]
+         * expect_result: pass
+         * glsl_version: {}
+         * require_extensions: GL_ARB_ham_sandwhich
+         * [end config]
+         */""".format(version)))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    # The arb_compat extension was added to the fast skipping arguments
+    assert extension in test.gl_required
+
+
+
+ at pytest.mark.parametrize("version,extension", [
+    pytest.mark.xfail(('1.00', 'ARB_ES2_compatibility')),
+    pytest.mark.xfail(('3.00', 'ARB_ES3_compatibility')),
+    pytest.mark.xfail(('3.10', 'ARB_ES3_1_compatibility')),
+    pytest.mark.xfail(('3.20', 'ARB_ES3_2_compatibility')),
+])
+def test_add_compatibility_requirement_binary(version, extension, tmpdir,
+                                              mocker):
+    """When running GLES tests using the GL binary ensure that the proper
+    ARB_ES<ver> compatibility extension is added to the requirements.
+
+    This test checks the glslparsertest binary command line.
+    """
+    mocker.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', False)
+
+    p = tmpdir.join('test.frag')
+    p.write(textwrap.dedent("""\
+        /* [config]
+         * expect_result: pass
+         * glsl_version: {}
+         * require_extensions: GL_ARB_ham_sandwhich
+         * [end config]
+         */""".format(version)))
+    test = glsl.GLSLParserTest(six.text_type(p))
+
+    # The compat extension was added to the slow skipping (C level)
+    # requirements
+    assert extension in test.command
diff --git a/unittests/glsl_parser_test_tests.py b/unittests/glsl_parser_test_tests.py
deleted file mode 100644
index 87d7db9..0000000
--- a/unittests/glsl_parser_test_tests.py
+++ /dev/null
@@ -1,525 +0,0 @@
-# Copyright (c) 2014-2016 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 (
-    absolute_import, division, print_function, unicode_literals
-)
-import os
-import textwrap
-
-try:
-    from unittest import mock
-except ImportError:
-    import mock
-
-import nose.tools as nt
-
-from . import utils
-import framework.test.glsl_parser_test as glsl
-from framework import exceptions
-from framework.test import TEST_BIN_DIR, TestIsSkip
-
-# pylint: disable=line-too-long,invalid-name
-
-
-class _Setup(object):
-    """A class holding setup and teardown methods.
-
-    These methods need to share data, and a class is a nice way to encapsulate
-    that.
-
-    """
-    def __init__(self):
-        self.patchers = [
-            mock.patch('framework.test.glsl_parser_test._HAS_GL_BIN', True),
-            mock.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', True),
-            mock.patch.dict('framework.test.opengl.OPTIONS.env', {'PIGLIT_PLATFORM': 'foo'}),
-        ]
-
-    def setup(self):
-        for p in self.patchers:
-            p.start()
-
-    def teardown(self):
-        for p in self.patchers:
-            p.stop()
-
-
-_setup = _Setup()
-setup = _setup.setup
-teardown = _setup.teardown
-
-
-def _check_config(content):
-    """ This is the test that actually checks the glsl config section """
-    with utils.nose.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.nose.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")
-
-
- at 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.nose.tempfile(content) as tfile:
-        glsl.GLSLParserTest(tfile)
-
-
- at 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.nose.tempfile('// [config]\n') as tfile:
-        glsl.GLSLParserTest(tfile)
-
-
- at 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.nose.tempfile(content) as tfile:
-        glsl.GLSLParserTest(tfile)
-
-
- at 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.nose.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.nose.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)
-
-
- at 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
-
-
- at 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.nose.tempfile(content) as tfile:
-        glsl.GLSLParserTest(tfile)
-
-
- at utils.nose.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)
-
-
- at 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.nose.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
-
-
- at 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 separating 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.nose.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
-
-
- at utils.nose.generator
-def test_good_extensions():
-    """ Generates tests with good extensions which shouldn't raise errors """
-
-    @utils.nose.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.nose.tempfile(test) as tfile:
-            yield check_good_extension, tfile
-
-
- at utils.nose.generator
-def test_get_glslparsertest_gles2():
-    """GLSLParserTest: gets gles2 binary if glsl is 1.00 or 3.00"""
-    def test(content, expected):
-        with utils.nose.tempfile(content) as f:
-            t = glsl.GLSLParserTest(f)
-            nt.eq_(os.path.basename(t.command[0]), expected)
-
-    content = textwrap.dedent("""\
-        /*
-         * [config]
-         * expect_result: pass
-         * glsl_version: {}
-         * [end config]
-         */
-        """)
-    versions = ['1.00', '3.00', '3.10', '3.20', '3.00 es', '3.10 es',
-                '3.20 es']
-    description = ("test.glsl_parser_test.GLSLParserTest: "
-                   "gets gles2 binary if glsl is '{}' and gles2 binary exists")
-
-    for version in versions:
-        test.description = description.format(version)
-        yield test, content.format(version), 'glslparsertest_gles2'
-
-    description = ("test.glsl_parser_test.GLSLParserTest: "
-                   "gets gl binary if glsl is '{}' and gles2 binary doesn't exist")
-
-    with mock.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', False):
-        for version in versions:
-            test.description = description.format(version)
-            yield test, content.format(version), 'glslparsertest'
-
-    description = ("test.glsl_parser_test.GLSLParserTest: "
-                   "gets gl binary if glsl is '{}' and "
-                   "PIGLIT_FORCE_GLSLPARSER_DESKTOP is true")
-
-    with mock.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', False):
-        with mock.patch('framework.test.glsl_parser_test._FORCE_DESKTOP_VERSION', True):
-            for version in versions:
-                test.description = description.format(version)
-                yield test, content.format(version), 'glslparsertest'
-
-
-def test_set_glsl_version():
-    """test.glsl_parser_test.GLSLParserTest: sets glsl_version"""
-    rt = {'glsl_version': '4.3'}
-    with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__parser',
-                           mock.Mock(return_value=rt)):
-        with mock.patch.object(glsl.GLSLParserTest,
-                               '_GLSLParserTest__get_command',
-                               return_value=['foo']):
-            with mock.patch('framework.test.glsl_parser_test.io.open',
-                            mock.mock_open()):
-                with mock.patch('framework.test.glsl_parser_test.os.stat',
-                                mock.mock_open()):
-                    test = glsl.GLSLParserTest('foo')
-    nt.eq_(test.glsl_version, 4.3)
-
-
-def test_set_glsl_es_version():
-    """test.glsl_parser_test.GLSLParserTest: sets glsl_es_version"""
-    rt = {'glsl_version': '3.00 es'}
-    with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__parser',
-                           mock.Mock(return_value=rt)):
-        with mock.patch.object(glsl.GLSLParserTest,
-                               '_GLSLParserTest__get_command',
-                               return_value=['foo']):
-            with mock.patch('framework.test.glsl_parser_test.io.open',
-                            mock.mock_open()):
-                with mock.patch('framework.test.glsl_parser_test.os.stat',
-                                mock.mock_open()):
-                    test = glsl.GLSLParserTest('foo')
-    nt.eq_(test.glsl_es_version, 3.0)
-
-
-def test_set_gl_required():
-    """test.glsl_parser_test.GLSLParserTest: sets gl_required"""
-    rt = {'require_extensions': 'GL_ARB_foobar GL_EXT_foobar'}
-    with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__parser',
-                           mock.Mock(return_value=rt)):
-        with mock.patch.object(glsl.GLSLParserTest,
-                               '_GLSLParserTest__get_command',
-                               return_value=['foo']):
-            with mock.patch('framework.test.glsl_parser_test.io.open',
-                            mock.mock_open()):
-                with mock.patch('framework.test.glsl_parser_test.os.stat',
-                                mock.mock_open()):
-                    test = glsl.GLSLParserTest('foo')
-    nt.eq_(test.gl_required, set(['GL_ARB_foobar', 'GL_EXT_foobar']))
-
-
-def test_set_exclude_gl_required():
-    """test.glsl_parser_test.GLSLParserTest: doesn't add excludes to gl_required"""
-    rt = {'require_extensions': 'GL_ARB_foobar !GL_EXT_foobar'}
-    with mock.patch.object(glsl.GLSLParserTest, '_GLSLParserTest__parser',
-                           mock.Mock(return_value=rt)):
-        with mock.patch.object(glsl.GLSLParserTest,
-                               '_GLSLParserTest__get_command',
-                               return_value=['foo']):
-            with mock.patch('framework.test.glsl_parser_test.io.open',
-                            mock.mock_open()):
-                with mock.patch('framework.test.glsl_parser_test.os.stat',
-                                mock.mock_open()):
-                    test = glsl.GLSLParserTest('foo')
-    nt.eq_(test.gl_required, set(['GL_ARB_foobar']))
-
-
- at mock.patch('framework.test.glsl_parser_test._HAS_GL_BIN', False)
- at nt.raises(TestIsSkip)
-def test_binary_skip():
-    """test.glsl_parser_test.GLSLParserTest.is_skip: skips OpenGL tests when not built with desktop support"""
-    content = textwrap.dedent("""\
-        /*
-         * [config]
-         * expect_result: pass
-         * glsl_version: 1.10
-         * [end config]
-         */
-        """)
-
-    with utils.nose.tempfile(content) as f:
-        test = glsl.GLSLParserTest(f)
-        test.is_skip()
-
-
- at utils.nose.generator
-def test_add_compatability():
-    """test.glsl_parser_test.GLSLParserTest: Adds ARB_ES<ver>_COMPATIBILITY
-    when shader is gles but only gl is available"""
-    content = textwrap.dedent("""\
-        /*
-         * [config]
-         * expect_result: pass
-         * glsl_version: {}
-         * require_extensions: GL_ARB_ham_sandwhich
-         * [end config]
-         */
-        """)
-
-    @mock.patch('framework.test.glsl_parser_test._HAS_GLES_BIN', False)
-    def test(ver, expected):
-        with utils.nose.tempfile(content.format(ver)) as f:
-            test = glsl.GLSLParserTest(f)
-        nt.assert_in(expected, test.gl_required)
-
-    desc = ('test.glsl_parser_test.GLSLParserTest: Add {} to gl_extensions '
-            'for GLES tests on OpenGL')
-
-    vers = [
-        ('1.00', 'ARB_ES2_compatibility'),
-        ('3.00', 'ARB_ES3_compatibility'),
-        ('3.10', 'ARB_ES3_1_compatibility'),
-        ('3.20', 'ARB_ES3_2_compatibility'),
-    ]
-
-    for ver, expected in vers:
-        test.description = desc.format(expected)
-        yield test, ver, expected
-- 
2.9.0



More information about the Piglit mailing list