run.py 3.4 KB
Newer Older
1
#!/usr/bin/env python3
2 3

import re
Dylan Baker's avatar
Dylan Baker committed
4 5 6
import sys
import os
import time
7
import argparse
8
import subprocess
9 10
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import cpu_count
11

12

13 14 15 16 17 18 19
def process_directories(items):
    for item in items:
        if os.path.isfile(item):
            yield item
        else:
            for dirpath, _, filenames in os.walk(item):
                for fname in filenames:
20
                    if os.path.splitext(fname)[1] == '.shader_test':
21
                        yield os.path.join(dirpath, fname)
22

23

24
def run_test(filename):
25 26 27
    if ".out" in filename:
        return ""

28 29
    timebefore = time.time()

30 31
    try:
        p = subprocess.Popen(
32
            ['./bin/shader_runner', filename, '-auto', '-fbo'],
33
            stdout=subprocess.PIPE,
34
            stderr=subprocess.PIPE)
35
        (stdout, stderr) = p.communicate()
36
        results = (stdout + stderr).decode("utf-8")
37 38 39
    except KeyboardInterrupt:
        exit(1)
    except:
40
        return filename + " FAIL\n"
41

42 43
    timeafter = time.time()

44 45 46 47
    with open(filename + '.out', 'w') as file:
        file.write(results)

    counts = {}
48 49 50

    lines = (line for line in results.splitlines())
    re_number = re.compile(
51
        r'Native code for (unnamed )?(fragment|vertex|geometry|tessellation control|tessellation evaluation|compute) shader (GLSL|ARB)(?P<number>\d+)')
52
    for line in lines:
53 54 55 56 57 58 59
        shader = re_number.match(line)
        if shader and int(shader.group('number')) > 0:
            break
    else:
        raise Exception('Only shader 0 found. {}'.format(filename))

    re_search = re.compile(
60
        r'(?P<stage>[A-Za-z0-9]+) (vec4 )?shader\: (?P<count>\d+) instructions.')
61 62 63 64 65 66
    for line in lines:
        match = re_search.match(line)
        if match is not None:
            counts[match.group('stage')] = int(match.group('count'))

    assert counts, 'File: {} does not have any shaders'.format(filename)
67

Eric Anholt's avatar
Eric Anholt committed
68
    timestr = "    {:.3f} secs".format(timeafter - timebefore)
69
    out = ''
70 71 72
    for k, v in counts.items():
        if v != 0:
            out += "{0:40} {1} : {2:6}{3}\n".format(filename, k, v, timestr)
73
            timestr = ""
74
    return out
75

76

77
def main():
78 79 80 81 82 83 84 85
    parser = argparse.ArgumentParser()
    parser.add_argument("shader",
                        nargs='*',
                        default=['shaders'],
                        metavar="<shader_file | shader dir>",
                        help="A shader file or directory containing shader "
                             "files. Defaults to 'shaders/'")
    args = parser.parse_args()
86

87 88
    os.environ["shader_precompile"] = "true"
    os.environ["allow_glsl_extension_directive_midshader"] = "true"
89
    os.environ["PIGLIT_PLATFORM"] = "gbm"
90 91
    if "INTEL_DEBUG" in os.environ:
        print("Warning: INTEL_DEBUG environment variable set!", file=sys.stderr)
92
        os.environ["INTEL_DEBUG"] += ",vs,gs,fs,tcs,tes,cs"
93
    else:
94
        os.environ["INTEL_DEBUG"] = "vs,gs,fs,tcs,tes,cs"
95

96
    try:
97
        os.stat("bin/shader_runner")
98
    except OSError:
99 100 101
        print("./bin must be a symlink to a built piglit bin directory")
        sys.exit(1)

102 103
    runtimebefore = time.time()

104
    filenames = process_directories(args.shader)
105

106
    executor = ThreadPoolExecutor(cpu_count())
107
    for t in executor.map(run_test, filenames):
108
        sys.stdout.write(t)
109

110
    runtime = time.time() - runtimebefore
111
    print("shader-db run completed in {:.1f} secs".format(runtime))
112

113

114
if __name__ == "__main__":
115
    main()