[Piglit] [PATCH 03/12] shader_tests_tests.py: Adds some tests for the shader_test module

Dylan Baker baker.dylan.c at gmail.com
Tue Feb 11 18:11:08 PST 2014


This adds a couple of tests for the regex searches in
shader_test.shader_test(), and some simple tests for the
add_shader_test* functions.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/tests/shader_test_tests.py | 99 ++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
 create mode 100644 framework/tests/shader_test_tests.py

diff --git a/framework/tests/shader_test_tests.py b/framework/tests/shader_test_tests.py
new file mode 100644
index 0000000..0aa7d47
--- /dev/null
+++ b/framework/tests/shader_test_tests.py
@@ -0,0 +1,99 @@
+# 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 """
+
+import os
+import tempfile
+from contextlib import contextmanager
+import nose.tools as nt
+import framework.shader_test as shader_test
+
+
+ at contextmanager
+def _tempfile(data):
+    """ Create a temporary file and cleanup afterwards """
+    temp = tempfile.NamedTemporaryFile(delete=False)
+    temp.write(data)
+    temp.close()
+    yield temp.name
+    os.unlink(temp.name)
+
+
+ at nt.raises(KeyError)
+def test_parse_gl_test_no_decimal():
+    """ The GL Parser excepts if GL version lacks decimal """
+    data = ('[require]\n'
+            'GL = 2\n')
+    with _tempfile (data) as temp:
+        test = shader_test.shader_test(temp)
+
+    nt.assert_equal(os.path.basename(test.command[0]), "shader_runner",
+                    msg="This test should have run with shader_runner, "
+                        "but instead ran with " + os.path.basename(test.command[0]))
+
+
+def test_parse_gl_test_no_decimal():
+    """ Test the GL Parser """
+    data = ('[require]\n'
+            'GL = 2.0\n')
+    with _tempfile (data) as temp:
+        test = shader_test.shader_test(temp)
+
+    nt.assert_equal(os.path.basename(test.command[0]), "shader_runner",
+                    msg="This test should have run with shader_runner, "
+                        "but instead ran with " + os.path.basename(test.command[0]))
+
+
+def test_parse_gles2_test():
+    """ Tests the parser for GLES2 tests """
+    data = ('[require]\n'
+            'GL ES >= 2.0\n'
+            'GLSL ES >= 1.00\n')
+    with _tempfile(data) as temp:
+        test = shader_test.shader_test(temp)
+
+    nt.assert_equal(os.path.basename(test.command[0]), "shader_runner_gles2",
+                    msg="This test should have run with shader_runner_gles2, "
+                        "but instead ran with " + os.path.basename(test.command[0]))
+
+
+def test_parse_gles3_test():
+    """ Tests the parser for GLES3 tests """
+    data = ('[require]\n'
+            'GL ES >= 3.0\n'
+            'GLSL ES >= 3.00\n')
+    with _tempfile(data) as temp:
+        test = shader_test.shader_test(temp)
+
+    nt.assert_equal(os.path.basename(test.command[0]), "shader_runner_gles3",
+                    msg="This test should have run with shader_runner_gles3, "
+                        "but instead ran with " + os.path.basename(test.command[0]))
+
+
+def test_add_shader_test():
+    """ Test that add_shader_test works """
+    shader_test.add_shader_test(
+        {}, 'test', 'tests/spec/glsl-es-3.00/execution/sanity.shader_test')
+
+
+def test_add_shader_test_dir():
+    """ Test that add_shader_test_dir works """
+    shader_test.add_shader_test_dir({}, 'tests/spec/glsl-es-3.00/execution')
-- 
1.8.5.4



More information about the Piglit mailing list