Skip to content

Commit

Permalink
feature: direct support for __dump_gcov
Browse files Browse the repository at this point in the history
- the previous implementation for dumping gcov statistics wasn't robust
  enough
- now, `__dump_gcov` is called directly from the signal handler and then
  `_exit` is called - this guarantees dumping of gcov statistics and
  immidiate module exit

Signed-off-by: aw <[email protected]>
  • Loading branch information
a-w50 committed Jan 15, 2025
1 parent e5d8408 commit a23a813
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmake/ev-project-bootstrap.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set_property(
GLOBAL
PROPERTY EVEREST_REQUIRED_EV_CLI_VERSION "0.4.0"
PROPERTY EVEREST_REQUIRED_EV_CLI_VERSION "0.4.5"
)

# FIXME (aw): clean up this inclusion chain
Expand Down
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ext-mbedtls:
# everest-testing and ev-dev-tools
everest-utils:
git: https://github.com/EVerest/everest-utils.git
git_tag: v0.4.4
git_tag: feature/support_dump_gcov
# linux_libnfc-nci for RFID
libnfc-nci:
git: https://github.com/EVerest/linux_libnfc-nci.git
Expand Down
9 changes: 9 additions & 0 deletions lib/staging/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ target_sources(everest_staging_helpers
lib/helpers.cpp
)

if (EVEREST_CORE_BUILD_TESTING)
target_compile_definitions(everest_staging_helpers PUBLIC EVEREST_COVERAGE_ENABLED)

target_sources(everest_staging_helpers
PRIVATE
lib/coverage.cpp
)
endif()

target_include_directories(everest_staging_helpers
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace everest::helpers {
void install_signal_handlers_for_gcov();
}
38 changes: 38 additions & 0 deletions lib/staging/helpers/lib/coverage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <everest/staging/helpers/coverage.hpp>

#include <atomic>

#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

extern "C" void __gcov_dump();

namespace {

static std::atomic_flag going_to_terminate = ATOMIC_FLAG_INIT;

void terminate_handler(int signal) {
if (going_to_terminate.test_and_set()) {
return;
}

__gcov_dump();

_exit(EXIT_FAILURE);
};

} // namespace

namespace everest::helpers {

void install_signal_handlers_for_gcov() {
struct sigaction action {};
action.sa_handler = &terminate_handler;
// action.sa_mask should be zero, so no blocked signals within the signal handler
// action.sa_flags should be fine with being zero
sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr);
}

} // namespace everest::helpers
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ foreach(type MODULES LIBRARIES)

foreach(target ${targets})
append_coverage_compiler_flags_to_target(${target})

if (type STREQUAL "MODULES")
target_link_libraries(${target} PRIVATE everest::staging::helpers)
endif()
endforeach()
endforeach()

Expand Down

0 comments on commit a23a813

Please sign in to comment.