From db53159a55a540f8bb4dabc291aeafd1750ce8be Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 5 Oct 2023 06:58:01 -0700 Subject: [PATCH] libtestutil: drop loopback_create() Problem: the libtestutil loopback_create() function duplicates loop:// for unit tests that could not rely on loop.so being built, but now that loop:// is built in, it is no longer required. Convert unit tests to use the real loop:// connector and remove the duplicate implementation. --- src/broker/test/overlay.c | 5 +- src/broker/test/runat.c | 5 +- src/common/libflux/test/conf.c | 5 +- src/common/libflux/test/disconnect.c | 5 +- src/common/libflux/test/dispatch.c | 5 +- src/common/libflux/test/event.c | 8 +- src/common/libflux/test/future.c | 11 +- src/common/libflux/test/handle.c | 5 +- src/common/libflux/test/module.c | 4 +- src/common/libflux/test/reactor_loop.c | 4 +- src/common/libflux/test/response.c | 9 +- src/common/libflux/test/rpc_security.c | 5 +- src/common/libflux/test/sync.c | 9 +- src/common/libsdexec/test/channel.c | 13 +- src/common/libsdexec/test/list.c | 5 +- src/common/libsdexec/test/property.c | 5 +- src/common/libsdexec/test/start.c | 5 +- src/common/libsdexec/test/stop.c | 5 +- src/common/libterminus/test/pty.c | 2 +- src/common/libterminus/test/terminus.c | 2 +- src/common/libtestutil/util.c | 159 ------------------------- src/common/libtestutil/util.h | 10 -- 22 files changed, 51 insertions(+), 235 deletions(-) diff --git a/src/broker/test/overlay.c b/src/broker/test/overlay.c index e36de9b17958..50488ffca13e 100644 --- a/src/broker/test/overlay.c +++ b/src/broker/test/overlay.c @@ -22,7 +22,6 @@ #include "src/common/libzmqutil/sockopt.h" #include "src/common/libzmqutil/cert.h" #include "src/common/libczmqcontainers/czmq_containers.h" -#include "src/common/libtestutil/util.h" #include "src/common/libutil/stdlog.h" #include "src/common/libutil/unlink_recursive.h" #include "ccan/str/str.h" @@ -709,8 +708,8 @@ int main (int argc, char *argv[]) if (!(logs = zlist_new ())) BAIL_OUT ("zlist_new failed"); - if (!(h = loopback_create (0))) - BAIL_OUT ("loopback_create failed"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop handle"); if (flux_attr_set_cacheonly (h, "rank", "0") < 0) BAIL_OUT ("flux_attr_set_cacheonly rank failed"); if (flux_attr_set_cacheonly (h, "hostlist", "test") < 0) diff --git a/src/broker/test/runat.c b/src/broker/test/runat.c index 089371e20d97..0cad48249ac3 100644 --- a/src/broker/test/runat.c +++ b/src/broker/test/runat.c @@ -18,7 +18,6 @@ #include "src/common/libtap/tap.h" #include "src/common/libczmqcontainers/czmq_containers.h" -#include "src/common/libtestutil/util.h" #include "src/common/libutil/stdlog.h" #include "src/broker/runat.h" @@ -361,8 +360,8 @@ int main (int argc, char *argv[]) BAIL_OUT ("zlist_new failed"); if (!(r = flux_reactor_create (FLUX_REACTOR_SIGCHLD))) BAIL_OUT ("flux_reactor_create failed"); - if (!(h = loopback_create (0))) - BAIL_OUT ("loopback_create failed"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop handle"); if (flux_set_reactor (h, r) < 0) BAIL_OUT ("flux_set_reactor failed"); if (flux_attr_set_cacheonly (h, "rank", "0") < 0) diff --git a/src/common/libflux/test/conf.c b/src/common/libflux/test/conf.c index 27a57da93641..e62aaf4704d5 100644 --- a/src/common/libflux/test/conf.c +++ b/src/common/libflux/test/conf.c @@ -25,7 +25,6 @@ #include "src/common/libflux/conf_private.h" #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "ccan/str/str.h" const char *t1 = \ @@ -351,8 +350,8 @@ void test_in_handle (void) /* create test handle */ - if (!(h = loopback_create (0))) - BAIL_OUT ("loopback_create failed"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("failed to create loop handle"); /* create test config */ diff --git a/src/common/libflux/test/disconnect.c b/src/common/libflux/test/disconnect.c index c98183c7e919..bef8e403cde6 100644 --- a/src/common/libflux/test/disconnect.c +++ b/src/common/libflux/test/disconnect.c @@ -16,7 +16,6 @@ #include #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" flux_msg_t *create_request (int sender, uint32_t rolemask, @@ -142,8 +141,8 @@ void check_cancel (void) int count; uint32_t matchtag; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback handle"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("failed to create loop handle"); /* populate list of requests with unique senders */ diff --git a/src/common/libflux/test/dispatch.c b/src/common/libflux/test/dispatch.c index 1ce08ecd8926..73fd2084487a 100644 --- a/src/common/libflux/test/dispatch.c +++ b/src/common/libflux/test/dispatch.c @@ -16,7 +16,6 @@ #include "src/common/libutil/xzmalloc.h" #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" int cb2_called; void cb2 (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg) @@ -524,8 +523,8 @@ int main (int argc, char *argv[]) plan (NO_PLAN); - if (!(h = loopback_create (0))) - BAIL_OUT ("can't continue without loopback handle"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("can't continue without loop handle"); ok ((r = flux_get_reactor (h)) != NULL, "handle created reactor on demand"); diff --git a/src/common/libflux/test/event.c b/src/common/libflux/test/event.c index 67e4adca87b8..767a3f2b8f06 100644 --- a/src/common/libflux/test/event.c +++ b/src/common/libflux/test/event.c @@ -102,8 +102,8 @@ void test_subscribe_badparams (void) { flux_t *h; - if (!(h = loopback_create (0))) - BAIL_OUT ("loopback_create failed"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop handle"); errno = 0; ok (flux_event_subscribe_ex (NULL, "foo", 0) == NULL && errno == EINVAL, @@ -288,8 +288,8 @@ void test_subscribe_nosub (void) { flux_t *h; - if (!(h = loopback_create (FLUX_O_TEST_NOSUB))) - BAIL_OUT ("loopback_create failed"); + if (!(h = flux_open ("loop://", FLUX_O_TEST_NOSUB))) + BAIL_OUT ("could not create loop handle"); ok (flux_event_subscribe (h, "foo") == 0, "flux_event_subscribe succeeds in loopback with TEST_NOSUB flag"); diff --git a/src/common/libflux/test/future.c b/src/common/libflux/test/future.c index 1e2343b2c6d6..7baf156c6f66 100644 --- a/src/common/libflux/test/future.c +++ b/src/common/libflux/test/future.c @@ -18,7 +18,6 @@ #include "src/common/libczmqcontainers/czmq_containers.h" #include "src/common/libutil/xzmalloc.h" -#include "src/common/libtestutil/util.h" #include "src/common/libtap/tap.h" #include "ccan/str/str.h" @@ -1366,8 +1365,8 @@ void test_rpc_like_thing_async (bool reverse_destroy_order) struct thing *t; flux_reactor_t *r; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback handle"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop handle"); if (!(r = flux_get_reactor (h))) BAIL_OUT ("flux_get_reactor failed"); @@ -1412,8 +1411,8 @@ void test_rpc_like_thing (bool reverse_destroy_order) flux_msg_t *msg; struct thing *t; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback handle"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop handle"); t = thing_create (h); @@ -1445,7 +1444,7 @@ void test_rpc_like_thing_unfulfilled (bool reverse_destroy_order) flux_t *h; struct thing *t; - if (!(h = loopback_create (0))) + if (!(h = flux_open ("loop://", 0))) BAIL_OUT ("could not create loopback handle"); t = thing_create (h); diff --git a/src/common/libflux/test/handle.c b/src/common/libflux/test/handle.c index 51a231463d4d..2415d97ff41f 100644 --- a/src/common/libflux/test/handle.c +++ b/src/common/libflux/test/handle.c @@ -16,7 +16,6 @@ #include "src/common/libutil/xzmalloc.h" #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "ccan/str/str.h" /* Destructor for malloc'ed string. @@ -98,8 +97,8 @@ int main (int argc, char *argv[]) plan (NO_PLAN); - if (!(h = loopback_create (0))) - BAIL_OUT ("can't continue without loopback handle"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("can't continue without loop handle"); test_handle_invalid_args (h); diff --git a/src/common/libflux/test/module.c b/src/common/libflux/test/module.c index c2e7d9d4d373..a7bdad6969f7 100644 --- a/src/common/libflux/test/module.c +++ b/src/common/libflux/test/module.c @@ -53,8 +53,8 @@ void test_set_running (void) { flux_t *h; - if (!(h = loopback_create (0))) - BAIL_OUT ("loopback_create failed"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop handle"); ok (flux_module_set_running (h) == 0, "flux_module_set_running returns success"); diff --git a/src/common/libflux/test/reactor_loop.c b/src/common/libflux/test/reactor_loop.c index 77b9ec593b94..d4859f339a4e 100644 --- a/src/common/libflux/test/reactor_loop.c +++ b/src/common/libflux/test/reactor_loop.c @@ -127,7 +127,7 @@ static void leak_msg_handler (void) flux_t *h; flux_msg_handler_t *mh; - if (!(h = loopback_create (0))) + if (!(h = flux_open ("loop://", 0))) exit (1); if (!(mh = flux_msg_handler_create (h, FLUX_MATCH_ANY, dummy, NULL))) exit (1); @@ -148,7 +148,7 @@ int main (int argc, char *argv[]) plan (NO_PLAN); - if (!(h = loopback_create (0))) + if (!(h = flux_open ("loop://", 0))) BAIL_OUT ("can't continue without loop handle"); flux_comms_error_set (h, comms_err, NULL); ok ((reactor = flux_get_reactor (h)) != NULL, diff --git a/src/common/libflux/test/response.c b/src/common/libflux/test/response.c index 6741e1934e36..2aaf5e436ff8 100644 --- a/src/common/libflux/test/response.c +++ b/src/common/libflux/test/response.c @@ -16,7 +16,6 @@ #include #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "ccan/str/str.h" int main (int argc, char *argv[]) @@ -157,9 +156,9 @@ int main (int argc, char *argv[]) flux_msg_destroy (msg); /* respond with request=NULL */ - h = loopback_create (0); + h = flux_open ("loop://", 0); if (!h) - BAIL_OUT ("loopback_create"); + BAIL_OUT ("could not create loop handle"); errno = 0; ok (flux_respond (h, NULL, NULL) < 0 && errno == EINVAL, "flux_respond msg=NULL fails with EINVAL"); @@ -175,9 +174,9 @@ int main (int argc, char *argv[]) flux_close (h); /* errnum=0 */ - h = loopback_create (0); + h = flux_open ("loop://", 0); if (!h) - BAIL_OUT ("loopback_create"); + BAIL_OUT ("could not create loop handle"); msg = flux_request_encode ("foo", NULL); if (!msg) BAIL_OUT ("flux_request_encode failed"); diff --git a/src/common/libflux/test/rpc_security.c b/src/common/libflux/test/rpc_security.c index 2733381cfac7..0b58c1fe7b8e 100644 --- a/src/common/libflux/test/rpc_security.c +++ b/src/common/libflux/test/rpc_security.c @@ -17,7 +17,6 @@ #include "src/common/libutil/xzmalloc.h" #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" static int cred_get (flux_t *h, struct flux_msg_cred *cr) { @@ -328,8 +327,8 @@ int main (int argc, char *argv[]) plan (NO_PLAN); - if (!(h = loopback_create (0))) - BAIL_OUT ("cannot continue without loopback handle"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("cannot continue without loop handle"); flux_comms_error_set (h, comms_err, NULL); check_rpc_oneway (h); diff --git a/src/common/libflux/test/sync.c b/src/common/libflux/test/sync.c index 62a0f7077da5..dd2f3c141f04 100644 --- a/src/common/libflux/test/sync.c +++ b/src/common/libflux/test/sync.c @@ -16,7 +16,6 @@ #include #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" void send_fake_heartbeat (flux_t *h, int seq) { @@ -42,8 +41,8 @@ void test_non_reactive_loop (void) int rc; int i; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback handle"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop handle"); f = flux_sync_create (h, 0.); ok (f != NULL, @@ -105,7 +104,7 @@ void continuation (flux_future_t *f, void *arg) void test_sync_reactive (double heartrate, double min, double max) { - flux_t *h = loopback_create (0); + flux_t *h = flux_open ("loop://", 0); struct heartbeat_ctx ctx = { .h = h, .seq = 0 }; flux_reactor_t *r; flux_watcher_t *timer; @@ -113,7 +112,7 @@ void test_sync_reactive (double heartrate, double min, double max) int count; if (!h) - BAIL_OUT ("could not create loopback handle"); + BAIL_OUT ("could not create loop handle"); if (!(r = flux_get_reactor (h))) BAIL_OUT ("flux_get_reactor failed on loopback handle"); diff --git a/src/common/libsdexec/test/channel.c b/src/common/libsdexec/test/channel.c index 11f11982a1bd..024a5b84eec1 100644 --- a/src/common/libsdexec/test/channel.c +++ b/src/common/libsdexec/test/channel.c @@ -18,7 +18,6 @@ #include "ccan/array_size/array_size.h" #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "src/common/libioencode/ioencode.h" #include "channel.h" @@ -58,8 +57,8 @@ void test_input (void) json_t *io; json_t *io_eof; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback flux_t handle for testing"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop flux_t handle for testing"); if (flux_attr_set_cacheonly (h, "rank", "0") < 0) BAIL_OUT ("could not set rank for testing"); ch = sdexec_channel_create_input (h, "in"); @@ -148,8 +147,8 @@ void test_output (void) struct channel *ch; int fd; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback flux_t handle for testing"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop flux_t handle for testing"); if (flux_attr_set_cacheonly (h, "rank", "0") < 0) BAIL_OUT ("could not set rank for testing"); ch = sdexec_channel_create_output (h, "out", output_cb, error_cb, NULL); @@ -200,8 +199,8 @@ void test_inval (void) flux_t *h; json_t *io; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback flux_t handle for testing"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop flux_t handle for testing"); if (!(io = ioencode ("foo", "0", NULL, 0, true))) BAIL_OUT ("could not create json io object"); diff --git a/src/common/libsdexec/test/list.c b/src/common/libsdexec/test/list.c index bc4db7214c03..3653a8e39657 100644 --- a/src/common/libsdexec/test/list.c +++ b/src/common/libsdexec/test/list.c @@ -17,7 +17,6 @@ #include #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "list.h" void test_inval (void) @@ -26,8 +25,8 @@ void test_inval (void) struct unit_info info; flux_future_t *f; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback flux_t handle for testing"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop flux_t handle for testing"); if (!(f = flux_future_create (NULL, 0))) BAIL_OUT ("could not create future for testing"); diff --git a/src/common/libsdexec/test/property.c b/src/common/libsdexec/test/property.c index 4fae581eeb73..e928ccbc199d 100644 --- a/src/common/libsdexec/test/property.c +++ b/src/common/libsdexec/test/property.c @@ -17,7 +17,6 @@ #include #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "property.h" void test_dict (void) @@ -45,8 +44,8 @@ void test_inval (void) flux_future_t *f; json_t *dict; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback flux_t handle for testing"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop flux_t handle for testing"); if (!(f = flux_future_create (NULL, 0))) BAIL_OUT ("could not create future for testing"); if (!(dict = json_pack ("{s:[si]}", "foo", "i", 42))) diff --git a/src/common/libsdexec/test/start.c b/src/common/libsdexec/test/start.c index 5488a4da2512..fc0586d12922 100644 --- a/src/common/libsdexec/test/start.c +++ b/src/common/libsdexec/test/start.c @@ -18,7 +18,6 @@ #include "src/common/libsubprocess/command.h" #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "src/common/libutil/jpath.h" #include "start.h" @@ -35,8 +34,8 @@ void test_inval (void) json_t *o; flux_error_t error; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback flux_t handle for testing"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop flux_t handle for testing"); if (!(f = flux_future_create (NULL, 0))) BAIL_OUT ("could not create future for testing"); if (!(cmd = flux_cmd_create (ac, av, environ)) diff --git a/src/common/libsdexec/test/stop.c b/src/common/libsdexec/test/stop.c index 19ae8dfff96f..25c8188e35a9 100644 --- a/src/common/libsdexec/test/stop.c +++ b/src/common/libsdexec/test/stop.c @@ -17,15 +17,14 @@ #include #include "src/common/libtap/tap.h" -#include "src/common/libtestutil/util.h" #include "stop.h" void test_inval (void) { flux_t *h; - if (!(h = loopback_create (0))) - BAIL_OUT ("could not create loopback flux_t handle for testing"); + if (!(h = flux_open ("loop://", 0))) + BAIL_OUT ("could not create loop flux_t handle for testing"); errno = 0; ok (sdexec_stop_unit (NULL, 0, "foo", "bar") == NULL && errno == EINVAL, diff --git a/src/common/libterminus/test/pty.c b/src/common/libterminus/test/pty.c index 12fa686672e8..a4b82c585f46 100644 --- a/src/common/libterminus/test/pty.c +++ b/src/common/libterminus/test/pty.c @@ -455,7 +455,7 @@ static void monitor_cb (struct flux_pty *pty, void *data, int len) void test_monitor () { int total = 0; - flux_t *h = loopback_create (0); + flux_t *h = flux_open ("loop://", 0); struct flux_pty *pty = flux_pty_open (); if (!h || !pty) diff --git a/src/common/libterminus/test/terminus.c b/src/common/libterminus/test/terminus.c index 9bcd2051b527..58407f0e31a3 100644 --- a/src/common/libterminus/test/terminus.c +++ b/src/common/libterminus/test/terminus.c @@ -401,7 +401,7 @@ void test_open_close_session (void) struct flux_pty *pty1 = NULL; struct flux_terminus_server *t = NULL; struct flux_terminus_server *t2 = NULL; - flux_t *h = loopback_create (0); + flux_t *h = flux_open ("loop://", 0); flux_reactor_t *r = flux_reactor_create (FLUX_REACTOR_SIGCHLD); if (!h || !r) diff --git a/src/common/libtestutil/util.c b/src/common/libtestutil/util.c index c809cb386730..2fbdf8ae4961 100644 --- a/src/common/libtestutil/util.c +++ b/src/common/libtestutil/util.c @@ -329,165 +329,6 @@ static flux_t *test_connector_create (void *zctx, return tcon->h; } -/* Loopback connector implementation - */ - -struct loopback_connector { - struct flux_msglist *queue; - flux_t *h; - int pollfd; - int pollevents; - struct flux_msg_cred cred; -}; - -static int loopback_connector_pollevents (void *impl) -{ - struct loopback_connector *lcon = impl; - int e; - int revents = 0; - - if ((e = flux_msglist_pollevents (lcon->queue)) < 0) - return -1; - if (e & POLLIN) - revents |= FLUX_POLLIN; - if (e & POLLOUT) - revents |= FLUX_POLLOUT; - if (e & POLLERR) - revents |= FLUX_POLLERR; - - return revents; -} - -static int loopback_connector_pollfd (void *impl) -{ - struct loopback_connector *lcon = impl; - - return flux_msglist_pollfd (lcon->queue); -} - -static int loopback_connector_send (void *impl, const flux_msg_t *msg, - int flags) -{ - struct loopback_connector *lcon = impl; - struct flux_msg_cred cred; - flux_msg_t *cpy; - - if (flux_msg_get_cred (msg, &cred) < 0) - return -1; - if (!(cpy = flux_msg_copy (msg, true))) - return -1; - if (cred.userid == FLUX_USERID_UNKNOWN) { - if (flux_msg_set_userid (cpy, lcon->cred.userid) < 0) - goto error; - } - if (cred.rolemask == FLUX_ROLE_NONE) { - if (flux_msg_set_rolemask (cpy, lcon->cred.rolemask) < 0) - goto error; - } - if (flux_msglist_append (lcon->queue, cpy) < 0) - goto error; - flux_msg_destroy (cpy); - return 0; -error: - flux_msg_destroy (cpy); - return -1; -} - -static flux_msg_t *loopback_connector_recv (void *impl, int flags) -{ - struct loopback_connector *lcon = impl; - flux_msg_t *msg; - - if (!(msg = (flux_msg_t *)flux_msglist_pop (lcon->queue))) { - errno = EWOULDBLOCK; - return NULL; - } - return msg; -} - -static int loopback_connector_getopt (void *impl, const char *option, - void *val, size_t size) -{ - struct loopback_connector *lcon = impl; - - if (option && streq (option, FLUX_OPT_TESTING_USERID)) { - if (size != sizeof (lcon->cred.userid)) - goto error; - memcpy (val, &lcon->cred.userid, size); - } - else if (option && streq (option, FLUX_OPT_TESTING_ROLEMASK)) { - if (size != sizeof (lcon->cred.rolemask)) - goto error; - memcpy (val, &lcon->cred.rolemask, size); - } - else - goto error; - return 0; -error: - errno = EINVAL; - return -1; -} - -static int loopback_connector_setopt (void *impl, const char *option, - const void *val, size_t size) -{ - struct loopback_connector *lcon = impl; - size_t val_size; - - if (option && streq (option, FLUX_OPT_TESTING_USERID)) { - val_size = sizeof (lcon->cred.userid); - if (size != val_size) - goto error; - memcpy (&lcon->cred.userid, val, val_size); - } - else if (option && streq (option, FLUX_OPT_TESTING_ROLEMASK)) { - val_size = sizeof (lcon->cred.rolemask); - if (size != val_size) - goto error; - memcpy (&lcon->cred.rolemask, val, val_size); - } - else - goto error; - return 0; -error: - errno = EINVAL; - return -1; -} - -static void loopback_connector_fini (void *impl) -{ - struct loopback_connector *lcon = impl; - - flux_msglist_destroy (lcon->queue); - free (lcon); -} - -static const struct flux_handle_ops loopback_ops = { - .pollfd = loopback_connector_pollfd, - .pollevents = loopback_connector_pollevents, - .send = loopback_connector_send, - .recv = loopback_connector_recv, - .getopt = loopback_connector_getopt, - .setopt = loopback_connector_setopt, - .impl_destroy = loopback_connector_fini, -}; - -flux_t *loopback_create (int flags) -{ - struct loopback_connector *lcon; - - if (!(lcon = calloc (1, sizeof (*lcon)))) - BAIL_OUT ("calloc"); - lcon->cred.userid = getuid (); - lcon->cred.rolemask = FLUX_ROLE_OWNER; - if (!(lcon->queue = flux_msglist_create ())) - BAIL_OUT ("flux_msglist_create"); - - if (!(lcon->h = flux_handle_create (lcon, &loopback_ops, flags))) - BAIL_OUT ("flux_handle_create"); - return lcon->h; -} - /* * vi:tabstop=4 shiftwidth=4 expandtab */ diff --git a/src/common/libtestutil/util.h b/src/common/libtestutil/util.h index 9d260c1a9a61..77ac6e4cf1fe 100644 --- a/src/common/libtestutil/util.h +++ b/src/common/libtestutil/util.h @@ -32,13 +32,3 @@ flux_t *test_server_create (void *zctx, void *arg); int test_server_stop (flux_t *c); - -/* Create a loopback connector for testing. - * The net effect is much the same as flux_open("loop://") except - * the implementation is self contained here. Close with flux_close(). - * - * Like loop://, this support test manipulation of credentials: - * flux_opt_set (h, FLUX_OPT_TESTING_USERID, &userid, sizeof (userid); - * flux_opt_set (h, FLUX_OPT_TESTING_ROLEMASK, &rolemask, sizeof (rolemask)) - */ -flux_t *loopback_create (int flags);