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

[Bug]: Death tests don't work with emscripten #4595

Open
dabrahams opened this issue Aug 13, 2024 · 0 comments
Open

[Bug]: Death tests don't work with emscripten #4595

dabrahams opened this issue Aug 13, 2024 · 0 comments

Comments

@dabrahams
Copy link

dabrahams commented Aug 13, 2024

Describe the issue

GTEST_DEATH_TEST et. al. are not defined under Emscripten. If you configure with emcmake cmake and run the tests with ctest, there are a number of failures (I tried to run the tests with bazel under emscripten, but couldn't figure out how to do that). The one I care about is the first one:

      Start  1: googletest-death-test-test
Process not started
 /Users/dave/src/googletest/.build/googletest/googletest-death-test-test.js
[permission denied]
 1/45 Test  #1: googletest-death-test-test .................***Not Run   0.00 sec

I realize that the wasm environment might not support the clone() or fork() calls needed to catch death tests in the generated test executable. If that is the obstacle, there's another way: when building with emscripten, create individual ctest death tests that check for the death of commands that launch a single death test from the test executable. Presumably bazel has its own test driver that could be leveraged in the same way.

For example, I use this CMake function when targeting emscripten:

# Turns all tests discovered in <test_executable> by
# gtest_discover_tests that are named with the "DeathTest" convention
# into CMake WILL_FAIL tests.
#
# It is expected that under emscripten, these tests are actually
# compiled as non-death tests; i.e. they simply execute the code that
# is expected to die.  There is no support for checking that the exit
# code or output meets expectations.
function(handle_emscripten_death_tests test_executable)
  set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${test_executable}_death.cmake")
  file(WRITE "${ctest_include_file}"
    "set(death_tests \"\${${test_executable}_TESTS}}\")\n"
    "list(FILTER death_tests INCLUDE REGEX \"DeathTest\")\n"
    "set_tests_properties(\${death_tests} PROPERTIES WILL_FAIL YES)\n"
  )
  set_property(DIRECTORY
    APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
  )
endfunction()

Steps to reproduce the problem

emcmake cmake -GNinja -DGOOGLETEST_VERSION=1.15.2 -Dgtest_build_tests=ON -S . -B build
cmake --build build 
ctest --output-on-failure --test-dir build

What version of GoogleTest are you using?

ff233bd

What operating system and version are you using?

MacOS Sonoma 14.5 (23F79)

What compiler and version are you using?

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.64-git
clang version 19.0.0git
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.64/libexec/llvm/bin

What build system are you using?

cmake version 3.30.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant