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

GoogleTest DeathTests not working correctly with --acpp-stdpar #1457

Open
breyerml opened this issue May 13, 2024 · 0 comments
Open

GoogleTest DeathTests not working correctly with --acpp-stdpar #1457

breyerml opened this issue May 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@breyerml
Copy link
Contributor

Bug summary
When using GoogleTest's EXPECT_DEATH/ASSERT_DEATH functions, it should be possible to specify the error message printed to stderr that should be emitted if a specific assertion fails.
However, when setting --acpp-stdpar and ACPP_VISIBILITY_MASK to something else than omp, the assertion message is always reported to be empty.

To Reproduce
Using the CMakeLists.txt:

project(
  DeathTestExample
  VERSION 1.0
  LANGUAGES CXX)

find_package(TBB)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --acpp-stdpar")

include(FetchContent)
FetchContent_Declare(googletest
                     GIT_REPOSITORY https://github.com/google/googletest
                     GIT_TAG v1.14.0
                     GIT_SHALLOW TRUE
                     QUIET
)
FetchContent_MakeAvailable(googletest)

add_executable(test main.cpp)

target_link_libraries(test PUBLIC TBB::tbb)
target_link_libraries(test PUBLIC GTest::gtest_main)

And then compiling the following code:

#include "gtest/gtest.h"

#include <iostream>

void func(int * ptr) {
  if (ptr == nullptr) {
    std::cerr << "nullptr" << std::flush;
    std::abort();
  }
  *ptr = 42;
}


TEST(Foo, bar) {
  int i = 10;
  int * ptr = &i;
  func(ptr);

  ASSERT_EQ(i, 42);

}

TEST(FooDeathTest, bar) {
  ASSERT_DEATH(func(nullptr), "nullptr");
}

int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::GTEST_FLAG(death_test_style) = "threadsafe";
    return RUN_ALL_TESTS();
}

with

cmake -DCMAKE_CXX_COMPILER=acpp -B build .
cmake --build build

and then running ./test outputs:

[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from FooDeathTest
[ RUN      ] FooDeathTest.bar
/home/username/Documents/test/sycl/stdpar_death_test/main.cpp:28: Failure
Death test: func(nullptr)
    Result: died but not with expected error.
  Expected: contains regular expression "nullptr"
Actual msg:
[  DEATH   ] 

[  FAILED  ] FooDeathTest.bar (4 ms)
[----------] 1 test from FooDeathTest (4 ms total)

[----------] 1 test from Foo
[ RUN      ] Foo.bar
[       OK ] Foo.bar (0 ms)
[----------] 1 test from Foo (0 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 2 test suites ran. (4 ms total)
[  PASSED  ] 1 test.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] FooDeathTest.bar

 1 FAILED TEST

Note that the Actual msg: is empty although it should contain the string "nullptr".
However, everything works when setting ACPP_VISIBILITY_MASK="omp".

Expected behavior
The Actual msg: should contain the string "nullptr".

Describe your setup
I used AdaptiveCpp in release version v24.2.0 build with clang 16.0.2 and CUDA enabled.

Additional context
I'm unsure whether this is an AdaptiveCpp error or a general problem with how GoogleTest's DeahtTests work.
Nevertheless, I thought it may be worthwhile to ask here whether it is a known problem and/or can be fixed. If this isn't the case, feel free to close this issue. It is easily possible to disable all DeathTests to work around this error.

@breyerml breyerml added the bug Something isn't working label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant