shader.py 2.84 KB
Newer Older
1 2
"""A profile that runs only ShaderTest instances."""

3 4 5
from __future__ import (
    absolute_import, division, print_function, unicode_literals
)
Dylan Baker's avatar
Dylan Baker committed
6 7
import collections
import os
8

9
from six.moves import zip
Dylan Baker's avatar
Dylan Baker committed
10 11 12 13 14
import six

from framework.options import OPTIONS
from framework import grouptools
from framework.profile import TestProfile
15
from framework.test.shader_test import ShaderTest, MultiShaderTest
Dylan Baker's avatar
Dylan Baker committed
16
from .py_modules.constants import GENERATED_TESTS_DIR, TESTS_DIR
17 18 19

__all__ = ['profile']

Dylan Baker's avatar
Dylan Baker committed
20 21 22 23 24 25
profile = TestProfile()

shader_tests = collections.defaultdict(list)

# Find and add all shader tests.
basepath = os.path.normpath(os.path.join(TESTS_DIR, '..'))
26 27
gen_basepath = os.path.relpath(os.path.join(GENERATED_TESTS_DIR, '..'), basepath)

Dylan Baker's avatar
Dylan Baker committed
28
for basedir in [TESTS_DIR, GENERATED_TESTS_DIR]:
29
    isgenerated = basedir == GENERATED_TESTS_DIR
Dylan Baker's avatar
Dylan Baker committed
30 31 32 33 34 35
    for dirpath, _, filenames in os.walk(basedir):
        groupname = grouptools.from_path(os.path.relpath(dirpath, basedir))
        for filename in filenames:
            testname, ext = os.path.splitext(filename)
            if ext == '.shader_test':
                dirname = os.path.relpath(dirpath, basepath)
36 37 38 39 40 41
                filepath = os.path.join(dirname, filename)
                if isgenerated:
                    installpath = os.path.relpath(filepath, gen_basepath)
                else:
                    installpath = None

Dylan Baker's avatar
Dylan Baker committed
42
                if OPTIONS.process_isolation:
43
                    test = ShaderTest.new(filepath, installpath)
Dylan Baker's avatar
Dylan Baker committed
44
                else:
45
                    shader_tests[groupname].append((filepath, installpath))
Dylan Baker's avatar
Dylan Baker committed
46 47 48 49 50 51 52 53
                    continue
            else:
                continue

            group = grouptools.join(groupname, testname)
            assert group not in profile.test_list, group

            profile.test_list[group] = test
54

Dylan Baker's avatar
Dylan Baker committed
55 56 57 58
# Because we need to handle duplicate group names in TESTS and GENERATED_TESTS
# this dictionary is constructed, then added to the actual test dictionary.
for group, files in six.iteritems(shader_tests):
    assert group not in profile.test_list, 'duplicate group: {}'.format(group)
59 60 61 62 63 64

    # We'll end up with a list of tuples, split that into two lists
    files, installedfiles = list(zip(*files))
    files = list(files)
    installedfiles = list(installedfiles)

Dylan Baker's avatar
Dylan Baker committed
65 66 67 68 69
    # If there is only one file in the directory use a normal shader_test.
    # Otherwise use a MultiShaderTest
    if len(files) == 1:
        group = grouptools.join(
            group, os.path.basename(os.path.splitext(files[0])[0]))
70
        profile.test_list[group] = ShaderTest.new(files[0], installedfiles[0])
Dylan Baker's avatar
Dylan Baker committed
71
    else:
72 73 74 75 76 77 78 79
        if all(i is None for i in installedfiles):
            installedfiles = None
        else:
            for i, n in enumerate(installedfiles):
                if n is None:
                    installedfiles[i] = files[i]

        profile.test_list[group] = MultiShaderTest.new(files, installedfiles)