2023-01-14 04:36:28 +08:00
|
|
|
#!/usr/bin/python3
|
2022-07-22 04:36:41 +08:00
|
|
|
# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os.path
|
|
|
|
import subprocess as sp
|
|
|
|
import sys
|
|
|
|
import xml.sax as x
|
2022-10-14 06:59:53 +08:00
|
|
|
import colorama as c
|
|
|
|
|
|
|
|
c.init()
|
2022-07-22 04:36:41 +08:00
|
|
|
|
|
|
|
SCRIPT_PATH = os.path.split(sys.argv[0])[0]
|
|
|
|
FAIL_LIST_PATH = os.path.join(SCRIPT_PATH, "faillist.txt")
|
|
|
|
|
|
|
|
|
|
|
|
def loadFailList():
|
|
|
|
with open(FAIL_LIST_PATH) as f:
|
|
|
|
return set(map(str.strip, f.readlines()))
|
|
|
|
|
2022-08-26 04:55:08 +08:00
|
|
|
|
2022-07-29 11:41:13 +08:00
|
|
|
def safeParseInt(i, default=0):
|
|
|
|
try:
|
|
|
|
return int(i)
|
|
|
|
except ValueError:
|
|
|
|
return default
|
2022-07-22 04:36:41 +08:00
|
|
|
|
2022-08-26 04:55:08 +08:00
|
|
|
|
2022-10-07 07:55:58 +08:00
|
|
|
def makeDottedName(path):
|
|
|
|
return ".".join(path)
|
|
|
|
|
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
class Handler(x.ContentHandler):
|
|
|
|
def __init__(self, failList):
|
|
|
|
self.currentTest = []
|
|
|
|
self.failList = failList # Set of dotted test names that are expected to fail
|
|
|
|
|
|
|
|
self.results = {} # {DottedName: TrueIfTheTestPassed}
|
|
|
|
|
2022-07-29 11:41:13 +08:00
|
|
|
self.numSkippedTests = 0
|
|
|
|
|
2022-10-14 06:59:53 +08:00
|
|
|
self.pass_count = 0
|
|
|
|
self.fail_count = 0
|
|
|
|
self.test_count = 0
|
|
|
|
|
2022-10-22 01:33:43 +08:00
|
|
|
self.crashed_tests = []
|
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
def startElement(self, name, attrs):
|
|
|
|
if name == "TestSuite":
|
|
|
|
self.currentTest.append(attrs["name"])
|
|
|
|
elif name == "TestCase":
|
|
|
|
self.currentTest.append(attrs["name"])
|
|
|
|
|
|
|
|
elif name == "OverallResultsAsserts":
|
|
|
|
if self.currentTest:
|
2022-09-30 06:11:54 +08:00
|
|
|
passed = attrs["test_case_success"] == "true"
|
2022-07-22 04:36:41 +08:00
|
|
|
|
2022-10-07 07:55:58 +08:00
|
|
|
dottedName = makeDottedName(self.currentTest)
|
2022-07-22 04:36:41 +08:00
|
|
|
|
2022-08-05 05:27:28 +08:00
|
|
|
# Sometimes we get multiple XML trees for the same test. All of
|
|
|
|
# them must report a pass in order for us to consider the test
|
|
|
|
# to have passed.
|
|
|
|
r = self.results.get(dottedName, True)
|
|
|
|
self.results[dottedName] = r and passed
|
2022-07-22 04:36:41 +08:00
|
|
|
|
2022-10-14 06:59:53 +08:00
|
|
|
self.test_count += 1
|
|
|
|
if passed:
|
|
|
|
self.pass_count += 1
|
|
|
|
else:
|
|
|
|
self.fail_count += 1
|
|
|
|
|
2022-08-26 04:55:08 +08:00
|
|
|
elif name == "OverallResultsTestCases":
|
2022-07-29 11:41:13 +08:00
|
|
|
self.numSkippedTests = safeParseInt(attrs.get("skipped", 0))
|
|
|
|
|
2022-10-22 01:33:43 +08:00
|
|
|
elif name == "Exception":
|
|
|
|
if attrs.get("crash") == "true":
|
|
|
|
self.crashed_tests.append(makeDottedName(self.currentTest))
|
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
def endElement(self, name):
|
|
|
|
if name == "TestCase":
|
|
|
|
self.currentTest.pop()
|
|
|
|
|
|
|
|
elif name == "TestSuite":
|
|
|
|
self.currentTest.pop()
|
|
|
|
|
|
|
|
|
2022-10-07 07:55:58 +08:00
|
|
|
def print_stderr(*args, **kw):
|
|
|
|
print(*args, **kw, file=sys.stderr)
|
|
|
|
|
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Run Luau.UnitTest with deferred constraint resolution enabled"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"path", action="store", help="Path to the Luau.UnitTest executable"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--dump",
|
|
|
|
dest="dump",
|
|
|
|
action="store_true",
|
|
|
|
help="Instead of doing any processing, dump the raw output of the test run. Useful for debugging this tool.",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--write",
|
|
|
|
dest="write",
|
|
|
|
action="store_true",
|
|
|
|
help="Write a new faillist.txt after running tests.",
|
|
|
|
)
|
2023-04-08 03:56:27 +08:00
|
|
|
parser.add_argument(
|
2023-04-28 19:55:55 +08:00
|
|
|
"--rwp",
|
|
|
|
dest="rwp",
|
2023-04-08 03:56:27 +08:00
|
|
|
action="store_true",
|
2023-04-28 19:55:55 +08:00
|
|
|
help="Run the tests with read-write properties enabled.",
|
2023-04-08 03:56:27 +08:00
|
|
|
)
|
2022-07-22 04:36:41 +08:00
|
|
|
|
2022-10-07 07:55:58 +08:00
|
|
|
parser.add_argument("--randomize", action="store_true", help="Pick a random seed")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--random-seed",
|
|
|
|
action="store",
|
|
|
|
dest="random_seed",
|
|
|
|
type=int,
|
|
|
|
help="Accept a specific RNG seed",
|
|
|
|
)
|
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
failList = loadFailList()
|
|
|
|
|
2023-04-08 03:56:27 +08:00
|
|
|
flags = ["true", "DebugLuauDeferredConstraintResolution"]
|
2023-04-28 19:55:55 +08:00
|
|
|
if args.rwp:
|
|
|
|
flags.append("DebugLuauReadWriteProperties")
|
2023-04-08 03:56:27 +08:00
|
|
|
|
|
|
|
commandLine = [args.path, "--reporters=xml", "--fflags=" + ",".join(flags)]
|
2022-09-02 07:00:14 +08:00
|
|
|
|
2022-10-07 07:55:58 +08:00
|
|
|
if args.random_seed:
|
|
|
|
commandLine.append("--random-seed=" + str(args.random_seed))
|
|
|
|
elif args.randomize:
|
|
|
|
commandLine.append("--randomize")
|
|
|
|
|
|
|
|
print_stderr(">", " ".join(commandLine))
|
2022-09-02 07:00:14 +08:00
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
p = sp.Popen(
|
2022-09-02 07:00:14 +08:00
|
|
|
commandLine,
|
2022-07-22 04:36:41 +08:00
|
|
|
stdout=sp.PIPE,
|
|
|
|
)
|
|
|
|
|
|
|
|
handler = Handler(failList)
|
|
|
|
|
|
|
|
if args.dump:
|
|
|
|
for line in p.stdout:
|
|
|
|
sys.stdout.buffer.write(line)
|
|
|
|
return
|
|
|
|
else:
|
2022-10-07 07:55:58 +08:00
|
|
|
try:
|
|
|
|
x.parse(p.stdout, handler)
|
|
|
|
except x.SAXParseException as e:
|
|
|
|
print_stderr(
|
|
|
|
f"XML parsing failed during test {makeDottedName(handler.currentTest)}. That probably means that the test crashed"
|
|
|
|
)
|
|
|
|
sys.exit(1)
|
2022-07-22 04:36:41 +08:00
|
|
|
|
|
|
|
p.wait()
|
|
|
|
|
2022-10-14 06:59:53 +08:00
|
|
|
unexpected_fails = 0
|
|
|
|
unexpected_passes = 0
|
|
|
|
|
2022-08-05 05:27:28 +08:00
|
|
|
for testName, passed in handler.results.items():
|
|
|
|
if passed and testName in failList:
|
2022-10-14 06:59:53 +08:00
|
|
|
unexpected_passes += 1
|
|
|
|
print_stderr(
|
|
|
|
f"UNEXPECTED: {c.Fore.RED}{testName}{c.Fore.RESET} should have failed"
|
|
|
|
)
|
2022-08-05 05:27:28 +08:00
|
|
|
elif not passed and testName not in failList:
|
2022-10-14 06:59:53 +08:00
|
|
|
unexpected_fails += 1
|
|
|
|
print_stderr(
|
|
|
|
f"UNEXPECTED: {c.Fore.GREEN}{testName}{c.Fore.RESET} should have passed"
|
|
|
|
)
|
|
|
|
|
|
|
|
if unexpected_fails or unexpected_passes:
|
|
|
|
print_stderr("")
|
|
|
|
print_stderr(f"Unexpected fails: {unexpected_fails}")
|
|
|
|
print_stderr(f"Unexpected passes: {unexpected_passes}")
|
|
|
|
|
|
|
|
pass_percent = int(handler.pass_count / handler.test_count * 100)
|
|
|
|
|
|
|
|
print_stderr("")
|
|
|
|
print_stderr(
|
|
|
|
f"{handler.pass_count} of {handler.test_count} tests passed. ({pass_percent}%)"
|
|
|
|
)
|
|
|
|
print_stderr(f"{handler.fail_count} tests failed.")
|
2022-08-05 05:27:28 +08:00
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
if args.write:
|
|
|
|
newFailList = sorted(
|
|
|
|
(
|
|
|
|
dottedName
|
|
|
|
for dottedName, passed in handler.results.items()
|
|
|
|
if not passed
|
|
|
|
),
|
|
|
|
key=str.lower,
|
|
|
|
)
|
|
|
|
with open(FAIL_LIST_PATH, "w", newline="\n") as f:
|
|
|
|
for name in newFailList:
|
|
|
|
print(name, file=f)
|
2022-10-07 07:55:58 +08:00
|
|
|
print_stderr("Updated faillist.txt")
|
2022-07-22 04:36:41 +08:00
|
|
|
|
2022-10-22 01:33:43 +08:00
|
|
|
if handler.crashed_tests:
|
|
|
|
print_stderr()
|
|
|
|
for test in handler.crashed_tests:
|
|
|
|
print_stderr(
|
|
|
|
f"{c.Fore.RED}{test}{c.Fore.RESET} threw an exception and crashed the test process!"
|
|
|
|
)
|
|
|
|
|
2022-07-29 11:41:13 +08:00
|
|
|
if handler.numSkippedTests > 0:
|
2022-10-22 01:33:43 +08:00
|
|
|
print_stderr(f"{handler.numSkippedTests} test(s) were skipped!")
|
|
|
|
|
|
|
|
ok = (
|
|
|
|
not handler.crashed_tests
|
|
|
|
and handler.numSkippedTests == 0
|
|
|
|
and all(
|
|
|
|
not passed == (dottedName in failList)
|
|
|
|
for dottedName, passed in handler.results.items()
|
2022-08-26 04:55:08 +08:00
|
|
|
)
|
2022-07-22 04:36:41 +08:00
|
|
|
)
|
|
|
|
|
2022-08-26 04:55:08 +08:00
|
|
|
if ok:
|
2022-10-07 07:55:58 +08:00
|
|
|
print_stderr("Everything in order!")
|
2022-08-26 04:55:08 +08:00
|
|
|
|
|
|
|
sys.exit(0 if ok else 1)
|
|
|
|
|
|
|
|
|
2022-07-22 04:36:41 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|