@@ -20,10 +20,38 @@ ExternalProject_Get_Property(libc-test SOURCE_DIR)
2020set (LIBC_TEST "${SOURCE_DIR} " )
2121message (STATUS "libc-test source directory: ${LIBC_TEST} " )
2222
23- # ========= Download wasmtime as a test runner ==================
23+ # ========= Download a test runner =========== ==================
2424include (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 )
4270endif ()
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
4580add_compile_options (--sysroot ${SYSROOT} )
4681add_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.
341376add_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 )
343378add_wasilibc_test (getentropy.c )
344379add_wasilibc_test (hello.c PASS_REGULAR_EXPRESSION "Hello, World!" )
345380add_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 )
394429endif ()
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 )
505540endif ()
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 )
514548if (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 )
520554endif ()
521555
522556# If enabled add a copy of Python which is built against `wasi-libc` and run
0 commit comments