[Piglit] [PATCH 2/6] all.py: filter directories traversed to find shader tests

Brian Paul brianp at vmware.com
Fri Oct 13 04:23:06 UTC 2017

The script searches all files under tests/ and generated_tests/ for
files ending in ".shader_test".  For each match, a ShaderTest() object
is created and added to the test list.

For GL extensions or versions not supported by the driver, this is
wasted effort.

This patch looks for directories under spec/ and tries to determine if
the extension/feature is actually supported by the current driver.  If
not, it's skipped.

This somewhat reduces Piglit start up time, but substantially more
time is spent in the ShaderTest() constructor which actually opens
and parses each file to determine its GL/ES dependencies.  I'll try
to address that in the future.
 tests/all.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/tests/all.py b/tests/all.py
index 54346d4..8c9e33d 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -8,11 +8,12 @@ import collections
 import itertools
 import os
 import platform
+import re
 import six
 from six.moves import range
 from framework import grouptools
+from framework.test import opengl
 from framework import options
 from framework.profile import TestProfile
 from framework.driver_classifier import DriverClassifier
@@ -204,16 +205,68 @@ def power_set(s):
         result.append(p + [s[-1]])
     return result
+def gl_extension_supported(extName):
+    """Is the named OpenGL extension supported?"""
+    return extName in wfl_info.gl_extensions
+def is_feature_directory_supported(dirName):
+    """Determine if dirName specifies an OpenGL feature (extension or GL
+    version) which is supported by the host.  If we return False, it means
+    the extension/version is definitely not supported.  If we return True,
+    it means the extension/version is possibly suppported.  We're a little
+    fuzzy because we don't yet parse all the directory name possibilities
+    (like ES tests).
+    """
+    if dirName[0:4] in { "amd_", "arb_", "ati_", "ext_", "khr_", "oes_" }:
+        # The directory is a GL extension name, but of the format "arb_foo_bar"
+        # instead of "GL_ARB_foo_bar".  We convert the former into the later
+        # and check if the extension is supported.
+        extName = "GL_" + dirName[0:4].upper() + dirName[4:]
+        return gl_extension_supported(extName)
+    elif re.match("gl-\d\.\d+", dirName[0:3]):
+        # The directory is a GL version
+        version = dirName[3:]
+        return float(version) <= float(wfl_info.gl_version)
+    elif re.match("glsl-\d\.\d+", dirName[0:5]):
+        # The directory is a GLSL version
+        version = dirName[5:]
+        return float(version) <= float(wfl_info.glsl_version)
+    else:
+        # The directory is something else.  Don't skip it.
+        return True
+def filter_directories(dirPath, dirNames):
+    """Examine the dirNames under dirPath.  If the a dirName corresponds
+    to an OpenGL feature/version, check if it's supported by the OpenGL
+    driver.  If it's not, remove it from the directory list.
+    This is used to prune the directory search for *.shader_runner, etc.
+    files.
+    """
+    lastPart = os.path.split(dirPath)[-1]
+    if lastPart == "spec":
+        for dir in dirNames:
+            if not is_feature_directory_supported(dir):
+                print("Skipping spec/%s" % dir)
+                dirNames.remove(dir)
 # Collecting all tests
 profile = TestProfile()  # pylint: disable=invalid-name
 shader_tests = collections.defaultdict(list)
+wfl_info = opengl.WflInfo()
 # Find and add all shader tests.
-    for dirpath, _, filenames in os.walk(basedir):
+    for dirpath, dirnames, filenames in os.walk(basedir):
         groupname = grouptools.from_path(os.path.relpath(dirpath, basedir))
+        filter_directories(dirpath, dirnames)
         for filename in filenames:
             testname, ext = os.path.splitext(filename)
             if ext == '.shader_test':

More information about the Piglit mailing list