Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm2c: run multi-memory tests #1834

Merged
merged 1 commit into from
Feb 18, 2022
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
19 changes: 13 additions & 6 deletions src/tools/wasm2c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ static const char s_description[] =
$ wasm2c test.wasm --no-debug-names -o test.c
)";

static const std::string supported_features[] = {"multi-memory"};

static bool IsFeatureSupported(const std::string& feature) {
return std::find(std::begin(supported_features), std::end(supported_features),
feature) != std::end(supported_features);
};

static void ParseOptions(int argc, char** argv) {
OptionParser parser("wasm2c", s_description);

Expand All @@ -80,15 +87,15 @@ static void ParseOptions(int argc, char** argv) {
});
parser.Parse(argc, argv);

// TODO(binji): currently wasm2c doesn't support any non-default feature
// flags.
bool any_non_default_feature = false;
#define WABT_FEATURE(variable, flag, default_, help) \
any_non_default_feature |= (s_features.variable##_enabled() != default_);
bool any_non_supported_feature = false;
#define WABT_FEATURE(variable, flag, default_, help) \
any_non_supported_feature |= \
(s_features.variable##_enabled() != default_) && \
!IsFeatureSupported(flag);
#include "src/feature.def"
#undef WABT_FEATURE

if (any_non_default_feature) {
if (any_non_supported_feature) {
fprintf(stderr,
"wasm2c currently only supports a fixed set of features.\n");
exit(1);
Expand Down
7 changes: 6 additions & 1 deletion test/run-spec-wasm2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def main(args):
help='print the commands that are run.',
action='store_true')
parser.add_argument('file', help='wast file.')
parser.add_argument('--enable-multi-memory', action='store_true')
options = parser.parse_args(args)

with utils.TempDirectory(options.out_dir, 'run-spec-wasm2c-') as out_dir:
Expand All @@ -385,7 +386,9 @@ def main(args):
find_exe.GetWast2JsonExecutable(options.bindir),
error_cmdline=options.error_cmdline)
wast2json.verbose = options.print_cmd
wast2json.AppendOptionalArgs({'-v': options.verbose})
wast2json.AppendOptionalArgs({
'-v': options.verbose,
'--enable-multi-memory': options.enable_multi_memory})

json_file_path = utils.ChangeDir(
utils.ChangeExt(options.file, '.json'), out_dir)
Expand All @@ -395,6 +398,8 @@ def main(args):
find_exe.GetWasm2CExecutable(options.bindir),
error_cmdline=options.error_cmdline)
wasm2c.verbose = options.print_cmd
wasm2c.AppendOptionalArgs({
'--enable-multi-memory': options.enable_multi_memory})

cc = utils.Executable(options.cc, *options.cflags)
cc.verbose = options.print_cmd
Expand Down
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/binary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/binary.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
0/0 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/data.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
14/14 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/memory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/memory.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
45/45 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/memory_grow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/memory_grow.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
131/131 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/memory_size.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/memory_size.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
40/40 tests passed.
;;; STDOUT ;;)