From caf041a836ee2fe233b2195320607f65febb6b33 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Fri, 13 Dec 2024 20:21:20 +0100 Subject: [PATCH] Fix liveliness test --- .github/workflows/build-check.yaml | 4 ++-- GNUmakefile | 1 + examples/unix/c11/z_liveliness.c | 23 ++++++++++------------- tests/memory_leak.py | 6 +++--- zenohpico.pc | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml index 6339ef357..fa0b5e7a6 100644 --- a/.github/workflows/build-check.yaml +++ b/.github/workflows/build-check.yaml @@ -272,9 +272,9 @@ jobs: - name: Build project and run test run: | sudo apt install -y ninja-build - Z_FEATURE_UNSTABLE_API=1 Z_FEATURE_LIVELINESS=1 CMAKE_GENERATOR=Ninja make + CMAKE_GENERATOR=Ninja make python3 ./build/tests/memory_leak.py - timeout-minutes: 5 + timeout-minutes: 10 - name: Kill Zenoh router if: always() diff --git a/GNUmakefile b/GNUmakefile index 15985b481..95942d486 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -62,6 +62,7 @@ Z_FEATURE_SUBSCRIPTION?=1 Z_FEATURE_QUERY?=1 Z_FEATURE_QUERYABLE?=1 Z_FEATURE_INTEREST?=1 +Z_FEATURE_LIVELINESS?=1 Z_FEATURE_RAWETH_TRANSPORT?=0 # Buffer sizes diff --git a/examples/unix/c11/z_liveliness.c b/examples/unix/c11/z_liveliness.c index 0798621fe..0db1a9c10 100644 --- a/examples/unix/c11/z_liveliness.c +++ b/examples/unix/c11/z_liveliness.c @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, -#include #include #include #include @@ -20,21 +19,15 @@ #if Z_FEATURE_LIVELINESS == 1 -static volatile int keepRunning = 1; - -void intHandler(int dummy) { - (void)dummy; - keepRunning = 0; -} - int main(int argc, char **argv) { const char *keyexpr = "group1/zenoh-pico"; const char *mode = "client"; const char *clocator = NULL; const char *llocator = NULL; + unsigned int timeout = 0; int opt; - while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:l:t:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -48,8 +41,12 @@ int main(int argc, char **argv) { case 'l': llocator = optarg; break; + case 't': + timeout = atoi(optarg); + break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l' || + optopt == 't') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -98,9 +95,9 @@ int main(int argc, char **argv) { } printf("Press CTRL-C to undeclare liveliness token and quit...\n"); - signal(SIGINT, intHandler); - while (keepRunning) { - z_sleep_s(1); + z_clock_t clock = z_clock_now(); + while (timeout == 0 || z_clock_elapsed_s(&clock) < timeout) { + z_sleep_ms(100); } // LivelinessTokens are automatically closed when dropped diff --git a/tests/memory_leak.py b/tests/memory_leak.py index 2191d2295..01412ef6b 100644 --- a/tests/memory_leak.py +++ b/tests/memory_leak.py @@ -121,7 +121,7 @@ def query_and_queryable(query_cmd, queryable_cmd): z_query_process.wait() print(f"Stop {queryable_cmd}") - time.sleep(2) + time.sleep(5) if z_queryable_process.poll() is None: # send SIGINT to group z_quaryable_process_gid = os.getpgid(z_queryable_process.pid) @@ -176,11 +176,11 @@ def query_and_queryable(query_cmd, queryable_cmd): EXIT_STATUS = 1 # Test liveliness query print("*** Get liveliness test ***") - if query_and_queryable('z_get_liveliness', 'z_liveliness') == 1: + if query_and_queryable('z_get_liveliness', 'z_liveliness -t 5') == 1: EXIT_STATUS = 1 # Test liveliness subscriber print("*** Liveliness subscriber test ***") - if query_and_queryable('z_sub_liveliness -h -n 1', 'z_liveliness') == 1: + if query_and_queryable('z_sub_liveliness -h -n 1', 'z_liveliness -t 1') == 1: EXIT_STATUS = 1 # Exit sys.exit(EXIT_STATUS) diff --git a/zenohpico.pc b/zenohpico.pc index 421fe0950..9ca8475b0 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 1.0.20241210dev +Version: 1.0.0.0 Cflags: -I${prefix}/include Libs: -L${prefix}/lib -lzenohpico