Skip to content

Commit 5442cb2

Browse files
authored
Move configuring V8 tests into CMake (#803)
I kept forgetting how to replicate CI so make it a flag to CMake which slims down CI configuration and moves more into something that can be more easily replicated locally
1 parent 7ff956b commit 5442cb2

2 files changed

Lines changed: 50 additions & 26 deletions

File tree

.github/workflows/main.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@ jobs:
9090
os: ubuntu-24.04
9191
clang_version: 20
9292
test: true
93-
test_with_v8: true
94-
args: -DTARGET_TRIPLE=wasm32-wasip1
93+
args: -DTARGET_TRIPLE=wasm32-wasip1 -DTEST_WITH_V8=ON
9594

9695
- name: Test wasm32-wasip1-threads in V8
9796
os: ubuntu-24.04
9897
clang_version: 20
9998
test: true
100-
test_with_v8: true
101-
args: -DTARGET_TRIPLE=wasm32-wasip1-threads
99+
args: -DTARGET_TRIPLE=wasm32-wasip1-threads -DTEST_WITH_V8=ON
102100

103101
- name: Test wasm32-wasi-simd
104102
os: ubuntu-24.04
@@ -177,14 +175,6 @@ jobs:
177175
clang_version: ${{ matrix.clang_version }}
178176
llvm_asset_suffix: ${{ matrix.llvm_asset_suffix }}
179177

180-
- name: Install V8 dependencies
181-
if: matrix.test_with_v8
182-
run: |
183-
npm -C test/scripts/browser-test install
184-
npx -C test/scripts/browser-test playwright install chromium-headless-shell
185-
echo ENGINE="$PWD/test/scripts/browser-test/harness.mjs" >> $GITHUB_ENV
186-
echo CTEST_ARGS="--label-exclude v8fail" >> $GITHUB_ENV
187-
188178
- name: Configure libc
189179
run: |
190180
cmake -G Ninja -S . -B build \
@@ -194,14 +184,14 @@ jobs:
194184
195185
- name: Configure testing
196186
if: matrix.test
197-
run: cmake -S . -B build -DENABLE_WERROR=ON -DBUILD_TESTS=ON -DENGINE=${{ env.ENGINE }}
187+
run: cmake -S . -B build -DENABLE_WERROR=ON -DBUILD_TESTS=ON
198188

199189
- name: Build
200190
run: ninja -C build -v
201191

202192
- name: Test
203193
if: matrix.test
204-
run: ctest --test-dir build/test --output-on-failure -j4 $CTEST_ARGS
194+
run: ctest --test-dir build/test --output-on-failure -j4
205195

206196
- uses: actions/upload-artifact@v6
207197
if: matrix.upload

test/CMakeLists.txt

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,38 @@ ExternalProject_Get_Property(libc-test SOURCE_DIR)
2020
set(LIBC_TEST "${SOURCE_DIR}")
2121
message(STATUS "libc-test source directory: ${LIBC_TEST}")
2222

23-
# ========= Download wasmtime as a test runner ==================
23+
# ========= Download a test runner =============================
2424
include(ba-download)
2525

26-
if(NOT ENGINE OR ENGINE STREQUAL "")
26+
option(TEST_WITH_V8 "Run tests in headless Chromium (V8) via Playwright instead of Wasmtime" OFF)
27+
28+
if(TEST_WITH_V8)
29+
find_program(NPM_EXECUTABLE npm REQUIRED)
30+
find_program(NPX_EXECUTABLE npx REQUIRED)
31+
32+
set(browser_test_src "${CMAKE_CURRENT_SOURCE_DIR}/scripts/browser-test")
33+
set(browser_test_dir "${CMAKE_CURRENT_BINARY_DIR}/browser-test")
34+
set(browser_test_stamp "${browser_test_dir}/deps.stamp")
35+
36+
set(browser_test_inputs
37+
"${browser_test_src}/package.json"
38+
"${browser_test_src}/package-lock.json"
39+
)
40+
41+
add_custom_command(
42+
OUTPUT ${browser_test_stamp}
43+
COMMAND ${NPM_EXECUTABLE} -C ${browser_test_src} install
44+
COMMAND ${NPX_EXECUTABLE} -C ${browser_test_src} playwright install chromium-headless-shell
45+
COMMAND ${CMAKE_COMMAND} -E touch ${browser_test_stamp}
46+
DEPENDS ${browser_test_inputs}
47+
)
48+
49+
set(ENGINE "${browser_test_src}/harness.mjs")
50+
add_custom_target(engine ALL DEPENDS ${browser_test_stamp})
51+
message(STATUS "Test engine: V8 (headless browser) via ${ENGINE}")
52+
53+
elseif(NOT ENGINE OR ENGINE STREQUAL "")
54+
# ====== Download Wasmtime as a test runner ==================
2755
set(wasmtime_version dev)
2856
if (TARGET_TRIPLE MATCHES "-threads")
2957
set(wasmtime_version "v44.0.0")
@@ -41,6 +69,13 @@ else()
4169
add_custom_target(engine)
4270
endif()
4371

72+
# Helper to completely disable tests which currently fail in v8.
73+
function(expect_fail_under_v8 test_name)
74+
if(TEST_WITH_V8)
75+
set_tests_properties(${test_name} PROPERTIES WILL_FAIL ON)
76+
endif()
77+
endfunction()
78+
4479
# All tests are compiled against the wasi-libc sysroot
4580
add_compile_options(--sysroot ${SYSROOT})
4681
add_link_options(--sysroot ${SYSROOT})
@@ -339,7 +374,7 @@ add_wasilibc_test(fwscanf.c FS)
339374
# main thread when doing file I/O. This is used to exercise this test's
340375
# behavior where file streams use fallback code for nonblocking reads/writes.
341376
add_wasilibc_test(fs-nonblocking.c FS ENGINE_ARG -Wtimeout=10s)
342-
set_tests_properties(fs-nonblocking.wasm PROPERTIES LABELS v8fail)
377+
expect_fail_under_v8(fs-nonblocking.wasm)
343378
add_wasilibc_test(getentropy.c)
344379
add_wasilibc_test(hello.c PASS_REGULAR_EXPRESSION "Hello, World!")
345380
add_wasilibc_test(ioctl.c FS)
@@ -390,7 +425,7 @@ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 20.0)
390425
# doesn't work well with tags exported from shared libraries. Probably related
391426
# to llvm-project/llvm#188367 and/or llvm/llvm-project#188120
392427
add_wasilibc_test(setjmp.c SETJMP NOSHARED)
393-
set_tests_properties(setjmp.wasm PROPERTIES LABELS v8fail)
428+
expect_fail_under_v8(setjmp.wasm)
394429
endif()
395430

396431
# This test works for single-threaded targets too
@@ -504,19 +539,18 @@ if (NOT (WASI STREQUAL "p1"))
504539
sockets-client-handle-hangups.wasm hello.wasm)
505540
endif()
506541

507-
# Flag some tests as failing in V8
508-
set_tests_properties(hello.wasm PROPERTIES LABELS v8fail)
509-
set_tests_properties(clock_nanosleep.wasm PROPERTIES LABELS v8fail)
542+
# Disable some tests that can't run in V8
543+
expect_fail_under_v8(hello.wasm)
510544
# Skip test that uses environment variables
511-
set_tests_properties(external_env.wasm PROPERTIES LABELS v8fail)
545+
expect_fail_under_v8(external_env.wasm)
512546
# Skip test that uses command-line arguments
513-
set_tests_properties(argv_two_args.wasm PROPERTIES LABELS v8fail)
547+
expect_fail_under_v8(argv_two_args.wasm)
514548
if (TARGET_TRIPLE MATCHES "-threads")
515549
# atomic.wait32 can't be executed on the main thread
516-
set_tests_properties(libc_test_functional_pthread_mutex.wasm PROPERTIES LABELS v8fail)
517-
set_tests_properties(libc_test_functional_pthread_tsd.wasm PROPERTIES LABELS v8fail)
550+
expect_fail_under_v8(libc_test_functional_pthread_mutex.wasm)
551+
expect_fail_under_v8(libc_test_functional_pthread_tsd.wasm)
518552
# "poll_oneoff" can't be implemented in the browser
519-
set_tests_properties(libc_test_functional_pthread_cond.wasm PROPERTIES LABELS v8fail)
553+
expect_fail_under_v8(libc_test_functional_pthread_cond.wasm)
520554
endif()
521555

522556
# If enabled add a copy of Python which is built against `wasi-libc` and run

0 commit comments

Comments
 (0)