summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rwxr-xr-xauto_update_tests.py13
-rwxr-xr-xbuild-js.sh1
-rwxr-xr-xcheck.py19
-rw-r--r--scripts/test/shared.py6
-rw-r--r--src/passes/CMakeLists.txt1
-rw-r--r--src/passes/PrintFeatures.cpp39
-rw-r--r--src/passes/StripTargetFeatures.cpp2
-rw-r--r--src/passes/pass.cpp1
-rw-r--r--src/passes/passes.h1
-rw-r--r--src/tools/tool-options.h10
-rw-r--r--src/tools/wasm-reduce.cpp9
-rw-r--r--src/wasm-features.h8
-rw-r--r--src/wasm.h2
-rw-r--r--src/wasm/wasm-emscripten.cpp1
-rw-r--r--test/lld/duplicate_imports.wast.out7
-rw-r--r--test/lld/em_asm.wast.mem.out7
-rw-r--r--test/lld/em_asm.wast.out7
-rw-r--r--test/lld/em_asm_O0.wast.out7
-rw-r--r--test/lld/em_asm_shared.wast.out7
-rw-r--r--test/lld/em_asm_table.wast.out7
-rw-r--r--test/lld/em_js_O0.wast.out7
-rw-r--r--test/lld/hello_world.wast.mem.out7
-rw-r--r--test/lld/hello_world.wast.out7
-rw-r--r--test/lld/init.wast.out7
-rw-r--r--test/lld/recursive.wast.out7
-rw-r--r--test/lld/reserved_func_ptr.wast.out7
-rw-r--r--test/lld/shared.wast.out7
-rw-r--r--test/passes/code-folding_enable-threads.txt (renamed from test/passes/code-folding.txt)0
-rw-r--r--test/passes/code-folding_enable-threads.wast (renamed from test/passes/code-folding.wast)0
-rw-r--r--test/passes/flatten_dfo_O3_enable-threads.txt (renamed from test/passes/flatten_dfo_O3.txt)0
-rw-r--r--test/passes/flatten_dfo_O3_enable-threads.wast (renamed from test/passes/flatten_dfo_O3.wast)0
-rw-r--r--test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt (renamed from test/passes/flatten_simplify-locals-nonesting_souperify-single-use.txt)0
-rw-r--r--test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.wast (renamed from test/passes/flatten_simplify-locals-nonesting_souperify-single-use.wast)0
-rw-r--r--test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt (renamed from test/passes/flatten_simplify-locals-nonesting_souperify.txt)0
-rw-r--r--test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.wast (renamed from test/passes/flatten_simplify-locals-nonesting_souperify.wast)0
-rw-r--r--test/passes/fuzz-exec_enable-sign-ext.txt (renamed from test/passes/fuzz-exec.txt)0
-rw-r--r--test/passes/fuzz-exec_enable-sign-ext.wast (renamed from test/passes/fuzz-exec.wast)0
-rw-r--r--test/passes/inlining-optimizing_enable-threads.txt (renamed from test/passes/inlining-optimizing.txt)0
-rw-r--r--test/passes/inlining-optimizing_enable-threads.wast (renamed from test/passes/inlining-optimizing.wast)0
-rw-r--r--test/passes/optimize-instructions_enable-threads.txt (renamed from test/passes/optimize-instructions.txt)0
-rw-r--r--test/passes/optimize-instructions_enable-threads.wast (renamed from test/passes/optimize-instructions.wast)0
-rw-r--r--test/passes/precompute_enable-simd.txt (renamed from test/passes/precompute.txt)0
-rw-r--r--test/passes/precompute_enable-simd.wast (renamed from test/passes/precompute.wast)0
-rw-r--r--test/passes/remove-unused-module-elements_enable-threads.txt (renamed from test/passes/remove-unused-module-elements.txt)0
-rw-r--r--test/passes/remove-unused-module-elements_enable-threads.wast (renamed from test/passes/remove-unused-module-elements.wast)0
-rw-r--r--test/passes/remove-unused-names_merge-blocks_enable-threads.txt (renamed from test/passes/remove-unused-names_merge-blocks.txt)0
-rw-r--r--test/passes/remove-unused-names_merge-blocks_enable-threads.wast (renamed from test/passes/remove-unused-names_merge-blocks.wast)0
-rw-r--r--test/passes/remove-unused-nonfunction-module-elements_enable-threads.txt (renamed from test/passes/remove-unused-nonfunction-module-elements.txt)0
-rw-r--r--test/passes/remove-unused-nonfunction-module-elements_enable-threads.wast (renamed from test/passes/remove-unused-nonfunction-module-elements.wast)0
-rw-r--r--test/passes/safe-heap_enable-threads_enable-simd.txt (renamed from test/passes/safe-heap.txt)0
-rw-r--r--test/passes/safe-heap_enable-threads_enable-simd.wast (renamed from test/passes/safe-heap.wast)0
-rw-r--r--test/passes/safe-heap_low-memory-unused_enable-threads_enable-simd.txt (renamed from test/passes/safe-heap_low-memory-unused.txt)0
-rw-r--r--test/passes/safe-heap_low-memory-unused_enable-threads_enable-simd.wast (renamed from test/passes/safe-heap_low-memory-unused.wast)0
-rw-r--r--test/passes/simplify-locals_all-features.txt (renamed from test/passes/simplify-locals.txt)0
-rw-r--r--test/passes/simplify-locals_all-features.wast (renamed from test/passes/simplify-locals.wast)0
-rw-r--r--test/passes/ssa_enable-threads.txt (renamed from test/passes/ssa.txt)0
-rw-r--r--test/passes/ssa_enable-threads.wast (renamed from test/passes/ssa.wast)0
-rw-r--r--test/passes/ssa_fuzz-exec_enable-threads.txt (renamed from test/passes/ssa_fuzz-exec.txt)0
-rw-r--r--test/passes/ssa_fuzz-exec_enable-threads.wast (renamed from test/passes/ssa_fuzz-exec.wast)0
-rw-r--r--test/passes/translate-to-fuzz_all-features.txt (renamed from test/passes/translate-to-fuzz.txt)0
-rw-r--r--test/passes/translate-to-fuzz_all-features.wast (renamed from test/passes/translate-to-fuzz.wast)0
-rw-r--r--test/passes/translate-to-fuzz_no-fuzz-nans_all-features.txt (renamed from test/passes/translate-to-fuzz_no-fuzz-nans.txt)0
-rw-r--r--test/passes/translate-to-fuzz_no-fuzz-nans_all-features.wast (renamed from test/passes/translate-to-fuzz_no-fuzz-nans.wast)0
-rw-r--r--test/unit/test_features.py70
-rw-r--r--test/unit/test_memory_packing.py4
-rw-r--r--test/unit/utils.py38
67 files changed, 146 insertions, 173 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03574e6f7..1b205ddcb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,9 @@ full changeset diff at the end of each section.
Current Trunk
-------------
+- Change default feature set in the absence of a target features section from
+ all features to MVP.
+
v79
---
diff --git a/auto_update_tests.py b/auto_update_tests.py
index 1ec7c4ece..937765fdd 100755
--- a/auto_update_tests.py
+++ b/auto_update_tests.py
@@ -36,6 +36,8 @@ def update_asm_js_tests():
for precise in [0, 1, 2]:
for opts in [1, 0]:
cmd = ASM2WASM + [os.path.join('test', asm)]
+ if 'threads' in asm:
+ cmd += ['--enable-threads']
wasm = asm.replace('.asm.js', '.fromasm')
if not precise:
cmd += ['--trap-mode=allow', '--ignore-implicit-traps']
@@ -79,18 +81,18 @@ def update_wasm_opt_tests():
run_command(cmd)
open(wast, 'w').write(open('a.wast').read())
- print '\n[ checking wasm-opt binary reading/writing... ]\n'
+ print '\n[ checking wasm-opt parsing & printing... ]\n'
for t in sorted(os.listdir(os.path.join('test', 'print'))):
if t.endswith('.wast'):
print '..', t
wasm = os.path.basename(t).replace('.wast', '')
- cmd = WASM_OPT + [os.path.join('test', 'print', t), '--print']
+ cmd = WASM_OPT + [os.path.join('test', 'print', t), '--print', '-all']
print ' ', ' '.join(cmd)
actual = subprocess.check_output(cmd)
print cmd, actual
with open(os.path.join('test', 'print', wasm + '.txt'), 'w') as o:
o.write(actual)
- cmd = WASM_OPT + [os.path.join('test', 'print', t), '--print-minified']
+ cmd = WASM_OPT + [os.path.join('test', 'print', t), '--print-minified', '-all']
print ' ', ' '.join(cmd)
actual = subprocess.check_output(cmd)
with open(os.path.join('test', 'print', wasm + '.minified.txt'), 'w') as o:
@@ -131,7 +133,7 @@ def update_wasm_opt_tests():
print '..', t
t = os.path.join('test', t)
f = t + '.from-wast'
- cmd = WASM_OPT + [t, '--print']
+ cmd = WASM_OPT + [t, '--print', '-all']
actual = run_command(cmd)
actual = actual.replace('printing before:\n', '')
open(f, 'w').write(actual)
@@ -287,8 +289,7 @@ def update_ctor_eval_tests():
print '..', t
t = os.path.join('test', 'ctor-eval', t)
ctors = open(t + '.ctors').read().strip()
- # TODO: remove --disable-bulk-memory once default feature set is MVP
- cmd = WASM_CTOR_EVAL + [t, '--disable-bulk-memory', '-o', 'a.wast', '-S', '--ctors', ctors]
+ cmd = WASM_CTOR_EVAL + [t, '-o', 'a.wast', '-S', '--ctors', ctors]
run_command(cmd)
actual = open('a.wast').read()
out = t + '.out'
diff --git a/build-js.sh b/build-js.sh
index 1ca2a1129..482901bc5 100755
--- a/build-js.sh
+++ b/build-js.sh
@@ -125,6 +125,7 @@ echo "building shared bitcode"
$BINARYEN_SRC/passes/PostEmscripten.cpp \
$BINARYEN_SRC/passes/Precompute.cpp \
$BINARYEN_SRC/passes/Print.cpp \
+ $BINARYEN_SRC/passes/PrintFeatures.cpp \
$BINARYEN_SRC/passes/PrintCallGraph.cpp \
$BINARYEN_SRC/passes/RedundantSetElimination.cpp \
$BINARYEN_SRC/passes/RelooperJumpThreading.cpp \
diff --git a/check.py b/check.py
index d95ad8020..37840fac0 100755
--- a/check.py
+++ b/check.py
@@ -140,12 +140,12 @@ def run_wasm_opt_tests():
if t.endswith('.wast'):
print '..', t
wasm = os.path.basename(t).replace('.wast', '')
- cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print']
+ cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print', '-all']
print ' ', ' '.join(cmd)
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate()
expected_file = os.path.join(options.binaryen_test, 'print', wasm + '.txt')
fail_if_not_identical_to_file(actual, expected_file)
- cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print-minified']
+ cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print-minified', '-all']
print ' ', ' '.join(cmd)
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate()
fail_if_not_identical(actual.strip(), open(os.path.join(options.binaryen_test, 'print', wasm + '.minified.txt')).read().strip())
@@ -157,7 +157,7 @@ def run_wasm_opt_tests():
print '..', t
t = os.path.join(options.binaryen_test, t)
f = t + '.from-wast'
- cmd = WASM_OPT + [t, '--print']
+ cmd = WASM_OPT + [t, '--print', '-all']
actual = run_command(cmd)
actual = actual.replace('printing before:\n', '')
@@ -197,7 +197,7 @@ def run_wasm_dis_tests():
# also verify there are no validation errors
def check():
- cmd = WASM_OPT + [t]
+ cmd = WASM_OPT + [t, '-all']
run_command(cmd)
with_pass_debug(check)
@@ -240,8 +240,7 @@ def run_ctor_eval_tests():
print '..', t
t = os.path.join(test_dir, t)
ctors = open(t + '.ctors').read().strip()
- # TODO: remove --disable-bulk-memory once default feature set is MVP
- cmd = WASM_CTOR_EVAL + [t, '--disable-bulk-memory', '-o', 'a.wast', '-S', '--ctors', ctors]
+ cmd = WASM_CTOR_EVAL + [t, '-o', 'a.wast', '-S', '--ctors', ctors]
run_command(cmd)
actual = open('a.wast').read()
out = t + '.out'
@@ -276,7 +275,7 @@ def run_wasm_reduce_tests():
t = os.path.join(test_dir, t)
# convert to wasm
run_command(WASM_AS + [t, '-o', 'a.wasm'])
- run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm', '--timeout=4'])
+ run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec -all' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm', '--timeout=4'])
expected = t + '.txt'
run_command(WASM_DIS + ['c.wasm', '-o', 'a.wast'])
with open('a.wast') as seen:
@@ -287,9 +286,9 @@ def run_wasm_reduce_tests():
if 'fsanitize=thread' not in str(os.environ):
print '\n[ checking wasm-reduce fuzz testcase ]\n'
- run_command(WASM_OPT + [os.path.join(options.binaryen_test, 'unreachable-import_wasm-only.asm.js'), '-ttf', '-Os', '-o', 'a.wasm'])
+ run_command(WASM_OPT + [os.path.join(options.binaryen_test, 'unreachable-import_wasm-only.asm.js'), '-ttf', '-Os', '-o', 'a.wasm', '-all'])
before = os.stat('a.wasm').st_size
- run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
+ run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec -all' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
after = os.stat('c.wasm').st_size
assert after < 0.6 * before, [before, after]
@@ -324,7 +323,7 @@ def run_spec_tests():
def run_opt_test(wast):
# check optimization validation
- cmd = WASM_OPT + [wast, '-O']
+ cmd = WASM_OPT + [wast, '-O', '-all']
run_command(cmd)
def check_expected(actual, expected):
diff --git a/scripts/test/shared.py b/scripts/test/shared.py
index 227b7b65e..8309d9b5c 100644
--- a/scripts/test/shared.py
+++ b/scripts/test/shared.py
@@ -399,7 +399,7 @@ def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'],
assert os.path.exists('ab.wast')
# make sure it is a valid wast
- cmd = WASM_OPT + ['ab.wast']
+ cmd = WASM_OPT + ['ab.wast', '-all']
print ' ', ' '.join(cmd)
subprocess.check_call(cmd, stdout=subprocess.PIPE)
@@ -414,12 +414,12 @@ def minify_check(wast, verify_final_result=True):
# checks we can parse minified output
print ' (minify check)'
- cmd = WASM_OPT + [wast, '--print-minified']
+ cmd = WASM_OPT + [wast, '--print-minified', '-all']
print ' ', ' '.join(cmd)
subprocess.check_call(cmd, stdout=open('a.wast', 'w'), stderr=subprocess.PIPE)
assert os.path.exists('a.wast')
subprocess.check_call(
- WASM_OPT + ['a.wast', '--print-minified'],
+ WASM_OPT + ['a.wast', '--print-minified', '-all'],
stdout=open('b.wast', 'w'), stderr=subprocess.PIPE)
assert os.path.exists('b.wast')
if verify_final_result:
diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt
index 10fdc7fe4..8a4b04de8 100644
--- a/src/passes/CMakeLists.txt
+++ b/src/passes/CMakeLists.txt
@@ -40,6 +40,7 @@ SET(passes_SOURCES
Precompute.cpp
Print.cpp
PrintCallGraph.cpp
+ PrintFeatures.cpp
StackIR.cpp
Strip.cpp
StripTargetFeatures.cpp
diff --git a/src/passes/PrintFeatures.cpp b/src/passes/PrintFeatures.cpp
new file mode 100644
index 000000000..9c7172eee
--- /dev/null
+++ b/src/passes/PrintFeatures.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2019 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.
+ */
+
+//
+// Print out the feature options corresponding to enabled features
+//
+
+#include "wasm.h"
+#include "wasm-features.h"
+#include "pass.h"
+
+namespace wasm {
+
+struct PrintFeatures : public Pass {
+ void run(PassRunner* runner, Module* module) override {
+ module->features.iterFeatures([](FeatureSet::Feature f) {
+ std::cout << "--enable-" << FeatureSet::toString(f) << std::endl;
+ });
+ }
+};
+
+Pass* createPrintFeaturesPass() {
+ return new PrintFeatures();
+}
+
+} // namespace wasm
diff --git a/src/passes/StripTargetFeatures.cpp b/src/passes/StripTargetFeatures.cpp
index 645fbb11c..8eb7b0b75 100644
--- a/src/passes/StripTargetFeatures.cpp
+++ b/src/passes/StripTargetFeatures.cpp
@@ -16,8 +16,6 @@
#include "pass.h"
-using namespace std;
-
namespace wasm {
struct StripTargetFeatures : public Pass {
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index fd5359206..41d2026bc 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -112,6 +112,7 @@ void PassRegistry::registerPasses() {
registerPass("precompute-propagate", "computes compile-time evaluatable expressions and propagates them through locals", createPrecomputePropagatePass);
registerPass("print", "print in s-expression format", createPrinterPass);
registerPass("print-minified", "print in minified s-expression format", createMinifiedPrinterPass);
+ registerPass("print-features", "print options for enabled features", createPrintFeaturesPass);
registerPass("print-full", "print in full s-expression format", createFullPrinterPass);
registerPass("print-call-graph", "print call graph", createPrintCallGraphPass);
registerPass("print-stack-ir", "print out Stack IR (useful for internal debugging)", createPrintStackIRPass);
diff --git a/src/passes/passes.h b/src/passes/passes.h
index e4111c43b..af9141ac9 100644
--- a/src/passes/passes.h
+++ b/src/passes/passes.h
@@ -69,6 +69,7 @@ Pass* createPrecomputePass();
Pass* createPrecomputePropagatePass();
Pass* createPrinterPass();
Pass* createPrintCallGraphPass();
+Pass* createPrintFeaturesPass();
Pass* createPrintStackIRPass();
Pass* createRelooperJumpThreadingPass();
Pass* createRemoveNonJSOpsPass();
diff --git a/src/tools/tool-options.h b/src/tools/tool-options.h
index dd585612f..02572d72e 100644
--- a/src/tools/tool-options.h
+++ b/src/tools/tool-options.h
@@ -92,12 +92,12 @@ struct ToolOptions : public Options {
void applyFeatures(Module& module) {
if (hasFeatureOptions) {
if (!detectFeatures && module.hasFeaturesSection) {
- FeatureSet optionsFeatures = FeatureSet::All;
+ FeatureSet optionsFeatures = FeatureSet::MVP;
optionsFeatures.enable(enabledFeatures);
optionsFeatures.disable(disabledFeatures);
- if (!(module.features <= optionsFeatures)) {
- Fatal() << "module uses features not explicitly specified, "
- << "use --detect-features to resolve";
+ if (module.features != optionsFeatures) {
+ Fatal() << "module features do not match specified features. "
+ << "Use --detect-features to resolve.";
}
}
module.features.enable(enabledFeatures);
@@ -108,7 +108,7 @@ struct ToolOptions : public Options {
private:
bool hasFeatureOptions = false;
bool detectFeatures = false;
- FeatureSet enabledFeatures = FeatureSet::All;
+ FeatureSet enabledFeatures = FeatureSet::MVP;
FeatureSet disabledFeatures = FeatureSet::MVP;
};
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp
index 1f58da0d5..e064abbcb 100644
--- a/src/tools/wasm-reduce.cpp
+++ b/src/tools/wasm-reduce.cpp
@@ -271,7 +271,9 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor<
// try both combining with a generic shrink (so minor pass overhead is compensated for), and without
for (auto pass : passes) {
std::string currCommand = Path::getBinaryenBinaryTool("wasm-opt") + " ";
- currCommand += working + " -o " + test + " " + pass;
+ // TODO(tlively): -all should be replaced with an option to use the
+ // existing feature set, once implemented.
+ currCommand += working + " -all -o " + test + " " + pass;
if (debugInfo) currCommand += " -g ";
if (verbose) std::cerr << "| trying pass command: " << currCommand << "\n";
if (!ProgramResult(currCommand).failed()) {
@@ -321,6 +323,7 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor<
Module wasm;
ModuleReader reader;
reader.read(working, *module);
+ wasm.features = FeatureSet::All;
builder = make_unique<Builder>(*module);
setModule(module.get());
}
@@ -999,7 +1002,9 @@ int main(int argc, const char* argv[]) {
std::cerr << "|checking that command has expected behavior on canonicalized (read-written) binary\n";
{
// read and write it
- auto cmd = Path::getBinaryenBinaryTool("wasm-opt") + " " + input + " -o " + test;
+ // TODO(tlively): -all should be replaced with an option to use the existing
+ // feature set, once implemented.
+ auto cmd = Path::getBinaryenBinaryTool("wasm-opt") + " " + input + " -all -o " + test;
if (!binary) cmd += " -S";
ProgramResult readWrite(cmd);
if (readWrite.failed()) {
diff --git a/src/wasm-features.h b/src/wasm-features.h
index a1e7a321d..6ef704f82 100644
--- a/src/wasm-features.h
+++ b/src/wasm-features.h
@@ -88,6 +88,14 @@ struct FeatureSet {
return !(features & ~other.features);
}
+ bool operator==(const FeatureSet& other) const {
+ return *this <= other && other <= *this;
+ }
+
+ bool operator!=(const FeatureSet& other) const {
+ return !(*this == other);
+ }
+
FeatureSet& operator|=(const FeatureSet& other) {
features |= other.features;
return *this;
diff --git a/src/wasm.h b/src/wasm.h
index 2171eeb12..f4180f7a0 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -928,7 +928,7 @@ public:
// respected regardless of the value of`hasFeaturesSection`.
// `hasFeaturesSection` means we read a features section and will emit one
// too.
- FeatureSet features = FeatureSet::All;
+ FeatureSet features = FeatureSet::MVP;
bool hasFeaturesSection = false;
MixedArena allocator;
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index b969a1fbd..837dcbea1 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -973,7 +973,6 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata(
meta << " \"features\": [";
commaFirst = true;
- meta << nextElement() << "\"--mvp-features\"";
wasm.features.iterFeatures([&](FeatureSet::Feature f) {
meta << nextElement() << "\"--enable-" << FeatureSet::toString(f) << '"';
});
diff --git a/test/lld/duplicate_imports.wast.out b/test/lld/duplicate_imports.wast.out
index cbb1db44a..b8d046ab7 100644
--- a/test/lld/duplicate_imports.wast.out
+++ b/test/lld/duplicate_imports.wast.out
@@ -138,13 +138,6 @@
"invoke_ffd"
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/em_asm.wast.mem.out b/test/lld/em_asm.wast.mem.out
index 13484ff3d..2aac1ef36 100644
--- a/test/lld/em_asm.wast.mem.out
+++ b/test/lld/em_asm.wast.mem.out
@@ -262,13 +262,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/em_asm.wast.out b/test/lld/em_asm.wast.out
index 7986466cd..5917fb187 100644
--- a/test/lld/em_asm.wast.out
+++ b/test/lld/em_asm.wast.out
@@ -263,13 +263,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/em_asm_O0.wast.out b/test/lld/em_asm_O0.wast.out
index 45868e567..d194c8185 100644
--- a/test/lld/em_asm_O0.wast.out
+++ b/test/lld/em_asm_O0.wast.out
@@ -123,13 +123,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/em_asm_shared.wast.out b/test/lld/em_asm_shared.wast.out
index 19eabedc8..220a10aca 100644
--- a/test/lld/em_asm_shared.wast.out
+++ b/test/lld/em_asm_shared.wast.out
@@ -255,13 +255,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/em_asm_table.wast.out b/test/lld/em_asm_table.wast.out
index 1ed2cd5bd..50f24876e 100644
--- a/test/lld/em_asm_table.wast.out
+++ b/test/lld/em_asm_table.wast.out
@@ -93,13 +93,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/em_js_O0.wast.out b/test/lld/em_js_O0.wast.out
index 3db4c83d7..02d4fed07 100644
--- a/test/lld/em_js_O0.wast.out
+++ b/test/lld/em_js_O0.wast.out
@@ -73,13 +73,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/hello_world.wast.mem.out b/test/lld/hello_world.wast.mem.out
index 79ef1342a..834f4945a 100644
--- a/test/lld/hello_world.wast.mem.out
+++ b/test/lld/hello_world.wast.mem.out
@@ -98,13 +98,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/hello_world.wast.out b/test/lld/hello_world.wast.out
index c4a54667b..67fd6428b 100644
--- a/test/lld/hello_world.wast.out
+++ b/test/lld/hello_world.wast.out
@@ -99,13 +99,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/init.wast.out b/test/lld/init.wast.out
index 676f00327..645f78f67 100644
--- a/test/lld/init.wast.out
+++ b/test/lld/init.wast.out
@@ -110,13 +110,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/recursive.wast.out b/test/lld/recursive.wast.out
index 277d3cf1f..8f81cdc91 100644
--- a/test/lld/recursive.wast.out
+++ b/test/lld/recursive.wast.out
@@ -156,13 +156,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/reserved_func_ptr.wast.out b/test/lld/reserved_func_ptr.wast.out
index 5a5a6f29d..3ddf2f0ce 100644
--- a/test/lld/reserved_func_ptr.wast.out
+++ b/test/lld/reserved_func_ptr.wast.out
@@ -193,13 +193,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/lld/shared.wast.out b/test/lld/shared.wast.out
index 7716daa32..135aa3e5b 100644
--- a/test/lld/shared.wast.out
+++ b/test/lld/shared.wast.out
@@ -124,13 +124,6 @@
"invokeFuncs": [
],
"features": [
- "--mvp-features",
- "--enable-threads",
- "--enable-bulk-memory",
- "--enable-mutable-globals",
- "--enable-nontrapping-float-to-int",
- "--enable-sign-ext",
- "--enable-simd"
]
}
-- END METADATA --
diff --git a/test/passes/code-folding.txt b/test/passes/code-folding_enable-threads.txt
index 0fe3aa144..0fe3aa144 100644
--- a/test/passes/code-folding.txt
+++ b/test/passes/code-folding_enable-threads.txt
diff --git a/test/passes/code-folding.wast b/test/passes/code-folding_enable-threads.wast
index d9c1cc950..d9c1cc950 100644
--- a/test/passes/code-folding.wast
+++ b/test/passes/code-folding_enable-threads.wast
diff --git a/test/passes/flatten_dfo_O3.txt b/test/passes/flatten_dfo_O3_enable-threads.txt
index 74ddb5e2e..74ddb5e2e 100644
--- a/test/passes/flatten_dfo_O3.txt
+++ b/test/passes/flatten_dfo_O3_enable-threads.txt
diff --git a/test/passes/flatten_dfo_O3.wast b/test/passes/flatten_dfo_O3_enable-threads.wast
index e6e136b68..e6e136b68 100644
--- a/test/passes/flatten_dfo_O3.wast
+++ b/test/passes/flatten_dfo_O3_enable-threads.wast
diff --git a/test/passes/flatten_simplify-locals-nonesting_souperify-single-use.txt b/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt
index af2ba0f59..af2ba0f59 100644
--- a/test/passes/flatten_simplify-locals-nonesting_souperify-single-use.txt
+++ b/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt
diff --git a/test/passes/flatten_simplify-locals-nonesting_souperify-single-use.wast b/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.wast
index cfb94aa5c..cfb94aa5c 100644
--- a/test/passes/flatten_simplify-locals-nonesting_souperify-single-use.wast
+++ b/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.wast
diff --git a/test/passes/flatten_simplify-locals-nonesting_souperify.txt b/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt
index 6d70acdcd..6d70acdcd 100644
--- a/test/passes/flatten_simplify-locals-nonesting_souperify.txt
+++ b/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt
diff --git a/test/passes/flatten_simplify-locals-nonesting_souperify.wast b/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.wast
index bd1b825b6..bd1b825b6 100644
--- a/test/passes/flatten_simplify-locals-nonesting_souperify.wast
+++ b/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.wast
diff --git a/test/passes/fuzz-exec.txt b/test/passes/fuzz-exec_enable-sign-ext.txt
index 409f93181..409f93181 100644
--- a/test/passes/fuzz-exec.txt
+++ b/test/passes/fuzz-exec_enable-sign-ext.txt
diff --git a/test/passes/fuzz-exec.wast b/test/passes/fuzz-exec_enable-sign-ext.wast
index 08042d2b9..08042d2b9 100644
--- a/test/passes/fuzz-exec.wast
+++ b/test/passes/fuzz-exec_enable-sign-ext.wast
diff --git a/test/passes/inlining-optimizing.txt b/test/passes/inlining-optimizing_enable-threads.txt
index 437870065..437870065 100644
--- a/test/passes/inlining-optimizing.txt
+++ b/test/passes/inlining-optimizing_enable-threads.txt
diff --git a/test/passes/inlining-optimizing.wast b/test/passes/inlining-optimizing_enable-threads.wast
index f0435baa4..f0435baa4 100644
--- a/test/passes/inlining-optimizing.wast
+++ b/test/passes/inlining-optimizing_enable-threads.wast
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions_enable-threads.txt
index 67f0516fb..67f0516fb 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions_enable-threads.txt
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions_enable-threads.wast
index fa683ca78..fa683ca78 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions_enable-threads.wast
diff --git a/test/passes/precompute.txt b/test/passes/precompute_enable-simd.txt
index f7f58f58f..f7f58f58f 100644
--- a/test/passes/precompute.txt
+++ b/test/passes/precompute_enable-simd.txt
diff --git a/test/passes/precompute.wast b/test/passes/precompute_enable-simd.wast
index d6b1cc1b7..d6b1cc1b7 100644
--- a/test/passes/precompute.wast
+++ b/test/passes/precompute_enable-simd.wast
diff --git a/test/passes/remove-unused-module-elements.txt b/test/passes/remove-unused-module-elements_enable-threads.txt
index c2471e743..c2471e743 100644
--- a/test/passes/remove-unused-module-elements.txt
+++ b/test/passes/remove-unused-module-elements_enable-threads.txt
diff --git a/test/passes/remove-unused-module-elements.wast b/test/passes/remove-unused-module-elements_enable-threads.wast
index 4bd5ccf10..4bd5ccf10 100644
--- a/test/passes/remove-unused-module-elements.wast
+++ b/test/passes/remove-unused-module-elements_enable-threads.wast
diff --git a/test/passes/remove-unused-names_merge-blocks.txt b/test/passes/remove-unused-names_merge-blocks_enable-threads.txt
index b60d01957..b60d01957 100644
--- a/test/passes/remove-unused-names_merge-blocks.txt
+++ b/test/passes/remove-unused-names_merge-blocks_enable-threads.txt
diff --git a/test/passes/remove-unused-names_merge-blocks.wast b/test/passes/remove-unused-names_merge-blocks_enable-threads.wast
index f9603a60d..f9603a60d 100644
--- a/test/passes/remove-unused-names_merge-blocks.wast
+++ b/test/passes/remove-unused-names_merge-blocks_enable-threads.wast
diff --git a/test/passes/remove-unused-nonfunction-module-elements.txt b/test/passes/remove-unused-nonfunction-module-elements_enable-threads.txt
index 2d9609efa..2d9609efa 100644
--- a/test/passes/remove-unused-nonfunction-module-elements.txt
+++ b/test/passes/remove-unused-nonfunction-module-elements_enable-threads.txt
diff --git a/test/passes/remove-unused-nonfunction-module-elements.wast b/test/passes/remove-unused-nonfunction-module-elements_enable-threads.wast
index 4370328ce..4370328ce 100644
--- a/test/passes/remove-unused-nonfunction-module-elements.wast
+++ b/test/passes/remove-unused-nonfunction-module-elements_enable-threads.wast
diff --git a/test/passes/safe-heap.txt b/test/passes/safe-heap_enable-threads_enable-simd.txt
index 1f9640ce2..1f9640ce2 100644
--- a/test/passes/safe-heap.txt
+++ b/test/passes/safe-heap_enable-threads_enable-simd.txt
diff --git a/test/passes/safe-heap.wast b/test/passes/safe-heap_enable-threads_enable-simd.wast
index 17c9995c4..17c9995c4 100644
--- a/test/passes/safe-heap.wast
+++ b/test/passes/safe-heap_enable-threads_enable-simd.wast
diff --git a/test/passes/safe-heap_low-memory-unused.txt b/test/passes/safe-heap_low-memory-unused_enable-threads_enable-simd.txt
index 469cf9f94..469cf9f94 100644
--- a/test/passes/safe-heap_low-memory-unused.txt
+++ b/test/passes/safe-heap_low-memory-unused_enable-threads_enable-simd.txt
diff --git a/test/passes/safe-heap_low-memory-unused.wast b/test/passes/safe-heap_low-memory-unused_enable-threads_enable-simd.wast
index 17c9995c4..17c9995c4 100644
--- a/test/passes/safe-heap_low-memory-unused.wast
+++ b/test/passes/safe-heap_low-memory-unused_enable-threads_enable-simd.wast
diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals_all-features.txt
index 7a6de1873..7a6de1873 100644
--- a/test/passes/simplify-locals.txt
+++ b/test/passes/simplify-locals_all-features.txt
diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals_all-features.wast
index 34a93d442..34a93d442 100644
--- a/test/passes/simplify-locals.wast
+++ b/test/passes/simplify-locals_all-features.wast
diff --git a/test/passes/ssa.txt b/test/passes/ssa_enable-threads.txt
index 54a5cd757..54a5cd757 100644
--- a/test/passes/ssa.txt
+++ b/test/passes/ssa_enable-threads.txt
diff --git a/test/passes/ssa.wast b/test/passes/ssa_enable-threads.wast
index bbfad89bf..bbfad89bf 100644
--- a/test/passes/ssa.wast
+++ b/test/passes/ssa_enable-threads.wast
diff --git a/test/passes/ssa_fuzz-exec.txt b/test/passes/ssa_fuzz-exec_enable-threads.txt
index 35499266e..35499266e 100644
--- a/test/passes/ssa_fuzz-exec.txt
+++ b/test/passes/ssa_fuzz-exec_enable-threads.txt
diff --git a/test/passes/ssa_fuzz-exec.wast b/test/passes/ssa_fuzz-exec_enable-threads.wast
index 1ad1e2a6f..1ad1e2a6f 100644
--- a/test/passes/ssa_fuzz-exec.wast
+++ b/test/passes/ssa_fuzz-exec_enable-threads.wast
diff --git a/test/passes/translate-to-fuzz.txt b/test/passes/translate-to-fuzz_all-features.txt
index fe24e738e..fe24e738e 100644
--- a/test/passes/translate-to-fuzz.txt
+++ b/test/passes/translate-to-fuzz_all-features.txt
diff --git a/test/passes/translate-to-fuzz.wast b/test/passes/translate-to-fuzz_all-features.wast
index 5b378f2b2..5b378f2b2 100644
--- a/test/passes/translate-to-fuzz.wast
+++ b/test/passes/translate-to-fuzz_all-features.wast
diff --git a/test/passes/translate-to-fuzz_no-fuzz-nans.txt b/test/passes/translate-to-fuzz_no-fuzz-nans_all-features.txt
index 294b4f986..294b4f986 100644
--- a/test/passes/translate-to-fuzz_no-fuzz-nans.txt
+++ b/test/passes/translate-to-fuzz_no-fuzz-nans_all-features.txt
diff --git a/test/passes/translate-to-fuzz_no-fuzz-nans.wast b/test/passes/translate-to-fuzz_no-fuzz-nans_all-features.wast
index cbf25fde1..cbf25fde1 100644
--- a/test/passes/translate-to-fuzz_no-fuzz-nans.wast
+++ b/test/passes/translate-to-fuzz_no-fuzz-nans_all-features.wast
diff --git a/test/unit/test_features.py b/test/unit/test_features.py
index 1672b957a..8764bef97 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -1,10 +1,9 @@
import os
-import unittest
from scripts.test.shared import WASM_OPT, run_process
-from utils import input_path, roundtrip
+from utils import BinaryenTestCase
-class FeatureValidationTest(unittest.TestCase):
+class FeatureValidationTest(BinaryenTestCase):
def check_feature(self, module, error, flag):
p = run_process(WASM_OPT + ['--mvp-features', '--print', '-o', os.devnull],
input=module, check=False, capture_output=True)
@@ -116,53 +115,50 @@ class FeatureValidationTest(unittest.TestCase):
self.check_bulk_mem(module, 'nonzero segment flags (bulk memory is disabled)')
-class TargetFeaturesSectionTest(unittest.TestCase):
- def disassemble(self, filename):
- path = input_path(filename)
- p = run_process(WASM_OPT + ['--print', '-o', os.devnull, path], check=False,
- capture_output=True)
- self.assertEqual(p.returncode, 0)
- self.assertEqual(p.stderr, '')
- return p.stdout
-
+class TargetFeaturesSectionTest(BinaryenTestCase):
def test_atomics(self):
- roundtrip(self, 'atomics_target_feature.wasm')
- module = self.disassemble('atomics_target_feature.wasm')
- self.assertIn('i32.atomic.rmw.add', module)
+ filename = 'atomics_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['threads'])
+ self.assertIn('i32.atomic.rmw.add', self.disassemble(filename))
def test_bulk_memory(self):
- roundtrip(self, 'bulkmem_target_feature.wasm')
- module = self.disassemble('bulkmem_target_feature.wasm')
- self.assertIn('memory.copy', module)
+ filename = 'bulkmem_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['bulk-memory'])
+ self.assertIn('memory.copy', self.disassemble(filename))
def test_nontrapping_fptoint(self):
- roundtrip(self, 'truncsat_target_feature.wasm')
- module = self.disassemble('truncsat_target_feature.wasm')
- self.assertIn('i32.trunc_sat_f32_u', module)
+ filename = 'truncsat_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['nontrapping-float-to-int'])
+ self.assertIn('i32.trunc_sat_f32_u', self.disassemble(filename))
def test_sign_ext(self):
- roundtrip(self, 'signext_target_feature.wasm')
- module = self.disassemble('signext_target_feature.wasm')
- self.assertIn('i32.extend8_s', module)
+ filename = 'signext_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['sign-ext'])
+ self.assertIn('i32.extend8_s', self.disassemble(filename))
def test_simd(self):
- roundtrip(self, 'simd_target_feature.wasm')
- module = self.disassemble('simd_target_feature.wasm')
- self.assertIn('i32x4.splat', module)
+ filename = 'simd_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['simd'])
+ self.assertIn('i32x4.splat', self.disassemble(filename))
def test_incompatible_features(self):
- path = input_path('signext_target_feature.wasm')
+ path = self.input_path('signext_target_feature.wasm')
p = run_process(
- WASM_OPT + ['--print', '-mvp', '--enable-simd', '-o', os.devnull, path],
+ WASM_OPT + ['--print', '--enable-simd', '-o', os.devnull, path],
check=False, capture_output=True
)
self.assertNotEqual(p.returncode, 0)
- self.assertIn('Fatal: module uses features not explicitly specified, ' +
- 'use --detect-features to resolve',
+ self.assertIn('Fatal: module features do not match specified features. ' +
+ 'Use --detect-features to resolve.',
p.stderr)
def test_incompatible_features_forced(self):
- path = input_path('signext_target_feature.wasm')
+ path = self.input_path('signext_target_feature.wasm')
p = run_process(
WASM_OPT + ['--print', '--detect-features', '-mvp', '--enable-simd',
'-o', os.devnull, path],
@@ -172,11 +168,5 @@ class TargetFeaturesSectionTest(unittest.TestCase):
self.assertIn('all used features should be allowed', p.stderr)
def test_explicit_detect_features(self):
- path = input_path('signext_target_feature.wasm')
- p = run_process(
- WASM_OPT + ['--print', '-mvp', '--detect-features',
- '-o', os.devnull, path],
- check=False, capture_output=True
- )
- self.assertEqual(p.returncode, 0)
- self.assertEqual(p.stderr, '')
+ self.check_features('signext_target_feature.wasm', ['sign-ext', 'simd'],
+ opts=['-mvp', '--detect-features', '--enable-simd'])
diff --git a/test/unit/test_memory_packing.py b/test/unit/test_memory_packing.py
index 0d62b0ed5..a0ccd3006 100644
--- a/test/unit/test_memory_packing.py
+++ b/test/unit/test_memory_packing.py
@@ -1,12 +1,12 @@
import os
-import unittest
from scripts.test.shared import WASM_OPT, run_process
+from utils import BinaryenTestCase
'''Test that MemoryPacking correctly respects the web limitations by not
generating more than 100K data segments'''
-class MemoryPackingTest(unittest.TestCase):
+class MemoryPackingTest(BinaryenTestCase):
def test_large_segment(self):
data = '"' + (('A' + ('\\00' * 9)) * 100001) + '"'
module = '''
diff --git a/test/unit/utils.py b/test/unit/utils.py
index eaeb29d42..876f2f4ec 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -1,16 +1,34 @@
import os
+import unittest
from scripts.test.shared import WASM_OPT, run_process, options
-def input_path(filename):
- return os.path.join(options.binaryen_test, 'unit', 'input', filename)
+class BinaryenTestCase(unittest.TestCase):
+ def input_path(self, filename):
+ return os.path.join(options.binaryen_test, 'unit', 'input', filename)
+ def roundtrip(self, filename, opts=[]):
+ path = self.input_path(filename)
+ p = run_process(WASM_OPT + ['-g', '-o', '-', path] + opts, check=False,
+ capture_output=True)
+ self.assertEqual(p.returncode, 0)
+ self.assertEqual(p.stderr, '')
+ with open(path, 'rb') as f:
+ self.assertEqual(str(p.stdout), str(f.read()))
-def roundtrip(testcase, filename, opts=[]):
- path = input_path(filename)
- p = run_process(WASM_OPT + ['-g', '-o', '-', path] + opts, check=False,
- capture_output=True)
- testcase.assertEqual(p.returncode, 0)
- testcase.assertEqual(p.stderr, '')
- with open(path, 'rb') as f:
- testcase.assertEqual(str(p.stdout), str(f.read()))
+ def disassemble(self, filename):
+ path = self.input_path(filename)
+ p = run_process(WASM_OPT + ['--print', '-o', os.devnull, path], check=False,
+ capture_output=True)
+ self.assertEqual(p.returncode, 0)
+ self.assertEqual(p.stderr, '')
+ return p.stdout
+
+ def check_features(self, filename, features, opts=[]):
+ path = self.input_path(filename)
+ cmd = WASM_OPT + ['--print-features', '-o', os.devnull, path] + opts
+ p = run_process(cmd, check=False, capture_output=True)
+ self.assertEqual(p.returncode, 0)
+ self.assertEqual(p.stderr, '')
+ self.assertEqual(p.stdout.split('\n')[:-1],
+ ['--enable-' + f for f in features])