Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/scripts/run_regression_tests.py
4201 views
1
import argparse
2
import glob
3
import sys
4
import os
5
import subprocess
6
import multiprocessing
7
from functools import partial
8
9
def is_game_path(path:str):
10
lpath = path.lower()
11
for extension in ["cue", "chd", "psxgpu", "psxgpu.zst", "psxgpu.xz"]:
12
if path.endswith(extension):
13
return True
14
return False
15
16
17
def run_regression_test(runner, destdir, dump_interval, frames, renderer, cargs, gamepath):
18
args = [runner,
19
"-log", "error",
20
"-dumpdir", destdir,
21
"-dumpinterval", str(dump_interval),
22
"-frames", str(frames),
23
"-renderer", ("Software" if renderer is None else renderer),
24
]
25
args += cargs
26
args += ["--", gamepath]
27
28
#print("Running '%s'" % (" ".join(args)))
29
subprocess.run(args)
30
return os.path.basename(gamepath)
31
32
33
def run_regression_tests(runner, gamedirs, destdir, dump_interval, frames, parallel, renderer, cargs):
34
paths = []
35
for gamedir in gamedirs:
36
paths += glob.glob(os.path.realpath(gamedir) + "/*.*", recursive=True)
37
gamepaths = list(filter(is_game_path, paths))
38
gamepaths.sort(key=lambda x: os.path.basename(x))
39
40
try:
41
if not os.path.isdir(destdir):
42
os.mkdir(destdir)
43
except OSError:
44
print("Failed to create directory")
45
return False
46
47
print("Found %u games" % len(gamepaths))
48
49
if parallel <= 1:
50
for game in gamepaths:
51
run_regression_test(runner, destdir, dump_interval, frames, renderer, cargs, game)
52
else:
53
print("Processing %u games on %u processors" % (len(gamepaths), parallel))
54
func = partial(run_regression_test, runner, destdir, dump_interval, frames, renderer, cargs)
55
pool = multiprocessing.Pool(parallel)
56
completed = 0
57
for filename in pool.imap_unordered(func, gamepaths, chunksize=1):
58
completed += 1
59
print("[%u%% %u/%u] %s" % ((completed * 100) // len(gamepaths), completed, len(gamepaths), filename))
60
pool.close()
61
62
63
return True
64
65
66
if __name__ == "__main__":
67
parser = argparse.ArgumentParser(description="Generate frame dump images for regression tests")
68
parser.add_argument("-runner", action="store", required=True, help="Path to DuckStation regression test runner")
69
parser.add_argument("-gamedir", action="append", required=True, help="Directory containing game images")
70
parser.add_argument("-destdir", action="store", required=True, help="Base directory to dump frames to")
71
parser.add_argument("-dumpinterval", action="store", type=int, default=600, help="Interval to dump frames at")
72
parser.add_argument("-frames", action="store", type=int, default=36000, help="Number of frames to run")
73
parser.add_argument("-parallel", action="store", type=int, default=1, help="Number of processes to run")
74
parser.add_argument("-renderer", action="store", type=str, help="Renderer to use")
75
parser.add_argument("-upscale", action="store", type=int, help="Upscale multiplier")
76
parser.add_argument("-pgxp", action="store_true", help="Enable PGXP")
77
parser.add_argument("-pgxpcpu", action="store_true", help="Enable PGXP CPU mode")
78
parser.add_argument("-cpu", action="store", help="CPU execution mode")
79
80
args = parser.parse_args()
81
cargs = []
82
if (args.upscale is not None):
83
cargs += ["-upscale", str(args.upscale)]
84
if (args.pgxp):
85
cargs += ["-pgxp"]
86
if (args.pgxpcpu):
87
cargs += ["-pgxp-cpu"]
88
if (args.cpu is not None):
89
cargs += ["-cpu", args.cpu]
90
91
if not run_regression_tests(args.runner, args.gamedir, os.path.realpath(args.destdir), args.dumpinterval, args.frames, args.parallel, args.renderer, cargs):
92
sys.exit(1)
93
else:
94
sys.exit(0)
95
96
97