From 1f973320a895b4a5574c403e89d730fd69cadb9a Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 30 Aug 2022 19:35:11 +0200 Subject: [PATCH] tests: Use weak attribute for torture_run_tests() if available Signed-off-by: Andreas Schneider Reviewed-by: Jakub Jelen (cherry picked from commit 7787dad9bd0f6947c9f09f5f085bf1ef869f8fc6) --- tests/CMakeLists.txt | 6 +----- tests/torture.c | 8 +++++--- tests/torture.h | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f9aa83a5..c4ad13ad 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,10 +39,6 @@ if (CLIENT_TESTING) # create shared test library set(TORTURE_SHARED_LIBRARY torture_shared) - if (MINGW) - set(USE_ATTRIBUTE_WEAK "-DUSE_ATTRIBUTE_WEAK") - endif () - # Create a list of symbols that should be wrapped for override test set(WRAP_SYMBOLS "") list(APPEND WRAP_SYMBOLS @@ -73,7 +69,7 @@ if (CLIENT_TESTING) ) target_compile_options(${TORTURE_SHARED_LIBRARY} PRIVATE -DSSH_PING_EXECUTABLE="${CMAKE_CURRENT_BINARY_DIR}/ssh_ping" - ${USE_ATTRIBUTE_WEAK} + -DTORTURE_SHARED ) endif () diff --git a/tests/torture.c b/tests/torture.c index 99e9a3d9..f5a6bcc7 100644 --- a/tests/torture.c +++ b/tests/torture.c @@ -1629,12 +1629,14 @@ void torture_reset_config(ssh_session session) memset(session->opts.options_seen, 0, sizeof(session->opts.options_seen)); } -#if ((defined _WIN32) || (defined _WIN64)) && (defined USE_ATTRIBUTE_WEAK) +#if defined(HAVE_WEAK_ATTRIBUTE) && defined(TORTURE_SHARED) __attribute__((weak)) int torture_run_tests(void) { - fail(); + fail_msg("torture_run_tests from shared library called"); + + return -1; } -#endif +#endif /* defined(HAVE_WEAK_ATTRIBUTE) && defined(TORTURE_SHARED) */ int main(int argc, char **argv) { struct argument_s arguments; diff --git a/tests/torture.h b/tests/torture.h index 58feb21e..67c249a3 100644 --- a/tests/torture.h +++ b/tests/torture.h @@ -141,12 +141,12 @@ void torture_setup_create_libssh_config(void **state); void torture_setup_libssh_server(void **state, const char *server_path); +#if defined(HAVE_WEAK_ATTRIBUTE) && defined(TORTURE_SHARED) +__attribute__((weak)) int torture_run_tests(void); +#else /* * This function must be defined in every unit test file. */ -#if ((defined _WIN32) || (defined _WIN64)) && (defined USE_ATTRIBUTE_WEAK) -__attribute__((weak)) int torture_run_tests(void); -#else int torture_run_tests(void); #endif