From 927182209dcd8e2d560b6f5db449529c51c80305 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Fri, 1 Dec 2023 20:24:39 +0100 Subject: [PATCH 1/5] Add interation test - helpers - pub/sub - pub_cache/sub_query --- tests/CMakeLists.txt | 13 ++- tests/z_int_helpers.h | 132 +++++++++++++++++++++++ tests/z_int_helpers_test.c | 57 ++++++++++ tests/z_int_pub_cache_query_sub_test.c | 142 +++++++++++++++++++++++++ tests/z_int_pub_sub_test.c | 110 +++++++++++++++++++ 5 files changed, 453 insertions(+), 1 deletion(-) create mode 100644 tests/z_int_helpers.h create mode 100644 tests/z_int_helpers_test.c create mode 100644 tests/z_int_pub_cache_query_sub_test.c create mode 100644 tests/z_int_pub_sub_test.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 37568bd7d..2a68c4e3d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,8 +7,19 @@ add_custom_target(tests) file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.c") foreach(file ${files}) get_filename_component(target ${file} NAME_WE) + + # Check the filename prefix to determine the test type + if (${file} MATCHES "^.*z_api_.*$") + set(test_type "unit") + elseif (${file} MATCHES "^.*z_int_.*$") + set(test_type "integration") + else() + message(FATAL_ERROR "Test file ${file} does not match any known type (z_api_ or z_int_)") + endif() + add_executable(${target} EXCLUDE_FROM_ALL ${file}) add_dependencies(tests ${target}) + if(ZENOHC_BUILD_TESTS_WITH_STATIC_LIB) add_dependencies(${target} zenohc::static) target_link_libraries(${target} PRIVATE zenohc::static) @@ -20,6 +31,6 @@ foreach(file ${files}) set_property(TARGET ${target} PROPERTY C_STANDARD 11) # set_property(TARGET ${target} PROPERTY RUNTIME_OUTPUT_DIRECTORY "${cargo_target_dir}/tests") - add_test(NAME "test_${file}" COMMAND ${target}) + add_test(NAME "${test_type}_${target}" COMMAND ${target}) endforeach() diff --git a/tests/z_int_helpers.h b/tests/z_int_helpers.h new file mode 100644 index 000000000..4ac82985e --- /dev/null +++ b/tests/z_int_helpers.h @@ -0,0 +1,132 @@ +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#define VALID_PLATFORM 0 +#else // def windows +#define VALID_PLATFORM 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef NDEBUG +#include + +typedef int (*func_ptr_t)(); + +int run_timeouted_test(func_ptr_t functions[], int num_functions, int timeout_seconds) { + pid_t child_pids[num_functions]; + int status; + int result = 0; + + // Fork a child process for each function + for (int i = 0; i < num_functions; ++i) { + child_pids[i] = fork(); + if (child_pids[i] == 0) { + // Child process + exit(functions[i]()); + } else if (child_pids[i] < 0) { + // Error forking + perror("Error forking"); + exit(EXIT_FAILURE); + } + } + + // Wait for all processes to finish or timeout + int remaining_time = timeout_seconds * 10; + int remaining_children = num_functions; + + while (remaining_time > 0 && remaining_children > 0 && result == 0) { + pid_t finished_pid = waitpid(-1, &status, WNOHANG); + if (finished_pid > 0) { + for (int i = 0; i < num_functions; ++i) { + if (finished_pid == child_pids[i]) { + child_pids[i] = 0; + --remaining_children; + if ((WIFEXITED(status) && WEXITSTATUS(status) != 0)) { + result = -1; + break; + } + } + } + } else if (finished_pid == 0) { + // No process finished yet + usleep(100000); // 0.1 sec + remaining_time--; + } else { + // Error in waitpid + perror("Error waiting for child process"); + break; + } + } + + if (remaining_time <= 0) { + fprintf(stderr, "Timeout reached\n"); + } + + // Check if the processes are still running and kill them if necessary + if (remaining_children != 0) { + for (int i = 0; i < num_functions; ++i) { + if (child_pids[i]) { + kill(child_pids[i], SIGKILL); + waitpid(child_pids[i], &status, 0); + } + } + result = -1; + } + + return result; +}; + +#define SEM_INIT(sem, name) \ + do { \ + sem_unlink(name); \ + sem = sem_open(name, O_CREAT | O_EXCL, 0666, 0); \ + if (sem == SEM_FAILED) { \ + perror("sem_open"); \ + exit(-1); \ + } \ + } while (0) + +#define SEM_DROP(sem, name) \ + do { \ + int r; \ + r = sem_close(sem); \ + if (r) { \ + perror("sem_close"); \ + exit(-1); \ + }; \ + r = sem_unlink(name); \ + if (r) { \ + perror("sem_close"); \ + exit(-1); \ + } \ + } while (0) + +#define SEM_WAIT(sem) \ + do { \ + int r; \ + do { \ + r = sem_wait(sem); \ + if (r == -1 && errno != EINTR) { \ + perror("sem_wait"); \ + exit(-1); \ + } \ + } while (r != 0); \ + } while (0) + +#define SEM_POST(sem) \ + do { \ + int r; \ + r = sem_post(sem); \ + if (r) { \ + perror("sem_post"); \ + exit(-1); \ + }; \ + } while (0) + +#endif // def windows diff --git a/tests/z_int_helpers_test.c b/tests/z_int_helpers_test.c new file mode 100644 index 000000000..ae0e1efe7 --- /dev/null +++ b/tests/z_int_helpers_test.c @@ -0,0 +1,57 @@ +#include + +#include "z_int_helpers.h" + +#ifdef VALID_PLATFORM + +int run_success() { return 0; } + +int run_failed() { return 1; } + +int run_hanged() { + while (1) { + sleep(1000); + }; + return 0; +} + +int all_success() { + func_ptr_t funcs[] = {run_success, run_success, run_success}; + assert(run_timeouted_test(funcs, 3, 10) == 0); +} + +int all_failed() { + func_ptr_t funcs[] = {run_failed, run_failed, run_failed}; + assert(run_timeouted_test(funcs, 3, 10) == -1); +} + +int first_failed() { + func_ptr_t funcs[] = {run_failed, run_success, run_success}; + assert(run_timeouted_test(funcs, 3, 10) == -1); +} + +int last_failed() { + func_ptr_t funcs[] = {run_success, run_success, run_failed}; + assert(run_timeouted_test(funcs, 3, 10) == -1); +} + +int all_hanged() { + func_ptr_t funcs[] = {run_hanged, run_hanged, run_hanged}; + assert(run_timeouted_test(funcs, 3, 1) == -1); +} + +int one_hanged() { + func_ptr_t funcs[] = {run_success, run_hanged, run_success}; + assert(run_timeouted_test(funcs, 3, 1) == -1); +} + +int main() { + all_success(); + all_failed(); + first_failed(); + last_failed(); + all_hanged(); + one_hanged(); +} + +#endif // VALID_PLATFORM diff --git a/tests/z_int_pub_cache_query_sub_test.c b/tests/z_int_pub_cache_query_sub_test.c new file mode 100644 index 000000000..40fa3b533 --- /dev/null +++ b/tests/z_int_pub_cache_query_sub_test.c @@ -0,0 +1,142 @@ +// +// 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 "z_int_helpers.h" +#include "zenoh.h" + +#ifdef VALID_PLATFORM + +const char *const SEM_NAME_PUB = "/z_int_test_sync_sem_pub"; +sem_t *sem_pub; +const char *const SEM_NAME_SUB = "/z_int_test_sync_sem_sub"; +sem_t *sem_sub; + +const char *const keyexpr = "test/key"; +const char *const values[] = {"test_value_1", "test_value_2", "test_value_3", + "test_value_4", "test_value_5", "test_value_6"}; +const size_t values_count = sizeof(values) / sizeof(values[0]); + +int run_publisher() { + z_owned_config_t config = z_config_default(); + if (zc_config_insert_json(z_loan(config), Z_CONFIG_ADD_TIMESTAMP_KEY, "true") < 0) { + perror("Unable to configure timestamps!"); + return -1; + } + + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + perror("Unable to open session!"); + return -1; + } + + ze_publication_cache_options_t pub_cache_opts = ze_publication_cache_options_default(); + pub_cache_opts.history = 42; + + ze_owned_publication_cache_t pub_cache = + ze_declare_publication_cache(z_loan(s), z_keyexpr(keyexpr), &pub_cache_opts); + if (!z_check(pub_cache)) { + perror("Unable to declare publication cache for key expression!\n"); + return -1; + } + + z_owned_publisher_t pub = z_declare_publisher(z_loan(s), z_keyexpr(keyexpr), NULL); + if (!z_check(pub)) { + perror("Unable to declare Publisher for key expression!"); + return -1; + } + + // values for cache + for (int i = 0; i < values_count / 2; ++i) { + z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)values[i], strlen(values[i]), NULL); + } + + SEM_POST(sem_pub); + SEM_WAIT(sem_sub); + + // values for subscribe + for (int i = values_count / 2; i < values_count; ++i) { + z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)values[i], strlen(values[i]), NULL); + } + + SEM_WAIT(sem_sub); + + z_drop(z_move(pub_cache)); + z_drop(z_move(pub)); + z_close(z_move(s)); + + return 0; +} + +void data_handler(const z_sample_t *sample, void *arg) { + printf("data_handler\n"); + static int val_num = 0; + z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); + if (strcmp(keyexpr, z_loan(keystr))) { + perror("Unexpected key received"); + exit(-1); + } + z_drop(z_move(keystr)); + + if (strncmp(values[val_num], sample->payload.start, (int)sample->payload.len)) { + perror("Unexpected value received"); + exit(-1); + } + + if (++val_num == values_count) { + SEM_POST(sem_sub); + exit(0); + }; +} + +int run_subscriber() { + SEM_WAIT(sem_pub); + + z_owned_config_t config = z_config_default(); + + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + perror("Unable to open session!"); + return -1; + } + + z_owned_closure_sample_t callback = z_closure(data_handler); + ze_owned_querying_subscriber_t sub = + ze_declare_querying_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL); + if (!z_check(sub)) { + perror("Unable to declare subscriber!"); + return -1; + } + + SEM_POST(sem_sub); + sleep(10); + + z_drop(z_move(sub)); + z_close(z_move(s)); + + return -1; +} + +void main() { + SEM_INIT(sem_pub, SEM_NAME_PUB); + SEM_INIT(sem_sub, SEM_NAME_SUB); + + func_ptr_t funcs[] = {run_publisher, run_subscriber}; + assert(run_timeouted_test(funcs, 2, 10) == 0); + + SEM_DROP(sem_pub, SEM_NAME_PUB); + SEM_DROP(sem_sub, SEM_NAME_SUB); +} + +#endif // VALID_PLATFORM diff --git a/tests/z_int_pub_sub_test.c b/tests/z_int_pub_sub_test.c new file mode 100644 index 000000000..bc5713f37 --- /dev/null +++ b/tests/z_int_pub_sub_test.c @@ -0,0 +1,110 @@ +// +// 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 "z_int_helpers.h" +#include "zenoh.h" + +#ifdef VALID_PLATFORM + +const char *const SEM_NAME = "/z_int_test_sync_sem"; +sem_t *sem; + +const char *const keyexpr = "test/key"; +const char *const values[] = {"test_value_1", "test_value_2", "test_value_3"}; +const size_t values_count = sizeof(values) / sizeof(values[0]); + +int run_publisher() { + SEM_WAIT(sem); + + z_owned_config_t config = z_config_default(); + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + perror("Unable to open session!"); + return -1; + } + + z_owned_publisher_t pub = z_declare_publisher(z_loan(s), z_keyexpr(keyexpr), NULL); + if (!z_check(pub)) { + perror("Unable to declare Publisher for key expression!"); + return -1; + } + + for (int i = 0; i < values_count; ++i) { + 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 *)values[i], strlen(values[i]), &options); + } + + z_undeclare_publisher(z_move(pub)); + z_close(z_move(s)); + return 0; +} + +void data_handler(const z_sample_t *sample, void *arg) { + static int val_num = 0; + z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); + if (strcmp(keyexpr, z_loan(keystr))) { + perror("Unexpected key received"); + exit(-1); + } + z_drop(z_move(keystr)); + + if (strncmp(values[val_num], sample->payload.start, (int)sample->payload.len)) { + perror("Unexpected value received"); + exit(-1); + } + + if (++val_num == values_count) { + exit(0); + }; +} + +int run_subscriber() { + z_owned_config_t config = z_config_default(); + + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + perror("Unable to open session!"); + return -1; + } + + z_owned_closure_sample_t callback = z_closure(data_handler); + z_owned_subscriber_t sub = z_declare_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL); + if (!z_check(sub)) { + perror("Unable to declare subscriber!"); + return -1; + } + + SEM_POST(sem); + sleep(10); + + z_undeclare_subscriber(z_move(sub)); + z_close(z_move(s)); + + return -1; +} + +void main() { + SEM_INIT(sem, SEM_NAME); + + func_ptr_t funcs[] = {run_publisher, run_subscriber}; + assert(run_timeouted_test(funcs, 2, 10) == 0); + + SEM_DROP(sem, SEM_NAME); +} + +#endif // VALID_PLATFORM From 3ced17ad113dd0655849c351bde8c1ddbd6d4a84 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Sat, 2 Dec 2023 01:10:19 +0100 Subject: [PATCH 2/5] Fix windows build and compilation warnings --- tests/z_int_helpers.h | 2 +- tests/z_int_helpers_test.c | 16 +++++++--------- tests/z_int_pub_cache_query_sub_test.c | 13 ++++++++----- tests/z_int_pub_sub_test.c | 15 ++++++++------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/tests/z_int_helpers.h b/tests/z_int_helpers.h index 4ac82985e..05c9ade39 100644 --- a/tests/z_int_helpers.h +++ b/tests/z_int_helpers.h @@ -1,5 +1,5 @@ #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#define VALID_PLATFORM 0 +#undef VALID_PLATFORM #else // def windows #define VALID_PLATFORM 1 diff --git a/tests/z_int_helpers_test.c b/tests/z_int_helpers_test.c index ae0e1efe7..520d9d4cd 100644 --- a/tests/z_int_helpers_test.c +++ b/tests/z_int_helpers_test.c @@ -1,5 +1,3 @@ -#include - #include "z_int_helpers.h" #ifdef VALID_PLATFORM @@ -15,37 +13,37 @@ int run_hanged() { return 0; } -int all_success() { +void all_success() { func_ptr_t funcs[] = {run_success, run_success, run_success}; assert(run_timeouted_test(funcs, 3, 10) == 0); } -int all_failed() { +void all_failed() { func_ptr_t funcs[] = {run_failed, run_failed, run_failed}; assert(run_timeouted_test(funcs, 3, 10) == -1); } -int first_failed() { +void first_failed() { func_ptr_t funcs[] = {run_failed, run_success, run_success}; assert(run_timeouted_test(funcs, 3, 10) == -1); } -int last_failed() { +void last_failed() { func_ptr_t funcs[] = {run_success, run_success, run_failed}; assert(run_timeouted_test(funcs, 3, 10) == -1); } -int all_hanged() { +void all_hanged() { func_ptr_t funcs[] = {run_hanged, run_hanged, run_hanged}; assert(run_timeouted_test(funcs, 3, 1) == -1); } -int one_hanged() { +void one_hanged() { func_ptr_t funcs[] = {run_success, run_hanged, run_success}; assert(run_timeouted_test(funcs, 3, 1) == -1); } -int main() { +void main() { all_success(); all_failed(); first_failed(); diff --git a/tests/z_int_pub_cache_query_sub_test.c b/tests/z_int_pub_cache_query_sub_test.c index 40fa3b533..dc173e6cd 100644 --- a/tests/z_int_pub_cache_query_sub_test.c +++ b/tests/z_int_pub_cache_query_sub_test.c @@ -11,13 +11,15 @@ // Contributors: // ZettaScale Zenoh Team, // -#include #include "z_int_helpers.h" -#include "zenoh.h" #ifdef VALID_PLATFORM +#include + +#include "zenoh.h" + const char *const SEM_NAME_PUB = "/z_int_test_sync_sem_pub"; sem_t *sem_pub; const char *const SEM_NAME_SUB = "/z_int_test_sync_sem_sub"; @@ -80,7 +82,6 @@ int run_publisher() { } void data_handler(const z_sample_t *sample, void *arg) { - printf("data_handler\n"); static int val_num = 0; z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); if (strcmp(keyexpr, z_loan(keystr))) { @@ -89,7 +90,7 @@ void data_handler(const z_sample_t *sample, void *arg) { } z_drop(z_move(keystr)); - if (strncmp(values[val_num], sample->payload.start, (int)sample->payload.len)) { + if (strncmp(values[val_num], (const char *)sample->payload.start, (int)sample->payload.len)) { perror("Unexpected value received"); exit(-1); } @@ -128,7 +129,7 @@ int run_subscriber() { return -1; } -void main() { +int main() { SEM_INIT(sem_pub, SEM_NAME_PUB); SEM_INIT(sem_sub, SEM_NAME_SUB); @@ -137,6 +138,8 @@ void main() { SEM_DROP(sem_pub, SEM_NAME_PUB); SEM_DROP(sem_sub, SEM_NAME_SUB); + + return 0; } #endif // VALID_PLATFORM diff --git a/tests/z_int_pub_sub_test.c b/tests/z_int_pub_sub_test.c index bc5713f37..11bb506aa 100644 --- a/tests/z_int_pub_sub_test.c +++ b/tests/z_int_pub_sub_test.c @@ -11,15 +11,14 @@ // Contributors: // ZettaScale Zenoh Team, // -#include -#include -#include - #include "z_int_helpers.h" -#include "zenoh.h" #ifdef VALID_PLATFORM +#include + +#include "zenoh.h" + const char *const SEM_NAME = "/z_int_test_sync_sem"; sem_t *sem; @@ -63,7 +62,7 @@ void data_handler(const z_sample_t *sample, void *arg) { } z_drop(z_move(keystr)); - if (strncmp(values[val_num], sample->payload.start, (int)sample->payload.len)) { + if (strncmp(values[val_num], (const char *)sample->payload.start, (int)sample->payload.len)) { perror("Unexpected value received"); exit(-1); } @@ -98,13 +97,15 @@ int run_subscriber() { return -1; } -void main() { +int main() { SEM_INIT(sem, SEM_NAME); func_ptr_t funcs[] = {run_publisher, run_subscriber}; assert(run_timeouted_test(funcs, 2, 10) == 0); SEM_DROP(sem, SEM_NAME); + + return 0; } #endif // VALID_PLATFORM From 8f33e38d0303d901c395d0278ddfdfda256d548a Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Sat, 2 Dec 2023 01:41:09 +0100 Subject: [PATCH 3/5] Fix windows build --- tests/z_int_helpers_test.c | 6 +++++- tests/z_int_pub_cache_query_sub_test.c | 2 ++ tests/z_int_pub_sub_test.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/z_int_helpers_test.c b/tests/z_int_helpers_test.c index 520d9d4cd..1c2ffbbd0 100644 --- a/tests/z_int_helpers_test.c +++ b/tests/z_int_helpers_test.c @@ -43,13 +43,17 @@ void one_hanged() { assert(run_timeouted_test(funcs, 3, 1) == -1); } -void main() { +int main() { all_success(); all_failed(); first_failed(); last_failed(); all_hanged(); one_hanged(); + + return 0; } +#else +int main() { return 0; } #endif // VALID_PLATFORM diff --git a/tests/z_int_pub_cache_query_sub_test.c b/tests/z_int_pub_cache_query_sub_test.c index dc173e6cd..7b14870b8 100644 --- a/tests/z_int_pub_cache_query_sub_test.c +++ b/tests/z_int_pub_cache_query_sub_test.c @@ -142,4 +142,6 @@ int main() { return 0; } +#else +int main() { return 0; } #endif // VALID_PLATFORM diff --git a/tests/z_int_pub_sub_test.c b/tests/z_int_pub_sub_test.c index 11bb506aa..403fc0bde 100644 --- a/tests/z_int_pub_sub_test.c +++ b/tests/z_int_pub_sub_test.c @@ -108,4 +108,6 @@ int main() { return 0; } +#else +int main() { return 0; } #endif // VALID_PLATFORM From 96c18a93aec2ba2bc1fa176ac3a58466e21d9044 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Mon, 4 Dec 2023 10:21:34 +0100 Subject: [PATCH 4/5] Add headers and diagnostic output --- tests/z_int_helpers.h | 14 ++++++++++++++ tests/z_int_helpers_test.c | 14 ++++++++++++++ tests/z_int_pub_cache_query_sub_test.c | 6 +++++- tests/z_int_pub_sub_test.c | 3 ++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/z_int_helpers.h b/tests/z_int_helpers.h index 05c9ade39..8b288edcf 100644 --- a/tests/z_int_helpers.h +++ b/tests/z_int_helpers.h @@ -1,3 +1,17 @@ +// +// Copyright (c) 2023 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, +// + #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) #undef VALID_PLATFORM #else // def windows diff --git a/tests/z_int_helpers_test.c b/tests/z_int_helpers_test.c index 1c2ffbbd0..a9ad1a53f 100644 --- a/tests/z_int_helpers_test.c +++ b/tests/z_int_helpers_test.c @@ -1,3 +1,17 @@ +// +// Copyright (c) 2023 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 "z_int_helpers.h" #ifdef VALID_PLATFORM diff --git a/tests/z_int_pub_cache_query_sub_test.c b/tests/z_int_pub_cache_query_sub_test.c index 7b14870b8..985690bd6 100644 --- a/tests/z_int_pub_cache_query_sub_test.c +++ b/tests/z_int_pub_cache_query_sub_test.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2022 ZettaScale Technology +// Copyright (c) 2023 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 @@ -65,6 +65,7 @@ int run_publisher() { } SEM_POST(sem_pub); + printf("wait: sem_sub\n"); SEM_WAIT(sem_sub); // values for subscribe @@ -72,6 +73,7 @@ int run_publisher() { z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)values[i], strlen(values[i]), NULL); } + printf("wait: sem_sub\n"); SEM_WAIT(sem_sub); z_drop(z_move(pub_cache)); @@ -95,6 +97,7 @@ void data_handler(const z_sample_t *sample, void *arg) { exit(-1); } + printf("data_handler: %i\n", val_num); if (++val_num == values_count) { SEM_POST(sem_sub); exit(0); @@ -102,6 +105,7 @@ void data_handler(const z_sample_t *sample, void *arg) { } int run_subscriber() { + printf("wait: sem_pub\n"); SEM_WAIT(sem_pub); z_owned_config_t config = z_config_default(); diff --git a/tests/z_int_pub_sub_test.c b/tests/z_int_pub_sub_test.c index 403fc0bde..8a2825618 100644 --- a/tests/z_int_pub_sub_test.c +++ b/tests/z_int_pub_sub_test.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2022 ZettaScale Technology +// Copyright (c) 2023 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 @@ -11,6 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // + #include "z_int_helpers.h" #ifdef VALID_PLATFORM From 1d200fd81283692a507d36690c431fe9f98d5178 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Mon, 4 Dec 2023 11:23:09 +0100 Subject: [PATCH 5/5] Add comment --- tests/z_int_helpers.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/z_int_helpers.h b/tests/z_int_helpers.h index 8b288edcf..11fd01b4e 100644 --- a/tests/z_int_helpers.h +++ b/tests/z_int_helpers.h @@ -12,6 +12,15 @@ // ZettaScale Zenoh Team, // +// +// This file contains hepler macros and functions for integration testing, this +// file also contains the implementations, since it is assumed that the integration test +// consists of one file and is not expected to include this file in +// several other *.c files of one binary. +// + +#pragma once + #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) #undef VALID_PLATFORM #else // def windows