Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**/*~
**/*.tmproj

_build
29 changes: 18 additions & 11 deletions ml-proto/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@

class RunTests(unittest.TestCase):
def _runTestFile(self, shortName, fileName, interpreterPath):
print("\n// %s" % shortName)
sys.stdout.flush()

logPath = fileName.replace("test/", "test/output/").replace(".wasm", ".wasm.log")
try:
os.remove(logPath)
except OSError:
pass

commandStr = ("%s %s | tee %s") % (interpreterPath, fileName, logPath)
commandStr = ("%s %s > %s") % (interpreterPath, fileName, logPath)
exitCode = subprocess.call(commandStr, shell=True)
self.assertEqual(0, exitCode, "test runner failed with exit code %i" % exitCode)

try:
expected = open(fileName.replace("test/", "test/expected-output/").replace(".wasm", ".wasm.log"))
except IOError:
print("// WARNING: No expected output found for this test")
# print("// WARNING: No expected output found for %s" % fileName)
return

output = open(logPath)
Expand All @@ -47,24 +44,34 @@ def generate_test_cases(cls, interpreterPath, files):
testCase = generate_test_case(rec)
setattr(cls, attrName, testCase)

def rebuild_interpreter():
interpreterPath = os.path.abspath("src/main.native")
def find_interpreter(path):
if not os.path.exists(path):
raise Exception("Interpreter has not been built. Looked for %s" % path)

print("// building main.native")
def rebuild_interpreter(path):
print("// building %s" % path)
sys.stdout.flush()
exitCode = subprocess.call(["ocamlbuild", "-libs", "bigarray", "main.native"], cwd=os.path.abspath("src"))
if (exitCode != 0):
raise Exception("ocamlbuild failed with exit code %i" % exitCode)

return interpreterPath
if not os.path.exists(path):
raise Exception("Interpreter has not been built. Looked for %s" % path)

if __name__ == "__main__":
interpreterPath = os.path.abspath("src/main.native")

try:
os.makedirs("test/output/")
except OSError:
pass

interpreterPath = rebuild_interpreter()
shouldBuildInterpreter = ("--build" in sys.argv)
if shouldBuildInterpreter:
sys.argv.remove("--build")
rebuild_interpreter(interpreterPath)
else:
find_interpreter(interpreterPath)

testFiles = glob.glob("test/*.wasm")
generate_test_cases(RunTests, interpreterPath, testFiles)
unittest.main()