Skip to content

Commit

Permalink
wamr-test-suites: Update runtest.py to support python3 (bytecodeallia…
Browse files Browse the repository at this point in the history
…nce#1684)

Update runtest.py of wamr-test-suites to support both python2 and python3
  • Loading branch information
no1wudi authored Nov 7, 2022
1 parent e278861 commit 8100078
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/wamr-test-suites/spec-test-script/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_case(
):
return True

CMD = ["python2.7", "runtest.py"]
CMD = ["python", "runtest.py"]
CMD.append("--wast2wasm")
CMD.append(WAST2WASM_CMD)
CMD.append("--interpreter")
Expand Down
21 changes: 13 additions & 8 deletions tests/wamr-test-suites/spec-test-script/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import print_function
import os, sys, re
from pickletools import long1
import argparse, time
import signal, atexit, tempfile, subprocess

Expand All @@ -18,11 +17,9 @@
import math
import traceback

try:
long
if sys.version_info[0] == 2:
IS_PY_3 = False
except NameError:
long = int
else:
IS_PY_3 = True

test_aot = False
Expand Down Expand Up @@ -154,7 +151,8 @@ def cleanup(self):
self.stdout.close()
self.stdin = 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):
# Wait for the initial prompt
Expand Down Expand Up @@ -1128,11 +1126,15 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile,
# workaround: spec test changes error message to "malformed" while iwasm still use "invalid"
error_msg = m.group(2).replace("malformed", "invalid")
log("Testing(malformed)")
f = open(wasm_tempfile, 'w')
f = open(wasm_tempfile, 'wb')
s = m.group(1)
while s:
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)
f.close()

Expand All @@ -1157,6 +1159,9 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile,
log("Running: %s" % " ".join(cmd))
output = subprocess.check_output(cmd)

if IS_PY_3:
output = str(output, "latin1")

if (error_msg == "unexpected end of section or function") \
and output.endswith("unexpected end\n"):
# one case in binary.wast
Expand Down

0 comments on commit 8100078

Please sign in to comment.