summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/find_exe.py6
-rwxr-xr-xtest/run-interp.py91
2 files changed, 97 insertions, 0 deletions
diff --git a/test/find_exe.py b/test/find_exe.py
index a946388d..4ef2b9db 100644
--- a/test/find_exe.py
+++ b/test/find_exe.py
@@ -28,6 +28,7 @@ BUILT_D8_EXE = os.path.join(REPO_ROOT_DIR, 'third_party', 'v8', 'v8', 'out',
'Release', 'd8')
DOWNLOAD_D8_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'd8')
DEFAULT_WASM_WAST_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'wasm-wast')
+DEFAULT_WASM_INTERP_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'wasm-interp')
if IS_WINDOWS:
@@ -35,6 +36,7 @@ if IS_WINDOWS:
BUILT_D8_EXE += '.exe'
DOWNLOAD_D8_EXE += '.exe'
DEFAULT_WASM_WAST_EXE += '.exe'
+ DEFAULT_WASM_INTERP_EXE += '.exe'
def FindExeWithFallback(name, default_exe_list, override_exe=None):
@@ -61,5 +63,9 @@ def GetWasmWastExecutable(override=None):
return FindExeWithFallback('wasm-wast', [DEFAULT_WASM_WAST_EXE], override)
+def GetWasmInterpExecutable(override=None):
+ return FindExeWithFallback('wasm-interp', [DEFAULT_WASM_INTERP_EXE], override)
+
+
def GetD8Executable(override=None):
return FindExeWithFallback('d8', [BUILT_D8_EXE, DOWNLOAD_D8_EXE], override)
diff --git a/test/run-interp.py b/test/run-interp.py
new file mode 100755
index 00000000..3d860ed5
--- /dev/null
+++ b/test/run-interp.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 WebAssembly Community Group participants
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import argparse
+import os
+import subprocess
+import sys
+import tempfile
+
+import find_exe
+from utils import Error
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+
+
+def main(args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-e', '--executable', metavar='PATH',
+ help='override sexpr-wasm executable.')
+ parser.add_argument('--wasm-interp-executable', metavar='PATH',
+ help='override wasm-interp executable.')
+ parser.add_argument('-v', '--verbose', help='print more diagnotic messages.',
+ action='store_true')
+ parser.add_argument('--use-libc-allocator', action='store_true')
+ parser.add_argument('file', help='test file.')
+ options = parser.parse_args(args)
+
+ sexpr_wasm_exe = find_exe.GetSexprWasmExecutable(options.executable)
+ wasm_interp_exe = find_exe.GetWasmInterpExecutable(
+ options.wasm_interp_executable)
+
+ generated = None
+ try:
+ # Use delete=False because Windows can't open a NamedTemporaryFile until it
+ # is cloesd, but it will be deleted by default if it is closed.
+ generated = tempfile.NamedTemporaryFile(prefix='sexpr-wasm-', delete=False)
+ generated.close()
+ wasm_file = generated.name
+ # First compile the file
+ cmd = [sexpr_wasm_exe, '-o', wasm_file]
+ if options.verbose:
+ cmd.append('-v')
+ if options.use_libc_allocator:
+ cmd.extend(['--use-libc-allocator'])
+ cmd.append(options.file)
+ try:
+ process = subprocess.Popen(cmd, stderr=subprocess.PIPE)
+ _, stderr = process.communicate()
+ if process.returncode != 0:
+ raise Error(stderr)
+ except OSError as e:
+ raise Error(str(e))
+
+ cmd = [wasm_interp_exe, wasm_file]
+ try:
+ process = subprocess.Popen(cmd, stderr=subprocess.PIPE,
+ universal_newlines=True)
+ _, stderr = process.communicate()
+ if process.returncode != 0:
+ raise Error(stderr)
+ except OSError as e:
+ raise Error(str(e))
+
+ finally:
+ if generated:
+ os.remove(generated.name)
+
+ return 0
+
+
+if __name__ == '__main__':
+ try:
+ sys.exit(main(sys.argv[1:]))
+ except Error as e:
+ sys.stderr.write(str(e) + '\n')
+ sys.exit(1)
+