From 8748123e15199f223a05a1b37be5abad98955b1b Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Wed, 18 Oct 2023 11:18:01 +0200 Subject: [PATCH 01/16] feat: add feature config symbols in make & cmake --- CMakeLists.txt | 15 +++++++++++++++ GNUmakefile | 11 ++++++++++- include/zenoh-pico/config.h | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2838ec142..5f2805172 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,21 @@ endif() add_definition(ZENOH_DEBUG=${ZENOH_DEBUG}) +# Zenoh pico feature configuration options +option(Z_FEATURE_PUBLICATION "Toggle publication feature" 1) +option(Z_FEATURE_SUBSCRIPTION "Toggle subscription feature" 1) +option(Z_FEATURE_QUERY "Toggle query feature" 1) +option(Z_FEATURE_QUERYABLE "Toggle queryable feature" 1) +add_definition(Z_FEATURE_PUBLICATION=${Z_FEATURE_PUBLICATION}) +add_definition(Z_FEATURE_SUBSCRIPTION=${Z_FEATURE_SUBSCRIPTION}) +add_definition(Z_FEATURE_QUERY=${Z_FEATURE_QUERY}) +add_definition(Z_FEATURE_QUERYABLE=${Z_FEATURE_QUERYABLE}) +message(STATUS "Building with feature confing:\n\ +* PUBLICATION: ${Z_FEATURE_PUBLICATION}\n\ +* SUBSCRIPTION: ${Z_FEATURE_SUBSCRIPTION}\n\ +* QUERY: ${Z_FEATURE_QUERY}\n\ +* QUERYABLE: ${Z_FEATURE_QUERYABLE}") + # Print summary of CMAKE configurations message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode") message(STATUS "Build shared library: ${BUILD_SHARED_LIBS}") diff --git a/GNUmakefile b/GNUmakefile index cf4512a1b..67932a3bc 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -45,6 +45,13 @@ BUILD_TOOLS?=OFF # 3: DEBUG + INFO + ERROR ZENOH_DEBUG?=0 +# Feature config toggle +# Accepted values: 0, 1 +Z_FEATURE_PUBLICATION?=1 +Z_FEATURE_SUBSCRIPTION?=1 +Z_FEATURE_QUERY?=1 +Z_FEATURE_QUERYABLE?=1 + # zenoh-pico/ directory ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) @@ -58,7 +65,9 @@ CROSSIMG_PREFIX=zenoh-pico_ # NOTES: # - ARM: old versions of dockcross/dockcross were creating some issues since they used an old GCC (4.8.3) which lacks (even using -std=gnu11) -CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H. +CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST)\ + -DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\ + -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H. all: make diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index 3d55a7edd..fc7fe5f97 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -103,6 +103,7 @@ #define Z_CONFIG_ADD_TIMESTAMP_DEFAULT "false" /*------------------ Compile-time feature configuration ------------------*/ +// WARNING: Default values may always be overridden by CMake/make values /** * Enable multi-thread support. From c308a0c10e52637b992071e397885ed39ed4ae24 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Wed, 18 Oct 2023 15:18:38 +0200 Subject: [PATCH 02/16] build: add modular build in CI --- .github/workflows/build-shared.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/build-shared.yaml b/.github/workflows/build-shared.yaml index 055524f04..86b3ec829 100644 --- a/.github/workflows/build-shared.yaml +++ b/.github/workflows/build-shared.yaml @@ -51,3 +51,24 @@ jobs: BUILD_TYPE: Debug BUILD_SHARED_LIBS: ON ZENOH_DEBUG: 3 + + modular_build: + name: Modular build on ubuntu-latest + runs-on: ubuntu-latest + strategy: + matrix: + feature_publication: [1, 0] + feature_subscription: [1, 0] + feature_queryable: [1, 0] + feature_query: [1, 0] + steps: + - uses: actions/checkout@v2 + - name: Build project + run: make all + env: + BUILD_TYPE: Debug + ZENOH_DEBUG: 3 + Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }} + Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }} + Z_FEATURE_QUERYABLE: ${{ matrix.feature_queryable }} + Z_FEATURE_QUERY: ${{ matrix.feature_query }} \ No newline at end of file From 9ab0b7c5acd98a175725bf25f502dcff8bd3b91a Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Fri, 20 Oct 2023 10:48:06 +0200 Subject: [PATCH 03/16] feat: add modular test --- CMakeLists.txt | 2 + tests/z_modular_test.c | 285 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 tests/z_modular_test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f2805172..2b4db14ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,6 +290,7 @@ if(UNIX OR MSVC) add_executable(z_keyexpr_test ${PROJECT_SOURCE_DIR}/tests/z_keyexpr_test.c) add_executable(z_api_null_drop_test ${PROJECT_SOURCE_DIR}/tests/z_api_null_drop_test.c) add_executable(z_api_double_drop_test ${PROJECT_SOURCE_DIR}/tests/z_api_double_drop_test.c) + add_executable(z_modular_test ${PROJECT_SOURCE_DIR}/tests/z_modular_test.c) target_link_libraries(z_data_struct_test ${Libname}) target_link_libraries(z_endpoint_test ${Libname}) @@ -298,6 +299,7 @@ if(UNIX OR MSVC) target_link_libraries(z_keyexpr_test ${Libname}) target_link_libraries(z_api_null_drop_test ${Libname}) target_link_libraries(z_api_double_drop_test ${Libname}) + target_link_libraries(z_modular_test ${Libname}) enable_testing() add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test) diff --git a/tests/z_modular_test.c b/tests/z_modular_test.c new file mode 100644 index 000000000..e5ea32b26 --- /dev/null +++ b/tests/z_modular_test.c @@ -0,0 +1,285 @@ +// +// Copyright (c) 2022 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, + +#include +#include +#include +#include + +#include "zenoh-pico.h" + +#undef NDEBUG +#include + +static const char *ARG_LIST[] = {"Z_FEATURE_PUBLICATION", "Z_FEATURE_SUBSCRIPTION", "Z_FEATURE_QUERYABLE", + "Z_FEATURE_QUERY"}; +#define ARG_NB (sizeof(ARG_LIST) / sizeof(ARG_LIST[0])) + +int test_publication(void) { +#if Z_FEATURE_PUBLICATION == 1 + const char *keyexpr = "demo/example/zenoh-pico-pub"; + const char *value = "Pub from Pico!"; + const char *mode = "client"; + + // Set up config + z_owned_config_t config = z_config_default(); + zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); + // Open session + printf("Opening session...\n"); + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + printf("Unable to open session!\n"); + return -1; + } + // Start read and lease tasks for zenoh-pico + if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { + printf("Unable to start read and lease tasks"); + return -1; + } + // Declare publisher + printf("Declaring publisher for '%s'...\n", keyexpr); + z_owned_publisher_t pub = z_declare_publisher(z_loan(s), z_keyexpr(keyexpr), NULL); + if (!z_check(pub)) { + printf("Unable to declare publisher for key expression!\n"); + return -1; + } + // Put data + printf("Putting Data ('%s': '%s')...\n", keyexpr, value); + z_publisher_put_options_t options = z_publisher_put_options_default(); + options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); + z_publisher_put(z_loan(pub), (const uint8_t *)value, strlen(value), &options); + + // Clean-up + z_undeclare_publisher(z_move(pub)); + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + z_close(z_move(s)); + return 1; +#else + return 0; +#endif +} + +#if Z_FEATURE_SUBSCRIPTION == 1 +static void subscription_data_handler(const z_sample_t *sample, void *ctx) { + (void)(ctx); + z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); + printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_loan(keystr), (int)sample->payload.len, + sample->payload.start); + z_drop(z_move(keystr)); +} +#endif + +int test_subscription(void) { +#if Z_FEATURE_SUBSCRIPTION == 1 + const char *keyexpr = "demo/example/**"; + const char *mode = "client"; + + // Set up config + z_owned_config_t config = z_config_default(); + zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); + // Open session + printf("Opening session...\n"); + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + printf("Unable to open session!\n"); + return -1; + } + // Start read and lease tasks for zenoh-pico + if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { + printf("Unable to start read and lease tasks"); + return -1; + } + // Declare subscriber + z_owned_closure_sample_t callback = z_closure(subscription_data_handler); + printf("Declaring Subscriber on '%s'...\n", keyexpr); + z_owned_subscriber_t sub = z_declare_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL); + if (!z_check(sub)) { + printf("Unable to declare subscriber.\n"); + return -1; + } + // Clean-up + z_undeclare_subscriber(z_move(sub)); + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + z_close(z_move(s)); + return 1; +#else + return 0; +#endif +} + +#if Z_FEATURE_QUERYABLE == 1 +static const char *queryable_keyexpr = "demo/example/zenoh-pico-queryable"; +static const char *queryable_value = "Queryable from Pico!"; + +void query_handler(const z_query_t *query, void *ctx) { + (void)(ctx); + z_owned_str_t keystr = z_keyexpr_to_string(z_query_keyexpr(query)); + z_bytes_t pred = z_query_parameters(query); + z_value_t payload_value = z_query_value(query); + printf(" >> [Queryable handler] Received Query '%s?%.*s'\n", z_loan(keystr), (int)pred.len, pred.start); + if (payload_value.payload.len > 0) { + printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); + } + z_query_reply_options_t options = z_query_reply_options_default(); + options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); + z_query_reply(query, z_keyexpr(queryable_keyexpr), (const unsigned char *)queryable_value, strlen(queryable_value), &options); + z_drop(z_move(keystr)); +} +#endif + +int test_queryable(void) { +#if Z_FEATURE_QUERYABLE == 1 + const char *mode = "client"; + + z_keyexpr_t ke = z_keyexpr(queryable_keyexpr); + if (!z_check(ke)) { + printf("%s is not a valid key expression", queryable_keyexpr); + return -1; + } + // Set up config + z_owned_config_t config = z_config_default(); + zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); + // Open session + printf("Opening session...\n"); + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + printf("Unable to open session!\n"); + return -1; + } + // Start read and lease tasks for zenoh-pico + if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { + printf("Unable to start read and lease tasks"); + return -1; + } + // Declare queryable + printf("Creating Queryable on '%s'...\n", queryable_keyexpr); + z_owned_closure_query_t callback = z_closure(query_handler); + z_owned_queryable_t qable = z_declare_queryable(z_loan(s), ke, z_move(callback), NULL); + if (!z_check(qable)) { + printf("Unable to create queryable.\n"); + return -1; + } + // Clean-up + z_undeclare_queryable(z_move(qable)); + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + z_close(z_move(s)); + + return 1; +#else + return 0; +#endif +} + +#if Z_FEATURE_QUERY == 1 +void reply_dropper(void *ctx) { + (void)(ctx); + printf(">> Received query final notification\n"); +} + +void reply_handler(z_owned_reply_t *reply, void *ctx) { + (void)(ctx); + if (z_reply_is_ok(reply)) { + z_sample_t sample = z_reply_ok(reply); + z_owned_str_t keystr = z_keyexpr_to_string(sample.keyexpr); + printf(">> Received ('%s': '%.*s')\n", z_loan(keystr), (int)sample.payload.len, sample.payload.start); + z_drop(z_move(keystr)); + } else { + printf(">> Received an error\n"); + } +} +#endif + +int test_query(void) { +#if Z_FEATURE_QUERY == 1 + const char *keyexpr = "demo/example/**"; + const char *mode = "client"; + + z_keyexpr_t ke = z_keyexpr(keyexpr); + if (!z_check(ke)) { + printf("%s is not a valid key expression", keyexpr); + return -1; + } + // Set up config + z_owned_config_t config = z_config_default(); + zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); + // Open session + printf("Opening session...\n"); + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + printf("Unable to open session!\n"); + return -1; + } + // Start read and lease tasks for zenoh-pico + if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { + printf("Unable to start read and lease tasks"); + return -1; + } + // Send query + printf("Sending Query '%s'...\n", keyexpr); + z_get_options_t opts = z_get_options_default(); + z_owned_closure_reply_t callback = z_closure(reply_handler, reply_dropper); + if (z_get(z_loan(s), ke, "", z_move(callback), &opts) < 0) { + printf("Unable to send query.\n"); + return -1; + } + // Clean-up + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + z_close(z_move(s)); + + return 1; +#else + return 0; +#endif +} + +// Send feature config as int list, and compare with compiled feature +int main(int argc, char **argv) { + if (argc < (int)(ARG_NB + 1)) { + printf("To start this test you must give the state of the feature config as argument\n"); + printf("Arg order: "); + for (size_t i = 0; i < ARG_NB; i++) { + printf("%s ", ARG_LIST[i]); + } + printf("\n"); + return -1; + } + if (test_publication() != atoi(argv[1])) { + printf("Problem during publication testing\n"); + return -1; + } else { + printf("Publication status ok\n"); + } + if (test_subscription() != atoi(argv[2])) { + printf("Problem during subscription testing\n"); + return -1; + } else { + printf("Subscription status ok\n"); + } + if (test_queryable() != atoi(argv[3])) { + printf("Problem during queryable testing\n"); + return -1; + } else { + printf("Queryable status ok\n"); + } + if (test_query() != atoi(argv[4])) { + printf("Problem during query testing\n"); + return -1; + } else { + printf("Query status ok\n"); + } + return 0; +} From 4b1aa507f2e605d3565c8ff9bdf141ce3313d315 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Fri, 20 Oct 2023 17:23:01 +0200 Subject: [PATCH 04/16] build: run modular test in CI --- .github/workflows/build-shared.yaml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-shared.yaml b/.github/workflows/build-shared.yaml index 86b3ec829..82b998db9 100644 --- a/.github/workflows/build-shared.yaml +++ b/.github/workflows/build-shared.yaml @@ -62,13 +62,27 @@ jobs: feature_queryable: [1, 0] feature_query: [1, 0] steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run docker image + run: docker run --name zenoh_router --init --net host -d eclipse/zenoh:master + continue-on-error: true + - name: Build project - run: make all + run: | + make all + ./build/tests/z_modular_test $Z_FEATURE_PUBLICATION $Z_FEATURE_SUBSCRIPTION $Z_FEATURE_QUERYABLE $Z_FEATURE_QUERY + continue-on-error: true env: BUILD_TYPE: Debug ZENOH_DEBUG: 3 Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }} Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }} Z_FEATURE_QUERYABLE: ${{ matrix.feature_queryable }} - Z_FEATURE_QUERY: ${{ matrix.feature_query }} \ No newline at end of file + Z_FEATURE_QUERY: ${{ matrix.feature_query }} + + - name: Stop docker image + run: | + docker stop zenoh_router + docker rm zenoh_router \ No newline at end of file From e00ed6a784e15b73413dc2470b28278705a7536c Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 24 Oct 2023 08:51:09 +0200 Subject: [PATCH 05/16] build: moved modular tests to its own workflow --- .github/workflows/build-check.yaml | 56 +++++++++++++++++++++++++++++ .github/workflows/build-shared.yaml | 37 +------------------ 2 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/build-check.yaml diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml new file mode 100644 index 000000000..fbf61f995 --- /dev/null +++ b/.github/workflows/build-check.yaml @@ -0,0 +1,56 @@ +# +# Copyright (c) 2022 ZettaScale Technology +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +# which is available at https://www.apache.org/licenses/LICENSE-2.0. +# +# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +# +# Contributors: +# ZettaScale Zenoh Team, +# +name: build-check + +on: + push: + branches: [ '**' ] + pull_request: + branches: [ '**' ] + +jobs: + modular_build: + name: Modular build on ubuntu-latest + runs-on: ubuntu-latest + strategy: + matrix: + feature_publication: [1, 0] + feature_subscription: [1, 0] + feature_queryable: [1, 0] + feature_query: [1, 0] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run docker image + run: docker run --name zenoh_router --init --net host -d eclipse/zenoh:master + continue-on-error: true + + - name: Build project + run: | + make all + ./build/tests/z_modular_test $Z_FEATURE_PUBLICATION $Z_FEATURE_SUBSCRIPTION $Z_FEATURE_QUERYABLE $Z_FEATURE_QUERY + continue-on-error: true + env: + BUILD_TYPE: Debug + ZENOH_DEBUG: 3 + Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }} + Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }} + Z_FEATURE_QUERYABLE: ${{ matrix.feature_queryable }} + Z_FEATURE_QUERY: ${{ matrix.feature_query }} + + - name: Stop docker image + run: | + docker stop zenoh_router + docker rm zenoh_router \ No newline at end of file diff --git a/.github/workflows/build-shared.yaml b/.github/workflows/build-shared.yaml index 82b998db9..a5b6d2a52 100644 --- a/.github/workflows/build-shared.yaml +++ b/.github/workflows/build-shared.yaml @@ -50,39 +50,4 @@ jobs: env: BUILD_TYPE: Debug BUILD_SHARED_LIBS: ON - ZENOH_DEBUG: 3 - - modular_build: - name: Modular build on ubuntu-latest - runs-on: ubuntu-latest - strategy: - matrix: - feature_publication: [1, 0] - feature_subscription: [1, 0] - feature_queryable: [1, 0] - feature_query: [1, 0] - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Run docker image - run: docker run --name zenoh_router --init --net host -d eclipse/zenoh:master - continue-on-error: true - - - name: Build project - run: | - make all - ./build/tests/z_modular_test $Z_FEATURE_PUBLICATION $Z_FEATURE_SUBSCRIPTION $Z_FEATURE_QUERYABLE $Z_FEATURE_QUERY - continue-on-error: true - env: - BUILD_TYPE: Debug - ZENOH_DEBUG: 3 - Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }} - Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }} - Z_FEATURE_QUERYABLE: ${{ matrix.feature_queryable }} - Z_FEATURE_QUERY: ${{ matrix.feature_query }} - - - name: Stop docker image - run: | - docker stop zenoh_router - docker rm zenoh_router \ No newline at end of file + ZENOH_DEBUG: 3 \ No newline at end of file From 9f1b75d2c3d5655d87ddc55ab667831537439764 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 30 Oct 2023 10:50:04 +0100 Subject: [PATCH 06/16] feat: return -2 error on missing features --- examples/mbed/z_get.cpp | 2 +- examples/mbed/z_pub.cpp | 2 +- examples/mbed/z_pull.cpp | 2 +- examples/mbed/z_queryable.cpp | 2 +- examples/mbed/z_sub.cpp | 2 +- examples/unix/c11/z_get.c | 2 +- examples/unix/c11/z_ping.c | 2 +- examples/unix/c11/z_pong.c | 2 +- examples/unix/c11/z_pub.c | 2 +- examples/unix/c11/z_pub_st.c | 2 +- examples/unix/c11/z_pull.c | 2 +- examples/unix/c11/z_put.c | 2 +- examples/unix/c11/z_queryable.c | 2 +- examples/unix/c11/z_sub.c | 2 +- examples/unix/c11/z_sub_st.c | 2 +- examples/unix/c99/z_get.c | 2 +- examples/unix/c99/z_ping.c | 2 +- examples/unix/c99/z_pong.c | 2 +- examples/unix/c99/z_pub.c | 2 +- examples/unix/c99/z_pub_st.c | 2 +- examples/unix/c99/z_pull.c | 2 +- examples/unix/c99/z_put.c | 2 +- examples/unix/c99/z_queryable.c | 2 +- examples/unix/c99/z_sub.c | 2 +- examples/unix/c99/z_sub_st.c | 2 +- examples/windows/z_get.c | 2 +- examples/windows/z_ping.c | 2 +- examples/windows/z_pong.c | 2 +- examples/windows/z_pub.c | 2 +- examples/windows/z_pub_st.c | 2 +- examples/windows/z_pull.c | 2 +- examples/windows/z_put.c | 2 +- examples/windows/z_queryable.c | 2 +- examples/windows/z_sub.c | 2 +- examples/windows/z_sub_st.c | 2 +- examples/zephyr/z_get.c | 2 +- examples/zephyr/z_pub.c | 2 +- examples/zephyr/z_pull.c | 2 +- examples/zephyr/z_queryable.c | 7 +++++++ examples/zephyr/z_sub.c | 2 +- 40 files changed, 46 insertions(+), 39 deletions(-) diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index 39ea2c5fd..283dd8f43 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -98,6 +98,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/mbed/z_pub.cpp b/examples/mbed/z_pub.cpp index b51127a37..309cb3d7b 100644 --- a/examples/mbed/z_pub.cpp +++ b/examples/mbed/z_pub.cpp @@ -89,6 +89,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/mbed/z_pull.cpp b/examples/mbed/z_pull.cpp index 8a5e0522c..c54c83ad6 100644 --- a/examples/mbed/z_pull.cpp +++ b/examples/mbed/z_pull.cpp @@ -95,6 +95,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/mbed/z_queryable.cpp b/examples/mbed/z_queryable.cpp index 5a0dd4901..fa8b8046b 100644 --- a/examples/mbed/z_queryable.cpp +++ b/examples/mbed/z_queryable.cpp @@ -98,6 +98,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/mbed/z_sub.cpp b/examples/mbed/z_sub.cpp index 27297b1c8..51699f9ca 100644 --- a/examples/mbed/z_sub.cpp +++ b/examples/mbed/z_sub.cpp @@ -93,6 +93,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index 6c47a550b..b72ea0e9f 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -133,6 +133,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index af13efb2a..379ff6dcf 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -177,6 +177,6 @@ int main(void) { printf( "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " "requires them.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_pong.c b/examples/unix/c11/z_pong.c index 0a9ee2d26..6202b38b1 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -74,6 +74,6 @@ int main(void) { printf( "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " "requires them.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_pub.c b/examples/unix/c11/z_pub.c index 35df1383d..f6f9e6bd5 100644 --- a/examples/unix/c11/z_pub.c +++ b/examples/unix/c11/z_pub.c @@ -121,6 +121,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif diff --git a/examples/unix/c11/z_pub_st.c b/examples/unix/c11/z_pub_st.c index 7dda9936e..ae152104b 100644 --- a/examples/unix/c11/z_pub_st.c +++ b/examples/unix/c11/z_pub_st.c @@ -107,6 +107,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_pull.c b/examples/unix/c11/z_pull.c index cc8297a29..4ed568f76 100644 --- a/examples/unix/c11/z_pull.c +++ b/examples/unix/c11/z_pull.c @@ -102,6 +102,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_put.c b/examples/unix/c11/z_put.c index 557a128a5..70838a062 100644 --- a/examples/unix/c11/z_put.c +++ b/examples/unix/c11/z_put.c @@ -105,6 +105,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index 01a04410b..92f13c652 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -128,6 +128,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index 77fdb29a8..0f1d07c6f 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -111,6 +111,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_sub_st.c b/examples/unix/c11/z_sub_st.c index d6ee0966f..a95e93188 100644 --- a/examples/unix/c11/z_sub_st.c +++ b/examples/unix/c11/z_sub_st.c @@ -100,6 +100,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 7b45b13f7..766cca309 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -133,6 +133,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 94fe42424..6528bfdd7 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -177,6 +177,6 @@ int main(void) { printf( "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " "requires them.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_pong.c b/examples/unix/c99/z_pong.c index b175c49b0..2614f7bc9 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -84,6 +84,6 @@ int main(void) { printf( "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " "requires them.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_pub.c b/examples/unix/c99/z_pub.c index 0e0c22f1f..a1c12adda 100644 --- a/examples/unix/c99/z_pub.c +++ b/examples/unix/c99/z_pub.c @@ -110,6 +110,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_pub_st.c b/examples/unix/c99/z_pub_st.c index 237a892d9..07680e557 100644 --- a/examples/unix/c99/z_pub_st.c +++ b/examples/unix/c99/z_pub_st.c @@ -107,6 +107,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_pull.c b/examples/unix/c99/z_pull.c index 88361ff27..c2a1ecd2f 100644 --- a/examples/unix/c99/z_pull.c +++ b/examples/unix/c99/z_pull.c @@ -103,6 +103,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_put.c b/examples/unix/c99/z_put.c index 20d13fb11..15273aecd 100644 --- a/examples/unix/c99/z_put.c +++ b/examples/unix/c99/z_put.c @@ -105,6 +105,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index 8c8539bfe..f5093d370 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -124,6 +124,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index 7cb1d2354..2a1cd2aee 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -112,6 +112,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index 37c7d48cc..6b3c8728f 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -101,6 +101,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_get.c b/examples/windows/z_get.c index 0d082a63e..e89c2f3f3 100644 --- a/examples/windows/z_get.c +++ b/examples/windows/z_get.c @@ -98,6 +98,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index f1a218386..6a0a3cb82 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -174,6 +174,6 @@ int main(void) { printf( "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " "requires them.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_pong.c b/examples/windows/z_pong.c index 0a9ee2d26..6202b38b1 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -74,6 +74,6 @@ int main(void) { printf( "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " "requires them.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_pub.c b/examples/windows/z_pub.c index aecc29806..89c542ad4 100644 --- a/examples/windows/z_pub.c +++ b/examples/windows/z_pub.c @@ -78,6 +78,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif diff --git a/examples/windows/z_pub_st.c b/examples/windows/z_pub_st.c index 4623098ae..caa342504 100644 --- a/examples/windows/z_pub_st.c +++ b/examples/windows/z_pub_st.c @@ -74,6 +74,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_pull.c b/examples/windows/z_pull.c index efaa7676e..3c31de4be 100644 --- a/examples/windows/z_pull.c +++ b/examples/windows/z_pull.c @@ -82,6 +82,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_put.c b/examples/windows/z_put.c index dff826725..ca89e386c 100644 --- a/examples/windows/z_put.c +++ b/examples/windows/z_put.c @@ -72,6 +72,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index 8fafa11d9..ef166b73a 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -93,6 +93,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_sub.c b/examples/windows/z_sub.c index e46e1fbcb..afe3b4785 100644 --- a/examples/windows/z_sub.c +++ b/examples/windows/z_sub.c @@ -81,6 +81,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/windows/z_sub_st.c b/examples/windows/z_sub_st.c index d34a2d17f..fb808e1ea 100644 --- a/examples/windows/z_sub_st.c +++ b/examples/windows/z_sub_st.c @@ -70,6 +70,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/zephyr/z_get.c b/examples/zephyr/z_get.c index 279bd69a5..08a1ccb17 100644 --- a/examples/zephyr/z_get.c +++ b/examples/zephyr/z_get.c @@ -92,6 +92,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/zephyr/z_pub.c b/examples/zephyr/z_pub.c index 09623fd49..4bfd33d88 100644 --- a/examples/zephyr/z_pub.c +++ b/examples/zephyr/z_pub.c @@ -86,6 +86,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/zephyr/z_pull.c b/examples/zephyr/z_pull.c index 7b3522529..e2906063f 100644 --- a/examples/zephyr/z_pull.c +++ b/examples/zephyr/z_pull.c @@ -89,6 +89,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file diff --git a/examples/zephyr/z_queryable.c b/examples/zephyr/z_queryable.c index 154075dfa..b92be70c1 100644 --- a/examples/zephyr/z_queryable.c +++ b/examples/zephyr/z_queryable.c @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_QUERYABLE == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -89,3 +90,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); + return -2; +} +#endif \ No newline at end of file diff --git a/examples/zephyr/z_sub.c b/examples/zephyr/z_sub.c index 4f1831154..0293954ef 100644 --- a/examples/zephyr/z_sub.c +++ b/examples/zephyr/z_sub.c @@ -87,6 +87,6 @@ int main(int argc, char **argv) { #else int main(void) { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); - return -1; + return -2; } #endif \ No newline at end of file From d0828e9fab5f67e1a985e0a90d107dab7aeb8805 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 10:24:32 +0100 Subject: [PATCH 07/16] feat: switch to a python script testing the examples --- CMakeLists.txt | 4 +- tests/modularity.py | 266 ++++++++++++++++++++++++++++++++++++++ tests/z_modular_test.c | 285 ----------------------------------------- 3 files changed, 268 insertions(+), 287 deletions(-) create mode 100644 tests/modularity.py delete mode 100644 tests/z_modular_test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b4db14ec..3d562f411 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,7 +290,6 @@ if(UNIX OR MSVC) add_executable(z_keyexpr_test ${PROJECT_SOURCE_DIR}/tests/z_keyexpr_test.c) add_executable(z_api_null_drop_test ${PROJECT_SOURCE_DIR}/tests/z_api_null_drop_test.c) add_executable(z_api_double_drop_test ${PROJECT_SOURCE_DIR}/tests/z_api_double_drop_test.c) - add_executable(z_modular_test ${PROJECT_SOURCE_DIR}/tests/z_modular_test.c) target_link_libraries(z_data_struct_test ${Libname}) target_link_libraries(z_endpoint_test ${Libname}) @@ -299,7 +298,8 @@ if(UNIX OR MSVC) target_link_libraries(z_keyexpr_test ${Libname}) target_link_libraries(z_api_null_drop_test ${Libname}) target_link_libraries(z_api_double_drop_test ${Libname}) - target_link_libraries(z_modular_test ${Libname}) + + configure_file(${PROJECT_SOURCE_DIR}/tests/modularity.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modularity.py COPYONLY) enable_testing() add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test) diff --git a/tests/modularity.py b/tests/modularity.py new file mode 100644 index 000000000..2b3f50551 --- /dev/null +++ b/tests/modularity.py @@ -0,0 +1,266 @@ +import argparse +import subprocess +import sys +import time + +# Specify the directory for the binaries +DIR_EXAMPLES = "build/examples" +exit_status = 0 + +def set_err_status(): + exit_status = 1 + +def pub_and_sub(args): + print("*** Pub & sub test ***") + + # Expected z_pub output & status + if args.pub == 1: + z_pub_expected_status = 0 + z_pub_expected_output = '''Opening session... +Declaring publisher for 'demo/example/zenoh-pico-pub'... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')... +Putting Data ('demo/example/zenoh-pico-pub': 'Pub from Pico!')...''' + else : + z_pub_expected_status = 254 + z_pub_expected_output = "ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it." + + # Expected z_sub output & status + if args.sub == 1: + z_sub_expected_status = 0 + if args.pub == 1: + z_sub_expected_output = '''Opening session... +Declaring Subscriber on 'demo/example/**'... +Enter 'q' to quit... +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!') +>> [Subscriber] Received ('demo/example/zenoh-pico-pub': 'Pub from Pico!')''' + else: + z_sub_expected_output = '''Opening session... +Declaring Subscriber on 'demo/example/**'... +Enter 'q' to quit...''' + else : + z_sub_expected_status = 254 + z_sub_expected_output = "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it." + + print("Start subscriber") + # Start z_sub in the background + z_sub_command = f"./{DIR_EXAMPLES}/z_sub" + z_sub_process = subprocess.Popen(z_sub_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + # Introduce a delay to ensure z_sub starts + time.sleep(2) + + print("Start publisher") + # Start z_pub + z_pub_command = f"./{DIR_EXAMPLES}/z_pub" + z_pub_process = subprocess.Popen(z_pub_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + # Wait for z_pub to finish + z_pub_process.wait() + + print("Stop subscriber") + if z_pub_process.poll() is None: + # Send "q" command to z_sub to stop it + z_sub_process.stdin.write("q\n") + z_sub_process.stdin.flush() + + # Wait for z_sub to finish + z_sub_process.wait() + + print("Check publisher status & output") + # Check the exit status of z_pub + z_pub_status = z_pub_process.returncode + if z_pub_status == z_pub_expected_status: + print("z_pub status valid") + else: + print(f"z_pub status invalid, expected: {z_pub_expected_status}, received: {z_pub_status}") + set_err_status() + + # Check output of z_pub + z_pub_output = z_pub_process.stdout.read() + if z_pub_output.__contains__(z_pub_expected_output): + print("z_pub output valid") + else: + print("z_pub output invalid:") + print(f"Expected: \"{z_pub_expected_output}\"") + print(f"Received: \"{z_pub_output}\"") + set_err_status() + + print("Check subscriber status & output") + # Check the exit status of z_sub + z_sub_status = z_sub_process.returncode + if z_sub_status == z_sub_expected_status: + print("z_sub status valid") + else: + print(f"z_sub status invalid, expected: {z_sub_expected_status}, received: {z_sub_status}") + set_err_status() + + # Check output of z_sub + z_sub_output = z_sub_process.stdout.read() + if z_sub_output.__contains__(z_sub_expected_output): + print("z_sub output valid") + else: + print("z_sub output invalid:") + print(f"Expected: \"{z_sub_expected_output}\"") + print(f"Received: \"{z_sub_output}\"") + set_err_status() + +def query_and_queryable(args): + print("*** Query & queryable test ***") + + # Expected z_query output & status + if args.query == 1: + z_query_expected_status = 0 + if args.queryable == 1: + z_query_expected_output = '''Opening session... +Enter any key to pull data or 'q' to quit... +Sending Query 'demo/example/**'... +>> Received ('demo/example/zenoh-pico-queryable': 'Queryable from Pico!') +>> Received query final notification +Sending Query 'demo/example/**'... +>> Received ('demo/example/zenoh-pico-queryable': 'Queryable from Pico!') +>> Received query final notification +Sending Query 'demo/example/**'... +>> Received ('demo/example/zenoh-pico-queryable': 'Queryable from Pico!') +>> Received query final notification''' + else: + z_query_expected_output = '''Opening session... +Enter any key to pull data or 'q' to quit... +Sending Query 'demo/example/**'... +>> Received query final notification +Sending Query 'demo/example/**'...\" +>> Received query final notification +Sending Query 'demo/example/**'... +>> Received query final notification''' + else : + z_query_expected_status = 254 + z_query_expected_output = "ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it." + + # Expected z_queryable output & status + if args.queryable == 1: + z_queryable_expected_status = 0 + if args.query == 1: + z_queryable_expected_output = '''Opening session... +Creating Queryable on 'demo/example/zenoh-pico-queryable'... +Enter 'q' to quit... + >> [Queryable handler] Received Query 'demo/example/**?' + >> [Queryable handler] Received Query 'demo/example/**?' + >> [Queryable handler] Received Query 'demo/example/**?''' + else: + z_queryable_expected_output = '''Opening session... +Creating Queryable on 'demo/example/zenoh-pico-queryable'... +Enter 'q' to quit...''' + else : + z_queryable_expected_status = 254 + z_queryable_expected_output = "ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it." + + print("Start queryable") + # Start z_queryable in the background + z_queryable_command = f"./{DIR_EXAMPLES}/z_queryable" + z_queryable_process = subprocess.Popen(z_queryable_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + # Introduce a delay to ensure z_queryable starts + time.sleep(2) + + print("Start query") + # Start z_query + z_query_command = f"./{DIR_EXAMPLES}/z_get" + z_query_process = subprocess.Popen(z_query_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + # Introduce a delay to ensure z_query starts + time.sleep(2) + + print("Send requests") + if z_query_process.poll() is None: + z_query_process.stdin.write("\n") + z_query_process.stdin.flush() + time.sleep(1) + z_query_process.stdin.write("\n") + z_query_process.stdin.flush() + time.sleep(1) + z_query_process.stdin.write("\n") + z_query_process.stdin.flush() + time.sleep(1) + + print("Stop query") + if z_query_process.poll() is None: + z_query_process.stdin.write("q\n") + z_query_process.stdin.flush() + + # Wait for z_query to finish + z_query_process.wait() + + print("Stop queryable") + if z_queryable_process.poll() is None: + # Send "q" command to z_sub to stop it + z_queryable_process.stdin.write("q\n") + z_queryable_process.stdin.flush() + + # Wait for z_queryable to finish + z_queryable_process.wait() + + print("Check query status & output") + # Check the exit status of z_query + z_query_status = z_query_process.returncode + if z_query_status == z_query_expected_status: + print("z_query status valid") + else: + print(f"z_query status invalid, expected: {z_query_expected_status}, received: {z_query_status}") + set_err_status() + + # Check output of z_query + z_query_output = z_query_process.stdout.read() + if z_query_output.__contains__(z_query_expected_output): + print("z_query output valid") + else: + print("z_query output invalid:") + print(f"Expected: \"{z_query_expected_output}\"") + print(f"Received: \"{z_query_output}\"") + set_err_status() + + print("Check queryable status & output") + # Check the exit status of z_queryable + z_queryable_status = z_queryable_process.returncode + if z_queryable_status == z_queryable_expected_status: + print("z_queryable status valid") + else: + print(f"z_queryable status invalid, expected: {z_queryable_expected_status}, received: {z_queryable_status}") + set_err_status() + + # Check output of z_queryable + z_queryable_output = z_queryable_process.stdout.read() + if z_queryable_output.__contains__(z_queryable_expected_output): + print("z_queryable output valid") + else: + print("z_queryable output invalid:") + print(f"Expected: \"{z_queryable_expected_output}\"") + print(f"Received: \"{z_queryable_output}\"") + set_err_status() + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="This script runs zenoh-pico examples and checks them according to the given configuration") + parser.add_argument("--pub", type=int, choices=[0, 1], help="Z_FEATURE_PUBLICATION (0 or 1)") + parser.add_argument("--sub", type=int, choices=[0, 1], help="Z_FEATURE_SUBSCRIPTION (0 or 1)") + parser.add_argument("--queryable", type=int, choices=[0, 1], help="Z_FEATURE_QUERYABLE (0 or 1)") + parser.add_argument("--query", type=int, choices=[0, 1], help="Z_FEATURE_QUERY (0 or 1)") + + args = parser.parse_args() + print(f"Args value, pub:{args.pub}, sub:{args.sub}, queryable:{args.queryable}, query:{args.query}") + pub_and_sub(args) + query_and_queryable(args) + sys.exit(exit_status) \ No newline at end of file diff --git a/tests/z_modular_test.c b/tests/z_modular_test.c deleted file mode 100644 index e5ea32b26..000000000 --- a/tests/z_modular_test.c +++ /dev/null @@ -1,285 +0,0 @@ -// -// Copyright (c) 2022 ZettaScale Technology -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// -// Contributors: -// ZettaScale Zenoh Team, - -#include -#include -#include -#include - -#include "zenoh-pico.h" - -#undef NDEBUG -#include - -static const char *ARG_LIST[] = {"Z_FEATURE_PUBLICATION", "Z_FEATURE_SUBSCRIPTION", "Z_FEATURE_QUERYABLE", - "Z_FEATURE_QUERY"}; -#define ARG_NB (sizeof(ARG_LIST) / sizeof(ARG_LIST[0])) - -int test_publication(void) { -#if Z_FEATURE_PUBLICATION == 1 - const char *keyexpr = "demo/example/zenoh-pico-pub"; - const char *value = "Pub from Pico!"; - const char *mode = "client"; - - // Set up config - z_owned_config_t config = z_config_default(); - zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - // Open session - printf("Opening session...\n"); - z_owned_session_t s = z_open(z_move(config)); - if (!z_check(s)) { - printf("Unable to open session!\n"); - return -1; - } - // Start read and lease tasks for zenoh-pico - if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); - return -1; - } - // Declare publisher - printf("Declaring publisher for '%s'...\n", keyexpr); - z_owned_publisher_t pub = z_declare_publisher(z_loan(s), z_keyexpr(keyexpr), NULL); - if (!z_check(pub)) { - printf("Unable to declare publisher for key expression!\n"); - return -1; - } - // Put data - printf("Putting Data ('%s': '%s')...\n", keyexpr, value); - z_publisher_put_options_t options = z_publisher_put_options_default(); - options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); - z_publisher_put(z_loan(pub), (const uint8_t *)value, strlen(value), &options); - - // Clean-up - z_undeclare_publisher(z_move(pub)); - zp_stop_read_task(z_loan(s)); - zp_stop_lease_task(z_loan(s)); - z_close(z_move(s)); - return 1; -#else - return 0; -#endif -} - -#if Z_FEATURE_SUBSCRIPTION == 1 -static void subscription_data_handler(const z_sample_t *sample, void *ctx) { - (void)(ctx); - z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); - printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_loan(keystr), (int)sample->payload.len, - sample->payload.start); - z_drop(z_move(keystr)); -} -#endif - -int test_subscription(void) { -#if Z_FEATURE_SUBSCRIPTION == 1 - const char *keyexpr = "demo/example/**"; - const char *mode = "client"; - - // Set up config - z_owned_config_t config = z_config_default(); - zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - // Open session - printf("Opening session...\n"); - z_owned_session_t s = z_open(z_move(config)); - if (!z_check(s)) { - printf("Unable to open session!\n"); - return -1; - } - // Start read and lease tasks for zenoh-pico - if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); - return -1; - } - // Declare subscriber - z_owned_closure_sample_t callback = z_closure(subscription_data_handler); - printf("Declaring Subscriber on '%s'...\n", keyexpr); - z_owned_subscriber_t sub = z_declare_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL); - if (!z_check(sub)) { - printf("Unable to declare subscriber.\n"); - return -1; - } - // Clean-up - z_undeclare_subscriber(z_move(sub)); - zp_stop_read_task(z_loan(s)); - zp_stop_lease_task(z_loan(s)); - z_close(z_move(s)); - return 1; -#else - return 0; -#endif -} - -#if Z_FEATURE_QUERYABLE == 1 -static const char *queryable_keyexpr = "demo/example/zenoh-pico-queryable"; -static const char *queryable_value = "Queryable from Pico!"; - -void query_handler(const z_query_t *query, void *ctx) { - (void)(ctx); - z_owned_str_t keystr = z_keyexpr_to_string(z_query_keyexpr(query)); - z_bytes_t pred = z_query_parameters(query); - z_value_t payload_value = z_query_value(query); - printf(" >> [Queryable handler] Received Query '%s?%.*s'\n", z_loan(keystr), (int)pred.len, pred.start); - if (payload_value.payload.len > 0) { - printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); - } - z_query_reply_options_t options = z_query_reply_options_default(); - options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); - z_query_reply(query, z_keyexpr(queryable_keyexpr), (const unsigned char *)queryable_value, strlen(queryable_value), &options); - z_drop(z_move(keystr)); -} -#endif - -int test_queryable(void) { -#if Z_FEATURE_QUERYABLE == 1 - const char *mode = "client"; - - z_keyexpr_t ke = z_keyexpr(queryable_keyexpr); - if (!z_check(ke)) { - printf("%s is not a valid key expression", queryable_keyexpr); - return -1; - } - // Set up config - z_owned_config_t config = z_config_default(); - zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - // Open session - printf("Opening session...\n"); - z_owned_session_t s = z_open(z_move(config)); - if (!z_check(s)) { - printf("Unable to open session!\n"); - return -1; - } - // Start read and lease tasks for zenoh-pico - if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); - return -1; - } - // Declare queryable - printf("Creating Queryable on '%s'...\n", queryable_keyexpr); - z_owned_closure_query_t callback = z_closure(query_handler); - z_owned_queryable_t qable = z_declare_queryable(z_loan(s), ke, z_move(callback), NULL); - if (!z_check(qable)) { - printf("Unable to create queryable.\n"); - return -1; - } - // Clean-up - z_undeclare_queryable(z_move(qable)); - zp_stop_read_task(z_loan(s)); - zp_stop_lease_task(z_loan(s)); - z_close(z_move(s)); - - return 1; -#else - return 0; -#endif -} - -#if Z_FEATURE_QUERY == 1 -void reply_dropper(void *ctx) { - (void)(ctx); - printf(">> Received query final notification\n"); -} - -void reply_handler(z_owned_reply_t *reply, void *ctx) { - (void)(ctx); - if (z_reply_is_ok(reply)) { - z_sample_t sample = z_reply_ok(reply); - z_owned_str_t keystr = z_keyexpr_to_string(sample.keyexpr); - printf(">> Received ('%s': '%.*s')\n", z_loan(keystr), (int)sample.payload.len, sample.payload.start); - z_drop(z_move(keystr)); - } else { - printf(">> Received an error\n"); - } -} -#endif - -int test_query(void) { -#if Z_FEATURE_QUERY == 1 - const char *keyexpr = "demo/example/**"; - const char *mode = "client"; - - z_keyexpr_t ke = z_keyexpr(keyexpr); - if (!z_check(ke)) { - printf("%s is not a valid key expression", keyexpr); - return -1; - } - // Set up config - z_owned_config_t config = z_config_default(); - zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - // Open session - printf("Opening session...\n"); - z_owned_session_t s = z_open(z_move(config)); - if (!z_check(s)) { - printf("Unable to open session!\n"); - return -1; - } - // Start read and lease tasks for zenoh-pico - if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); - return -1; - } - // Send query - printf("Sending Query '%s'...\n", keyexpr); - z_get_options_t opts = z_get_options_default(); - z_owned_closure_reply_t callback = z_closure(reply_handler, reply_dropper); - if (z_get(z_loan(s), ke, "", z_move(callback), &opts) < 0) { - printf("Unable to send query.\n"); - return -1; - } - // Clean-up - zp_stop_read_task(z_loan(s)); - zp_stop_lease_task(z_loan(s)); - z_close(z_move(s)); - - return 1; -#else - return 0; -#endif -} - -// Send feature config as int list, and compare with compiled feature -int main(int argc, char **argv) { - if (argc < (int)(ARG_NB + 1)) { - printf("To start this test you must give the state of the feature config as argument\n"); - printf("Arg order: "); - for (size_t i = 0; i < ARG_NB; i++) { - printf("%s ", ARG_LIST[i]); - } - printf("\n"); - return -1; - } - if (test_publication() != atoi(argv[1])) { - printf("Problem during publication testing\n"); - return -1; - } else { - printf("Publication status ok\n"); - } - if (test_subscription() != atoi(argv[2])) { - printf("Problem during subscription testing\n"); - return -1; - } else { - printf("Subscription status ok\n"); - } - if (test_queryable() != atoi(argv[3])) { - printf("Problem during queryable testing\n"); - return -1; - } else { - printf("Queryable status ok\n"); - } - if (test_query() != atoi(argv[4])) { - printf("Problem during query testing\n"); - return -1; - } else { - printf("Query status ok\n"); - } - return 0; -} From 4c7f14159175aabddc5a18528a03a1c5aa1ee005 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 10:25:05 +0100 Subject: [PATCH 08/16] fix: update freertos examples with modular features --- examples/freertos_plus_tcp/CMakeLists.txt | 4 ++++ examples/freertos_plus_tcp/include/FreeRTOSConfig.h | 2 +- examples/freertos_plus_tcp/include/FreeRTOSIPConfig.h | 2 +- examples/freertos_plus_tcp/z_get.c | 10 ++++++++-- examples/freertos_plus_tcp/z_pub.c | 8 +++++++- examples/freertos_plus_tcp/z_pub_st.c | 8 +++++++- examples/freertos_plus_tcp/z_pull.c | 8 +++++++- examples/freertos_plus_tcp/z_put.c | 8 +++++++- examples/freertos_plus_tcp/z_queryable.c | 8 +++++++- examples/freertos_plus_tcp/z_scout.c | 2 +- examples/freertos_plus_tcp/z_sub.c | 7 ++++++- examples/freertos_plus_tcp/z_sub_st.c | 7 ++++++- 12 files changed, 62 insertions(+), 12 deletions(-) diff --git a/examples/freertos_plus_tcp/CMakeLists.txt b/examples/freertos_plus_tcp/CMakeLists.txt index 8130e0a23..ba0b53501 100644 --- a/examples/freertos_plus_tcp/CMakeLists.txt +++ b/examples/freertos_plus_tcp/CMakeLists.txt @@ -64,6 +64,10 @@ target_link_libraries(zenohpico target_compile_definitions(zenohpico PUBLIC Z_FEATURE_MULTI_THREAD=1 + Z_FEATURE_PUBLICATION=1 + Z_FEATURE_SUBSCRIPTION=1 + Z_FEATURE_QUERY=1 + Z_FEATURE_QUERYABLE=1 Z_FEATURE_LINK_TCP=1 Z_FEATURE_SCOUTING_UDP=1 Z_FEATURE_LINK_UDP_UNICAST=1 diff --git a/examples/freertos_plus_tcp/include/FreeRTOSConfig.h b/examples/freertos_plus_tcp/include/FreeRTOSConfig.h index cbd027ce3..faeb5bbd5 100644 --- a/examples/freertos_plus_tcp/include/FreeRTOSConfig.h +++ b/examples/freertos_plus_tcp/include/FreeRTOSConfig.h @@ -20,7 +20,7 @@ #define configUSE_PREEMPTION 1 #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES (56) -#define configMINIMAL_STACK_SIZE ((uint16_t) PTHREAD_STACK_MIN) +#define configMINIMAL_STACK_SIZE ((uint16_t)PTHREAD_STACK_MIN) #define configMAX_TASK_NAME_LEN (16) #define configUSE_16_BIT_TICKS 0 #define configQUEUE_REGISTRY_SIZE 0 diff --git a/examples/freertos_plus_tcp/include/FreeRTOSIPConfig.h b/examples/freertos_plus_tcp/include/FreeRTOSIPConfig.h index 2070ad000..430e92b4d 100644 --- a/examples/freertos_plus_tcp/include/FreeRTOSIPConfig.h +++ b/examples/freertos_plus_tcp/include/FreeRTOSIPConfig.h @@ -48,7 +48,7 @@ // Set ipconfigBUFFER_PADDING on 64-bit platforms #if INTPTR_MAX == INT64_MAX - #define ipconfigBUFFER_PADDING 14U +#define ipconfigBUFFER_PADDING 14U #endif #endif /* FREERTOS_IP_CONFIG_H */ \ No newline at end of file diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index 8a0f74b4f..3a95518c1 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -16,6 +16,7 @@ #include "FreeRTOS.h" +#if Z_FEATURE_QUERY == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -47,7 +48,7 @@ void reply_handler(z_owned_reply_t *reply, void *ctx) { } } -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -92,4 +93,9 @@ void app_main() { zp_stop_lease_task(z_loan(s)); z_close(z_move(s)); -} \ No newline at end of file +} +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); +} +#endif \ No newline at end of file diff --git a/examples/freertos_plus_tcp/z_pub.c b/examples/freertos_plus_tcp/z_pub.c index 969202074..f53a786da 100644 --- a/examples/freertos_plus_tcp/z_pub.c +++ b/examples/freertos_plus_tcp/z_pub.c @@ -16,6 +16,7 @@ #include "FreeRTOS.h" +#if Z_FEATURE_PUBLICATION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -30,7 +31,7 @@ #define KEYEXPR "demo/example/zenoh-pico-pub" #define VALUE "[FreeRTOS-Plus-TCP] Pub from Zenoh-Pico!" -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -104,3 +105,8 @@ void app_main() { z_close(z_move(s)); } +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); +} +#endif diff --git a/examples/freertos_plus_tcp/z_pub_st.c b/examples/freertos_plus_tcp/z_pub_st.c index f31516b72..03311e25c 100644 --- a/examples/freertos_plus_tcp/z_pub_st.c +++ b/examples/freertos_plus_tcp/z_pub_st.c @@ -16,6 +16,7 @@ #include "FreeRTOS.h" +#if Z_FEATURE_PUBLICATION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -30,7 +31,7 @@ #define KEYEXPR "demo/example/zenoh-pico-pub" #define VALUE "[FreeRTOS-Plus-TCP] Pub from Zenoh-Pico!" -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -72,3 +73,8 @@ void app_main() { z_close(z_move(s)); } +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); +} +#endif diff --git a/examples/freertos_plus_tcp/z_pull.c b/examples/freertos_plus_tcp/z_pull.c index b6d5d84f8..601bfe720 100644 --- a/examples/freertos_plus_tcp/z_pull.c +++ b/examples/freertos_plus_tcp/z_pull.c @@ -14,6 +14,7 @@ #include +#if Z_FEATURE_PUBLICATION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -35,7 +36,7 @@ void data_handler(const z_sample_t *sample, void *ctx) { z_drop(z_move(keystr)); } -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -77,3 +78,8 @@ void app_main() { z_close(z_move(s)); } +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); +} +#endif diff --git a/examples/freertos_plus_tcp/z_put.c b/examples/freertos_plus_tcp/z_put.c index f8913146d..43c6a4975 100644 --- a/examples/freertos_plus_tcp/z_put.c +++ b/examples/freertos_plus_tcp/z_put.c @@ -14,6 +14,7 @@ #include +#if Z_FEATURE_PUBLICATION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -28,7 +29,7 @@ #define KEYEXPR "demo/example/zenoh-pico-put" #define VALUE "[FreeRTOS-Plus-TCP] Pub from Zenoh-Pico!" -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -74,3 +75,8 @@ void app_main() { z_close(z_move(s)); } +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); +} +#endif diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index 1a9f19514..de60b9c53 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -14,6 +14,7 @@ #include +#if Z_FEATURE_QUERYABLE == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -43,7 +44,7 @@ void query_handler(const z_query_t *query, void *ctx) { z_drop(z_move(keystr)); } -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -89,3 +90,8 @@ void app_main() { z_close(z_move(s)); } +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); +} +#endif \ No newline at end of file diff --git a/examples/freertos_plus_tcp/z_scout.c b/examples/freertos_plus_tcp/z_scout.c index c73785779..0f3087eee 100644 --- a/examples/freertos_plus_tcp/z_scout.c +++ b/examples/freertos_plus_tcp/z_scout.c @@ -82,7 +82,7 @@ void drop(void *context) { } } -void app_main() { +void app_main(void) { int *context = (int *)pvPortMalloc(sizeof(int)); *context = 0; z_owned_scouting_config_t config = z_scouting_config_default(); diff --git a/examples/freertos_plus_tcp/z_sub.c b/examples/freertos_plus_tcp/z_sub.c index 62e39ba59..d62e3cc29 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -35,7 +35,7 @@ void data_handler(const z_sample_t *sample, void *ctx) { z_drop(z_move(keystr)); } -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -75,3 +75,8 @@ void app_main() { z_close(z_move(s)); } +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); +} +#endif diff --git a/examples/freertos_plus_tcp/z_sub_st.c b/examples/freertos_plus_tcp/z_sub_st.c index b051ed467..f9a373cb9 100644 --- a/examples/freertos_plus_tcp/z_sub_st.c +++ b/examples/freertos_plus_tcp/z_sub_st.c @@ -35,7 +35,7 @@ void data_handler(const z_sample_t *sample, void *ctx) { z_drop(z_move(keystr)); } -void app_main() { +void app_main(void) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(MODE)); if (strcmp(CONNECT, "") != 0) { @@ -67,3 +67,8 @@ void app_main() { z_close(z_move(s)); } +#else +void app_main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); +} +#endif From 0b0e734c02c0c2e29b213b1e38a1d974f39ead94 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 10:38:40 +0100 Subject: [PATCH 09/16] fix: use python script in CI --- .github/workflows/build-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml index fbf61f995..c9d24a011 100644 --- a/.github/workflows/build-check.yaml +++ b/.github/workflows/build-check.yaml @@ -40,7 +40,7 @@ jobs: - name: Build project run: | make all - ./build/tests/z_modular_test $Z_FEATURE_PUBLICATION $Z_FEATURE_SUBSCRIPTION $Z_FEATURE_QUERYABLE $Z_FEATURE_QUERY + python3 ./build/tests/modularity.py --pub $Z_FEATURE_PUBLICATION --sub $Z_FEATURE_SUBSCRIPTION --queryable $Z_FEATURE_QUERYABLE --query $Z_FEATURE_QUERY continue-on-error: true env: BUILD_TYPE: Debug From a96945f1abdb08367b7fdc89ef11a89e21fc3b4a Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 10:42:19 +0100 Subject: [PATCH 10/16] fix: missing precompile flag check --- examples/freertos_plus_tcp/z_sub.c | 1 + examples/freertos_plus_tcp/z_sub_st.c | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/freertos_plus_tcp/z_sub.c b/examples/freertos_plus_tcp/z_sub.c index d62e3cc29..7f403d58a 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -14,6 +14,7 @@ #include +#if Z_FEATURE_SUBSCRIPTION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" diff --git a/examples/freertos_plus_tcp/z_sub_st.c b/examples/freertos_plus_tcp/z_sub_st.c index f9a373cb9..811a49877 100644 --- a/examples/freertos_plus_tcp/z_sub_st.c +++ b/examples/freertos_plus_tcp/z_sub_st.c @@ -14,6 +14,7 @@ #include +#if Z_FEATURE_SUBSCRIPTION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" From b07c8083f44a0be1acdfe1c0206b9be4ff0f678a Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 10:56:33 +0100 Subject: [PATCH 11/16] fix: define config tokens in workflow --- .github/workflows/freertos_plus_tcp.yaml | 5 +++++ examples/freertos_plus_tcp/CMakeLists.txt | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/freertos_plus_tcp.yaml b/.github/workflows/freertos_plus_tcp.yaml index 1e8ee0fe7..65231e75f 100644 --- a/.github/workflows/freertos_plus_tcp.yaml +++ b/.github/workflows/freertos_plus_tcp.yaml @@ -40,3 +40,8 @@ jobs: cmake -Bbuild -G"Ninja Multi-Config" cmake --build ./build --config Debug cmake --build ./build --config Release + env: + Z_FEATURE_PUBLICATION: 1 + Z_FEATURE_SUBSCRIPTION: 1 + Z_FEATURE_QUERYABLE: 1 + Z_FEATURE_QUERY: 1 diff --git a/examples/freertos_plus_tcp/CMakeLists.txt b/examples/freertos_plus_tcp/CMakeLists.txt index ba0b53501..8130e0a23 100644 --- a/examples/freertos_plus_tcp/CMakeLists.txt +++ b/examples/freertos_plus_tcp/CMakeLists.txt @@ -64,10 +64,6 @@ target_link_libraries(zenohpico target_compile_definitions(zenohpico PUBLIC Z_FEATURE_MULTI_THREAD=1 - Z_FEATURE_PUBLICATION=1 - Z_FEATURE_SUBSCRIPTION=1 - Z_FEATURE_QUERY=1 - Z_FEATURE_QUERYABLE=1 Z_FEATURE_LINK_TCP=1 Z_FEATURE_SCOUTING_UDP=1 Z_FEATURE_LINK_UDP_UNICAST=1 From 4d1dba5237a16342cabfe3adb3f04ebe7e87dec2 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 10:57:26 +0100 Subject: [PATCH 12/16] build: run check modularity in release --- .github/workflows/build-check.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml index c9d24a011..2b7b59b68 100644 --- a/.github/workflows/build-check.yaml +++ b/.github/workflows/build-check.yaml @@ -43,8 +43,6 @@ jobs: python3 ./build/tests/modularity.py --pub $Z_FEATURE_PUBLICATION --sub $Z_FEATURE_SUBSCRIPTION --queryable $Z_FEATURE_QUERYABLE --query $Z_FEATURE_QUERY continue-on-error: true env: - BUILD_TYPE: Debug - ZENOH_DEBUG: 3 Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }} Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }} Z_FEATURE_QUERYABLE: ${{ matrix.feature_queryable }} From a0e36963a4c1d883d2888aa17eb2c8570bf01a49 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 11:08:07 +0100 Subject: [PATCH 13/16] fix: bad return status from python script --- tests/modularity.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tests/modularity.py b/tests/modularity.py index 2b3f50551..5be8c5851 100644 --- a/tests/modularity.py +++ b/tests/modularity.py @@ -5,13 +5,10 @@ # Specify the directory for the binaries DIR_EXAMPLES = "build/examples" -exit_status = 0 - -def set_err_status(): - exit_status = 1 def pub_and_sub(args): print("*** Pub & sub test ***") + test_status = 0 # Expected z_pub output & status if args.pub == 1: @@ -89,7 +86,7 @@ def pub_and_sub(args): print("z_pub status valid") else: print(f"z_pub status invalid, expected: {z_pub_expected_status}, received: {z_pub_status}") - set_err_status() + test_status = 1 # Check output of z_pub z_pub_output = z_pub_process.stdout.read() @@ -99,7 +96,7 @@ def pub_and_sub(args): print("z_pub output invalid:") print(f"Expected: \"{z_pub_expected_output}\"") print(f"Received: \"{z_pub_output}\"") - set_err_status() + test_status = 1 print("Check subscriber status & output") # Check the exit status of z_sub @@ -108,7 +105,7 @@ def pub_and_sub(args): print("z_sub status valid") else: print(f"z_sub status invalid, expected: {z_sub_expected_status}, received: {z_sub_status}") - set_err_status() + test_status = 1 # Check output of z_sub z_sub_output = z_sub_process.stdout.read() @@ -118,10 +115,13 @@ def pub_and_sub(args): print("z_sub output invalid:") print(f"Expected: \"{z_sub_expected_output}\"") print(f"Received: \"{z_sub_output}\"") - set_err_status() + test_status = 1 + # Return value + return test_status def query_and_queryable(args): print("*** Query & queryable test ***") + test_status = 0 # Expected z_query output & status if args.query == 1: @@ -221,7 +221,7 @@ def query_and_queryable(args): print("z_query status valid") else: print(f"z_query status invalid, expected: {z_query_expected_status}, received: {z_query_status}") - set_err_status() + test_status = 1 # Check output of z_query z_query_output = z_query_process.stdout.read() @@ -231,7 +231,7 @@ def query_and_queryable(args): print("z_query output invalid:") print(f"Expected: \"{z_query_expected_output}\"") print(f"Received: \"{z_query_output}\"") - set_err_status() + test_status = 1 print("Check queryable status & output") # Check the exit status of z_queryable @@ -240,7 +240,7 @@ def query_and_queryable(args): print("z_queryable status valid") else: print(f"z_queryable status invalid, expected: {z_queryable_expected_status}, received: {z_queryable_status}") - set_err_status() + test_status = 1 # Check output of z_queryable z_queryable_output = z_queryable_process.stdout.read() @@ -250,7 +250,9 @@ def query_and_queryable(args): print("z_queryable output invalid:") print(f"Expected: \"{z_queryable_expected_output}\"") print(f"Received: \"{z_queryable_output}\"") - set_err_status() + test_status = 1 + # Return status + return test_status if __name__ == "__main__": parser = argparse.ArgumentParser(description="This script runs zenoh-pico examples and checks them according to the given configuration") @@ -259,8 +261,15 @@ def query_and_queryable(args): parser.add_argument("--queryable", type=int, choices=[0, 1], help="Z_FEATURE_QUERYABLE (0 or 1)") parser.add_argument("--query", type=int, choices=[0, 1], help="Z_FEATURE_QUERY (0 or 1)") + exit_status = 0 args = parser.parse_args() print(f"Args value, pub:{args.pub}, sub:{args.sub}, queryable:{args.queryable}, query:{args.query}") - pub_and_sub(args) - query_and_queryable(args) + + # Test pub and sub examples + if pub_and_sub(args) == 1: + exit_status = 1 + # Test query and queryable examples + if query_and_queryable(args) == 1: + exit_status = 1 + # Exit sys.exit(exit_status) \ No newline at end of file From d2118bcda0dde2196971e309d6e57944a5549a5e Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 11:27:07 +0100 Subject: [PATCH 14/16] fix: infinite wait in build-check workflow --- .github/workflows/build-check.yaml | 4 ++-- tests/modularity.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml index 2b7b59b68..b8a13d880 100644 --- a/.github/workflows/build-check.yaml +++ b/.github/workflows/build-check.yaml @@ -35,13 +35,12 @@ jobs: - name: Run docker image run: docker run --name zenoh_router --init --net host -d eclipse/zenoh:master - continue-on-error: true - name: Build project run: | make all python3 ./build/tests/modularity.py --pub $Z_FEATURE_PUBLICATION --sub $Z_FEATURE_SUBSCRIPTION --queryable $Z_FEATURE_QUERYABLE --query $Z_FEATURE_QUERY - continue-on-error: true + timeout-minutes: 5 env: Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }} Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }} @@ -49,6 +48,7 @@ jobs: Z_FEATURE_QUERY: ${{ matrix.feature_query }} - name: Stop docker image + if: always() run: | docker stop zenoh_router docker rm zenoh_router \ No newline at end of file diff --git a/tests/modularity.py b/tests/modularity.py index 5be8c5851..cac7c9394 100644 --- a/tests/modularity.py +++ b/tests/modularity.py @@ -75,6 +75,7 @@ def pub_and_sub(args): # Send "q" command to z_sub to stop it z_sub_process.stdin.write("q\n") z_sub_process.stdin.flush() + time.sleep(1) # Wait for z_sub to finish z_sub_process.wait() From b59c39eaa537259561183d90c3f05f4ec33e8df6 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 11:36:34 +0100 Subject: [PATCH 15/16] fix: remove stray \" --- tests/modularity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/modularity.py b/tests/modularity.py index cac7c9394..925f7fb49 100644 --- a/tests/modularity.py +++ b/tests/modularity.py @@ -144,7 +144,7 @@ def query_and_queryable(args): Enter any key to pull data or 'q' to quit... Sending Query 'demo/example/**'... >> Received query final notification -Sending Query 'demo/example/**'...\" +Sending Query 'demo/example/**'... >> Received query final notification Sending Query 'demo/example/**'... >> Received query final notification''' From e16a788cf51bf0b49cd3bd51103baca7a3e1f319 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 31 Oct 2023 11:43:16 +0100 Subject: [PATCH 16/16] fix: check for correct process --- tests/modularity.py | 3 +-- zenohpico.pc | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/modularity.py b/tests/modularity.py index 925f7fb49..44c66d8e5 100644 --- a/tests/modularity.py +++ b/tests/modularity.py @@ -71,11 +71,10 @@ def pub_and_sub(args): z_pub_process.wait() print("Stop subscriber") - if z_pub_process.poll() is None: + if z_sub_process.poll() is None: # Send "q" command to z_sub to stop it z_sub_process.stdin.write("q\n") z_sub_process.stdin.flush() - time.sleep(1) # Wait for z_sub to finish z_sub_process.wait() diff --git a/zenohpico.pc b/zenohpico.pc index bcc1e5d18..e08e8cce2 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 0.11.20231019dev +Version: 0.11.20231031dev Cflags: -I${prefix}/include Libs: -L${prefix}/lib -lzenohpico