Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ include(GNUInstallDirs)
include(CheckSymbolExists)
include(cmake/export.cmake)

# Coverage
option(DICE_COVERAGE "Enable test coverage" off)

# TSAN on Clang requires the following flag
set(LIBSAN_SHARED)
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
Expand Down Expand Up @@ -84,6 +87,7 @@ else()
endif()
option(DICE_TESTS "Enable Dice tests" ${TESTS_DEFAULT})
if(${DICE_TESTS})
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
Expand Down
9 changes: 9 additions & 0 deletions src/dice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ add_library(dice SHARED ${SRCS})
target_link_libraries(dice PUBLIC dice.h pthread)
install(TARGETS dice DESTINATION lib)

if(${DICE_COVERAGE})
# do not involve dice-dispatch/dice-box in the coverage metrics
set(TARGETS dice.o dice)
foreach(TARGET ${TARGETS})
target_compile_options(${TARGET} PRIVATE --coverage)
target_link_options(${TARGET} PUBLIC --coverage)
endforeach()
endif()

if(${ENABLE_SANITIZER})
set(TARGETS rbtree_test dice.o dice)
foreach(TARGET ${TARGETS})
Expand Down
7 changes: 7 additions & 0 deletions src/mod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ foreach(SRC ${SRCS})
PRIVATE -fsanitize=${DICE_SANITIZER})
endif()
endif()

if(${DICE_COVERAGE})
foreach(ENDING "" ".o" "_testing.o")
target_compile_options(${TARGET}${ENDING} PRIVATE --coverage)
target_link_options(${TARGET}${ENDING} PUBLIC --coverage)
endforeach()
endif()
endforeach()

target_link_libraries(dice-self PRIVATE pthread)
Expand Down
8 changes: 7 additions & 1 deletion test/pthread_exit_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static int exit_called;
// TLS key and once guard
static pthread_key_t key;
static pthread_once_t once;
static void *arg_check; // keep arg in a variable to double check later

// A once-initializer to make Alpine Linux happy. This is called in the second
// thread and in the main thread but the compilation on Alpine doesn't like it.
Expand All @@ -36,7 +37,8 @@ run(void *_)
{
(void)_;
pthread_once(&once, tls_init);
if (pthread_setspecific(key, (const void *)malloc(123)) != 0)
arg_check = malloc(123);
if (pthread_setspecific(key, (const void *)arg_check) != 0)
abort();
log_printf("1) tid = %p\n", (void *)pthread_self());
return 0;
Expand Down Expand Up @@ -75,6 +77,10 @@ PS_SUBSCRIBE(CAPTURE_BEFORE, EVENT_FREE, {
if (exit_called == 0)
return PS_OK;

struct free_event *ev = EVENT_PAYLOAD(ev);
if (ev->ptr != arg_check)
return PS_OK;

log_printf("4) tid = %p\tself = %p\n", (void *)pthread_self(), md);
log_printf("Retired thread before free. ID should be 2\n");
log_printf("\tuid = %lu\n", self_id(md));
Expand Down
8 changes: 8 additions & 0 deletions test/traces/trace_lock_unlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <trace_checker.h>

#include <dice/chains/capture.h>
#include <dice/events/memaccess.h>
#include <dice/events/pthread.h>
#include <dice/events/self.h>
#include <dice/events/thread.h>
Expand All @@ -13,8 +14,15 @@

struct expected_event expected[] = {
EXPECTED_EVENT(CAPTURE_EVENT, EVENT_SELF_INIT),
EXPECTED_SUFFIX(CAPTURE_EVENT, EVENT_THREAD_START),
EXPECTED_SUFFIX(CAPTURE_BEFORE, EVENT_PTHREAD_MUTEX_LOCK),
EXPECTED_EVENT(CAPTURE_AFTER, EVENT_PTHREAD_MUTEX_LOCK),

// when checking coverage, these are also triggered
EXPECTED_SOME(CAPTURE_EVENT, EVENT_MA_READ, 0, 1),
EXPECTED_SOME(CAPTURE_EVENT, EVENT_MA_WRITE, 0, 1),
// end

EXPECTED_EVENT(CAPTURE_BEFORE, EVENT_PTHREAD_MUTEX_UNLOCK),
EXPECTED_EVENT(CAPTURE_AFTER, EVENT_PTHREAD_MUTEX_UNLOCK),
EXPECTED_SUFFIX(CAPTURE_EVENT, EVENT_SELF_FINI),
Expand Down
9 changes: 4 additions & 5 deletions test/traces/trace_mutex_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ struct expected_event expected_1[] = {
EXPECTED_EVENT(CAPTURE_BEFORE, EVENT_THREAD_JOIN),
EXPECTED_EVENT(CAPTURE_AFTER, EVENT_THREAD_JOIN),

#if defined(__linux__)
EXPECTED_EVENT(CAPTURE_EVENT, EVENT_STACKTRACE_EXIT),
EXPECTED_EVENT(CAPTURE_EVENT, EVENT_THREAD_EXIT),
EXPECTED_EVENT(CAPTURE_EVENT, EVENT_SELF_FINI),
EXPECTED_END,
#elif defined(__NetBSD__)
EXPECTED_SUFFIX(CAPTURE_EVENT, EVENT_THREAD_EXIT),
EXPECTED_SUFFIX(CAPTURE_EVENT, EVENT_SELF_FINI),

#if defined(__linux__)
EXPECTED_END,
#elif defined(__NetBSD__)
EXPECTED_ANY_SUFFIX,
#endif
};
Expand Down