[Piglit] [PATCH 10/10] Generate .tests files at build time

Paul Berry stereotype441 at gmail.com
Wed Sep 11 10:41:14 PDT 2013


From: Dylan Baker <baker.dylan.c at gmail.com>

This patch allows testlists to be generated at build time by cmake,
these generated testlist are python TestProfile objects that have been
pickled, a process that converts a python object to a textual
representation of itself. Since this is done using cPickle it is backed
by native code it is very fast.

This is a big win in two ways: first it elimnates any need to parse
through the python test files at the start of every run, since there is
already a testprofile object which is loaded and unpickled, again using
native code, it's very fast.

Second, it creates freedom to change the way the tests are generated,
since all piglit-run.py needs is a valid pickled TestProfile object.
The biggest usecase for this is to replace ``execfile'', since it has
been dropped from python 3.x.

This moves all of the tests/*.tests files to
testlists/(gl|cl|external)/*.tests files.
---

(Paul Berry): Re-sending on Dylan's behalf, since the previous patch
appears to have been too big for the mailing list.  This patch was
generated with "--find-renames", so it's much smaller.

 .gitignore                                         |  1 +
 CMakeLists.txt                                     |  1 +
 __init__.py                                        |  0
 piglit-run.py                                      |  4 +-
 testslist/CMakeLists.txt                           | 43 +++++++++++++++++++++
 testslist/__init__.py                              |  0
 tests/all_cl.tests => testslist/cl/all.py          |  2 +-
 .../external/es3conform.py                         |  0
 tests/gtf.tests => testslist/external/gtf.py       |  0
 tests/igt.tests => testslist/external/igt.py       |  0
 .../external/oglconform.py                         |  0
 testslist/generate_lists.py                        | 44 ++++++++++++++++++++++
 testslist/gl/__init__.py                           |  0
 tests/all.tests => testslist/gl/all.py             | 19 +++++-----
 .../gl/glean-fragProg1.py                          |  0
 .../gl/glean-glsl1.py                              |  0
 .../gl/glean-vertProg1.py                          |  0
 tests/gpu.tests => testslist/gl/gpu.py             |  3 +-
 .../gl/quick-driver.py                             |  4 +-
 tests/quick.tests => testslist/gl/quick.py         |  4 +-
 tests/r300.tests => testslist/gl/r300.py           |  4 +-
 tests/r500.tests => testslist/gl/r500.py           |  4 +-
 tests/sanity.tests => testslist/gl/sanity.py       |  0
 23 files changed, 107 insertions(+), 26 deletions(-)
 create mode 100644 __init__.py
 create mode 100644 testslist/CMakeLists.txt
 create mode 100644 testslist/__init__.py
 rename tests/all_cl.tests => testslist/cl/all.py (98%)
 rename tests/es3conform.tests => testslist/external/es3conform.py (100%)
 rename tests/gtf.tests => testslist/external/gtf.py (100%)
 rename tests/igt.tests => testslist/external/igt.py (100%)
 rename tests/oglconform.tests => testslist/external/oglconform.py (100%)
 create mode 100644 testslist/generate_lists.py
 create mode 100644 testslist/gl/__init__.py
 rename tests/all.tests => testslist/gl/all.py (99%)
 rename tests/glean-fragProg1.tests => testslist/gl/glean-fragProg1.py (100%)
 rename tests/glean-glsl1.tests => testslist/gl/glean-glsl1.py (100%)
 rename tests/glean-vertProg1.tests => testslist/gl/glean-vertProg1.py (100%)
 rename tests/gpu.tests => testslist/gl/gpu.py (94%)
 rename tests/quick-driver.tests => testslist/gl/quick-driver.py (83%)
 rename tests/quick.tests => testslist/gl/quick.py (71%)
 rename tests/r300.tests => testslist/gl/r300.py (76%)
 rename tests/r500.tests => testslist/gl/r500.py (77%)
 rename tests/sanity.tests => testslist/gl/sanity.py (100%)

diff --git a/.gitignore b/.gitignore
index 635a107..3f63fd9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
 *.tar.bz2
 *.zip
 *~
+*.tests
 
 /.ninja_log
 /build.ninja
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a39d9df..4a79f1a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -280,6 +280,7 @@ include(cmake/piglit_dispatch.cmake)
 include_directories(src)
 add_subdirectory(cmake/target_api)
 add_subdirectory(generated_tests)
+add_subdirectory(testslist)
 
 
 ##############################################################################
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/piglit-run.py b/piglit-run.py
index e8e11b7..9c907fe 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -29,6 +29,7 @@ import os.path as path
 import time
 import traceback
 import json
+import cPickle
 
 sys.path.append(path.dirname(path.realpath(sys.argv[0])))
 import framework.core as core
@@ -144,7 +145,8 @@ def main():
     for (key, value) in env.collectData().items():
         json_writer.write_dict_item(key, value)
 
-    profile = core.loadTestProfile(profileFilename)
+    with open(profileFilename, "r") as file:
+        profile = cPickle.load(file)
 
     json_writer.write_dict_key('tests')
     json_writer.open_dict()
diff --git a/testslist/CMakeLists.txt b/testslist/CMakeLists.txt
new file mode 100644
index 0000000..3669a05
--- /dev/null
+++ b/testslist/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Create a custom command to generate pickled python test lists using the
+# generate_python.py file. This is based on ``piglit_make_generated_tests``
+# from generated_tests/CMakeLists.txt
+
+function(pickle_object generate_script tests_file)
+	add_custom_command(
+		OUTPUT ${tests_file}
+		COMMAND ${python} generate_lists.py ${generate_script} ${CMAKE_SOURCE_DIR}/tests/${tests_file}
+		DEPENDS ${generate_script}
+		VERBATIM)
+endfunction(pickle_object generate_script tests_file)
+
+# Piglit Gl tests
+pickle_object(gl/all.py all.tests)
+pickle_object(gl/gpu.py gpu.tests)
+pickle_object(gl/quick-driver.py quick-driver.tests)
+pickle_object(gl/quick.py quick.tests)
+pickle_object(gl/sanity.py sanity.tests)
+pickle_object(gl/r500.py r500.tests)
+pickle_object(gl/r300.py r300.tests)
+
+# Piglit CL tests
+pickle_object(cl/all.py all_cl.tests)
+
+# External tests
+pickle_object(external/igt.py igt.tests)
+pickle_object(external/gtf.py gtf.tests)
+pickle_object(external/es3conform.py es3conform.tests)
+pickle_object(external/oglconform.py oglconform.tests)
+
+add_custom_target(generate-lists ALL
+	DEPENDS all.tests
+	        gpu.tests
+			quick.tests
+			quick-driver.tests
+			sanity.tests
+			r300.tests
+			r500.tests
+			all_cl.tests
+			igt.tests
+			gtf.tests
+			es3conform.tests
+			oglconform.tests)
diff --git a/testslist/__init__.py b/testslist/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/all_cl.tests b/testslist/cl/all.py
similarity index 98%
rename from tests/all_cl.tests
rename to testslist/cl/all.py
index 367319a..9f4f8c2 100644
--- a/tests/all_cl.tests
+++ b/testslist/cl/all.py
@@ -89,7 +89,7 @@ add_plain_test(program, 'Bitcoin: phatk kernel', ['cl-program-bitcoin-phatk'])
 # Program tester
 
 def add_program_test_dir(group, dirpath):
-	for filename in os.listdir(dirpath):
+	for filename in os.listdir(path.join("..", dirpath)):
 		filepath = path.join(dirpath, filename)
 		ext = filename.rsplit('.')[-1]
 		if ext != 'cl' and ext != 'program_test':
diff --git a/tests/es3conform.tests b/testslist/external/es3conform.py
similarity index 100%
rename from tests/es3conform.tests
rename to testslist/external/es3conform.py
diff --git a/tests/gtf.tests b/testslist/external/gtf.py
similarity index 100%
rename from tests/gtf.tests
rename to testslist/external/gtf.py
diff --git a/tests/igt.tests b/testslist/external/igt.py
similarity index 100%
rename from tests/igt.tests
rename to testslist/external/igt.py
diff --git a/tests/oglconform.tests b/testslist/external/oglconform.py
similarity index 100%
rename from tests/oglconform.tests
rename to testslist/external/oglconform.py
diff --git a/testslist/generate_lists.py b/testslist/generate_lists.py
new file mode 100644
index 0000000..fb5f7f3
--- /dev/null
+++ b/testslist/generate_lists.py
@@ -0,0 +1,44 @@
+# Copyright (c) 2013 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 (including the next
+# paragraph) 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.
+
+import sys
+import argparse
+import cPickle
+
+# Allow execfiles to look in the root for imports
+sys.path.append("../")
+
+
+parser = argparse.ArgumentParser()
+parser.add_argument("execfile",
+                    help="The name of the python file to execute")
+parser.add_argument("output",
+                    help="The location to write the file to")
+arguments = parser.parse_args()
+
+# Make the profile object a global object, so it is returned after the file is
+# executed
+global profile
+execfile(arguments.execfile)
+
+# Write the pickled object out to a file
+with open(arguments.output, 'w+') as file:
+    cPickle.dump(profile, file)
diff --git a/testslist/gl/__init__.py b/testslist/gl/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/all.tests b/testslist/gl/all.py
similarity index 99%
rename from tests/all.tests
rename to testslist/gl/all.py
index a8ed99e..c8578a2 100644
--- a/tests/all.tests
+++ b/testslist/gl/all.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 # All tests that come with piglit, using default settings
 
 import itertools
@@ -18,7 +17,7 @@ blacklist = [
 	]
 
 # Path to tests dir, correct even when not running from the top directory.
-testsDir = path.dirname(__file__)
+testsDir = "../tests"
 
 # Find the generated_tests directory, by looking either in
 # $PIGLIT_BUILD_DIR (if that environment variable exists) or in the
@@ -63,13 +62,13 @@ def power_set(s):
 profile = TestProfile()
 
 try:
-    execfile(path.join(testsDir, 'gtf.tests'))
-except SystemExit:
+    execfile('external/gtf.py')
+except (IOError, SystemExit):
     pass
 
 try:
-    execfile(path.join(testsDir, 'es3conform.tests'))
-except SystemExit:
+    execfile('external/es3conform.py')
+except (IOError, SystemExit):
     pass
 
 # List of all of the MSAA sample counts we wish to test
@@ -161,19 +160,19 @@ def add_glsl1(name):
     testname = 'glsl1-' + name
     glean[testname] = GleanTest('glsl1')
     glean[testname].env['PIGLIT_TEST'] = name
-execfile(testsDir + '/glean-glsl1.tests')
+execfile('gl/glean-glsl1.py')
 
 def add_fp1(name):
     testname = 'fp1-' + name
     glean[testname] = GleanTest('fragProg1')
     glean[testname].env['PIGLIT_TEST'] = name
-execfile(testsDir + '/glean-fragProg1.tests')
+execfile('gl/glean-fragProg1.py')
 
 def add_vp1(name):
     testname = 'vp1-' + name
     glean[testname] = GleanTest('vertProg1')
     glean[testname].env['PIGLIT_TEST'] = name
-execfile(testsDir + '/glean-vertProg1.tests')
+execfile('gl/glean-vertProg1.py')
 
 def add_fbo_formats_tests(path, extension, suffix=''):
     profile.tests[path + '/fbo-generatemipmap-formats' + suffix] = PlainExecTest('fbo-generatemipmap-formats -auto ' + extension)
@@ -226,7 +225,7 @@ def add_getactiveuniform_count(group, name, expected):
                                                                expected])
 
 add_shader_test_dir(shaders,
-                    testsDir + '/shaders',
+                    path.join(testsDir, 'shaders'),
                     recursive=True)
 add_plain_test(shaders, 'activeprogram-bad-program')
 add_plain_test(shaders, 'activeprogram-get')
diff --git a/tests/glean-fragProg1.tests b/testslist/gl/glean-fragProg1.py
similarity index 100%
rename from tests/glean-fragProg1.tests
rename to testslist/gl/glean-fragProg1.py
diff --git a/tests/glean-glsl1.tests b/testslist/gl/glean-glsl1.py
similarity index 100%
rename from tests/glean-glsl1.tests
rename to testslist/gl/glean-glsl1.py
diff --git a/tests/glean-vertProg1.tests b/testslist/gl/glean-vertProg1.py
similarity index 100%
rename from tests/glean-vertProg1.tests
rename to testslist/gl/glean-vertProg1.py
diff --git a/tests/gpu.tests b/testslist/gl/gpu.py
similarity index 94%
rename from tests/gpu.tests
rename to testslist/gl/gpu.py
index 3009a08..dc439cd 100644
--- a/tests/gpu.tests
+++ b/testslist/gl/gpu.py
@@ -16,7 +16,7 @@ def add_glsl_parser_test(group, filepath, test_name):
 framework.glsl_parser_test.add_glsl_parser_test = add_glsl_parser_test
 
 
-execfile(os.path.dirname(__file__) + '/quick.tests')
+execfile('gl/quick.py')
 
 # Drop these as they're basically compiler tests and take forever.
 del profile.tests['shaders']['glsl-fs-inline-explosion']
@@ -26,4 +26,3 @@ del profile.tests['shaders']['glsl-vs-unroll-explosion']
 
 # Drop ARB_vertex_program/ARB_fragment_program compiler tests.
 del profile.tests['asmparsertest']
-
diff --git a/tests/quick-driver.tests b/testslist/gl/quick-driver.py
similarity index 83%
rename from tests/quick-driver.tests
rename to testslist/gl/quick-driver.py
index f7c1a0f..89dcd63 100644
--- a/tests/quick-driver.tests
+++ b/testslist/gl/quick-driver.py
@@ -1,10 +1,8 @@
 # -*- coding: utf-8 -*-
 
-import os.path
-
 global profile
 
-execfile(os.path.dirname(__file__) + '/quick.tests')
+execfile('gl/quick.py')
 
 # These take too long
 del profile.tests['shaders']['glsl-fs-inline-explosion']
diff --git a/tests/quick.tests b/testslist/gl/quick.py
similarity index 71%
rename from tests/quick.tests
rename to testslist/gl/quick.py
index 58c5d41..ada534d 100644
--- a/tests/quick.tests
+++ b/testslist/gl/quick.py
@@ -3,11 +3,9 @@
 # Testing drivers for Radeon hardware
 #
 
-import os.path
-
 global profile
 from framework.gleantest import GleanTest
 
 GleanTest.globalParams += [ "--quick" ]
 
-execfile(os.path.dirname(__file__) + '/all.tests')
+execfile('gl/all.py')
diff --git a/tests/r300.tests b/testslist/gl/r300.py
similarity index 76%
rename from tests/r300.tests
rename to testslist/gl/r300.py
index 2c48764..69dab6a 100644
--- a/tests/r300.tests
+++ b/testslist/gl/r300.py
@@ -2,11 +2,9 @@
 # Testing the r300 DRI driver
 #
 
-import os.path
-
 global profile
 
-execfile(os.path.dirname(__file__) + '/quick-driver.tests')
+execfile('gl/quick-driver.py')
 
 # glean/blendFunc
 #   R300 blending hardware appears to be bad
diff --git a/tests/r500.tests b/testslist/gl/r500.py
similarity index 77%
rename from tests/r500.tests
rename to testslist/gl/r500.py
index ebf3173..3e4c68e 100644
--- a/tests/r500.tests
+++ b/testslist/gl/r500.py
@@ -2,11 +2,9 @@
 # Testing the r500 DRI driver
 #
 
-import os.path
-
 global profile
 
-execfile(os.path.dirname(__file__) + '/quick-driver.tests')
+execfile('gl/quick-driver.py')
 
 # glean/blendFunc
 #   R500 blending hardware appears to be a bit better than R300
diff --git a/tests/sanity.tests b/testslist/gl/sanity.py
similarity index 100%
rename from tests/sanity.tests
rename to testslist/gl/sanity.py
-- 
1.8.4



More information about the Piglit mailing list