Skip to content

Commit 8dcf271

Browse files
committed
Merge branch 'main' into feature/condvar_timedwait
2 parents 600f3fe + a4f07d6 commit 8dcf271

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+574
-133
lines changed

.github/workflows/build-check.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Build & run tests
3131
run: |
3232
sudo apt install -y ninja-build
33-
CMAKE_GENERATOR=Ninja make test
33+
CMAKE_GENERATOR=Ninja ASAN=ON make test
3434
3535
check_format:
3636
name: Check codebase format with clang-format
@@ -272,7 +272,7 @@ jobs:
272272
- name: Build project and run test
273273
run: |
274274
sudo apt install -y ninja-build
275-
CMAKE_GENERATOR=Ninja make
275+
Z_FEATURE_UNSTABLE_API=1 Z_FEATURE_LIVELINESS=1 CMAKE_GENERATOR=Ninja make
276276
python3 ./build/tests/memory_leak.py
277277
timeout-minutes: 5
278278

@@ -290,6 +290,6 @@ jobs:
290290
- name: Build & test pico
291291
run: |
292292
sudo apt install -y ninja-build
293-
CMAKE_GENERATOR=Ninja make
293+
CMAKE_GENERATOR=Ninja ASAN=ON make
294294
python3 ./build/tests/no_router.py
295295
timeout-minutes: 5

.github/workflows/cpp-check.yaml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#
2+
# Copyright (c) 2024 ZettaScale Technology
3+
#
4+
# This program and the accompanying materials are made available under the
5+
# terms of the Eclipse Public License 2.0 which is available at
6+
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
#
9+
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
#
11+
# Contributors:
12+
# ZettaScale zenoh Team, <[email protected]>
13+
#
14+
name: cpp-check
15+
16+
on:
17+
push:
18+
branches:
19+
- main
20+
pull_request:
21+
branches:
22+
- main
23+
workflow_dispatch:
24+
inputs:
25+
zenoh_cpp_branch:
26+
description: 'Branch of zenoh-cpp to use'
27+
required: false
28+
default: 'main'
29+
30+
jobs:
31+
build-and-test:
32+
name: Build and test zenoh-cpp on ${{ matrix.os }}
33+
runs-on: ${{ matrix.os }}
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
os: [ubuntu-latest, macOS-latest, windows-latest]
38+
unstable: [0, 1]
39+
40+
steps:
41+
- name: checkout zenoh-pico
42+
uses: actions/checkout@v3
43+
44+
- name: build zenoh-pico
45+
run: |
46+
mkdir build && cd build
47+
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/local -DZ_FEATURE_UNSTABLE_API=${{ matrix.unstable }} -DZ_FEATURE_LIVELINESS=1 -DASAN=ON
48+
cmake --build . --target install --config Release
49+
50+
- name: clone zenoh-cpp
51+
run: |
52+
git clone https://github.com/eclipse-zenoh/zenoh-cpp.git
53+
cd zenoh-cpp
54+
git fetch --all
55+
git checkout ${{ github.event.inputs.zenoh_cpp_branch || 'main' }}
56+
git submodule update --init --recursive
57+
58+
- name: build zenoh-cpp
59+
run: |
60+
cd zenoh-cpp
61+
mkdir build && cd build
62+
cmake .. -DCMAKE_INSTALL_PREFIX=~/local -DCMAKE_BUILD_TYPE=Release -DZENOHCXX_ZENOHPICO=ON -DZENOHCXX_ZENOHC=OFF
63+
cmake --build . --config Release
64+
65+
- name: build examples
66+
run: |
67+
cd zenoh-cpp/build
68+
cmake --build . --target examples --config Release
69+
70+
- name: build tests
71+
run: |
72+
cd zenoh-cpp/build
73+
cmake --build . --target tests --config Release
74+
75+
- name: run tests
76+
run: |
77+
cd zenoh-cpp/build
78+
ctest -C Release --output-on-failure

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ jobs:
174174
version: ${{ needs.tag.outputs.version }}
175175
176176
ssh-host-path: /home/data/httpd/download.eclipse.org/zenoh/zenoh-pico
177-
ssh-private-key: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
178-
ssh-passphrase: ${{ secrets.ORG_GPG_PASSPHRASE }}
177+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
178+
ssh-passphrase: ${{ secrets.SSH_PASSPHRASE }}
179179
archive-patterns: '.*\.zip'
180180

181181
github:

CMakeLists.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ else()
9797
add_compile_options(-Wpedantic)
9898
endif()
9999
# add_compile_options(-Wconversion)
100-
# add_link_options(-fsanitize=address)
101100
elseif(MSVC)
102101
add_compile_options(/W4 /WX /Od /wd4127)
103102
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
@@ -216,7 +215,7 @@ set(Z_FEATURE_PUBLICATION 1 CACHE STRING "Toggle publication feature")
216215
set(Z_FEATURE_SUBSCRIPTION 1 CACHE STRING "Toggle subscription feature")
217216
set(Z_FEATURE_QUERY 1 CACHE STRING "Toggle query feature")
218217
set(Z_FEATURE_QUERYABLE 1 CACHE STRING "Toggle queryable feature")
219-
set(Z_FEATURE_LIVELINESS 1 CACHE STRING "Toggle liveliness feature")
218+
set(Z_FEATURE_LIVELINESS 0 CACHE STRING "Toggle liveliness feature")
220219
set(Z_FEATURE_INTEREST 1 CACHE STRING "Toggle interests")
221220
set(Z_FEATURE_FRAGMENTATION 1 CACHE STRING "Toggle fragmentation")
222221
set(Z_FEATURE_ENCODING_VALUES 1 CACHE STRING "Toggle encoding values")
@@ -235,6 +234,12 @@ set(Z_FEATURE_UNICAST_TRANSPORT 1 CACHE STRING "Toggle unicast transport")
235234
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport")
236235
set(Z_FEATURE_TCP_NODELAY 1 CACHE STRING "Toggle TCP_NODELAY")
237236

237+
# Add a warning message if someone tries to enable Z_FEATURE_LIVELINESS directly
238+
if(Z_FEATURE_LIVELINESS AND NOT Z_FEATURE_UNSTABLE_API)
239+
message(WARNING "Z_FEATURE_LIVELINESS can only be enabled when Z_FEATURE_UNSTABLE_API is also enabled. Disabling Z_FEATURE_LIVELINESS.")
240+
set(Z_FEATURE_LIVELINESS 0 CACHE STRING "Toggle liveliness feature" FORCE)
241+
endif()
242+
238243
add_compile_definitions("Z_BUILD_DEBUG=$<CONFIG:Debug>")
239244
message(STATUS "Building with feature confing:\n\
240245
* UNSTABLE_API: ${Z_FEATURE_UNSTABLE_API}\n\
@@ -373,12 +378,14 @@ option(BUILD_EXAMPLES "Use this to also build the examples." ON)
373378
option(BUILD_TOOLS "Use this to also build the tools." OFF)
374379
option(BUILD_TESTING "Use this to also build tests." ON)
375380
option(BUILD_INTEGRATION "Use this to also build integration tests." OFF)
381+
option(ASAN "Enable AddressSanitizer." OFF)
376382

377383
message(STATUS "Produce Debian and RPM packages: ${PACKAGING}")
378384
message(STATUS "Build examples: ${BUILD_EXAMPLES}")
379385
message(STATUS "Build tools: ${BUILD_TOOLS}")
380386
message(STATUS "Build tests: ${BUILD_TESTING}")
381387
message(STATUS "Build integration: ${BUILD_INTEGRATION}")
388+
message(STATUS "AddressSanitizer: ${ASAN}")
382389

383390
set(PICO_LIBS "")
384391
if(PICO_STATIC)
@@ -447,6 +454,11 @@ if(BUILD_EXAMPLES)
447454
add_subdirectory(examples)
448455
endif()
449456

457+
if(ASAN)
458+
add_compile_options(-fsanitize=address)
459+
add_link_options(-fsanitize=address)
460+
endif()
461+
450462
if(UNIX OR MSVC)
451463
if(BUILD_TOOLS)
452464
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools)

GNUmakefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ BUILD_TOOLS?=OFF
4141
# Accepted values: ON, OFF
4242
FORCE_C99?=OFF
4343

44+
# Enable AddressSanitizer.
45+
# Accepted values: ON, OFF
46+
ASAN?=OFF
47+
4448
# Debug level. This sets the ZENOH_DEBUG variable.
4549
# Accepted values:
4650
# 0: NONE
@@ -82,7 +86,7 @@ CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAK
8286
-DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) -DZ_FEATURE_INTEREST=$(Z_FEATURE_INTEREST) -DZ_FEATURE_UNSTABLE_API=$(Z_FEATURE_UNSTABLE_API)\
8387
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
8488
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DFRAG_MAX_SIZE=$(FRAG_MAX_SIZE) -DBATCH_UNICAST_SIZE=$(BATCH_UNICAST_SIZE) -DBATCH_MULTICAST_SIZE=$(BATCH_MULTICAST_SIZE)\
85-
-DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
89+
-DASAN=$(ASAN) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
8690

8791
ifeq ($(FORCE_C99), ON)
8892
CMAKE_OPT += -DCMAKE_C_STANDARD=99

PackageConfig.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(ZENOHPICO_FEATURE_QUERY @Z_FEATURE_QUERY@)
88
set(ZENOHPICO_FEATURE_QUERYABLE @Z_FEATURE_QUERYABLE@)
99
set(ZENOHPICO_FEATURE_RAWETH_TRANSPORT @Z_FEATURE_RAWETH_TRANSPORT@)
1010
set(ZENOHPICO_FEATURE_INTEREST @Z_FEATURE_INTEREST@)
11+
set(ZENOHPICO_FEATURE_LIVELINESS @Z_FEATURE_LIVELINESS@)
1112

1213
if(@CHECK_THREADS@)
1314
find_dependency(Threads REQUIRED)

docs/api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ See details at :ref:`owned_types_concept`
12891289
12901290
Functions
12911291
---------
1292-
.. autocfunction:: liveliness.h::z_liveliness_token_options_t_default
1292+
.. autocfunction:: liveliness.h::z_liveliness_token_options_default
12931293
.. autocfunction:: liveliness.h::z_liveliness_declare_token
12941294
.. autocfunction:: liveliness.h::z_liveliness_undeclare_token
12951295
.. autocfunction:: liveliness.h::z_liveliness_subscriber_options_default

examples/unix/c11/z_get_liveliness.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ int main(int argc, char **argv) {
9999
} else {
100100
printf("Received an error\n");
101101
}
102+
z_drop(z_move(reply));
102103
}
103104

104-
z_drop(z_move(reply));
105+
z_drop(z_move(closure));
105106
z_drop(z_move(handler));
106107
z_drop(z_move(s));
107108
return 0;

examples/unix/c11/z_sub_liveliness.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_LIVELINESS == 1
2323

24+
static volatile int msg_nb = 0;
25+
2426
void data_handler(z_loaned_sample_t *sample, void *ctx) {
2527
(void)(ctx);
2628
z_view_string_t key_string;
@@ -35,6 +37,7 @@ void data_handler(z_loaned_sample_t *sample, void *ctx) {
3537
z_string_data(z_loan(key_string)));
3638
break;
3739
}
40+
msg_nb++;
3841
}
3942

4043
int main(int argc, char **argv) {
@@ -43,6 +46,7 @@ int main(int argc, char **argv) {
4346
char *clocator = NULL;
4447
char *llocator = NULL;
4548
bool history = false;
49+
int n = 0;
4650

4751
int opt;
4852
while ((opt = getopt(argc, argv, "k:e:m:l:n:h")) != -1) {
@@ -62,8 +66,11 @@ int main(int argc, char **argv) {
6266
case 'h':
6367
history = true;
6468
break;
69+
case 'n':
70+
n = atoi(optarg);
71+
break;
6572
case '?':
66-
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
73+
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l' || optopt == 'n') {
6774
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
6875
} else {
6976
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
@@ -116,6 +123,9 @@ int main(int argc, char **argv) {
116123

117124
printf("Press CTRL-C to quit...\n");
118125
while (1) {
126+
if (n != 0 && msg_nb >= n) {
127+
break;
128+
}
119129
z_sleep_s(1);
120130
}
121131

include/zenoh-pico/api/liveliness.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typedef struct {
3131
_z_session_weak_t _zn;
3232
} _z_liveliness_token_t;
3333

34+
_z_liveliness_token_t _z_liveliness_token_null(void);
3435
_Z_OWNED_TYPE_VALUE(_z_liveliness_token_t, liveliness_token)
3536
_Z_OWNED_FUNCTIONS_DEF(liveliness_token)
3637

@@ -48,7 +49,7 @@ typedef struct z_liveliness_token_options_t {
4849
/**
4950
* Constructs default value for :c:type:`z_liveliness_token_options_t`.
5051
*/
51-
z_result_t z_liveliness_token_options_t_default(z_liveliness_token_options_t *options);
52+
z_result_t z_liveliness_token_options_default(z_liveliness_token_options_t *options);
5253

5354
/**
5455
* Constructs and declares a liveliness token on the network.

include/zenoh-pico/config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#define Z_FEATURE_SUBSCRIPTION 1
2828
#define Z_FEATURE_QUERY 1
2929
#define Z_FEATURE_QUERYABLE 1
30-
#define Z_FEATURE_LIVELINESS 1
30+
#define Z_FEATURE_LIVELINESS 0
3131
#define Z_FEATURE_RAWETH_TRANSPORT 0
3232
#define Z_FEATURE_INTEREST 1
3333
#define Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION 0

include/zenoh-pico/protocol/definitions/transport.h

+21-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ extern "C" {
9191
// Z Extensions if Z==1 then Zenoh extensions are present
9292
#define _Z_FLAG_T_CLOSE_S 0x20 // 1 << 5
9393

94+
/*=============================*/
95+
/* Patch */
96+
/*=============================*/
97+
/// Used to negotiate the patch version of the protocol
98+
/// if not present (or 0), then protocol as released with 1.0.0
99+
/// if >= 1, then fragmentation start/stop marker
100+
#define _Z_NO_PATCH 0x00
101+
#define _Z_CURRENT_PATCH 0x01
102+
#define _Z_PATCH_HAS_FRAGMENT_MARKERS(patch) (patch >= 1)
103+
94104
/*=============================*/
95105
/* Transport Messages */
96106
/*=============================*/
@@ -235,6 +245,9 @@ typedef struct {
235245
uint8_t _req_id_res;
236246
uint8_t _seq_num_res;
237247
uint8_t _version;
248+
#if Z_FEATURE_FRAGMENTATION == 1
249+
uint8_t _patch;
250+
#endif
238251
} _z_t_msg_join_t;
239252
void _z_t_msg_join_clear(_z_t_msg_join_t *msg);
240253

@@ -315,6 +328,9 @@ typedef struct {
315328
uint8_t _req_id_res;
316329
uint8_t _seq_num_res;
317330
uint8_t _version;
331+
#if Z_FEATURE_FRAGMENTATION == 1
332+
uint8_t _patch;
333+
#endif
318334
} _z_t_msg_init_t;
319335
void _z_t_msg_init_clear(_z_t_msg_init_t *msg);
320336

@@ -478,11 +494,11 @@ void _z_t_msg_frame_clear(_z_t_msg_frame_t *msg);
478494
typedef struct {
479495
_z_slice_t _payload;
480496
_z_zint_t _sn;
497+
bool first;
498+
bool drop;
481499
} _z_t_msg_fragment_t;
482500
void _z_t_msg_fragment_clear(_z_t_msg_fragment_t *msg);
483501

484-
#define _Z_FRAGMENT_HEADER_SIZE 12
485-
486502
/*------------------ Transport Message ------------------*/
487503
typedef union {
488504
_z_t_msg_join_t _join;
@@ -514,9 +530,10 @@ _z_transport_message_t _z_t_msg_make_keep_alive(void);
514530
_z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_t messages,
515531
z_reliability_t reliability);
516532
_z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, z_reliability_t reliability);
517-
_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, bool is_last);
533+
_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, bool is_last,
534+
bool first, bool drop);
518535
_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t messages, z_reliability_t reliability,
519-
bool is_last);
536+
bool is_last, bool first, bool drop);
520537

521538
/*------------------ Copy ------------------*/
522539
void _z_t_msg_copy(_z_transport_message_t *clone, _z_transport_message_t *msg);

include/zenoh-pico/protocol/ext.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ extern "C" {
4343
/*=============================*/
4444
/* Extension IDs */
4545
/*=============================*/
46-
// #define _Z_MSG_EXT_ID_FOO 0x00 // Hex(ENC|M|ID)
46+
#define _Z_MSG_EXT_ID_JOIN_QOS (0x01 | _Z_MSG_EXT_FLAG_M | _Z_MSG_EXT_ENC_ZBUF)
47+
#define _Z_MSG_EXT_ID_JOIN_PATCH (0x07 | _Z_MSG_EXT_ENC_ZINT)
48+
#define _Z_MSG_EXT_ID_INIT_PATCH (0x07 | _Z_MSG_EXT_ENC_ZINT)
49+
#define _Z_MSG_EXT_ID_FRAGMENT_FIRST (0x02 | _Z_MSG_EXT_ENC_UNIT)
50+
#define _Z_MSG_EXT_ID_FRAGMENT_DROP (0x03 | _Z_MSG_EXT_ENC_UNIT)
4751

4852
/*=============================*/
4953
/* Extension Encodings */
@@ -58,6 +62,7 @@ extern "C" {
5862
#define _Z_MSG_EXT_FLAG_M 0x10
5963
#define _Z_MSG_EXT_IS_MANDATORY(h) ((h & _Z_MSG_EXT_FLAG_M) != 0)
6064
#define _Z_MSG_EXT_FLAG_Z 0x80
65+
#define _Z_MSG_EXT_MORE(more) (more ? _Z_MSG_EXT_FLAG_Z : 0)
6166

6267
typedef struct {
6368
uint8_t __dummy; // Just to avoid empty structures that might cause undefined behavior

include/zenoh-pico/system/platform/mbed.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef void *_z_mutex_t; // Workaround as MBED is a C++ library
3333
typedef void *_z_condvar_t; // Workaround as MBED is a C++ library
3434
#endif // Z_FEATURE_MULTI_THREAD == 1
3535

36-
typedef void *z_clock_t; // Not defined
36+
typedef struct timespec z_clock_t;
3737
typedef struct timeval z_time_t;
3838

3939
typedef struct BufferedSerial BufferedSerial; // Forward declaration to be used in _z_sys_net_socket_t

0 commit comments

Comments
 (0)