diff options
-rw-r--r-- | apt-pkg/CMakeLists.txt | 4 | ||||
-rw-r--r-- | test/interactive-helper/CMakeLists.txt | 3 | ||||
-rw-r--r-- | test/interactive-helper/libnoprofile.c | 50 |
3 files changed, 57 insertions, 0 deletions
diff --git a/apt-pkg/CMakeLists.txt b/apt-pkg/CMakeLists.txt index bdaa93d67..1b493c819 100644 --- a/apt-pkg/CMakeLists.txt +++ b/apt-pkg/CMakeLists.txt @@ -49,3 +49,7 @@ add_version_script(apt-pkg) install(TARGETS apt-pkg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt-pkg) flatify(${PROJECT_BINARY_DIR}/include/apt-pkg/ "${headers}") + +if(CMAKE_BUILD_TYPE STREQUAL "Coverage") + target_link_libraries(apt-pkg PUBLIC noprofile) +endif() diff --git a/test/interactive-helper/CMakeLists.txt b/test/interactive-helper/CMakeLists.txt index fc08d6a8f..423fa30e6 100644 --- a/test/interactive-helper/CMakeLists.txt +++ b/test/interactive-helper/CMakeLists.txt @@ -8,3 +8,6 @@ add_executable(aptwebserver aptwebserver.cc) target_link_libraries(aptwebserver apt-pkg ${CMAKE_THREAD_LIBS_INIT}) add_executable(test_fileutl test_fileutl.cc) target_link_libraries(test_fileutl apt-pkg) + +add_library(noprofile SHARED libnoprofile.c) +target_link_libraries(noprofile ${CMAKE_DL_LIBS}) diff --git a/test/interactive-helper/libnoprofile.c b/test/interactive-helper/libnoprofile.c new file mode 100644 index 000000000..2cba6dc8b --- /dev/null +++ b/test/interactive-helper/libnoprofile.c @@ -0,0 +1,50 @@ +#define _GNU_SOURCE +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <unistd.h> +#include <stdio.h> + +int vprintf(const char *format, va_list ap) { + static int (*func_fprintf)(const char *format, va_list ap) = NULL; + if (func_fprintf == NULL) + func_fprintf = (int (*) (const char *format, va_list ap)) dlsym(RTLD_NEXT, "vprintf"); + + va_list ap2; + va_copy(ap2, ap); + if (strncmp(format, "profiling:", strlen("profiling:")) == 0) + return 0; + int res = func_fprintf(format, ap2); + va_end(ap2); + return res; +} +int printf(const char *format, ...) { + va_list ap; + va_start(ap, format); + int res = vprintf(format, ap); + va_end(ap); + return res; +} + +int vfprintf(FILE *stream, const char *format, va_list ap) { + static int (*func_vfprintf)(FILE *stream, const char *format, va_list ap) = NULL; + if (func_vfprintf == NULL) + func_vfprintf = (int (*) (FILE *stream, const char *format, va_list ap)) dlsym(RTLD_NEXT, "vfprintf"); + + va_list ap2; + va_copy(ap2, ap); + if (strncmp(format, "profiling:", strlen("profiling:")) == 0) + return 0; + int res = func_vfprintf(stream, format, ap2); + va_end(ap2); + return res; +} + +int fprintf(FILE *stream, const char *format, ...) { + va_list ap; + va_start(ap, format); + int res = vfprintf(stream, format, ap); + va_end(ap); + return res; +} |