From 5ba066244f4aac24d5c3aca5ec8c58961bcbef8f Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 13 Dec 2021 17:48:58 +0100 Subject: [PATCH] test/auto-pts: compile-time selection of __gcov_dump vs. __gcov_flush __gcov_flush is a private symbol in Clang 10 and cannot be resolved with dlsym --- test/auto-pts/CMakeLists.txt | 17 +++++++++++++++++ test/auto-pts/btpclient.c | 37 +++++++++++++++++------------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/test/auto-pts/CMakeLists.txt b/test/auto-pts/CMakeLists.txt index ae3eea74f..bb228f47d 100644 --- a/test/auto-pts/CMakeLists.txt +++ b/test/auto-pts/CMakeLists.txt @@ -69,6 +69,23 @@ add_compile_options(--coverage) add_link_options( --coverage) add_definitions( -DCOVERAGE) +# figure out how to flush gcov data, clang 10 provides __gcov_flush, while clang 13 provides __gcov_dump +message("Compiler: ${CMAKE_CXX_COMPILER_VERSION}") +if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*") + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13) + message("Using __gcov_dump") + add_definitions( -DHAVE_GCOV_DUMP) + else() + message("Using __gcov_flush") + add_definitions( -DHAVE_GCOV_FLUSH) + endif() +else() + # assume GCC + message("Using __gcov_flush") + add_definitions( -DHAVE_GCOV_FLUSH) +endif() + + # create static lib add_library(btstack STATIC ${SOURCES}) diff --git a/test/auto-pts/btpclient.c b/test/auto-pts/btpclient.c index eee3c6da4..704987d28 100644 --- a/test/auto-pts/btpclient.c +++ b/test/auto-pts/btpclient.c @@ -125,28 +125,25 @@ static btstack_timer_source_t heartbeat; // static bd_addr_t pts_addr = { 0x00, 0x1b, 0xdc, 0x07, 0x32, 0xef}; static bd_addr_t pts_addr = { 0x00, 0x1b, 0xdc, 0x08, 0xe2, 0x5c}; -// GCOV Flush +// flush gcov data +#ifdef HAVE_GCOV_FLUSH +void __gcov_flush(void); +#endif +#ifdef HAVE_GCOV_DUMP +void __gcov_dump(void); +void __gcov_reset(void); +#endif + static void my_gcov_flush(void){ #ifdef COVERAGE - static void (*gcov_flush_fn)(void) = NULL; - if (gcov_flush_fn == NULL){ - // look up __gov_flush - gcov_flush_fn = dlsym(RTLD_DEFAULT, "__gcov_flush"); - if (gcov_flush_fn != NULL){ - printf("Using __gcov_flush %p\n", gcov_flush_fn); - } - } - if (gcov_flush_fn == NULL){ - // lookup __gov_dump - gcov_flush_fn = dlsym(RTLD_DEFAULT, "__gcov_dump"); - if (gcov_flush_fn != NULL){ - printf("Using __gcov_dump %p\n", gcov_flush_fn); - } - } - if (gcov_flush_fn != NULL){ - // call either one - (*gcov_flush_fn)(); - } +#ifdef HAVE_GCOV_DUMP + __gcov_dump(); + __gcov_reset(); +#elif defined(HAVE_GCOV_FLUSH) + __gcov_flush(); +#else +#error "COVERAGE defined, but neither HAVE_GCOV_DUMP nor HAVE_GCOV_FLUSH" +#endif #endif }