glsl-1.30: add more loop unroll tests
[piglit.git] / tests / shader.py
blobe6e65d1ba791939bd8eb98b6081a4df2e58feb7f
1 # coding=utf-8
2 """A profile that runs only ShaderTest instances."""
4 import collections
5 import os
7 from framework.options import OPTIONS
8 from framework import grouptools
9 from framework.profile import TestProfile
10 from framework.test.shader_test import ShaderTest, MultiShaderTest
11 from .py_modules.constants import GENERATED_TESTS_DIR, TESTS_DIR
13 __all__ = ['profile']
15 profile = TestProfile()
17 shader_tests = collections.defaultdict(list)
19 # Find and add all shader tests.
20 basepath = os.path.normpath(os.path.join(TESTS_DIR, '..'))
21 gen_basepath = os.path.relpath(os.path.join(GENERATED_TESTS_DIR, '..'), basepath)
23 for basedir in [TESTS_DIR, GENERATED_TESTS_DIR]:
24 isgenerated = basedir == GENERATED_TESTS_DIR
25 for dirpath, _, filenames in os.walk(basedir):
26 groupname = grouptools.from_path(os.path.relpath(dirpath, basedir))
27 for filename in filenames:
28 testname, ext = os.path.splitext(filename)
29 if ext == '.shader_test':
30 dirname = os.path.relpath(dirpath, basepath)
31 filepath = os.path.join(dirname, filename)
32 if isgenerated:
33 installpath = os.path.relpath(filepath, gen_basepath)
34 else:
35 installpath = None
37 if OPTIONS.process_isolation:
38 test = ShaderTest.new(filepath, installpath)
39 else:
40 shader_tests[groupname].append((filepath, installpath))
41 continue
42 else:
43 continue
45 group = grouptools.join(groupname, testname)
46 assert group not in profile.test_list, group
48 profile.test_list[group] = test
50 # Because we need to handle duplicate group names in TESTS and GENERATED_TESTS
51 # this dictionary is constructed, then added to the actual test dictionary.
52 for group, files in shader_tests.items():
53 assert group not in profile.test_list, 'duplicate group: {}'.format(group)
55 # This makes the xml output reproducible, as os.walk() order is random
56 files.sort()
57 # We'll end up with a list of tuples, split that into two list
58 files, installedfiles = list(zip(*files))
59 files = list(files)
60 installedfiles = list(installedfiles)
62 # If there is only one file in the directory use a normal shader_test.
63 # Otherwise use a MultiShaderTest
64 if len(files) == 1:
65 group = grouptools.join(
66 group, os.path.basename(os.path.splitext(files[0])[0]))
67 profile.test_list[group] = ShaderTest.new(files[0], installedfiles[0])
68 else:
69 if all(i is None for i in installedfiles):
70 installedfiles = None
71 else:
72 for i, n in enumerate(installedfiles):
73 if n is None:
74 installedfiles[i] = files[i]
76 profile.test_list[group] = MultiShaderTest.new(files, installedfiles)