From be0c558bcccc28255b2130d454e23ceac5cd2897 Mon Sep 17 00:00:00 2001 From: Eshan Kelkar Date: Thu, 1 Jun 2023 21:10:19 +0530 Subject: [PATCH] Link benchmark code statically with libssh benchmark code present in tests/benchmarks/ directory was linked with libssh dynamically due to which it could use only the functions exposed in the public API of libssh. To be able to use those functions in the benchmark code which are a part of libssh api but not a part of the public api for libssh (examples of such functions are ssh_list api functions), the benchmark code needs to be linked statically to libssh. Signed-off-by: Eshan Kelkar Reviewed-by: Sahana Prasad Reviewed-by: Jakub Jelen --- tests/benchmarks/CMakeLists.txt | 2 +- tests/benchmarks/benchmarks.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/CMakeLists.txt b/tests/benchmarks/CMakeLists.txt index ca4f0006..4074b8f4 100644 --- a/tests/benchmarks/CMakeLists.txt +++ b/tests/benchmarks/CMakeLists.txt @@ -14,4 +14,4 @@ include_directories(${libssh_BINARY_DIR}) add_executable(benchmarks ${benchmarks_SRCS}) -target_link_libraries(benchmarks ssh::ssh) +target_link_libraries(benchmarks ssh::static) diff --git a/tests/benchmarks/benchmarks.c b/tests/benchmarks/benchmarks.c index 0dedffe3..0091fc22 100644 --- a/tests/benchmarks/benchmarks.c +++ b/tests/benchmarks/benchmarks.c @@ -19,6 +19,8 @@ * MA 02111-1307, USA. */ +#define LIBSSH_STATIC + #include "config.h" #include "benchmarks.h" #include @@ -390,7 +392,7 @@ int main(int argc, char **argv) { struct argument_s arguments; ssh_session session = NULL; - int i; + int i, r; arguments_init(&arguments); cmdline_parse(argc, argv, &arguments); @@ -427,6 +429,12 @@ int main(int argc, char **argv) fprintf(stdout,"\n"); } + r = ssh_init(); + if (r == SSH_ERROR) { + fprintf(stderr, "Failed to initialize libssh\n"); + return EXIT_FAILURE; + } + for (i = 0; i < arguments.nhosts; ++i) { if (arguments.verbose > 0) fprintf(stdout, "Connecting to \"%s\"...\n", arguments.hosts[i]); @@ -447,6 +455,12 @@ int main(int argc, char **argv) ssh_free(session); } + r = ssh_finalize(); + if (r == SSH_ERROR) { + fprintf(stderr, "Failed to finalize libssh\n"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; }