Meta+CMake: Extract Wasm spec tests into the binary directory

Clean up the Wasm spec tests CMake rules to extract and compile the wat
files into wasm files in the LibWasm binary directory instead of its
source directory. Also make the rules more robust to missing host tools,
and use more CMake install rules for the test files rather than relying
on build-root-filesystem.sh. Add some FIXMEs for later, we really
shouldn't be doing installation of test files into /home/anon at the
build-root-filesystem stage in $CURRENT_YEAR. Tests go in /usr/Tests
This commit is contained in:
Andrew Kaster 2022-12-10 12:23:36 -07:00 committed by Ali Mohammad Pur
parent ab49dbf137
commit 733a318709
Notes: sideshowbarker 2024-07-17 14:36:19 +09:00
5 changed files with 29 additions and 18 deletions

View file

@ -208,7 +208,6 @@ add_custom_target(components ALL)
option(BUILD_EVERYTHING "Build all optional components" ON) option(BUILD_EVERYTHING "Build all optional components" ON)
include(utils) include(utils)
include(wasm_spec_tests)
include(flac_spec_tests) include(flac_spec_tests)
serenity_component( serenity_component(

View file

@ -1,12 +1,11 @@
#
# Download and compile the WebAssembly testsuite into the WebAssembly binary format
#
if(INCLUDE_WASM_SPEC_TESTS) if(INCLUDE_WASM_SPEC_TESTS)
if (CMAKE_PROJECT_NAME STREQUAL "SerenityOS")
set(SOURCE_DIR "${SerenityOS_SOURCE_DIR}")
else()
set(SOURCE_DIR "${SERENITY_PROJECT_ROOT}")
endif()
set(WASM_SPEC_TEST_GZ_URL https://github.com/WebAssembly/testsuite/archive/refs/heads/main.tar.gz) set(WASM_SPEC_TEST_GZ_URL https://github.com/WebAssembly/testsuite/archive/refs/heads/main.tar.gz)
set(WASM_SPEC_TEST_GZ_PATH ${CMAKE_BINARY_DIR}/wasm-spec-testsuite.tar.gz) set(WASM_SPEC_TEST_GZ_PATH ${CMAKE_BINARY_DIR}/wasm-spec-testsuite.tar.gz CACHE PATH "")
set(WASM_SPEC_TEST_PATH ${SOURCE_DIR}/Userland/Libraries/LibWasm/Tests/Fixtures/SpecTests) set(WASM_SPEC_TEST_PATH ${CMAKE_CURRENT_BINARY_DIR}/Tests/Fixtures/SpecTests CACHE PATH "")
if(NOT EXISTS ${WASM_SPEC_TEST_GZ_PATH}) if(NOT EXISTS ${WASM_SPEC_TEST_GZ_PATH})
message(STATUS "Downloading the WebAssembly testsuite from ${WASM_SPEC_TEST_GZ_URL}...") message(STATUS "Downloading the WebAssembly testsuite from ${WASM_SPEC_TEST_GZ_URL}...")
@ -18,7 +17,13 @@ if(INCLUDE_WASM_SPEC_TESTS)
set(SKIP_PRETTIER true) set(SKIP_PRETTIER true)
endif() endif()
if(EXISTS ${WASM_SPEC_TEST_GZ_PATH} AND NOT EXISTS ${WASM_SPEC_TEST_PATH}) find_program(WAT2WASM wat2wasm REQUIRED)
find_program(PRETTIER prettier OPTIONAL)
if (NOT SKIP_PRETTIER AND NOT PRETTIER_FOUND)
message(FATAL_ERROR "Prettier required to format Wasm spec tests! Install prettier or set WASM_SPEC_TEST_SKIP_FORMATTING to ON")
endif()
if(EXISTS ${WASM_SPEC_TEST_GZ_PATH} AND NOT EXISTS ${WASM_SPEC_TEST_PATH}/const_0.wasm)
message(STATUS "Extracting the WebAssembly testsuite from ${WASM_SPEC_TEST_GZ_PATH}...") message(STATUS "Extracting the WebAssembly testsuite from ${WASM_SPEC_TEST_GZ_PATH}...")
file(MAKE_DIRECTORY ${WASM_SPEC_TEST_PATH}) file(MAKE_DIRECTORY ${WASM_SPEC_TEST_PATH})
if (CMAKE_VERSION VERSION_LESS 3.18.0) if (CMAKE_VERSION VERSION_LESS 3.18.0)
@ -26,7 +31,7 @@ if(INCLUDE_WASM_SPEC_TESTS)
else() else()
file(ARCHIVE_EXTRACT INPUT ${WASM_SPEC_TEST_GZ_PATH} ) file(ARCHIVE_EXTRACT INPUT ${WASM_SPEC_TEST_GZ_PATH} )
endif() endif()
file(GLOB WASM_TESTS "${CMAKE_BINARY_DIR}/testsuite-main/*.wast") file(GLOB WASM_TESTS "${CMAKE_CURRENT_BINARY_DIR}/testsuite-main/*.wast")
foreach(PATH ${WASM_TESTS}) foreach(PATH ${WASM_TESTS})
get_filename_component(NAME ${PATH} NAME_WLE) get_filename_component(NAME ${PATH} NAME_WLE)
message(STATUS "Generating test cases for WebAssembly test ${NAME}...") message(STATUS "Generating test cases for WebAssembly test ${NAME}...")
@ -36,8 +41,13 @@ if(INCLUDE_WASM_SPEC_TESTS)
continue() continue()
endif() endif()
execute_process( execute_process(
COMMAND env SKIP_PRETTIER=${SKIP_PRETTIER} bash ${SOURCE_DIR}/Meta/generate-libwasm-spec-test.sh "${PATH}" "${SOURCE_DIR}/Userland/Libraries/LibWasm/Tests/Spec" "${NAME}" "${WASM_SPEC_TEST_PATH}") COMMAND env SKIP_PRETTIER=${SKIP_PRETTIER} bash ${SerenityOS_SOURCE_DIR}/Meta/generate-libwasm-spec-test.sh "${PATH}" "${CMAKE_CURRENT_BINARY_DIR}/Tests/Spec" "${NAME}" "${WASM_SPEC_TEST_PATH}")
endforeach() endforeach()
file(REMOVE testsuite-main) file(REMOVE testsuite-main)
endif() endif()
# FIXME: Install these into usr/Tests/LibWasm
if (SERENITYOS)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Tests/ DESTINATION home/anon/Tests/wasm-tests)
endif()
endif() endif()

View file

@ -65,7 +65,6 @@ if (ENABLE_FUZZERS OR CMAKE_CROSSCOMPILING)
set(BUILD_LAGOM_TOOLS OFF) set(BUILD_LAGOM_TOOLS OFF)
endif() endif()
include(wasm_spec_tests)
include(flac_spec_tests) include(flac_spec_tests)
include(lagom_compile_options) include(lagom_compile_options)
@ -665,13 +664,12 @@ if (BUILD_LAGOM)
../../Tests/LibWasm/test-wasm.cpp ../../Tests/LibWasm/test-wasm.cpp
../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp) ../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
target_link_libraries(test-wasm LibCore LibTest LibWasm LibJS) target_link_libraries(test-wasm LibCore LibTest LibWasm LibJS)
# FIXME: Don't require passing test-common.js path if you only want to pass a custom Test root path
add_test( add_test(
NAME WasmParser NAME WasmParser
COMMAND test-wasm --show-progress=false COMMAND test-wasm --show-progress=false ${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries/LibWasm/Tests ${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibJS/Tests/test-common.js
) )
set_tests_properties(WasmParser PROPERTIES set_tests_properties(WasmParser PROPERTIES SKIP_RETURN_CODE 1)
ENVIRONMENT SERENITY_SOURCE_DIR=${SERENITY_PROJECT_ROOT}
SKIP_RETURN_CODE 1)
# Tests that are not LibTest based # Tests that are not LibTest based
# Shell # Shell

View file

@ -154,7 +154,8 @@ mkdir -p mnt/home/anon
mkdir -p mnt/home/anon/Desktop mkdir -p mnt/home/anon/Desktop
mkdir -p mnt/home/anon/Downloads mkdir -p mnt/home/anon/Downloads
mkdir -p mnt/home/nona mkdir -p mnt/home/nona
rm -fr mnt/home/anon/Tests/js-tests mnt/home/anon/Tests/web-tests mnt/home/anon/Tests/cpp-tests mnt/home/anon/Tests/wasm-tests # FIXME: Handle these test copies using CMake install rules
rm -fr mnt/home/anon/Tests/js-tests mnt/home/anon/Tests/web-tests mnt/home/anon/Tests/cpp-tests
mkdir -p mnt/home/anon/Tests/cpp-tests/ mkdir -p mnt/home/anon/Tests/cpp-tests/
cp "$SERENITY_SOURCE_DIR"/README.md mnt/home/anon/ cp "$SERENITY_SOURCE_DIR"/README.md mnt/home/anon/
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibJS/Tests mnt/home/anon/Tests/js-tests cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibJS/Tests mnt/home/anon/Tests/js-tests
@ -162,7 +163,6 @@ cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibWeb/Tests mnt/home/anon/Tests
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibCodeComprehension/Cpp/Tests mnt/home/anon/Tests/cpp-tests/comprehension cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibCodeComprehension/Cpp/Tests mnt/home/anon/Tests/cpp-tests/comprehension
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibCpp/Tests/parser mnt/home/anon/Tests/cpp-tests/parser cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibCpp/Tests/parser mnt/home/anon/Tests/cpp-tests/parser
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibCpp/Tests/preprocessor mnt/home/anon/Tests/cpp-tests/preprocessor cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibCpp/Tests/preprocessor mnt/home/anon/Tests/cpp-tests/preprocessor
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibWasm/Tests mnt/home/anon/Tests/wasm-tests
cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibJS/Tests/test-common.js mnt/home/anon/Tests/wasm-tests cp -r "$SERENITY_SOURCE_DIR"/Userland/Libraries/LibJS/Tests/test-common.js mnt/home/anon/Tests/wasm-tests
cp -r "$SERENITY_SOURCE_DIR"/Userland/Applications/Spreadsheet/Tests mnt/home/anon/Tests/spreadsheet-tests cp -r "$SERENITY_SOURCE_DIR"/Userland/Applications/Spreadsheet/Tests mnt/home/anon/Tests/spreadsheet-tests

View file

@ -9,3 +9,7 @@ set(SOURCES
serenity_lib(LibWasm wasm) serenity_lib(LibWasm wasm)
target_link_libraries(LibWasm PRIVATE LibCore) target_link_libraries(LibWasm PRIVATE LibCore)
# FIXME: Install these into usr/Tests/LibWasm
include(wasm_spec_tests)
install(DIRECTORY Tests/ DESTINATION home/anon/Tests/wasm-tests)