sat-solver/test.py

87 lines
1.8 KiB
Python
Executable file

#!/usr/bin/env python3
import os;
import sys, glob, subprocess, shlex, pickle, atexit, time, argparse;
parser = argparse.ArgumentParser(
prog='test',
description='What the program does',
epilog='Text at the bottom of help')
parser.add_argument('executable')
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-c', '--color', action='store_true', default=os.isatty(0));
parser.add_argument('--no-color', action='store_const', dest='color', const=False);
args = parser.parse_args(sys.argv[1:]);
try:
with open(".test.db", "rb") as stream:
failtimes, runtimes = pickle.load(stream);
except:
failtimes = dict();
runtimes = dict();
def write_failtimes():
with open(".test.db", "wb") as stream:
pickle.dump((failtimes, runtimes), stream);
atexit.register(write_failtimes);
all_tests = list(glob.glob("tests/**/*.cnf", recursive = True));
for test in all_tests:
if test not in failtimes:
failtimes[test] = time.time();
def printgreen(text):
if args.color:
print("\033[38;2;0;200;0m" + text + "\033[0m");
else:
print(text);
n = len(all_tests);
for i, test in enumerate(sorted(all_tests, key = lambda x: -failtimes[x])):
command = [args.executable, "-i", test, "-V"];
# if we don't know how long this test will take, or if we know that it will
# take a long time (more than 5 seconds): add the verbose option.
if test not in runtimes or runtimes[test] > 10:
command += ['-v'];
prettycommand = f"[{i}/{n}]: {test} ...";
printgreen(prettycommand);
before = time.time();
res = subprocess.run(command);
after = time.time();
runtimes[test] = after - before;
if res.returncode:
failtimes[test] = time.time();
exit(1);
printgreen("All tests pass!");