From 85a57d7a0988c3a297936e0d5e2f51f298c8e28a Mon Sep 17 00:00:00 2001 From: lukas-he Date: Mon, 3 Mar 2025 19:10:12 +0100 Subject: [PATCH 1/6] Align CI with up-cpp CI (#113) * align ci with up-cpp * correct trigger * pin ubuntu version 22.04 and clang-tidy 12 --- .github/workflows/ci.yml | 325 +++++++++++++++++++++++++++-- .github/workflows/ci_conan_profile | 8 + 2 files changed, 313 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/ci_conan_profile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65fdb3d..8f2589b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,22 +2,33 @@ name: CI on: push: - branches: [ main ] + branches: ["main"] pull_request: branches: ["**"] jobs: build: name: Build up-transport-zenoh-cpp and dependencies - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: + - name: Fetch up-transport-zenoh-cpp + uses: actions/checkout@v4 + with: + path: up-transport-zenoh-cpp + - name: Install Conan id: conan uses: turtlebrowser/get-conan@main - - - name: Create default Conan profile - run: conan profile detect + with: + version: 2.3.2 + + - name: Install conan CI profile + shell: bash + run: | + conan profile detect + cp up-transport-zenoh-cpp/.github/workflows/ci_conan_profile "$(conan profile path default)" + conan profile show - name: Fetch up-core-api conan recipe uses: actions/checkout@v4 @@ -41,18 +52,14 @@ jobs: conan create --version 1.0.0-rc5 up-conan-recipes/zenohc-tmp/prebuilt conan create --version 1.0.0-rc5 up-conan-recipes/zenohcpp-tmp/from-source - - name: Fetch up-transport-zenoh-cpp - uses: actions/checkout@v4 - with: - path: up-transport-zenoh-cpp - - name: Build up-transport-zenoh-cpp with tests shell: bash run: | cd up-transport-zenoh-cpp - conan install . --deployer=full_deploy --build=missing + conan install --build=missing . --deployer=full_deploy cmake --preset conan-release -DCMAKE_EXPORT_COMPILE_COMMANDS=yes - cmake --build --preset conan-release -- -j + cd build/Release + cmake --build . -- -j - name: Upload build artifacts uses: actions/upload-artifact@v4 @@ -82,7 +89,7 @@ jobs: test: name: Run up-transport-zenoh-cpp tests - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: build steps: @@ -108,7 +115,7 @@ jobs: lint: name: Lint C++ sources - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: build steps: @@ -120,6 +127,8 @@ jobs: - name: Install Conan id: conan uses: turtlebrowser/get-conan@main + with: + version: 2.3.2 - name: Create default Conan profile run: conan profile detect @@ -150,6 +159,8 @@ jobs: style: 'file' # read .clang-format for configuration tidy-checks: '' # Read .clang-tidy for configuration database: compile_commands.json + version: 12 + - name: Run linters on tests id: test-linter @@ -162,12 +173,290 @@ jobs: style: 'file' # read .clang-format for configuration tidy-checks: '' # Read .clang-tidy for configuration database: compile_commands.json + version: 12 - name: Report lint failure if: steps.source-linter.outputs.checks-failed > 0 || steps.test-linter.outputs.checks-failed > 0 run: | exit 1 + memcheck: + name: Run Valgrind Memcheck + runs-on: ubuntu-22.04 + needs: build + + steps: + - name: Get build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: up-transport-zenoh-cpp + + - name: Install Valgrind + run: | + sudo apt-get update + sudo apt-get install -y valgrind + + - name: Run Valgrind Memcheck + continue-on-error: true + run: | + cd up-transport-zenoh-cpp/build/Release + touch valgrind_exclude_test_memcheck.txt + chmod +x bin/* + mkdir -p valgrind_logs + : > valgrind_logs/valgrind_memcheck_summary.log + declare -A EXCLUDE_TESTS + while IFS= read -r line; do + test_binary=$(echo $line | cut -d'.' -f1) + test_suite=$(echo $line | cut -d'.' -f2) + test_name=$(echo $line | cut -d'.' -f3) + if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then + EXCLUDE_TESTS["$test_binary"]="-" + else + EXCLUDE_TESTS["$test_binary"]+=":" + fi + EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" + done < valgrind_exclude_test_memcheck.txt + + for test_binary in bin/*Test; do + test_binary_name=$(basename $test_binary) + echo "Running Valgrind on $test_binary_name" + if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then + exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}" + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary --gtest_filter="$exclude_pattern" || true + else + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary || true + fi + + cat "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_complete_memcheck_log.log + + if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name.log"; then + echo "Valgrind errors found in $test_binary_name:" + grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_memcheck_summary.log + echo "Valgrind log for $test_binary_name:" + cat "valgrind_logs/$test_binary_name.log" + echo "------------------------" + fi + done + echo "Valgrind Memcheck Summary:" + cat valgrind_logs/valgrind_memcheck_summary.log + + - name: Upload Valgrind Memcheck logs + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: valgrind-memcheck-log + path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_memcheck_log.log + + threadcheck: + name: Run Valgrind ThreadCheck + runs-on: ubuntu-22.04 + needs: build + + steps: + - name: Get build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: up-transport-zenoh-cpp + + - name: Install Valgrind + run: | + sudo apt-get update + sudo apt-get install -y valgrind + + - name: Run Valgrind ThreadCheck + continue-on-error: true + run: | + cd up-transport-zenoh-cpp/build/Release + touch valgrind_exclude_test_threadcheck.txt + chmod +x bin/* + mkdir -p valgrind_logs + : > valgrind_logs/valgrind_threadcheck_summary.log + : > valgrind_logs/valgrind_complete_threadcheck_log.log + declare -A EXCLUDE_TESTS + while IFS= read -r line; do + test_binary=$(echo $line | cut -d'.' -f1) + test_suite=$(echo $line | cut -d'.' -f2) + test_name=$(echo $line | cut -d'.' -f3) + if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then + EXCLUDE_TESTS["$test_binary"]="-" + else + EXCLUDE_TESTS["$test_binary"]+=":" + fi + EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" + done < valgrind_exclude_test_threadcheck.txt + + for test_binary in bin/*Test; do + test_binary_name=$(basename $test_binary) + echo "Running Valgrind ThreadCheck on $test_binary_name" + if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then + exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}" + valgrind --tool=drd --log-file="valgrind_logs/$test_binary_name_threadcheck.log" ./$test_binary --gtest_filter="$exclude_pattern" || true + else + valgrind --tool=drd --log-file="valgrind_logs/$test_binary_name_threadcheck.log" ./$test_binary || true + fi + + cat "valgrind_logs/$test_binary_name_threadcheck.log" >> valgrind_logs/valgrind_complete_threadcheck_log.log + + if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_threadcheck.log"; then + echo "Valgrind ThreadCheck errors found in $test_binary_name:" + grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_threadcheck.log" >> valgrind_logs/valgrind_threadcheck_summary.log + echo "Valgrind ThreadCheck log for $test_binary_name:" + cat "valgrind_logs/$test_binary_name_threadcheck.log" + echo "------------------------" + fi + done + + echo "Valgrind ThreadCheck Summary:" + cat valgrind_logs/valgrind_threadcheck_summary.log + + - name: Upload Valgrind ThreadCheck logs + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: valgrind-threadcheck-log + path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_threadcheck_log.log + + helgrind: + name: Run Valgrind Helgrind + runs-on: ubuntu-22.04 + needs: build + + steps: + - name: Get build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: up-transport-zenoh-cpp + + - name: Install Valgrind + run: | + sudo apt-get update + sudo apt-get install -y valgrind + + - name: Run Valgrind Helgrind + continue-on-error: true + run: | + cd up-transport-zenoh-cpp/build/Release + touch valgrind_exclude_test_helgrind.txt + chmod +x bin/* + mkdir -p valgrind_logs + : > valgrind_logs/valgrind_helgrind_summary.log + : > valgrind_logs/valgrind_complete_helgrind_log.log + declare -A EXCLUDE_TESTS + while IFS= read -r line; do + test_binary=$(echo $line | cut -d'.' -f1) + test_suite=$(echo $line | cut -d'.' -f2) + test_name=$(echo $line | cut -d'.' -f3) + if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then + EXCLUDE_TESTS["$test_binary"]="-" + else + EXCLUDE_TESTS["$test_binary"]+=":" + fi + EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" + done < valgrind_exclude_test_helgrind.txt + + for test_binary in bin/*Test; do + test_binary_name=$(basename $test_binary) + echo "Running Valgrind Helgrind on $test_binary_name" + if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then + exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}" + valgrind --tool=helgrind --log-file="valgrind_logs/$test_binary_name_helgrind.log" ./$test_binary --gtest_filter="$exclude_pattern" || true + else + valgrind --tool=helgrind --log-file="valgrind_logs/$test_binary_name_helgrind.log" ./$test_binary || true + fi + + cat "valgrind_logs/$test_binary_name_helgrind.log" >> valgrind_logs/valgrind_complete_helgrind_log.log + + if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_helgrind.log"; then + echo "Valgrind Helgrind errors found in $test_binary_name:" + grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_helgrind.log" >> valgrind_logs/valgrind_helgrind_summary.log + echo "Valgrind Helgrind log for $test_binary_name:" + cat "valgrind_logs/$test_binary_name_helgrind.log" + echo "------------------------" + fi + done + + echo "Valgrind Helgrind Summary:" + cat valgrind_logs/valgrind_helgrind_summary.log + + - name: Upload Valgrind Helgrind logs + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: valgrind-helgrind-log + path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_helgrind_log.log + + dhat: + name: Run Valgrind DHAT + runs-on: ubuntu-22.04 + needs: build + + steps: + - name: Get build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: up-transport-zenoh-cpp + + - name: Install Valgrind + run: | + sudo apt-get update + sudo apt-get install -y valgrind + + - name: Run Valgrind DHAT + continue-on-error: true + run: | + cd up-transport-zenoh-cpp/build/Release + touch valgrind_exclude_test_dhat.txt + chmod +x bin/* + mkdir -p valgrind_logs + : > valgrind_logs/valgrind_dhat_summary.log + : > valgrind_logs/valgrind_complete_dhat_log.log + declare -A EXCLUDE_TESTS + while IFS= read -r line; do + test_binary=$(echo $line | cut -d'.' -f1) + test_suite=$(echo $line | cut -d'.' -f2) + test_name=$(echo $line | cut -d'.' -f3) + if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then + EXCLUDE_TESTS["$test_binary"]="-" + else + EXCLUDE_TESTS["$test_binary"]+=":" + fi + EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" + done < valgrind_exclude_test_dhat.txt + + for test_binary in bin/*Test; do + test_binary_name=$(basename $test_binary) + echo "Running Valgrind DHAT on $test_binary_name" + if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then + exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}" + valgrind --tool=dhat --log-file="valgrind_logs/$test_binary_name_dhat.log" ./$test_binary --gtest_filter="$exclude_pattern" || true + else + valgrind --tool=dhat --log-file="valgrind_logs/$test_binary_name_dhat.log" ./$test_binary || true + fi + + cat "valgrind_logs/$test_binary_name_dhat.log" >> valgrind_logs/valgrind_complete_dhat_log.log + + if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_dhat.log"; then + echo "Valgrind DHAT errors found in $test_binary_name:" + grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_dhat.log" >> valgrind_logs/valgrind_dhat_summary.log + echo "Valgrind DHAT log for $test_binary_name:" + cat "valgrind_logs/$test_binary_name_dhat.log" + echo "------------------------" + fi + done + + echo "Valgrind DHAT Summary:" + cat valgrind_logs/valgrind_dhat_summary.log + + - name: Upload Valgrind DHAT logs + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: valgrind-dhat-log + path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_dhat_log.log # NOTE: In GitHub repository settings, the "Require status checks to pass # before merging" branch protection rule ensures that commits are only merged # from branches where specific status checks have passed. These checks are @@ -175,12 +464,8 @@ jobs: # job to signal whether all CI checks have passed. ci: name: CI status checks - runs-on: ubuntu-latest - #needs: [build, test] - # NOTE tests are currently known failing. At this early stage, we will allow - # some PRs to merge without fixing those tests. This will be reverted in the - # near future. - needs: [build] + runs-on: ubuntu-22.04 + needs: [build, test, memcheck, threadcheck, helgrind, dhat] if: always() steps: - name: Check whether all jobs pass diff --git a/.github/workflows/ci_conan_profile b/.github/workflows/ci_conan_profile new file mode 100644 index 0000000..86745c5 --- /dev/null +++ b/.github/workflows/ci_conan_profile @@ -0,0 +1,8 @@ +[settings] +arch=x86_64 +build_type=Release +compiler=gcc +compiler.cppstd=gnu17 +compiler.libcxx=libstdc++11 +compiler.version=11 +os=Linux \ No newline at end of file From 08336915473e6153d23710f2b3b3a97ea8e9eff9 Mon Sep 17 00:00:00 2001 From: Greg Medding Date: Fri, 16 Aug 2024 20:08:03 -0700 Subject: [PATCH 2/6] Update dependency to zenoh-cpp 1.0.0.6 Current uProtocol spec requires this release for compatibility. It corresponds to the zenoh rust core at 1.0.0-alpha6. --- .github/workflows/ci.yml | 4 ++-- README.md | 7 ++++--- conanfile.txt | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f2589b..37514f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,8 +49,8 @@ jobs: - name: Build zenohcpp conan package shell: bash run: | - conan create --version 1.0.0-rc5 up-conan-recipes/zenohc-tmp/prebuilt - conan create --version 1.0.0-rc5 up-conan-recipes/zenohcpp-tmp/from-source + conan create --version 1.0.0-rc6 up-conan-recipes/zenohc-tmp/prebuilt + conan create --version 1.0.0-rc6 up-conan-recipes/zenohcpp-tmp/from-source - name: Build up-transport-zenoh-cpp with tests shell: bash diff --git a/README.md b/README.md index 9c000fd..2367f75 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,10 @@ from [up-cpp][cpp-api-repo]. Using the recipes found in [up-conan-recipes][conan-recipe-repo], build these Conan packages: -1. [up-core-api][spec-repo] - `conan create --version 1.6.0 --build=missing up-core-api/release` -1. [up-cpp][cpp-api-repo] - `conan create --version 1.0.1-rc1 --build=missing up-cpp/release` -2. [zenoh-c][zenoh-repo] - `conan create --version 0.11.0 zenoh-tmp/from-source` +1. [up-core-api][spec-repo] - `conan create --version 1.6.0-alpha3 --build=missing up-core-api/release` +1. [up-cpp][cpp-api-repo] - `conan create --version 1.0.1 --build=missing up-cpp/release` +2. [zenoh-c][zenoh-repo] - `conan create --version 1.0.0-rc6 zenohc-tmp/prebuilt` +2. [zenoh-c][zenoh-repo] - `conan create --version 1.0.0-rc6 zenohcpp-tmp/from-source` **NOTE:** all `conan` commands in this document use Conan 2.x syntax. Please adjust accordingly when using Conan 1.x. diff --git a/conanfile.txt b/conanfile.txt index 8b4affc..fb378f7 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,7 +1,7 @@ [requires] up-cpp/[^1.0.1] -zenohcpp/1.0.0-rc5 -zenohc/1.0.0-rc5 +zenohcpp/1.0.0-rc6 +zenohc/1.0.0-rc6 spdlog/[~1.13] up-core-api/[~1.6, include_prerelease] protobuf/[~3.21] From 78df16970a6e6461d452f60503b55e9dac6c03ef Mon Sep 17 00:00:00 2001 From: Jonas Lammers Date: Wed, 19 Feb 2025 15:28:29 +0100 Subject: [PATCH 3/6] chore: update dependency to zenoh-cpp 1.2.1 --- conanfile.txt | 4 +-- .../up-transport-zenoh-cpp/ZenohUTransport.h | 3 +- src/ZenohUTransport.cpp | 29 ++++++++++++------- test/coverage/ZenohUTransportTest.cpp | 2 +- test/extra/NotificationTest.cpp | 4 +-- test/extra/PublisherSubscriberTest.cpp | 2 +- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/conanfile.txt b/conanfile.txt index fb378f7..042c163 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,7 +1,7 @@ [requires] up-cpp/[^1.0.1] -zenohcpp/1.0.0-rc6 -zenohc/1.0.0-rc6 +zenohcpp/1.2.1 +zenohc/1.2.1 spdlog/[~1.13] up-core-api/[~1.6, include_prerelease] protobuf/[~3.21] diff --git a/include/up-transport-zenoh-cpp/ZenohUTransport.h b/include/up-transport-zenoh-cpp/ZenohUTransport.h index 38074a4..9cdf032 100644 --- a/include/up-transport-zenoh-cpp/ZenohUTransport.h +++ b/include/up-transport-zenoh-cpp/ZenohUTransport.h @@ -106,7 +106,8 @@ struct ZenohUTransport : public UTransport { uattributesToAttachment(const v1::UAttributes& attributes); static v1::UAttributes attachmentToUAttributes( - const zenoh::Bytes& attachment); + const std::optional>& + attachment); static zenoh::Priority mapZenohPriority(v1::UPriority upriority); diff --git a/src/ZenohUTransport.cpp b/src/ZenohUTransport.cpp index b25f690..a0b8770 100644 --- a/src/ZenohUTransport.cpp +++ b/src/ZenohUTransport.cpp @@ -99,10 +99,15 @@ ZenohUTransport::uattributesToAttachment(const v1::UAttributes& attributes) { } v1::UAttributes ZenohUTransport::attachmentToUAttributes( - const zenoh::Bytes& attachment) { - auto attachment_vec = - attachment - .deserialize>>(); + const std::optional>& + attachment) { + if (!attachment.has_value()) { + spdlog::error("attachmentToUAttributes: attachment has no value"); + // TODO: error report, exception? + } + auto attachment_vec = zenoh::ext::deserialize< + std::vector>>( + attachment.value().get()); if (attachment_vec.size() != 2) { spdlog::error("attachmentToUAttributes: attachment size != 2"); @@ -158,7 +163,8 @@ v1::UMessage ZenohUTransport::sampleToUMessage(const zenoh::Sample& sample) { v1::UMessage message; *message.mutable_attributes() = attachmentToUAttributes(sample.get_attachment()); - std::string payload(sample.get_payload().deserialize()); + std::string payload( + zenoh::ext::deserialize(sample.get_payload())); message.set_payload(payload); return message; @@ -168,8 +174,11 @@ v1::UMessage ZenohUTransport::queryToUMessage(const zenoh::Query& query) { v1::UMessage message; *message.mutable_attributes() = attachmentToUAttributes(query.get_attachment()); - std::string payload(query.get_payload().deserialize()); - message.set_payload(payload); + if (query.get_payload().has_value()) { + std::string payload(zenoh::ext::deserialize( + query.get_payload().value().get())); + message.set_payload(payload); + } return message; } @@ -218,9 +227,9 @@ v1::UStatus ZenohUTransport::sendPublishNotification_( zenoh::Session::PutOptions options; options.priority = priority; options.encoding = zenoh::Encoding("app/custom"); - options.attachment = attachment; - session_.put(zenoh::KeyExpr(zenoh_key), - zenoh::Bytes::serialize(payload), std::move(options)); + options.attachment = zenoh::ext::serialize(attachment); + session_.put(zenoh::KeyExpr(zenoh_key), zenoh::ext::serialize(payload), + std::move(options)); } catch (const zenoh::ZException& e) { return uError(v1::UCode::INTERNAL, e.what()); } diff --git a/test/coverage/ZenohUTransportTest.cpp b/test/coverage/ZenohUTransportTest.cpp index 0fd3c65..29a5397 100644 --- a/test/coverage/ZenohUTransportTest.cpp +++ b/test/coverage/ZenohUTransportTest.cpp @@ -66,7 +66,7 @@ v1::UUri create_uuri(std::string_view serialized) { TEST_F(TestZenohUTransport, ConstructDestroy) { std::cout << ZENOH_CONFIG_FILE << std::endl; - zenoh::init_logger(); + zenoh::init_log_from_env_or("error"); auto transport = std::make_shared( create_uuri(ENTITY_URI_STR), ZENOH_CONFIG_FILE); diff --git a/test/extra/NotificationTest.cpp b/test/extra/NotificationTest.cpp index 0adc624..6a20476 100644 --- a/test/extra/NotificationTest.cpp +++ b/test/extra/NotificationTest.cpp @@ -57,7 +57,7 @@ std::shared_ptr getTransport( } TEST_F(NotificationTest, BasicNotificationTestWithPayload) { - zenoh::init_logger(); + zenoh::init_log_from_env_or("error"); auto transport = getTransport(); auto source = getUUri(0x8000); @@ -103,7 +103,7 @@ TEST_F(NotificationTest, BasicNotificationTestWithPayload) { } TEST_F(NotificationTest, BasicNotificationTestWithoutPayload) { - zenoh::init_logger(); + zenoh::init_log_from_env_or("error"); auto transport = getTransport(); auto source = getUUri(0x8000); diff --git a/test/extra/PublisherSubscriberTest.cpp b/test/extra/PublisherSubscriberTest.cpp index 6477a4a..8dc9308 100644 --- a/test/extra/PublisherSubscriberTest.cpp +++ b/test/extra/PublisherSubscriberTest.cpp @@ -37,7 +37,7 @@ class PublisherSubscriberTest : public testing::Test { // Run once per execution of the test application. // Used for setup of all tests. Has access to this instance. - PublisherSubscriberTest() { zenoh::init_logger(); } + PublisherSubscriberTest() { zenoh::init_log_from_env_or("error"); } ~PublisherSubscriberTest() = default; // Run once per execution of the test application. From a9e4468cff512e2fa048f433a81487037a07b399 Mon Sep 17 00:00:00 2001 From: Jonas Lammers Date: Thu, 6 Mar 2025 08:21:38 +0100 Subject: [PATCH 4/6] refactor: check for attachments instead of ref wrapping --- .../up-transport-zenoh-cpp/ZenohUTransport.h | 3 +- src/ZenohUTransport.cpp | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/up-transport-zenoh-cpp/ZenohUTransport.h b/include/up-transport-zenoh-cpp/ZenohUTransport.h index 9cdf032..38074a4 100644 --- a/include/up-transport-zenoh-cpp/ZenohUTransport.h +++ b/include/up-transport-zenoh-cpp/ZenohUTransport.h @@ -106,8 +106,7 @@ struct ZenohUTransport : public UTransport { uattributesToAttachment(const v1::UAttributes& attributes); static v1::UAttributes attachmentToUAttributes( - const std::optional>& - attachment); + const zenoh::Bytes& attachment); static zenoh::Priority mapZenohPriority(v1::UPriority upriority); diff --git a/src/ZenohUTransport.cpp b/src/ZenohUTransport.cpp index a0b8770..7279123 100644 --- a/src/ZenohUTransport.cpp +++ b/src/ZenohUTransport.cpp @@ -99,15 +99,9 @@ ZenohUTransport::uattributesToAttachment(const v1::UAttributes& attributes) { } v1::UAttributes ZenohUTransport::attachmentToUAttributes( - const std::optional>& - attachment) { - if (!attachment.has_value()) { - spdlog::error("attachmentToUAttributes: attachment has no value"); - // TODO: error report, exception? - } + const zenoh::Bytes& attachment) { auto attachment_vec = zenoh::ext::deserialize< - std::vector>>( - attachment.value().get()); + std::vector>>(attachment); if (attachment_vec.size() != 2) { spdlog::error("attachmentToUAttributes: attachment size != 2"); @@ -161,8 +155,14 @@ zenoh::Priority ZenohUTransport::mapZenohPriority(v1::UPriority upriority) { v1::UMessage ZenohUTransport::sampleToUMessage(const zenoh::Sample& sample) { v1::UMessage message; - *message.mutable_attributes() = - attachmentToUAttributes(sample.get_attachment()); + const auto attachment = sample.get_attachment(); + if (attachment.has_value()) { + *message.mutable_attributes() = + attachmentToUAttributes(attachment.value()); + } else { + spdlog::error("sampleToUMessage: empty attachment"); + // TODO: error report? attachments are optional, attributes are not + } std::string payload( zenoh::ext::deserialize(sample.get_payload())); message.set_payload(payload); @@ -172,8 +172,14 @@ v1::UMessage ZenohUTransport::sampleToUMessage(const zenoh::Sample& sample) { v1::UMessage ZenohUTransport::queryToUMessage(const zenoh::Query& query) { v1::UMessage message; - *message.mutable_attributes() = - attachmentToUAttributes(query.get_attachment()); + const auto attachment = query.get_attachment(); + if (attachment.has_value()) { + *message.mutable_attributes() = + attachmentToUAttributes(attachment.value()); + } else { + spdlog::error("sampleToUMessage: empty attachment"); + // TODO: report error? attachments are optional, attributes are not + } if (query.get_payload().has_value()) { std::string payload(zenoh::ext::deserialize( query.get_payload().value().get())); From ab6075e99086d4649f2509b31b482cea0d0e7a63 Mon Sep 17 00:00:00 2001 From: Jonas Lammers Date: Wed, 19 Feb 2025 15:37:40 +0100 Subject: [PATCH 5/6] ci: pin ubuntu and conan version, fix conan profile --- .github/workflows/ci.yml | 217 ++++++++++++++++++++------------------- 1 file changed, 113 insertions(+), 104 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37514f7..3122ee5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: ["main"] + branches: ['main'] pull_request: - branches: ["**"] + branches: ['**'] jobs: build: @@ -22,13 +22,13 @@ jobs: uses: turtlebrowser/get-conan@main with: version: 2.3.2 - + - name: Install conan CI profile shell: bash run: | conan profile detect cp up-transport-zenoh-cpp/.github/workflows/ci_conan_profile "$(conan profile path default)" - conan profile show + conan profile show - name: Fetch up-core-api conan recipe uses: actions/checkout@v4 @@ -49,8 +49,8 @@ jobs: - name: Build zenohcpp conan package shell: bash run: | - conan create --version 1.0.0-rc6 up-conan-recipes/zenohc-tmp/prebuilt - conan create --version 1.0.0-rc6 up-conan-recipes/zenohcpp-tmp/from-source + conan create --version 1.2.1 up-conan-recipes/zenohc-tmp/prebuilt + conan create --version 1.2.1 up-conan-recipes/zenohcpp-tmp/from-source - name: Build up-transport-zenoh-cpp with tests shell: bash @@ -119,6 +119,11 @@ jobs: needs: build steps: + - name: Fetch up-transport-zenoh-cpp + uses: actions/checkout@v4 + with: + path: up-transport-zenoh-cpp + - name: Get build commands uses: actions/download-artifact@v4 with: @@ -130,8 +135,12 @@ jobs: with: version: 2.3.2 - - name: Create default Conan profile - run: conan profile detect + - name: Install conan CI profile + shell: bash + run: | + conan profile detect + cp up-transport-zenoh-cpp/.github/workflows/ci_conan_profile "$(conan profile path default)" + conan profile show - name: Get conan cache uses: actions/download-artifact@v4 @@ -143,11 +152,6 @@ jobs: run: | conan cache restore conan-cache.tgz - - name: Fetch up-transport-zenoh-cpp - uses: actions/checkout@v4 - with: - path: up-transport-zenoh-cpp - - name: Run linters on source id: source-linter uses: cpp-linter/cpp-linter-action@v2 @@ -161,7 +165,6 @@ jobs: database: compile_commands.json version: 12 - - name: Run linters on tests id: test-linter uses: cpp-linter/cpp-linter-action@v2 @@ -176,95 +179,97 @@ jobs: version: 12 - name: Report lint failure - if: steps.source-linter.outputs.checks-failed > 0 || steps.test-linter.outputs.checks-failed > 0 + if: + steps.source-linter.outputs.checks-failed > 0 || + steps.test-linter.outputs.checks-failed > 0 run: | exit 1 memcheck: - name: Run Valgrind Memcheck - runs-on: ubuntu-22.04 - needs: build - - steps: - - name: Get build artifacts - uses: actions/download-artifact@v4 - with: - name: build-artifacts - path: up-transport-zenoh-cpp - - - name: Install Valgrind - run: | - sudo apt-get update - sudo apt-get install -y valgrind - - - name: Run Valgrind Memcheck - continue-on-error: true - run: | - cd up-transport-zenoh-cpp/build/Release - touch valgrind_exclude_test_memcheck.txt - chmod +x bin/* - mkdir -p valgrind_logs - : > valgrind_logs/valgrind_memcheck_summary.log - declare -A EXCLUDE_TESTS - while IFS= read -r line; do - test_binary=$(echo $line | cut -d'.' -f1) - test_suite=$(echo $line | cut -d'.' -f2) - test_name=$(echo $line | cut -d'.' -f3) - if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then - EXCLUDE_TESTS["$test_binary"]="-" - else - EXCLUDE_TESTS["$test_binary"]+=":" - fi - EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" - done < valgrind_exclude_test_memcheck.txt - - for test_binary in bin/*Test; do - test_binary_name=$(basename $test_binary) - echo "Running Valgrind on $test_binary_name" - if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then - exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}" - valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary --gtest_filter="$exclude_pattern" || true - else - valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary || true - fi - - cat "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_complete_memcheck_log.log - - if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name.log"; then - echo "Valgrind errors found in $test_binary_name:" - grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_memcheck_summary.log - echo "Valgrind log for $test_binary_name:" - cat "valgrind_logs/$test_binary_name.log" - echo "------------------------" - fi - done - echo "Valgrind Memcheck Summary:" - cat valgrind_logs/valgrind_memcheck_summary.log - - - name: Upload Valgrind Memcheck logs - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: valgrind-memcheck-log - path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_memcheck_log.log + name: Run Valgrind Memcheck + runs-on: ubuntu-22.04 + needs: build + + steps: + - name: Get build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: up-transport-zenoh-cpp + + - name: Install Valgrind + run: | + sudo apt-get update + sudo apt-get install -y valgrind + + - name: Run Valgrind Memcheck + continue-on-error: true + run: | + cd up-transport-zenoh-cpp/build/Release + touch valgrind_exclude_test_memcheck.txt + chmod +x bin/* + mkdir -p valgrind_logs + : > valgrind_logs/valgrind_memcheck_summary.log + declare -A EXCLUDE_TESTS + while IFS= read -r line; do + test_binary=$(echo $line | cut -d'.' -f1) + test_suite=$(echo $line | cut -d'.' -f2) + test_name=$(echo $line | cut -d'.' -f3) + if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then + EXCLUDE_TESTS["$test_binary"]="-" + else + EXCLUDE_TESTS["$test_binary"]+=":" + fi + EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" + done < valgrind_exclude_test_memcheck.txt + + for test_binary in bin/*Test; do + test_binary_name=$(basename $test_binary) + echo "Running Valgrind on $test_binary_name" + if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then + exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}" + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary --gtest_filter="$exclude_pattern" || true + else + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary || true + fi + + cat "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_complete_memcheck_log.log + + if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name.log"; then + echo "Valgrind errors found in $test_binary_name:" + grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_memcheck_summary.log + echo "Valgrind log for $test_binary_name:" + cat "valgrind_logs/$test_binary_name.log" + echo "------------------------" + fi + done + echo "Valgrind Memcheck Summary:" + cat valgrind_logs/valgrind_memcheck_summary.log + + - name: Upload Valgrind Memcheck logs + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: valgrind-memcheck-log + path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_memcheck_log.log threadcheck: name: Run Valgrind ThreadCheck runs-on: ubuntu-22.04 needs: build - + steps: - name: Get build artifacts uses: actions/download-artifact@v4 with: name: build-artifacts - path: up-transport-zenoh-cpp - + path: up-transport-zenoh-cpp + - name: Install Valgrind run: | sudo apt-get update sudo apt-get install -y valgrind - + - name: Run Valgrind ThreadCheck continue-on-error: true run: | @@ -286,7 +291,7 @@ jobs: fi EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" done < valgrind_exclude_test_threadcheck.txt - + for test_binary in bin/*Test; do test_binary_name=$(basename $test_binary) echo "Running Valgrind ThreadCheck on $test_binary_name" @@ -296,9 +301,9 @@ jobs: else valgrind --tool=drd --log-file="valgrind_logs/$test_binary_name_threadcheck.log" ./$test_binary || true fi - + cat "valgrind_logs/$test_binary_name_threadcheck.log" >> valgrind_logs/valgrind_complete_threadcheck_log.log - + if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_threadcheck.log"; then echo "Valgrind ThreadCheck errors found in $test_binary_name:" grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_threadcheck.log" >> valgrind_logs/valgrind_threadcheck_summary.log @@ -307,34 +312,34 @@ jobs: echo "------------------------" fi done - + echo "Valgrind ThreadCheck Summary:" cat valgrind_logs/valgrind_threadcheck_summary.log - + - name: Upload Valgrind ThreadCheck logs uses: actions/upload-artifact@v4 if: success() || failure() with: name: valgrind-threadcheck-log - path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_threadcheck_log.log - + path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_threadcheck_log.log + helgrind: name: Run Valgrind Helgrind runs-on: ubuntu-22.04 needs: build - + steps: - name: Get build artifacts uses: actions/download-artifact@v4 with: name: build-artifacts - path: up-transport-zenoh-cpp - + path: up-transport-zenoh-cpp + - name: Install Valgrind run: | sudo apt-get update sudo apt-get install -y valgrind - + - name: Run Valgrind Helgrind continue-on-error: true run: | @@ -356,7 +361,7 @@ jobs: fi EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name" done < valgrind_exclude_test_helgrind.txt - + for test_binary in bin/*Test; do test_binary_name=$(basename $test_binary) echo "Running Valgrind Helgrind on $test_binary_name" @@ -366,9 +371,9 @@ jobs: else valgrind --tool=helgrind --log-file="valgrind_logs/$test_binary_name_helgrind.log" ./$test_binary || true fi - + cat "valgrind_logs/$test_binary_name_helgrind.log" >> valgrind_logs/valgrind_complete_helgrind_log.log - + if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_helgrind.log"; then echo "Valgrind Helgrind errors found in $test_binary_name:" grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_helgrind.log" >> valgrind_logs/valgrind_helgrind_summary.log @@ -377,17 +382,17 @@ jobs: echo "------------------------" fi done - + echo "Valgrind Helgrind Summary:" cat valgrind_logs/valgrind_helgrind_summary.log - + - name: Upload Valgrind Helgrind logs uses: actions/upload-artifact@v4 if: success() || failure() with: name: valgrind-helgrind-log - path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_helgrind_log.log - + path: up-transport-zenoh-cpp/build/Release/valgrind_logs/valgrind_complete_helgrind_log.log + dhat: name: Run Valgrind DHAT runs-on: ubuntu-22.04 @@ -465,7 +470,11 @@ jobs: ci: name: CI status checks runs-on: ubuntu-22.04 - needs: [build, test, memcheck, threadcheck, helgrind, dhat] + #needs: [build, test] + # NOTE tests are currently known failing. At this early stage, we will allow + # some PRs to merge without fixing those tests. This will be reverted in the + # near future. + needs: [build] if: always() steps: - name: Check whether all jobs pass From 7a01e35d8f92c1c5161fa09f572946a44744c79e Mon Sep 17 00:00:00 2001 From: lammjo Date: Mon, 3 Mar 2025 21:16:44 +0100 Subject: [PATCH 6/6] doc: bump version in readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2367f75..95fd9d2 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ from [up-cpp][cpp-api-repo]. Using the recipes found in [up-conan-recipes][conan-recipe-repo], build these Conan packages: -1. [up-core-api][spec-repo] - `conan create --version 1.6.0-alpha3 --build=missing up-core-api/release` -1. [up-cpp][cpp-api-repo] - `conan create --version 1.0.1 --build=missing up-cpp/release` -2. [zenoh-c][zenoh-repo] - `conan create --version 1.0.0-rc6 zenohc-tmp/prebuilt` -2. [zenoh-c][zenoh-repo] - `conan create --version 1.0.0-rc6 zenohcpp-tmp/from-source` +1. [up-core-api][spec-repo] - `conan create --version 1.6.0-alpha4 --build=missing up-core-api/release` +2. [up-cpp][cpp-api-repo] - `conan create --version 1.0.1 --build=missing up-cpp/release` +3. [zenoh-c][zenoh-repo] - `conan create --version 1.2.1 zenohc-tmp/prebuilt` +4. [zenoh-c][zenoh-repo] - `conan create --version 1.2.1 zenohcpp-tmp/from-source` **NOTE:** all `conan` commands in this document use Conan 2.x syntax. Please adjust accordingly when using Conan 1.x.