2 """A profile that runs only ShaderTest instances."""
4 from __future__
import (
5 absolute_import
, division
, print_function
, unicode_literals
10 from six
.moves
import zip
13 from framework
.options
import OPTIONS
14 from framework
import grouptools
15 from framework
.profile
import TestProfile
16 from framework
.test
.shader_test
import ShaderTest
, MultiShaderTest
17 from .py_modules
.constants
import GENERATED_TESTS_DIR
, TESTS_DIR
21 profile
= TestProfile()
23 shader_tests
= collections
.defaultdict(list)
25 # Find and add all shader tests.
26 basepath
= os
.path
.normpath(os
.path
.join(TESTS_DIR
, '..'))
27 gen_basepath
= os
.path
.relpath(os
.path
.join(GENERATED_TESTS_DIR
, '..'), basepath
)
29 for basedir
in [TESTS_DIR
, GENERATED_TESTS_DIR
]:
30 isgenerated
= basedir
== GENERATED_TESTS_DIR
31 for dirpath
, _
, filenames
in os
.walk(basedir
):
32 groupname
= grouptools
.from_path(os
.path
.relpath(dirpath
, basedir
))
33 for filename
in filenames
:
34 testname
, ext
= os
.path
.splitext(filename
)
35 if ext
== '.shader_test':
36 dirname
= os
.path
.relpath(dirpath
, basepath
)
37 filepath
= os
.path
.join(dirname
, filename
)
39 installpath
= os
.path
.relpath(filepath
, gen_basepath
)
43 if OPTIONS
.process_isolation
:
44 test
= ShaderTest
.new(filepath
, installpath
)
46 shader_tests
[groupname
].append((filepath
, installpath
))
51 group
= grouptools
.join(groupname
, testname
)
52 assert group
not in profile
.test_list
, group
54 profile
.test_list
[group
] = test
56 # Because we need to handle duplicate group names in TESTS and GENERATED_TESTS
57 # this dictionary is constructed, then added to the actual test dictionary.
58 for group
, files
in six
.iteritems(shader_tests
):
59 assert group
not in profile
.test_list
, 'duplicate group: {}'.format(group
)
61 # We'll end up with a list of tuples, split that into two lists
62 files
, installedfiles
= list(zip(*files
))
64 installedfiles
= list(installedfiles
)
66 # If there is only one file in the directory use a normal shader_test.
67 # Otherwise use a MultiShaderTest
69 group
= grouptools
.join(
70 group
, os
.path
.basename(os
.path
.splitext(files
[0])[0]))
71 profile
.test_list
[group
] = ShaderTest
.new(files
[0], installedfiles
[0])
73 if all(i
is None for i
in installedfiles
):
76 for i
, n
in enumerate(installedfiles
):
78 installedfiles
[i
] = files
[i
]
80 profile
.test_list
[group
] = MultiShaderTest
.new(files
, installedfiles
)