mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-05-25 18:22:29 +03:00
pkd: run with SOCKET_WRAPPER_LIBRARY
Use the socket_wrapper preload shim when running the `pkd_hello` test with `make test`. The end goal here is to get this test running alongside normal tests in regular CI. Changes to do this: * Configure PKD_ENVIRONMENT for the `pkd_hello_i1` test in the CMakeLists.txt file. * Add a `--socket-wrapper-dir|-w` flag that is used to opt-in to initializing a SOCKET_WRAPPER_DIR as expected by the socket_wrapper library. A runtime flag is used here to make it easy to run `pkd_hello` with the socket_wrapper library while avoiding a hard dependency. Testing done: observed socker_wrapper in effect with `strace`; running `make test` uses the wrapper correctly on my local machine. Signed-off-by: Jon Simons <jon@jonsimons.org> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
parent
4e3fb81172
commit
54690e6cdd
@ -38,6 +38,18 @@ target_link_libraries(pkd_hello ${pkd_libs})
|
|||||||
# specified with `-i` and may be helpful for chasing down bugs that
|
# specified with `-i` and may be helpful for chasing down bugs that
|
||||||
# are not 100% reproducible.
|
# are not 100% reproducible.
|
||||||
#
|
#
|
||||||
add_test(pkd_hello_i1 ${CMAKE_CURRENT_BINARY_DIR}/pkd_hello -i1)
|
add_test(pkd_hello_i1 ${CMAKE_CURRENT_BINARY_DIR}/pkd_hello -i1 -w /tmp/pkd_socket_wrapper_XXXXXX)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configure environment for cwrap socket wrapper.
|
||||||
|
#
|
||||||
|
find_package(socket_wrapper 1.1.5 REQUIRED)
|
||||||
|
if (OSX)
|
||||||
|
set(PKD_ENVIRONMENT "DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${SOCKET_WRAPPER_LIBRARY}")
|
||||||
|
else ()
|
||||||
|
set(PKD_ENVIRONMENT "LD_PRELOAD=${SOCKET_WRAPPER_LIBRARY}")
|
||||||
|
endif ()
|
||||||
|
message(STATUS "PKD_ENVIRONMENT=${PKD_ENVIRONMENT}")
|
||||||
|
set_property(TEST pkd_hello_i1 PROPERTY ENVIRONMENT ${PKD_ENVIRONMENT})
|
||||||
|
|
||||||
endif (WITH_SERVER AND UNIX AND NOT WIN32)
|
endif (WITH_SERVER AND UNIX AND NOT WIN32)
|
||||||
|
@ -32,6 +32,10 @@ struct pkd_daemon_args {
|
|||||||
const char *testname;
|
const char *testname;
|
||||||
const char *testmatch;
|
const char *testmatch;
|
||||||
unsigned int iterations;
|
unsigned int iterations;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
const char *mkdtemp_str;
|
||||||
|
} socket_wrapper;
|
||||||
} opts;
|
} opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* pkd_hello.c --
|
* pkd_hello.c --
|
||||||
*
|
*
|
||||||
* (c) 2014, 2017 Jon Simons <jon@jonsimons.org>
|
* (c) 2014, 2017-2018 Jon Simons <jon@jonsimons.org>
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <setjmp.h> // for cmocka
|
#include <setjmp.h> // for cmocka
|
||||||
#include <stdarg.h> // for cmocka
|
#include <stdarg.h> // for cmocka
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h> // for cmocka
|
#include <unistd.h> // for cmocka
|
||||||
#include <cmocka.h>
|
#include <cmocka.h>
|
||||||
|
|
||||||
@ -51,6 +52,8 @@ static struct argp_option options[] = {
|
|||||||
"Run each test for the given number of iterations (default is 10)", 0 },
|
"Run each test for the given number of iterations (default is 10)", 0 },
|
||||||
{ "match", 'm', "testmatch", 0,
|
{ "match", 'm', "testmatch", 0,
|
||||||
"Run all tests with the given string", 0 },
|
"Run all tests with the given string", 0 },
|
||||||
|
{ "socket-wrapper-dir", 'w', "<mkdtemp-template>", 0,
|
||||||
|
"Run in socket-wrapper mode using the given mkdtemp directory template", 0 },
|
||||||
{ "stdout", 'o', NULL, 0,
|
{ "stdout", 'o', NULL, 0,
|
||||||
"Emit pkd stdout messages", 0 },
|
"Emit pkd stdout messages", 0 },
|
||||||
{ "test", 't', "testname", 0,
|
{ "test", 't', "testname", 0,
|
||||||
@ -87,6 +90,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
case 'v':
|
case 'v':
|
||||||
pkd_dargs.opts.libssh_log_level += 1;
|
pkd_dargs.opts.libssh_log_level += 1;
|
||||||
break;
|
break;
|
||||||
|
case 'w':
|
||||||
|
pkd_dargs.opts.socket_wrapper.mkdtemp_str = arg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return ARGP_ERR_UNKNOWN;
|
return ARGP_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
@ -651,6 +657,75 @@ static int pkd_run_tests(void) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pkd_init_socket_wrapper(void) {
|
||||||
|
int rc = 0;
|
||||||
|
char *mkdtemp_str = NULL;
|
||||||
|
|
||||||
|
if (pkd_dargs.opts.socket_wrapper.mkdtemp_str == NULL) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdtemp_str = strdup(pkd_dargs.opts.socket_wrapper.mkdtemp_str);
|
||||||
|
if (mkdtemp_str == NULL) {
|
||||||
|
fprintf(stderr, "pkd_init_socket_wrapper strdup failed\n");
|
||||||
|
goto errstrdup;
|
||||||
|
}
|
||||||
|
pkd_dargs.opts.socket_wrapper.mkdtemp_str = mkdtemp_str;
|
||||||
|
|
||||||
|
if (mkdtemp(mkdtemp_str) == NULL) {
|
||||||
|
fprintf(stderr, "pkd_init_socket_wrapper mkdtemp '%s' failed\n", mkdtemp_str);
|
||||||
|
goto errmkdtemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setenv("SOCKET_WRAPPER_DIR", mkdtemp_str, 1) != 0) {
|
||||||
|
fprintf(stderr, "pkd_init_socket_wrapper setenv failed\n");
|
||||||
|
goto errsetenv;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto out;
|
||||||
|
errsetenv:
|
||||||
|
errmkdtemp:
|
||||||
|
free(mkdtemp_str);
|
||||||
|
errstrdup:
|
||||||
|
rc = -1;
|
||||||
|
out:
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pkd_rmfiles(const char *path) {
|
||||||
|
char bin[1024] = { 0 };
|
||||||
|
snprintf(&bin[0], sizeof(bin), "rm -f %s/*", path);
|
||||||
|
return system_checked(bin);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pkd_cleanup_socket_wrapper(void) {
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (pkd_dargs.opts.socket_wrapper.mkdtemp_str == NULL) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clean up socket-wrapper unix domain sockets */
|
||||||
|
if (pkd_rmfiles(pkd_dargs.opts.socket_wrapper.mkdtemp_str) != 0) {
|
||||||
|
fprintf(stderr, "pkd_cleanup_socket_wrapper pkd_rmfiles '%s' failed\n",
|
||||||
|
pkd_dargs.opts.socket_wrapper.mkdtemp_str);
|
||||||
|
goto errrmfiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rmdir(pkd_dargs.opts.socket_wrapper.mkdtemp_str) != 0) {
|
||||||
|
fprintf(stderr, "pkd_cleanup_socket_wrapper rmdir '%s' failed\n",
|
||||||
|
pkd_dargs.opts.socket_wrapper.mkdtemp_str);
|
||||||
|
goto errrmdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto out;
|
||||||
|
errrmdir:
|
||||||
|
errrmfiles:
|
||||||
|
rc = -1;
|
||||||
|
out:
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -670,6 +745,12 @@ int main(int argc, char **argv) {
|
|||||||
(void) argc; (void) argv;
|
(void) argc; (void) argv;
|
||||||
#endif /* HAVE_ARGP_H */
|
#endif /* HAVE_ARGP_H */
|
||||||
|
|
||||||
|
rc = pkd_init_socket_wrapper();
|
||||||
|
if (rc != 0) {
|
||||||
|
fprintf(stderr, "pkd_init_socket_wrapper failed: %d\n", rc);
|
||||||
|
goto out_finalize;
|
||||||
|
}
|
||||||
|
|
||||||
if (pkd_dargs.opts.list != 0) {
|
if (pkd_dargs.opts.list != 0) {
|
||||||
while (testmap[i].testname != NULL) {
|
while (testmap[i].testname != NULL) {
|
||||||
printf("%s\n", testmap[i++].testname);
|
printf("%s\n", testmap[i++].testname);
|
||||||
@ -681,6 +762,12 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = pkd_cleanup_socket_wrapper();
|
||||||
|
if (rc != 0) {
|
||||||
|
fprintf(stderr, "pkd_cleanup_socket_wrapper failed: %d\n", rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
out_finalize:
|
||||||
rc = ssh_finalize();
|
rc = ssh_finalize();
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
fprintf(stderr, "ssh_finalize: %d\n", rc);
|
fprintf(stderr, "ssh_finalize: %d\n", rc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user