wamr-test-suites: Update runtest.py to support python3 (#1684)

Update runtest.py of wamr-test-suites to support both python2 and python3
This commit is contained in:
Huang Qi 2022-11-07 14:16:10 +08:00 committed by GitHub
parent e278861206
commit 810007857b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -121,7 +121,7 @@ def test_case(
): ):
return True return True
CMD = ["python2.7", "runtest.py"] CMD = ["python", "runtest.py"]
CMD.append("--wast2wasm") CMD.append("--wast2wasm")
CMD.append(WAST2WASM_CMD) CMD.append(WAST2WASM_CMD)
CMD.append("--interpreter") CMD.append("--interpreter")

View File

@ -2,7 +2,6 @@
from __future__ import print_function from __future__ import print_function
import os, sys, re import os, sys, re
from pickletools import long1
import argparse, time import argparse, time
import signal, atexit, tempfile, subprocess import signal, atexit, tempfile, subprocess
@ -18,11 +17,9 @@ import struct
import math import math
import traceback import traceback
try: if sys.version_info[0] == 2:
long
IS_PY_3 = False IS_PY_3 = False
except NameError: else:
long = int
IS_PY_3 = True IS_PY_3 = True
test_aot = False test_aot = False
@ -154,7 +151,8 @@ class Runner():
self.stdout.close() self.stdout.close()
self.stdin = None self.stdin = None
self.stdout = None self.stdout = None
sys.exc_clear() if not IS_PY_3:
sys.exc_clear()
def assert_prompt(runner, prompts, timeout, is_need_execute_result): def assert_prompt(runner, prompts, timeout, is_need_execute_result):
# Wait for the initial prompt # Wait for the initial prompt
@ -1128,11 +1126,15 @@ if __name__ == "__main__":
# workaround: spec test changes error message to "malformed" while iwasm still use "invalid" # workaround: spec test changes error message to "malformed" while iwasm still use "invalid"
error_msg = m.group(2).replace("malformed", "invalid") error_msg = m.group(2).replace("malformed", "invalid")
log("Testing(malformed)") log("Testing(malformed)")
f = open(wasm_tempfile, 'w') f = open(wasm_tempfile, 'wb')
s = m.group(1) s = m.group(1)
while s: while s:
res = re.match("[^\"]*\"([^\"]*)\"(.*)", s, re.DOTALL) res = re.match("[^\"]*\"([^\"]*)\"(.*)", s, re.DOTALL)
f.write(res.group(1).replace("\\", "\\x").decode("string_escape")) if IS_PY_3:
context = res.group(1).replace("\\", "\\x").encode("latin1").decode("unicode-escape").encode("latin1")
f.write(context)
else:
f.write(res.group(1).replace("\\", "\\x").decode("string-escape"))
s = res.group(2) s = res.group(2)
f.close() f.close()
@ -1157,6 +1159,9 @@ if __name__ == "__main__":
log("Running: %s" % " ".join(cmd)) log("Running: %s" % " ".join(cmd))
output = subprocess.check_output(cmd) output = subprocess.check_output(cmd)
if IS_PY_3:
output = str(output, "latin1")
if (error_msg == "unexpected end of section or function") \ if (error_msg == "unexpected end of section or function") \
and output.endswith("unexpected end\n"): and output.endswith("unexpected end\n"):
# one case in binary.wast # one case in binary.wast