[PATCH] testsuite/smokey/net: Synchronize on server startup in loopback tests
Jan Kiszka <[email protected]> Mon, 15 Jun 2026 16:48:22 +0200
| Newsgroups | dev.linux.lists.xenomai |
|---|---|
| Message-ID | <[email protected]> |
From: Jan Kiszka <[email protected]> Do not assume that the server thread is up and ready for reception. It may very well lag behind in loopback tests when the client is sending its first packet, potentially causing single lost packets this way. We do not need this for stand-alone servers, obviously. Therefore, make the ready semaphore optional. Related to #23, though not yet clear if it fully fixes it. Signed-off-by: Jan Kiszka <[email protected]> --- Another attempt of mine to get something useful out of opus failed here (4.7, no newer version at hand yet). In the desired to solve the given task "fix the bug", the model suggested that we should try to identify delayed final packets, classify them as delayed (so far so not wrong), but then simply sweep them under the carpet. Not only that this is very unlikely the reason for the single lost packets, it would also be like rewriting test results, rather than making them reliable. testsuite/smokey/net_common/server.c | 5 ++++- testsuite/smokey/net_common/setup.c | 18 ++++++++++++++++-- .../smokey/net_common/smokey_net_server.c | 2 +- .../smokey/net_common/smokey_net_server.h | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/testsuite/smokey/net_common/server.c b/testsuite/smokey/net_common/server.c index 42edb0f427..270f813c8b 100644 --- a/testsuite/smokey/net_common/server.c +++ b/testsuite/smokey/net_common/server.c @@ -120,7 +120,7 @@ static void server_loop_cleanup(void *cookie) free(fds); } -void smokey_net_server_loop(int net_config) +void smokey_net_server_loop(int net_config, sem_t *ready) { struct sched_param prio; const struct proto *p; @@ -153,6 +153,9 @@ void smokey_net_server_loop(int net_config) check_pthread( __RT(pthread_setschedparam(pthread_self(), SCHED_FIFO, &prio))); + if (ready) + check_unix(__RT(sem_post(ready))); + for (;;) { fd_set tfds; diff --git a/testsuite/smokey/net_common/setup.c b/testsuite/smokey/net_common/setup.c index 8a3562ba96..f4b9693cd2 100644 --- a/testsuite/smokey/net_common/setup.c +++ b/testsuite/smokey/net_common/setup.c @@ -35,6 +35,7 @@ struct module { static struct rtnet_core_cmd cmd; static int fd; static pthread_t loopback_server_tid; +static sem_t loopback_server_ready; static bool loopback_thread_created, ifup; static struct module modules[] = { { @@ -335,7 +336,7 @@ int smokey_net_server_check_inner(const char *file, int line, static void *loopback_server(void *cookie) { int net_config = (long)cookie; - smokey_net_server_loop(net_config); + smokey_net_server_loop(net_config, &loopback_server_ready); return NULL; } @@ -425,13 +426,21 @@ running: } if (strcmp(driver, "rt_loopback") == 0) { - err = smokey_check_status( + err = smokey_check_errno( + __RT(sem_init(&loopback_server_ready, 0, 0))); + if (err < 0) + goto err; + err = smokey_check_status( __RT(pthread_create(&loopback_server_tid, NULL, loopback_server, (void *)(long)tested_config))); if (err < 0) goto err; loopback_thread_created = true; + err = smokey_check_errno( + __RT(sem_wait(&loopback_server_ready))); + if (err < 0) + goto err; } switch (peer->sa_family) { @@ -476,6 +485,11 @@ int smokey_net_teardown(const char *driver, const char *intf, int tested_config) err = tmp; if (err == 0 && status != PTHREAD_CANCELED) err = (long)status; + + tmp = smokey_check_errno( + __RT(sem_destroy(&loopback_server_ready))); + if (err == 0) + err = tmp; } tmp = smokey_check_errno(open("/dev/rtnet", O_RDWR)); diff --git a/testsuite/smokey/net_common/smokey_net_server.c b/testsuite/smokey/net_common/smokey_net_server.c index 5a94126031..9b65d70d7b 100644 --- a/testsuite/smokey/net_common/smokey_net_server.c +++ b/testsuite/smokey/net_common/smokey_net_server.c @@ -206,6 +206,6 @@ int main(int argc, char *argv[]) close(fd); - smokey_net_server_loop(net_config); + smokey_net_server_loop(net_config, NULL); exit(EXIT_SUCCESS); } diff --git a/testsuite/smokey/net_common/smokey_net_server.h b/testsuite/smokey/net_common/smokey_net_server.h index 34d5692728..c193b00da7 100644 --- a/testsuite/smokey/net_common/smokey_net_server.h +++ b/testsuite/smokey/net_common/smokey_net_server.h @@ -26,6 +26,6 @@ struct smokey_server; int smokey_net_server_check_inner(const char *file, int line, const char *msg, int status); -void smokey_net_server_loop(int net_config); +void smokey_net_server_loop(int net_config, sem_t *ready); #endif /* SMOKEY_NET_CHECK_H */ -- 2.47.3