diff options
author | Brad King <brad.king@kitware.com> | 2024-04-16 12:51:36 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-04-16 12:51:59 (GMT) |
commit | f494bbaf8f797cc6658f7328b4803bb89baaf48a (patch) | |
tree | 2bad62bf6793ce4a486bf04ae9ab2071c1b1b80e /Tests | |
parent | e9fcec6ac17ef91a1880f30740ef6f36bcdbbc1f (diff) | |
parent | 9433755e5dda33d078f8ca7070ba1f9113448b99 (diff) | |
download | CMake-f494bbaf8f797cc6658f7328b4803bb89baaf48a.zip CMake-f494bbaf8f797cc6658f7328b4803bb89baaf48a.tar.gz CMake-f494bbaf8f797cc6658f7328b4803bb89baaf48a.tar.bz2 |
Merge topic 'FindBacktrace-imported-library'
9433755e5d FindBacktrace: Add imported library
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9406
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/FindBacktrace/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindBacktrace/Test/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Tests/FindBacktrace/Test/backtrace.c | 53 |
4 files changed, 75 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index bcf9254..fa388e0 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1455,6 +1455,7 @@ if(BUILD_TESTING) _mod IN ITEMS ALSA + Backtrace BLAS Boost BZip2 diff --git a/Tests/FindBacktrace/CMakeLists.txt b/Tests/FindBacktrace/CMakeLists.txt new file mode 100644 index 0000000..8ee2a4d --- /dev/null +++ b/Tests/FindBacktrace/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindBacktrace.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindBacktrace/Test" + "${CMake_BINARY_DIR}/Tests/FindBacktrace/Test" + ${build_generator_args} + --build-project TestFindBacktrace + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) diff --git a/Tests/FindBacktrace/Test/CMakeLists.txt b/Tests/FindBacktrace/Test/CMakeLists.txt new file mode 100644 index 0000000..7f5d8ec --- /dev/null +++ b/Tests/FindBacktrace/Test/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.29) +project(TestFindBLAS C) +include(CTest) + +find_package(Backtrace REQUIRED) + +add_executable(test_tgt backtrace.c) +target_link_libraries(test_tgt Backtrace::Backtrace) +target_compile_options(test_tgt PUBLIC -rdynamic -fno-omit-frame-pointer) +target_link_options(test_tgt PUBLIC -rdynamic -fno-omit-frame-pointer) +add_test(NAME test_tgt COMMAND test_tgt) diff --git a/Tests/FindBacktrace/Test/backtrace.c b/Tests/FindBacktrace/Test/backtrace.c new file mode 100644 index 0000000..1a60b14 --- /dev/null +++ b/Tests/FindBacktrace/Test/backtrace.c @@ -0,0 +1,53 @@ +/* This is the code from `man backtrace_symbols`, reformatted, and without + * requiring a command-line argument */ + +#include <execinfo.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#define BT_BUF_SIZE 100 + +void myfunc3(void) +{ + int nptrs; + void* buffer[BT_BUF_SIZE]; + char** strings; + + nptrs = backtrace(buffer, BT_BUF_SIZE); + printf("backtrace() returned %d addresses\n", nptrs); + + /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) + would produce similar output to the following: */ + + strings = backtrace_symbols(buffer, nptrs); + if (strings == NULL) { + perror("backtrace_symbols"); + exit(EXIT_FAILURE); + } + + for (size_t j = 0; j < nptrs; j++) + printf("%s\n", strings[j]); + + free(strings); +} + +static void /* "static" means don't export the symbol... */ +myfunc2(void) +{ + myfunc3(); +} + +void myfunc(int ncalls) +{ + if (ncalls > 1) + myfunc(ncalls - 1); + else + myfunc2(); +} + +int main(int argc, char* argv[]) +{ + myfunc(5); + exit(EXIT_SUCCESS); +} |