From ffe4f045622a774850a4e2edd1f660e169c9e370 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 18 Dec 2023 12:07:18 +0100 Subject: [PATCH] fix: make perf tests cross compilable --- tests/z_perf_rx.c | 35 +++++++++++++---------------------- tests/z_perf_tx.c | 39 +++++++++++++++------------------------ 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/tests/z_perf_rx.c b/tests/z_perf_rx.c index b862d5ecf..0ab9e0d45 100644 --- a/tests/z_perf_rx.c +++ b/tests/z_perf_rx.c @@ -15,19 +15,19 @@ #include #include #include -#include #include "zenoh-pico.h" typedef struct { volatile unsigned long count; - size_t curr_len; + unsigned long curr_len; z_clock_t start; } z_stats_t; static z_stats_t test_stats; static volatile bool test_end; +#if Z_FEATURE_SUBSCRIPTION == 1 void z_stats_stop(z_stats_t *stats) { // Ignore default value if (stats->curr_len == 0) { @@ -62,24 +62,12 @@ int main(int argc, char **argv) { char *keyexpr = "test/thr"; const char *mode = "client"; char *llocator = NULL; - char *clocator = NULL; + (void)argv; - // Get args - int opt; - while ((opt = getopt(argc, argv, "m:l:e:")) != -1) { - switch (opt) { - case 'm': - mode = optarg; - break; - case 'l': - llocator = optarg; - break; - case 'e': - clocator = optarg; - break; - default: - return -1; - } + // Check if peer mode + if (argc > 1) { + mode = "peer"; + llocator = "udp/224.0.0.224:7447#iface=lo"; } // Set config z_owned_config_t config = z_config_default(); @@ -87,9 +75,6 @@ int main(int argc, char **argv) { if (llocator != NULL) { zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } - if (clocator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); - } // Open session z_owned_session_t s = z_open(z_move(config)); if (!z_check(s)) { @@ -122,3 +107,9 @@ int main(int argc, char **argv) { z_close(z_move(s)); exit(0); } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this test requires it.\n"); + return -2; +} +#endif diff --git a/tests/z_perf_tx.c b/tests/z_perf_tx.c index a404b1ba0..454d72de2 100644 --- a/tests/z_perf_tx.c +++ b/tests/z_perf_tx.c @@ -15,14 +15,14 @@ #include #include #include -#include #include "zenoh-pico.h" #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) #define TEST_DURATION_US 10000000 -int send_packets(size_t pkt_len, z_owned_publisher_t *pub, uint8_t *value) { +#if Z_FEATURE_PUBLICATION == 1 +int send_packets(unsigned long pkt_len, z_owned_publisher_t *pub, uint8_t *value) { z_clock_t test_start = z_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < TEST_DURATION_US) { @@ -36,31 +36,19 @@ int send_packets(size_t pkt_len, z_owned_publisher_t *pub, uint8_t *value) { } int main(int argc, char **argv) { - size_t len_array[] = {1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, - 2048, 1024, 512, 256, 128, 64, 32, 16, 8}; // Biggest value first + unsigned long len_array[] = {1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, + 2048, 1024, 512, 256, 128, 64, 32, 16, 8}; // Biggest value first uint8_t *value = (uint8_t *)malloc(len_array[0]); memset(value, 1, len_array[0]); char *keyexpr = "test/thr"; const char *mode = "client"; char *llocator = NULL; - char *clocator = NULL; + (void)argv; - // Get args - int opt; - while ((opt = getopt(argc, argv, "m:l:e:")) != -1) { - switch (opt) { - case 'm': - mode = optarg; - break; - case 'l': - llocator = optarg; - break; - case 'e': - clocator = optarg; - break; - default: - return -1; - } + // Check if peer mode + if (argc > 1) { + mode = "peer"; + llocator = "udp/224.0.0.224:7447#iface=lo"; } // Set config z_owned_config_t config = z_config_default(); @@ -68,9 +56,6 @@ int main(int argc, char **argv) { if (llocator != NULL) { zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } - if (clocator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); - } // Open session z_owned_session_t s = z_open(z_move(config)); if (!z_check(s)) { @@ -111,3 +96,9 @@ int main(int argc, char **argv) { free(value); exit(0); } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this test requires it.\n"); + return -2; +} +#endif