summaryrefslogtreecommitdiff
path: root/run.py
blob: 891a5aca4a92d37703bca628ff253d421682ebf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3

from getopt import getopt, GetoptError
import re
import sys, os, time
import subprocess
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import cpu_count

def usage():
    USAGE = """\
Usage: %(progName)s <dir | apitrace.trace>...

Options:
  -h, --help                Show this message
"""
    print(USAGE % {'progName': sys.argv[0]})
    sys.exit(1)

def process_directories(dirpath):
    filenames = set()
    if os.path.isdir(dirpath):
        for filename in os.listdir(dirpath):
            filenames.update(process_directories(os.path.join(dirpath, filename)))
    else:
        filenames.add(dirpath)
    return filenames

def run_test(filename):
    basename = os.path.basename(filename)
    m = re.match('(.*).trace', basename)
    if m is None:
        return ""

    command = ['apitrace',
        'replay',
        '-b',
        filename]

    progname = m.group(1)
    timebefore = time.time()

    out=""

    try:
        p = subprocess.Popen(
            command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (stdout, stderr) = p.communicate()
        results = (stdout + stderr).decode("utf-8")
    except KeyboardInterrupt:
        exit(1)
    except:
        out += 'SHADER-DB: {0}: FAIL'.format(progname)

    timeafter = time.time()

    lines = list(results.split('\n'))
    for line in lines:
        m = re.match("SHADER-DB: (.*)", line)
        if m != None:
            out += 'SHADER-DB: {0}: {1}\n'.format(progname, m.group(1))

    out += 'SHADER-DB: {}: {:.3f} secs\n'.format(progname, timeafter - timebefore)
    return out

def main():
    try:
        option_list = [
            "help",
            ]
        options, args = getopt(sys.argv[1:], "h", option_list)
    except GetoptError:
        usage()

    env_add = {}
    env_add["VC4_DEBUG"] = "shaderdb,norast"
    env_add["force_glsl_extensions_warn"] = "true"

    os.environ.update(env_add)

    for name, value in options:
        if name in ('-h', '--help'):
            usage()

    if len(args) < 1:
        args.append("traces")

    runtimebefore = time.time()

    filenames = set()
    for i in args:
        filenames.update(process_directories(i))

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

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

if __name__ == "__main__":
	main()