[Piglit] [PATCH 09/12] framework: merge shadertest into exectest
Dylan Baker
baker.dylan.c at gmail.com
Fri Apr 25 09:58:57 PDT 2014
This has all of the same advantages as merging GLSLParserTest did.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/exectest.py | 93 +++++++++++++++++++++++++++
framework/shader_test.py | 121 -----------------------------------
framework/tests/dmesg_tests.py | 3 +-
framework/tests/exectest_test.py | 57 +++++++++++++++++
framework/tests/shader_test_tests.py | 83 ------------------------
tests/all.py | 3 +-
6 files changed, 152 insertions(+), 208 deletions(-)
delete mode 100644 framework/shader_test.py
delete mode 100644 framework/tests/shader_test_tests.py
diff --git a/framework/exectest.py b/framework/exectest.py
index 5f3a9ac..ec4f724 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -39,8 +39,12 @@ __all__ = ['Test',
'GleanTest',
'GLSLParserTest',
'GLSLParserException',
+ 'ShaderTest',
+ 'ShaderTestParserException',
'add_glsl_parser_test',
'import_glsl_parser_tests',
+ 'add_shader_test',
+ 'add_shader_test_dir',
'TEST_BIN_DIR']
# Platform global variables
@@ -416,6 +420,65 @@ class GLSLParserException(Exception):
pass
+class ShaderTest(PiglitTest):
+ """ Parse a shader test file and return a PiglitTest instance
+
+ This function parses a shader test to determine if it's a GL, GLES2 or
+ GLES3 test, and then returns a PiglitTest setup properly.
+
+ """
+ def __init__(self, arguments):
+ is_gl = re.compile(r'GL (<|<=|=|>=|>) \d\.\d')
+ # Iterate over the lines in shader file looking for the config section.
+ # By using a generator this can be split into two for loops at minimal
+ # cost. The first one looks for the start of the config block or raises
+ # an exception. The second looks for the GL version or raises an
+ # exception
+ with open(arguments, 'r') as shader_file:
+ lines = (l for l in shader_file)
+
+ # Find the config section
+ for line in lines:
+ # We need to find the first line of the configuration file, as
+ # soon as we do then we can move on to geting the
+ # configuration. The first line needs to be parsed by the next
+ # block.
+ if line.lstrip().startswith('[require]'):
+ break
+ else:
+ raise ShaderTestParserException("Config block not found")
+
+ # Find the OpenGL API to use
+ for line in lines:
+ line = line.strip()
+ if line.startswith('GL ES'):
+ if line.endswith('3.0'):
+ prog = path.join(TEST_BIN_DIR, 'shader_runner_gles3')
+ elif line.endswith('2.0'):
+ prog = path.join(TEST_BIN_DIR, 'shader_runner_gles2')
+ # If we don't set gles2 or gles3 continue the loop,
+ # probably htting the exception in the for/else
+ else:
+ raise ShaderTestParserException("No GL ES version set")
+ break
+ elif line.startswith('[') or is_gl.match(line):
+ # In the event that we reach the end of the config black
+ # and an API hasn't been found, it's an old test and uses
+ # "GL"
+ prog = path.join(TEST_BIN_DIR, 'shader_runner')
+ break
+ else:
+ raise ShaderTestParserException("No GL version set")
+
+ super(ShaderTest, self).__init__([prog, arguments, '-auto'],
+ run_concurrent=True)
+
+
+class ShaderTestParserException(Exception):
+ """ An excpetion to be raised for errors in the ShaderTest parser """
+ pass
+
+
def add_glsl_parser_test(group, filepath, test_name):
"""Add an instance of GLSLParserTest to the given group."""
group[test_name] = GLSLParserTest(filepath)
@@ -451,3 +514,33 @@ def import_glsl_parser_tests(group, basepath, subdirectories):
testname = testname.replace(os.path.sep, '/', -1)
assert isinstance(testname, basestring)
add_glsl_parser_test(group, filepath, testname)
+
+
+def add_shader_test(group, testname, filepath):
+ """ Add a shader test to a group
+
+ Arguments:
+ group -- a dictionary-like object to add the test to
+ testname -- the key to use in the group
+ filepath -- the argument to pass to ShaderTest
+
+ """
+ group[testname] = ShaderTest(filepath)
+
+
+def add_shader_test_dir(group, dirpath, recursive=False):
+ """Add all shader tests in a directory to the given group."""
+ for filename in os.listdir(dirpath):
+ filepath = path.join(dirpath, filename)
+ if path.isdir(filepath):
+ if not recursive:
+ continue
+ if not filename in group:
+ group[filename] = {}
+ add_shader_test_dir(group[filename], filepath, recursive)
+ else:
+ ext = filename.rsplit('.')[-1]
+ if ext != 'shader_test':
+ continue
+ testname = filename[0:-(len(ext) + 1)] # +1 for '.'
+ add_shader_test(group, testname, filepath)
diff --git a/framework/shader_test.py b/framework/shader_test.py
deleted file mode 100644
index 0083072..0000000
--- a/framework/shader_test.py
+++ /dev/null
@@ -1,121 +0,0 @@
-# Copyright (C) 2012, 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:
-#
-# 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 AUTHOR(S) 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.
-
-""" This module enables running shader tests. """
-
-import os
-import os.path as path
-import re
-
-from .exectest import PiglitTest, TEST_BIN_DIR
-
-__all__ = ['add_shader_test', 'add_shader_test_dir']
-
-
-class ShaderTest(PiglitTest):
- """ Parse a shader test file and return a PiglitTest instance
-
- This function parses a shader test to determine if it's a GL, GLES2 or
- GLES3 test, and then returns a PiglitTest setup properly.
-
- """
- def __init__(self, arguments):
- is_gl = re.compile(r'GL (<|<=|=|>=|>) \d\.\d')
- # Iterate over the lines in shader file looking for the config section.
- # By using a generator this can be split into two for loops at minimal
- # cost. The first one looks for the start of the config block or raises
- # an exception. The second looks for the GL version or raises an
- # exception
- with open(arguments, 'r') as shader_file:
- lines = (l for l in shader_file)
-
- # Find the config section
- for line in lines:
- # We need to find the first line of the configuration file, as
- # soon as we do then we can move on to geting the
- # configuration. The first line needs to be parsed by the next
- # block.
- if line.lstrip().startswith('[require]'):
- break
- else:
- raise ShaderTestParserException("Config block not found")
-
- # Find the OpenGL API to use
- for line in lines:
- line = line.strip()
- if line.startswith('GL ES'):
- if line.endswith('3.0'):
- prog = path.join(TEST_BIN_DIR, 'shader_runner_gles3')
- elif line.endswith('2.0'):
- prog = path.join(TEST_BIN_DIR, 'shader_runner_gles2')
- # If we don't set gles2 or gles3 continue the loop,
- # probably htting the exception in the for/else
- else:
- raise ShaderTestParserException("No GL ES version set")
- break
- elif line.startswith('[') or is_gl.match(line):
- # In the event that we reach the end of the config black
- # and an API hasn't been found, it's an old test and uses
- # "GL"
- prog = path.join(TEST_BIN_DIR, 'shader_runner')
- break
- else:
- raise ShaderTestParserException("No GL version set")
-
- super(ShaderTest, self).__init__([prog, arguments, '-auto'],
- run_concurrent=True)
-
-
-class ShaderTestParserException(Exception):
- """ An excpetion to be raised for errors in the ShaderTest parser """
- pass
-
-
-def add_shader_test(group, testname, filepath):
- """ Add a shader test to a group
-
- Arguments:
- group -- a dictionary-like object to add the test to
- testname -- the key to use in the group
- filepath -- the argument to pass to ShaderTest
-
- """
- group[testname] = ShaderTest(filepath)
-
-
-def add_shader_test_dir(group, dirpath, recursive=False):
- """Add all shader tests in a directory to the given group."""
- for filename in os.listdir(dirpath):
- filepath = path.join(dirpath, filename)
- if path.isdir(filepath):
- if not recursive:
- continue
- if not filename in group:
- group[filename] = {}
- add_shader_test_dir(group[filename], filepath, recursive)
- else:
- ext = filename.rsplit('.')[-1]
- if ext != 'shader_test':
- continue
- testname = filename[0:-(len(ext) + 1)] # +1 for '.'
- add_shader_test(group, testname, filepath)
diff --git a/framework/tests/dmesg_tests.py b/framework/tests/dmesg_tests.py
index 2456384..3f463b2 100644
--- a/framework/tests/dmesg_tests.py
+++ b/framework/tests/dmesg_tests.py
@@ -28,7 +28,6 @@ from nose.plugins.skip import SkipTest
from framework.dmesg import DummyDmesg, LinuxDmesg, get_dmesg, DmesgError
from framework.core import TestResult, PiglitJSONEncoder
import framework.exectest as exectest
-from framework.shader_test import ShaderTest
def _get_dmesg():
@@ -229,7 +228,7 @@ def test_testclasses_dmesg():
""" Generator that creates tests for """
lists = [(exectest.PiglitTest, ['attribs', '-auto', '-fbo'], 'PiglitTest'),
(exectest.GleanTest, 'basic', "GleanTest"),
- (ShaderTest, 'tests/shaders/loopfunc.shader_test',
+ (exectest.ShaderTest, 'tests/shaders/loopfunc.shader_test',
'ShaderTest'),
(exectest.GLSLParserTest, 'tests/glslparsertest/shaders/main1.vert',
'GLSLParserTest')]
diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py
index b68eb21..0543f5b 100644
--- a/framework/tests/exectest_test.py
+++ b/framework/tests/exectest_test.py
@@ -203,3 +203,60 @@ def test_blank_in_config():
def test_glslparser_initializer():
""" GLSLParserTest initializes """
exectest.GLSLParserTest('tests/spec/glsl-es-1.00/compiler/version-macro.frag')
+
+
+def test_initialize_shader_test():
+ """ Test that ShaderTest initializes """
+ exectest.ShaderTest('tests/spec/glsl-es-1.00/execution/sanity.shader_test')
+
+
+def test_parse_gl_test_no_decimal():
+ """ The GL Parser raises an exception if GL version lacks decimal """
+ data = ('[require]\n'
+ 'GL = 2\n')
+ with utils.with_tempfile(data) as temp:
+ with nt.assert_raises(exectest.ShaderTestParserException) as exc:
+ exectest.ShaderTest(temp)
+ nt.assert_equal(exc.exception, "No GL version set",
+ msg="A GL version was passed without a decimal, "
+ "which should have raised an exception, but "
+ "did not")
+
+
+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 utils.with_tempfile(data) as temp:
+ test = exectest.ShaderTest(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 utils.with_tempfile(data) as temp:
+ test = exectest.ShaderTest(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 """
+ exectest.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 """
+ exectest.add_shader_test_dir({}, 'tests/spec/glsl-es-3.00/execution')
diff --git a/framework/tests/shader_test_tests.py b/framework/tests/shader_test_tests.py
deleted file mode 100644
index 6600dee..0000000
--- a/framework/tests/shader_test_tests.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# 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 nose.tools as nt
-import framework.shader_test as shader_test
-import framework.tests.utils as utils
-
-
-def test_initialize_shader_test():
- """ Test that ShaderTest initializes """
- shader_test.ShaderTest('tests/spec/glsl-es-1.00/execution/sanity.shader_test')
-
-
-def test_parse_gl_test_no_decimal():
- """ The GL Parser raises an exception if GL version lacks decimal """
- data = ('[require]\n'
- 'GL = 2\n')
- with utils.with_tempfile(data) as temp:
- with nt.assert_raises(shader_test.ShaderTestParserException) as exc:
- shader_test.ShaderTest(temp)
- nt.assert_equal(exc.exception, "No GL version set",
- msg="A GL version was passed without a decimal, "
- "which should have raised an exception, but "
- "did not")
-
-
-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 utils.with_tempfile(data) as temp:
- test = shader_test.ShaderTest(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 utils.with_tempfile(data) as temp:
- test = shader_test.ShaderTest(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')
diff --git a/tests/all.py b/tests/all.py
index 179ad0e..cee345d 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -11,8 +11,7 @@ import shlex
from framework.profile import TestProfile
from framework.exectest import (PiglitTest, GleanTest, add_glsl_parser_test,
- import_glsl_parser_tests)
-from framework.shader_test import add_shader_test_dir
+ import_glsl_parser_tests, add_shader_test_dir)
# Path to tests dir, correct even when not running from the top directory.
testsDir = path.dirname(__file__)
--
2.0.0.rc0
More information about the Piglit
mailing list