2021-08-04 10:17:05 +00:00
|
|
|
import argparse
|
|
|
|
import glob
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import multiprocessing
|
|
|
|
from functools import partial
|
|
|
|
|
|
|
|
def is_game_path(path):
|
|
|
|
idx = path.rfind('.')
|
|
|
|
if idx < 0:
|
|
|
|
return False
|
|
|
|
|
|
|
|
extension = path[idx + 1:].strip().lower()
|
|
|
|
return extension in ["cue", "chd"]
|
|
|
|
|
|
|
|
|
2023-12-13 10:56:43 +00:00
|
|
|
def run_regression_test(runner, destdir, dump_interval, frames, renderer, cargs, gamepath):
|
2021-08-04 10:17:05 +00:00
|
|
|
args = [runner,
|
2023-08-19 09:50:17 +00:00
|
|
|
"-log", "error",
|
2021-08-04 10:17:05 +00:00
|
|
|
"-dumpdir", destdir,
|
|
|
|
"-dumpinterval", str(dump_interval),
|
|
|
|
"-frames", str(frames),
|
2023-08-19 09:50:17 +00:00
|
|
|
"-renderer", ("Software" if renderer is None else renderer),
|
2021-08-04 10:17:05 +00:00
|
|
|
]
|
2023-12-13 10:56:43 +00:00
|
|
|
args += cargs
|
|
|
|
args += ["--", gamepath]
|
2021-08-04 10:17:05 +00:00
|
|
|
|
|
|
|
print("Running '%s'" % (" ".join(args)))
|
|
|
|
subprocess.run(args)
|
|
|
|
|
|
|
|
|
2023-12-13 10:56:43 +00:00
|
|
|
def run_regression_tests(runner, gamedir, destdir, dump_interval, frames, parallel, renderer, cargs):
|
2021-08-04 10:17:05 +00:00
|
|
|
paths = glob.glob(gamedir + "/*.*", recursive=True)
|
|
|
|
gamepaths = list(filter(is_game_path, paths))
|
|
|
|
|
2023-11-25 10:06:30 +00:00
|
|
|
try:
|
|
|
|
if not os.path.isdir(destdir):
|
|
|
|
os.mkdir(destdir)
|
|
|
|
except OSError:
|
2021-08-04 10:17:05 +00:00
|
|
|
print("Failed to create directory")
|
|
|
|
return False
|
|
|
|
|
|
|
|
print("Found %u games" % len(gamepaths))
|
|
|
|
|
|
|
|
if parallel <= 1:
|
|
|
|
for game in gamepaths:
|
2023-12-13 10:56:43 +00:00
|
|
|
run_regression_test(runner, destdir, dump_interval, frames, renderer, cargs, game)
|
2021-08-04 10:17:05 +00:00
|
|
|
else:
|
|
|
|
print("Processing %u games on %u processors" % (len(gamepaths), parallel))
|
2023-12-13 10:56:43 +00:00
|
|
|
func = partial(run_regression_test, runner, destdir, dump_interval, frames, renderer, cargs)
|
2021-08-04 10:17:05 +00:00
|
|
|
pool = multiprocessing.Pool(parallel)
|
2023-08-19 09:50:17 +00:00
|
|
|
pool.map(func, gamepaths, chunksize=1)
|
2021-08-04 10:17:05 +00:00
|
|
|
pool.close()
|
|
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description="Generate frame dump images for regression tests")
|
|
|
|
parser.add_argument("-runner", action="store", required=True, help="Path to DuckStation regression test runner")
|
|
|
|
parser.add_argument("-gamedir", action="store", required=True, help="Directory containing game images")
|
|
|
|
parser.add_argument("-destdir", action="store", required=True, help="Base directory to dump frames to")
|
2022-10-13 12:17:23 +00:00
|
|
|
parser.add_argument("-dumpinterval", action="store", type=int, default=600, help="Interval to dump frames at")
|
|
|
|
parser.add_argument("-frames", action="store", type=int, default=36000, help="Number of frames to run")
|
2023-08-19 09:50:17 +00:00
|
|
|
parser.add_argument("-parallel", action="store", type=int, default=1, help="Number of processes to run")
|
|
|
|
parser.add_argument("-renderer", action="store", type=str, help="Renderer to use")
|
2023-12-13 10:56:43 +00:00
|
|
|
parser.add_argument("-upscale", action="store", type=int, help="Upscale multiplier")
|
|
|
|
parser.add_argument("-pgxp", action="store_true", help="Enable PGXP")
|
|
|
|
parser.add_argument("-pgxpcpu", action="store_true", help="Enable PGXP CPU mode")
|
|
|
|
parser.add_argument("-cpu", action="store", help="CPU execution mode")
|
2021-08-04 10:17:05 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
2023-12-13 10:56:43 +00:00
|
|
|
cargs = []
|
|
|
|
if (args.upscale is not None):
|
|
|
|
cargs += ["-upscale", str(args.upscale)]
|
|
|
|
if (args.pgxp):
|
|
|
|
cargs += ["-pgxp"]
|
|
|
|
if (args.pgxpcpu):
|
|
|
|
cargs += ["-pgxp-cpu"]
|
|
|
|
if (args.cpu is not None):
|
|
|
|
cargs += ["-cpu", args.cpu]
|
|
|
|
|
|
|
|
if not run_regression_tests(args.runner, os.path.realpath(args.gamedir), os.path.realpath(args.destdir), args.dumpinterval, args.frames, args.parallel, args.renderer, cargs):
|
2021-08-04 10:17:05 +00:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
sys.exit(0)
|
|
|
|
|