google / google/googletest

Death tests always fail with exit code 4 with Address Sanitizer

Open
#3,378 6 comments 0 reactions 1 assignee Claimed by @derekmauro View on GitHub
bug
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

**Describe the bug**

Tests built with Address Sanitizer fail without even running the death test.
The output of the test doesn't contain "hello world" that should be there if `func()` is run.
Also, it fails with signal 4 for no apparent cause in `func()`.
My guess is `fork()` function called down the stack.
```
1: [ RUN ] HelloTest.BasicAssertions
1: /Users/t/trash_/gtt/main.cc:8: Failure
1: Death test: func()
1: Result: died but not with expected exit code:
1: Terminated by signal 4
```

**Steps to reproduce the bug**

See the attached `CMakeLists.txt` and `main.cc`
`cmake ../gtt && make && ctest`

**Does the bug persist in the most recent commit?**

Latest commit not tested
```
googletest: stable 1.10.0 (bottled)
```
**What operating system and version are you using?**

macOS 10.14

**What compiler and version are you using?**
```
clang version 13.0.0 (https://github.com/llvm/llvm-project.git 3b47bd32f9df4a57db98db5f35e680c7bd9fde3e)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
```

**What build system are you using?**

cmake version 3.18.5

**Additional context**

CMakeLists.txt:
```
cmake_minimum_required(VERSION 3.14)
project(gtt)

set(CMAKE_CXX_STANDARD 17)
enable_testing()

add_executable(hello_test main.cc)

find_package(GTest REQUIRED)
target_link_libraries( hello_test ${GTEST_BOTH_LIBRARIES})
target_include_directories(hello_test PRIVATE ${GTEST_INCLUDE_DIRS})

include(GoogleTest)
gtest_discover_tests(hello_test)

target_compile_options(hello_test PRIVATE "-fsanitize=address")
target_link_options(hello_test PRIVATE "-fsanitize=address")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE STRING "" FORCE)

```

main.cc
```
#include
#include
#include

void func() { printf("hello world\n"); }

TEST(HelloTest, BasicAssertions) {
EXPECT_EXIT(func(), ::testing::ExitedWithCode(0), "");
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.