From f423c31962aeb47b2c2c00027a2d8e8baf6afd3c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 26 May 2023 23:59:20 +0900 Subject: [PATCH 01/15] toywasm-on-toywasm.py: rename an input environment variable to allow it to be set to this script --- test/toywasm-on-toywasm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/toywasm-on-toywasm.py b/test/toywasm-on-toywasm.py index 6ab84270..6c1fdf35 100755 --- a/test/toywasm-on-toywasm.py +++ b/test/toywasm-on-toywasm.py @@ -7,7 +7,7 @@ import sys import subprocess -executable = os.getenv("TOYWASM", "./build.native/toywasm") +executable = os.getenv("TOYWASM_NATIVE", "./build.native/toywasm") executable_wasm = os.getenv("TOYWASM_WASM", "./build.wasm/toywasm") parser = argparse.ArgumentParser(allow_abbrev=False) From cdfbd3fa52b106cc72f68a99cc59cd73e065d308 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:00:47 +0900 Subject: [PATCH 02/15] toywasm-on-toywasm.py: make the mapdir logic cover a bit more situations --- test/toywasm-on-toywasm.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/test/toywasm-on-toywasm.py b/test/toywasm-on-toywasm.py index 6c1fdf35..ff458823 100755 --- a/test/toywasm-on-toywasm.py +++ b/test/toywasm-on-toywasm.py @@ -16,6 +16,7 @@ args, unknown = parser.parse_known_args() sys_prefix = "@TOYWASM@" +debug = False def translate_path(cat, name): @@ -38,13 +39,40 @@ def translate_path(cat, name): g, h = x.split("::", maxsplit=2) options.append(f"--wasi-dir={h}") -# assume that the first argument which doesn't -# start with "--" is a wasm module. +# assume that the first argument which doesn't start with "--" is +# a wasm module. +# also, translate --load argument. +# note: this logic recognizes only a subset of toywasm cli options. +# you can use "--invoke=foo" instead of "--invoke foo" to avoid +# misinterpretations. user_args = sys.argv[1:] +if debug: + print(f"Original: {user_args}") +load_arg = False +options_done = False for i in range(0, len(user_args)): - if not user_args[i].startswith("--"): + if load_arg: + user_args[i] = translate_path(f"load-wasm-{i}", user_args[i]) + load_arg = False + continue + if not options_done: + if user_args[i] == "--": + options_done = True + continue + if user_args[i] == "--load": + load_arg = True + continue + if user_args[i].startswith("--load="): + _, wasm = user_args[i].split("=", 1) + translated = translate_path(f"load-wasm-{i}", wasm) + user_args[i] = f"--load={translated}" + continue + if options_done or not user_args[i].startswith("--"): user_args[i] = translate_path("user-wasm", user_args[i]) break +if debug: + print(f"Translated: {user_args}") + print(f"Host toywasm options: {options}") cmd = ( shlex.split(executable) + ["--wasi"] + options + ["--", executable_wasm] + user_args From fb7c08e3df1ba16a5c3eab57b4c6aa7c2cdbde9a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:02:50 +0900 Subject: [PATCH 03/15] wasi-testsuite-adapter.py: prefer "--long=arg" style over "--long arg" because toywasm-on-toywasm.py can only deal with the former --- test/wasi-testsuite-adapter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/wasi-testsuite-adapter.py b/test/wasi-testsuite-adapter.py index c0067a83..ed3bc5d8 100755 --- a/test/wasi-testsuite-adapter.py +++ b/test/wasi-testsuite-adapter.py @@ -30,9 +30,9 @@ options = [] for x in args.env: - options.extend(["--wasi-env", x]) + options.extend([f"--wasi-env={x}"]) for x in args.dir: - options.extend(["--wasi-dir", x]) + options.extend([f"--wasi-dir={x}"]) result = subprocess.run( shlex.split(executable) + ["--wasi"] + options + ["--", args.test_file] + args.arg ) From 7a0e783dfc14f8c8bdcdce9369ab2d4226a79dde Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:04:29 +0900 Subject: [PATCH 04/15] run-wasmtime-wasi-tests.sh: make this a bit toywasm-on-toywasm.py friendly --- test/run-wasmtime-wasi-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-wasmtime-wasi-tests.sh b/test/run-wasmtime-wasi-tests.sh index d0a1cfee..ad86cd49 100755 --- a/test/run-wasmtime-wasi-tests.sh +++ b/test/run-wasmtime-wasi-tests.sh @@ -36,7 +36,7 @@ if [ "${WASM_ON_WASM:-0}" -ne 0 ]; then else run_wasi_test() { - ${EXE} --wasi-dir ${TMP} ${w} ${TMP}; + ${EXE} --wasi-dir=${TMP} -- ${w} ${TMP}; } if ${EXE} --version | grep -F "sizeof(void *) = 4"; then SKIPLIST="${SKIPLIST} ${THIS_DIR}/wasmtime-wasi-tests-skip-32bit.txt" From ae21a986598921b8a6295bb6fe368295baab91d0 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:07:29 +0900 Subject: [PATCH 05/15] cmake: add TOYWASM_BUILD_UNITTEST option to allow to disable only toywasm-test. a preparation to allow toywasm-cli tests for wasm-on-wasm. --- CMakeLists.txt | 2 ++ cmake/ToywasmConfig.cmake | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7279417f..d310964b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,7 @@ endif() # unit test if(BUILD_TESTING) +if(TOYWASM_BUILD_UNITTEST) find_package(cmocka REQUIRED) # compat with cmocka <1.1.6 @@ -196,6 +197,7 @@ target_link_libraries(toywasm-test toywasm-lib-core m ${CMOCKA_LIBRARY}) add_test(NAME toywasm-test COMMAND toywasm-test) set_tests_properties(toywasm-test PROPERTIES ENVIRONMENT "${TEST_ENV}") target_link_libraries(toywasm-test cmocka::cmocka) +endif() # TOYWASM_BUILD_UNITTEST endif() # XXX Is there a way to create the file list from install() commands? diff --git a/cmake/ToywasmConfig.cmake b/cmake/ToywasmConfig.cmake index ced36f14..e7ed3514 100644 --- a/cmake/ToywasmConfig.cmake +++ b/cmake/ToywasmConfig.cmake @@ -26,6 +26,8 @@ option(TOYWASM_ENABLE_WASM_THREADS "Enable WASM threads proposal" OFF) option(TOYWASM_ENABLE_WASI "Enable WASI snapshow preview1" ON) option(TOYWASM_ENABLE_WASI_THREADS "Enable wasi-threads proposal" OFF) +option(TOYWASM_BUILD_UNITTEST "Build toywasm-test" ON) + if(NOT DEFINED USE_LSAN) set(USE_LSAN ON) endif() From e769ec8964fa92ce3851e0b24f8e506b29a6666a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:23:16 +0900 Subject: [PATCH 06/15] cmake: use toywasm-on-toywasm.py when testing wasi target --- CMakeLists.txt | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d310964b..8871b632 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,21 @@ if(TOYWASM_ENABLE_WASI) add_subdirectory(libwasi) endif() +if(CMAKE_C_COMPILER_TARGET MATCHES "wasm") +set(TOYWASM_CLI "${CMAKE_CURRENT_SOURCE_DIR}/test/toywasm-on-toywasm.py") +if(NOT DEFINED ENV{TOYWASM_NATIVE}) +list(APPEND TEST_ENV "TOYWASM_NATIVE=${CMAKE_CURRENT_SOURCE_DIR}/build.native/toywasm") +endif() +if(NOT DEFINED ENV{TOYWASM_WASM}) +list(APPEND TEST_ENV "TOYWASM_WASM=${CMAKE_BINARY_DIR}/toywasm") +endif() +else() +set(TOYWASM_CLI "${CMAKE_BINARY_DIR}/toywasm") +endif() + +# for wasi-testsuite-adapter.py +list(APPEND TEST_ENV "TEST_RUNTIME_EXE=${TOYWASM_CLI}") + # cli set(cli_sources @@ -37,7 +52,7 @@ target_link_libraries(toywasm-cli toywasm-lib-core $<$:TESTS=proposals/wasi-threads/>") +set_tests_properties(toywasm-cli-wasi-testsuite PROPERTIES ENVIRONMENT "${TEST_ENV};TOYWASM=${TOYWASM_CLI};$<$:TESTS=proposals/wasi-threads/>") set_tests_properties(toywasm-cli-wasi-testsuite PROPERTIES LABELS "wasi-testsuite") add_test(NAME toywasm-cli-wasmtime-wasi-tests - COMMAND ./test/run-wasmtime-wasi-tests.sh "${CMAKE_BINARY_DIR}/toywasm --wasi --wasi-dir ." + COMMAND ./test/run-wasmtime-wasi-tests.sh "${TOYWASM_CLI} --wasi --wasi-dir=." WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(toywasm-cli-wasmtime-wasi-tests PROPERTIES ENVIRONMENT "${TEST_ENV}") set_tests_properties(toywasm-cli-wasmtime-wasi-tests PROPERTIES LABELS "wasmtime-wasi-tests") add_test(NAME toywasm-cli-spidermonkey - COMMAND ./test/run-spidermonkey.sh ${CMAKE_BINARY_DIR}/toywasm --wasi + COMMAND ./test/run-spidermonkey.sh ${TOYWASM_CLI} --wasi WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(toywasm-cli-spidermonkey PROPERTIES ENVIRONMENT "${TEST_ENV}") add_test(NAME toywasm-cli-ffmpeg - COMMAND ./test/run-ffmpeg.sh ${CMAKE_BINARY_DIR}/toywasm --wasi --wasi-dir .video -- + COMMAND ./test/run-ffmpeg.sh ${TOYWASM_CLI} --wasi --wasi-dir=.video -- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(toywasm-cli-ffmpeg PROPERTIES ENVIRONMENT "${TEST_ENV}") @@ -133,7 +148,7 @@ if(NOT TOYWASM_ENABLE_WASM_MULTI_MEMORY) add_test(NAME toywasm-cli-wasm3-spec-test-disable-optimizations # Note: arbitrary limits for stack overflow tests in call.wast. # (--max-frames and --max-stack-cells) - COMMAND ./test/run-wasm3-spec-test-opam-2.0.0.sh --exec "${CMAKE_BINARY_DIR}/toywasm --disable-jump-table --disable-resulttype-cellidx --disable-localtype-cellidx --max-frames 2000 --max-stack-cells 10000 --repl --repl-prompt wasm3" --timeout 60 --spectest ${CMAKE_BINARY_DIR}/spectest.wasm + COMMAND ./test/run-wasm3-spec-test-opam-2.0.0.sh --exec "${TOYWASM_CLI} --disable-jump-table --disable-resulttype-cellidx --disable-localtype-cellidx --max-frames=2000 --max-stack-cells=10000 --repl --repl-prompt=wasm3" --timeout 60 --spectest ${CMAKE_BINARY_DIR}/spectest.wasm WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(toywasm-cli-wasm3-spec-test-disable-optimizations PROPERTIES ENVIRONMENT "${TEST_ENV}") @@ -142,7 +157,7 @@ endif() if(TOYWASM_ENABLE_WASI) add_test(NAME toywasm-cli-wasm3-wasi-test - COMMAND ./test/run-wasm3-wasi-test.sh --exec "${CMAKE_BINARY_DIR}/toywasm --wasi --wasi-dir ." --separate-args --timeout 1200 + COMMAND ./test/run-wasm3-wasi-test.sh --exec "${TOYWASM_CLI} --wasi --wasi-dir=." --separate-args --timeout 1200 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(toywasm-cli-wasm3-wasi-test PROPERTIES ENVIRONMENT "${TEST_ENV}") From 7cd66e0d84de6cba4294386d68b79d792b26a6c0 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:24:03 +0900 Subject: [PATCH 07/15] ci: enable more tests for wasm-on-wasm jobs --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25fbdb9b..1413f190 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -371,6 +371,11 @@ jobs: runs-on: ${{matrix.os}} steps: + - name: Set environment + run: | + echo "builddir=${{github.workspace}}/build.wasm" >> ${GITHUB_ENV} + echo "TOYWASM_NATIVE=${{github.workspace}/build.native/toywasm" >> ${GITHUB_ENV} + - name: Install dependencies (ubuntu) if: startsWith(matrix.os, 'ubuntu-') run: sudo apt-get update && sudo apt-get install -y pax ninja-build @@ -390,6 +395,21 @@ jobs: EXTRA_CMAKE_OPTIONS: -G Ninja -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/dist -DTOYWASM_TARBALL_SUFFIX=-${{matrix.name}} ${{matrix.extra}} run: ./wasm-on-wasm.sh + - name: toywasm --version + working-directory: ${{env.builddir}} + run: | + ${{github.workspace}}/test/toywasm-on-toywasm.py --version + + - name: Test + working-directory: ${{env.builddir}} + run: | + ctest -V -LE slow + + - name: Test (slow) + working-directory: ${{env.builddir}} + run: | + ctest -V -L slow + - name: Install run: | cmake --build build.wasm --target install From 541acb0c2f63c18f6bb8f3d1bfd76988f3219a0c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:26:50 +0900 Subject: [PATCH 08/15] fix a typo --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1413f190..7f8e8412 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -374,7 +374,7 @@ jobs: - name: Set environment run: | echo "builddir=${{github.workspace}}/build.wasm" >> ${GITHUB_ENV} - echo "TOYWASM_NATIVE=${{github.workspace}/build.native/toywasm" >> ${GITHUB_ENV} + echo "TOYWASM_NATIVE=${{github.workspace}}/build.native/toywasm" >> ${GITHUB_ENV} - name: Install dependencies (ubuntu) if: startsWith(matrix.os, 'ubuntu-') From 4d314f11224d83eefd986a07d6e2541c4dd6fc41 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:42:52 +0900 Subject: [PATCH 09/15] ci: don't forget to set TOYWASM_WASM --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f8e8412..fd82058c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -396,6 +396,8 @@ jobs: run: ./wasm-on-wasm.sh - name: toywasm --version + env: + TOYWASM_WASM: ${{env.builddir}}/toywasm working-directory: ${{env.builddir}} run: | ${{github.workspace}}/test/toywasm-on-toywasm.py --version From 17c79c1b159d1f4671bb9544d0ff9104d5e859c5 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:47:32 +0900 Subject: [PATCH 10/15] build-wasm32-wasi.sh: only disable unittests --- build-wasm32-wasi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-wasm32-wasi.sh b/build-wasm32-wasi.sh index b46244f8..517392d0 100755 --- a/build-wasm32-wasi.sh +++ b/build-wasm32-wasi.sh @@ -50,7 +50,7 @@ cmake \ -B ${BUILD_DIR} \ -DWASI_SDK_PREFIX=${WASI_SDK_DIR} \ -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \ --DBUILD_TESTING=OFF \ +-DTOYWASM_BUILD_UNITTEST=OFF \ -DTOYWASM_USE_TAILCALL=${USE_TAILCALL:-OFF} \ ${EXTRA_CMAKE_OPTIONS} \ . From 839406ae49f11791c29fca4d2c63eba9cd58983f Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 00:52:47 +0900 Subject: [PATCH 11/15] ci: install wat2wasm for wasm-on-wasm as well --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd82058c..0169a026 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -378,11 +378,12 @@ jobs: - name: Install dependencies (ubuntu) if: startsWith(matrix.os, 'ubuntu-') - run: sudo apt-get update && sudo apt-get install -y pax ninja-build + run: sudo apt-get update && sudo apt-get install -y wabt pax ninja-build - name: Install dependencies (macOS) if: startsWith(matrix.os, 'macos-') run: | + brew install wabt brew install ninja - uses: actions/checkout@v3 From 2a76edef85ea00e323be16e8cca790e5f60225e3 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 01:10:35 +0900 Subject: [PATCH 12/15] ci: install virtualenv for wasm-on-wasm as well --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0169a026..b231bb42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -378,12 +378,13 @@ jobs: - name: Install dependencies (ubuntu) if: startsWith(matrix.os, 'ubuntu-') - run: sudo apt-get update && sudo apt-get install -y wabt pax ninja-build + run: sudo apt-get update && sudo apt-get install -y wabt pax virtualenv ninja-build - name: Install dependencies (macOS) if: startsWith(matrix.os, 'macos-') run: | brew install wabt + brew install virtualenv brew install ninja - uses: actions/checkout@v3 From 3712188c1594d246810914005e56134365e53904 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 01:26:47 +0900 Subject: [PATCH 13/15] cmake: use toywasm-on-toywasm.py when testing wasi target (cont) i forgot to update update toywasm-cli-wasm3-spec-test-threads --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8871b632..3715c210 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ endif() if(TOYWASM_ENABLE_WASM_THREADS) add_test(NAME toywasm-cli-wasm3-spec-test-threads - COMMAND ./test/run-wasm3-spec-test-threads.sh --exec "${CMAKE_BINARY_DIR}/toywasm --repl --repl-prompt wasm3" --timeout 60 --spectest ${CMAKE_BINARY_DIR}/spectest.wasm + COMMAND ./test/run-wasm3-spec-test-threads.sh --exec "${TOYWASM_CLI} --repl --repl-prompt=wasm3" --timeout 60 --spectest ${CMAKE_BINARY_DIR}/spectest.wasm WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(toywasm-cli-wasm3-spec-test-threads PROPERTIES ENVIRONMENT "${TEST_ENV}") From 8171c12244ce46ace426105e26e7c32102a20f53 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 02:16:34 +0900 Subject: [PATCH 14/15] ci: skip slow tests for wasm-on-wasm --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b231bb42..664ec585 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -410,6 +410,7 @@ jobs: ctest -V -LE slow - name: Test (slow) + if: false working-directory: ${{env.builddir}} run: | ctest -V -L slow From 404073fc8b19b8f2a3966c6fdf8108d363a95f67 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 27 May 2023 02:21:37 +0900 Subject: [PATCH 15/15] README.md: update CI notes --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59972c37..a72b31d8 100644 --- a/README.md +++ b/README.md @@ -84,13 +84,21 @@ It includes * macOS/amd64 * Ubuntu/amd64 -#### With qemu (less coverage because of slowness) +#### With qemu * Ubuntu/arm64 * Ubuntu/armhf (Note: 32-bit) + +#### With qemu (less coverage because of slowness) + * Ubuntu/s390x (Note: big endian) +* Ubuntu/risc-v + +(I haven't investigated why they are slower than others. +It might be related to the fact that our build disables LTO +for them for toolchain issues.) -#### with even less coverage +#### With toywasm (less coverage because of slowness) * wasm32-wasi