81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
|
import os
|
||
|
import sys
|
||
|
import time
|
||
|
import glob
|
||
|
import fnmatch
|
||
|
from optparse import OptionParser
|
||
|
|
||
|
rustDir = os.path.abspath('.')
|
||
|
rustTestDir = rustDir + "/test";
|
||
|
rustTestRunPassDir = rustTestDir + "/run-pass";
|
||
|
rustTestRunFailDir = rustTestDir + "/run-fail";
|
||
|
rustTestCompileFailDir = rustTestDir + "/run-compile-fail";
|
||
|
rustTestRunBenchDir = rustTestDir + "/run-bench";
|
||
|
|
||
|
parser = OptionParser()
|
||
|
parser.set_usage("run.py [options] pattern : run.py -n 100 \"bas*\" -q");
|
||
|
parser.add_option("-n", dest="repetitions",
|
||
|
help="number of repetitions", metavar="NUMBER")
|
||
|
parser.add_option("-q", action="store_true", dest="quiet", default=False,
|
||
|
help="suppresses rust log output")
|
||
|
parser.add_option("-p", action="store_true", dest="printSource",
|
||
|
default=False, help="prints the test case's source")
|
||
|
parser.add_option("-s", dest="seed", metavar="NUMBER", default=-1,
|
||
|
help="seeds the rust scheduler, use -1 to generate seeds, "
|
||
|
+ " or >= 0 to specify a seed")
|
||
|
|
||
|
(options, args) = parser.parse_args()
|
||
|
|
||
|
def getRustTests(filter):
|
||
|
tests = []
|
||
|
for root, dirnames, filenames in os.walk(rustTestDir):
|
||
|
for filename in fnmatch.filter(filenames, filter + '.rs'):
|
||
|
tests.append(os.path.join(root, filename).
|
||
|
replace(rustDir + "/", ""));
|
||
|
return tests
|
||
|
|
||
|
|
||
|
if len(args) != 1:
|
||
|
parser.print_usage();
|
||
|
sys.exit(0);
|
||
|
|
||
|
tests = getRustTests(args[0]);
|
||
|
|
||
|
# Make
|
||
|
for rustProgram in tests:
|
||
|
print "Making: " + rustProgram;
|
||
|
result = os.system("make " + rustProgram.replace(".rs", ".x86")) >> 8;
|
||
|
if (result != 0):
|
||
|
print "Make failed!";
|
||
|
sys.exit(1);
|
||
|
|
||
|
if (options.quiet):
|
||
|
os.putenv("RUST_LOG", "none")
|
||
|
|
||
|
# Rut
|
||
|
totalPassed = 0;
|
||
|
for rustProgram in tests:
|
||
|
repetitions = 1;
|
||
|
if (options.repetitions):
|
||
|
repetitions = int(options.repetitions);
|
||
|
passed = 0;
|
||
|
if (options.printSource):
|
||
|
os.system("cat " + rustProgram);
|
||
|
for i in range(0, repetitions):
|
||
|
print "Running: " + rustProgram + " " + str(i) + \
|
||
|
" of " + str(repetitions);
|
||
|
if (options.seed):
|
||
|
if (int(options.seed) >= 0):
|
||
|
os.putenv("RUST_SEED", options.seed);
|
||
|
else:
|
||
|
os.putenv("RUST_SEED", str(i));
|
||
|
result = os.system(rustProgram.replace(".rs", ".x86"));
|
||
|
exitStatus = result >> 8;
|
||
|
signalNumber = result & 0xF;
|
||
|
if (result == 0):
|
||
|
passed += 1;
|
||
|
print "Result for: " + rustProgram + " " + str(passed) + \
|
||
|
" of " + str(repetitions) + " passed.";
|
||
|
totalPassed += passed;
|
||
|
print "Total: " + str(totalPassed) + " of " + \
|
||
|
str(len(tests) * repetitions) + " passed."
|