Skip to content

Commit

Permalink
Merge branch 'main' into feature/condvar_timedwait
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Dec 7, 2024
2 parents 600f3fe + a4f07d6 commit 8dcf271
Show file tree
Hide file tree
Showing 46 changed files with 574 additions and 133 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Build & run tests
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make test
CMAKE_GENERATOR=Ninja ASAN=ON make test
check_format:
name: Check codebase format with clang-format
Expand Down Expand Up @@ -272,7 +272,7 @@ jobs:
- name: Build project and run test
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make
Z_FEATURE_UNSTABLE_API=1 Z_FEATURE_LIVELINESS=1 CMAKE_GENERATOR=Ninja make
python3 ./build/tests/memory_leak.py
timeout-minutes: 5

Expand All @@ -290,6 +290,6 @@ jobs:
- name: Build & test pico
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make
CMAKE_GENERATOR=Ninja ASAN=ON make
python3 ./build/tests/no_router.py
timeout-minutes: 5
78 changes: 78 additions & 0 deletions .github/workflows/cpp-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# Copyright (c) 2024 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, <[email protected]>
#
name: cpp-check

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
zenoh_cpp_branch:
description: 'Branch of zenoh-cpp to use'
required: false
default: 'main'

jobs:
build-and-test:
name: Build and test zenoh-cpp on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
unstable: [0, 1]

steps:
- name: checkout zenoh-pico
uses: actions/checkout@v3

- name: build zenoh-pico
run: |
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/local -DZ_FEATURE_UNSTABLE_API=${{ matrix.unstable }} -DZ_FEATURE_LIVELINESS=1 -DASAN=ON
cmake --build . --target install --config Release
- name: clone zenoh-cpp
run: |
git clone https://github.com/eclipse-zenoh/zenoh-cpp.git
cd zenoh-cpp
git fetch --all
git checkout ${{ github.event.inputs.zenoh_cpp_branch || 'main' }}
git submodule update --init --recursive
- name: build zenoh-cpp
run: |
cd zenoh-cpp
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=~/local -DCMAKE_BUILD_TYPE=Release -DZENOHCXX_ZENOHPICO=ON -DZENOHCXX_ZENOHC=OFF
cmake --build . --config Release
- name: build examples
run: |
cd zenoh-cpp/build
cmake --build . --target examples --config Release
- name: build tests
run: |
cd zenoh-cpp/build
cmake --build . --target tests --config Release
- name: run tests
run: |
cd zenoh-cpp/build
ctest -C Release --output-on-failure
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ jobs:
version: ${{ needs.tag.outputs.version }}
ssh-host: [email protected]
ssh-host-path: /home/data/httpd/download.eclipse.org/zenoh/zenoh-pico
ssh-private-key: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
ssh-passphrase: ${{ secrets.ORG_GPG_PASSPHRASE }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-passphrase: ${{ secrets.SSH_PASSPHRASE }}
archive-patterns: '.*\.zip'

github:
Expand Down
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ else()
add_compile_options(-Wpedantic)
endif()
# add_compile_options(-Wconversion)
# add_link_options(-fsanitize=address)
elseif(MSVC)
add_compile_options(/W4 /WX /Od /wd4127)
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
Expand Down Expand Up @@ -216,7 +215,7 @@ set(Z_FEATURE_PUBLICATION 1 CACHE STRING "Toggle publication feature")
set(Z_FEATURE_SUBSCRIPTION 1 CACHE STRING "Toggle subscription feature")
set(Z_FEATURE_QUERY 1 CACHE STRING "Toggle query feature")
set(Z_FEATURE_QUERYABLE 1 CACHE STRING "Toggle queryable feature")
set(Z_FEATURE_LIVELINESS 1 CACHE STRING "Toggle liveliness feature")
set(Z_FEATURE_LIVELINESS 0 CACHE STRING "Toggle liveliness feature")
set(Z_FEATURE_INTEREST 1 CACHE STRING "Toggle interests")
set(Z_FEATURE_FRAGMENTATION 1 CACHE STRING "Toggle fragmentation")
set(Z_FEATURE_ENCODING_VALUES 1 CACHE STRING "Toggle encoding values")
Expand All @@ -235,6 +234,12 @@ set(Z_FEATURE_UNICAST_TRANSPORT 1 CACHE STRING "Toggle unicast transport")
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport")
set(Z_FEATURE_TCP_NODELAY 1 CACHE STRING "Toggle TCP_NODELAY")

# Add a warning message if someone tries to enable Z_FEATURE_LIVELINESS directly
if(Z_FEATURE_LIVELINESS AND NOT Z_FEATURE_UNSTABLE_API)
message(WARNING "Z_FEATURE_LIVELINESS can only be enabled when Z_FEATURE_UNSTABLE_API is also enabled. Disabling Z_FEATURE_LIVELINESS.")
set(Z_FEATURE_LIVELINESS 0 CACHE STRING "Toggle liveliness feature" FORCE)
endif()

add_compile_definitions("Z_BUILD_DEBUG=$<CONFIG:Debug>")
message(STATUS "Building with feature confing:\n\
* UNSTABLE_API: ${Z_FEATURE_UNSTABLE_API}\n\
Expand Down Expand Up @@ -373,12 +378,14 @@ option(BUILD_EXAMPLES "Use this to also build the examples." ON)
option(BUILD_TOOLS "Use this to also build the tools." OFF)
option(BUILD_TESTING "Use this to also build tests." ON)
option(BUILD_INTEGRATION "Use this to also build integration tests." OFF)
option(ASAN "Enable AddressSanitizer." OFF)

message(STATUS "Produce Debian and RPM packages: ${PACKAGING}")
message(STATUS "Build examples: ${BUILD_EXAMPLES}")
message(STATUS "Build tools: ${BUILD_TOOLS}")
message(STATUS "Build tests: ${BUILD_TESTING}")
message(STATUS "Build integration: ${BUILD_INTEGRATION}")
message(STATUS "AddressSanitizer: ${ASAN}")

set(PICO_LIBS "")
if(PICO_STATIC)
Expand Down Expand Up @@ -447,6 +454,11 @@ if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

if(UNIX OR MSVC)
if(BUILD_TOOLS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools)
Expand Down
6 changes: 5 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ BUILD_TOOLS?=OFF
# Accepted values: ON, OFF
FORCE_C99?=OFF

# Enable AddressSanitizer.
# Accepted values: ON, OFF
ASAN?=OFF

# Debug level. This sets the ZENOH_DEBUG variable.
# Accepted values:
# 0: NONE
Expand Down Expand Up @@ -82,7 +86,7 @@ CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAK
-DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) -DZ_FEATURE_INTEREST=$(Z_FEATURE_INTEREST) -DZ_FEATURE_UNSTABLE_API=$(Z_FEATURE_UNSTABLE_API)\
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
-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)\
-DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
-DASAN=$(ASAN) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.

ifeq ($(FORCE_C99), ON)
CMAKE_OPT += -DCMAKE_C_STANDARD=99
Expand Down
1 change: 1 addition & 0 deletions PackageConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(ZENOHPICO_FEATURE_QUERY @Z_FEATURE_QUERY@)
set(ZENOHPICO_FEATURE_QUERYABLE @Z_FEATURE_QUERYABLE@)
set(ZENOHPICO_FEATURE_RAWETH_TRANSPORT @Z_FEATURE_RAWETH_TRANSPORT@)
set(ZENOHPICO_FEATURE_INTEREST @Z_FEATURE_INTEREST@)
set(ZENOHPICO_FEATURE_LIVELINESS @Z_FEATURE_LIVELINESS@)

if(@CHECK_THREADS@)
find_dependency(Threads REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ See details at :ref:`owned_types_concept`
Functions
---------
.. autocfunction:: liveliness.h::z_liveliness_token_options_t_default
.. autocfunction:: liveliness.h::z_liveliness_token_options_default
.. autocfunction:: liveliness.h::z_liveliness_declare_token
.. autocfunction:: liveliness.h::z_liveliness_undeclare_token
.. autocfunction:: liveliness.h::z_liveliness_subscriber_options_default
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_get_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ int main(int argc, char **argv) {
} else {
printf("Received an error\n");
}
z_drop(z_move(reply));
}

z_drop(z_move(reply));
z_drop(z_move(closure));
z_drop(z_move(handler));
z_drop(z_move(s));
return 0;
Expand Down
12 changes: 11 additions & 1 deletion examples/unix/c11/z_sub_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_LIVELINESS == 1

static volatile int msg_nb = 0;

void data_handler(z_loaned_sample_t *sample, void *ctx) {
(void)(ctx);
z_view_string_t key_string;
Expand All @@ -35,6 +37,7 @@ void data_handler(z_loaned_sample_t *sample, void *ctx) {
z_string_data(z_loan(key_string)));
break;
}
msg_nb++;
}

int main(int argc, char **argv) {
Expand All @@ -43,6 +46,7 @@ int main(int argc, char **argv) {
char *clocator = NULL;
char *llocator = NULL;
bool history = false;
int n = 0;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:l:n:h")) != -1) {
Expand All @@ -62,8 +66,11 @@ int main(int argc, char **argv) {
case 'h':
history = true;
break;
case 'n':
n = atoi(optarg);
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l' || optopt == 'n') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down Expand Up @@ -116,6 +123,9 @@ int main(int argc, char **argv) {

printf("Press CTRL-C to quit...\n");
while (1) {
if (n != 0 && msg_nb >= n) {
break;
}
z_sleep_s(1);
}

Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/api/liveliness.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct {
_z_session_weak_t _zn;
} _z_liveliness_token_t;

_z_liveliness_token_t _z_liveliness_token_null(void);
_Z_OWNED_TYPE_VALUE(_z_liveliness_token_t, liveliness_token)
_Z_OWNED_FUNCTIONS_DEF(liveliness_token)

Expand All @@ -48,7 +49,7 @@ typedef struct z_liveliness_token_options_t {
/**
* Constructs default value for :c:type:`z_liveliness_token_options_t`.
*/
z_result_t z_liveliness_token_options_t_default(z_liveliness_token_options_t *options);
z_result_t z_liveliness_token_options_default(z_liveliness_token_options_t *options);

/**
* Constructs and declares a liveliness token on the network.
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define Z_FEATURE_SUBSCRIPTION 1
#define Z_FEATURE_QUERY 1
#define Z_FEATURE_QUERYABLE 1
#define Z_FEATURE_LIVELINESS 1
#define Z_FEATURE_LIVELINESS 0
#define Z_FEATURE_RAWETH_TRANSPORT 0
#define Z_FEATURE_INTEREST 1
#define Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION 0
Expand Down
25 changes: 21 additions & 4 deletions include/zenoh-pico/protocol/definitions/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ extern "C" {
// Z Extensions if Z==1 then Zenoh extensions are present
#define _Z_FLAG_T_CLOSE_S 0x20 // 1 << 5

/*=============================*/
/* Patch */
/*=============================*/
/// Used to negotiate the patch version of the protocol
/// if not present (or 0), then protocol as released with 1.0.0
/// if >= 1, then fragmentation start/stop marker
#define _Z_NO_PATCH 0x00
#define _Z_CURRENT_PATCH 0x01
#define _Z_PATCH_HAS_FRAGMENT_MARKERS(patch) (patch >= 1)

/*=============================*/
/* Transport Messages */
/*=============================*/
Expand Down Expand Up @@ -235,6 +245,9 @@ typedef struct {
uint8_t _req_id_res;
uint8_t _seq_num_res;
uint8_t _version;
#if Z_FEATURE_FRAGMENTATION == 1
uint8_t _patch;
#endif
} _z_t_msg_join_t;
void _z_t_msg_join_clear(_z_t_msg_join_t *msg);

Expand Down Expand Up @@ -315,6 +328,9 @@ typedef struct {
uint8_t _req_id_res;
uint8_t _seq_num_res;
uint8_t _version;
#if Z_FEATURE_FRAGMENTATION == 1
uint8_t _patch;
#endif
} _z_t_msg_init_t;
void _z_t_msg_init_clear(_z_t_msg_init_t *msg);

Expand Down Expand Up @@ -478,11 +494,11 @@ void _z_t_msg_frame_clear(_z_t_msg_frame_t *msg);
typedef struct {
_z_slice_t _payload;
_z_zint_t _sn;
bool first;
bool drop;
} _z_t_msg_fragment_t;
void _z_t_msg_fragment_clear(_z_t_msg_fragment_t *msg);

#define _Z_FRAGMENT_HEADER_SIZE 12

/*------------------ Transport Message ------------------*/
typedef union {
_z_t_msg_join_t _join;
Expand Down Expand Up @@ -514,9 +530,10 @@ _z_transport_message_t _z_t_msg_make_keep_alive(void);
_z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_t messages,
z_reliability_t reliability);
_z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, z_reliability_t reliability);
_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, bool is_last);
_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, bool is_last,
bool first, bool drop);
_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t messages, z_reliability_t reliability,
bool is_last);
bool is_last, bool first, bool drop);

/*------------------ Copy ------------------*/
void _z_t_msg_copy(_z_transport_message_t *clone, _z_transport_message_t *msg);
Expand Down
7 changes: 6 additions & 1 deletion include/zenoh-pico/protocol/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ extern "C" {
/*=============================*/
/* Extension IDs */
/*=============================*/
// #define _Z_MSG_EXT_ID_FOO 0x00 // Hex(ENC|M|ID)
#define _Z_MSG_EXT_ID_JOIN_QOS (0x01 | _Z_MSG_EXT_FLAG_M | _Z_MSG_EXT_ENC_ZBUF)
#define _Z_MSG_EXT_ID_JOIN_PATCH (0x07 | _Z_MSG_EXT_ENC_ZINT)
#define _Z_MSG_EXT_ID_INIT_PATCH (0x07 | _Z_MSG_EXT_ENC_ZINT)
#define _Z_MSG_EXT_ID_FRAGMENT_FIRST (0x02 | _Z_MSG_EXT_ENC_UNIT)
#define _Z_MSG_EXT_ID_FRAGMENT_DROP (0x03 | _Z_MSG_EXT_ENC_UNIT)

/*=============================*/
/* Extension Encodings */
Expand All @@ -58,6 +62,7 @@ extern "C" {
#define _Z_MSG_EXT_FLAG_M 0x10
#define _Z_MSG_EXT_IS_MANDATORY(h) ((h & _Z_MSG_EXT_FLAG_M) != 0)
#define _Z_MSG_EXT_FLAG_Z 0x80
#define _Z_MSG_EXT_MORE(more) (more ? _Z_MSG_EXT_FLAG_Z : 0)

typedef struct {
uint8_t __dummy; // Just to avoid empty structures that might cause undefined behavior
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/system/platform/mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef void *_z_mutex_t; // Workaround as MBED is a C++ library
typedef void *_z_condvar_t; // Workaround as MBED is a C++ library
#endif // Z_FEATURE_MULTI_THREAD == 1

typedef void *z_clock_t; // Not defined
typedef struct timespec z_clock_t;
typedef struct timeval z_time_t;

typedef struct BufferedSerial BufferedSerial; // Forward declaration to be used in _z_sys_net_socket_t
Expand Down
Loading

0 comments on commit 8dcf271

Please sign in to comment.