Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2330 Refactor systemd notification handling
Browse files Browse the repository at this point in the history
iox-eclipse-iceoryx#2330 Refactor ci scripts
  • Loading branch information
khromenokroman committed Sep 5, 2024
1 parent 2528bd2 commit aa06475
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 55 deletions.
1 change: 0 additions & 1 deletion .github/actions/install-iceoryx-deps-and-clang/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ runs:
sudo apt-get install -y libacl1-dev libncurses5-dev
sudo apt-get install -y libacl1-dev:i386 libc6-dev-i386 libc6-dev-i386-cross libstdc++6-i386-cross gcc-multilib g++-multilib
sudo apt-get install -y clang-format-15 clang-tidy-15 clang-tools-15 clang-15 lld
sudo apt install libsystemd-dev
sudo rm /usr/bin/clang
sudo rm /usr/bin/clang++
sudo rm /usr/bin/clang-tidy
Expand Down
41 changes: 6 additions & 35 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,43 +211,14 @@ jobs:
runs-on: ubuntu-latest
needs: pre-flight-check
steps:
- name: Update
run: sudo apt update
- name: Install depends
run: sudo apt install -y gcc g++ cmake libacl1-dev libncurses5-dev pkg-config libsystemd-dev
- name: Checkout
uses: actions/checkout@v4
- name: Cmake cache
run: cmake -Bbuild -Hiceoryx_meta -DBUILD_SHARED_LIBS=ON -DUSE_SYSTEMD=ON -DBUILD_TEST=ON
- name: build
run: cmake --build build -j 16
- name: Install
run: sudo cmake --build build --target install
- name: Ldconfig run
run: sudo ldconfig
- name: Create unit file
run: echo -e "[Unit]\nDescription=Test application roudi\n\n[Service]\nType=notify\nRestartSec=10\nRestart=always\nExecStart=/usr/local/bin/iox-roudi\nTimeoutStartSec=10\nWatchdogSec=5\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /usr/lib/systemd/system/test_iox.service > /dev/null
- name: Show unit
run: cat /usr/lib/systemd/system/test_iox.service
- name: Daemon reload
run: sudo systemctl daemon-reload
- name: Check status
run: sudo systemctl status test_iox || true
- name: Start roudi
run: |
sudo systemctl start test_iox || (echo "Failed to start service"; sudo journalctl -u test_iox -n 50; exit 1)
- name: Wait for 30 seconds
run: sleep 30
- name: Check roudi
run: sudo systemctl status test_iox || (echo "Failed to start service"; sudo journalctl -u test_iox -n 50; exit 1)
- name: Stop roudi
run: sudo systemctl stop test_iox
- name: Show journal
run: sudo journalctl -u test_iox -n 100
- name: Start test (integration) posh with systemd
run: cd build/posh/test && ./posh_integrationtests
- name: Start test (module) posh with systemd
run: cd build/posh/test && ./posh_moduletests
- name: Install iceoryx dependencies and clang-tidy
uses: ./.github/actions/install-iceoryx-deps-and-clang
- name: Build project and test and run unit test
run: sudo ./tools/ci/build-test-ubuntu-support-systemd-unit.sh
- name: Start integration test
run: sudo ./tools/ci/build-test-ubuntu-support-systemd-integrations.sh

coverage-and-docs:
# prevent stuck jobs consuming runners for 6 hours
Expand Down
7 changes: 6 additions & 1 deletion iceoryx_platform/cmake/IceoryxPackageHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ Macro(iox_add_executable)
target_compile_options(${IOX_TARGET} PRIVATE ${ICEORYX_CXX_FLAGS} ${ICEORYX_CXX_WARNINGS} ${ICEORYX_SANITIZER_FLAGS} ${ICEORYX_GRCOV_FLAGS})
endif()

if(USE_SYSTEMD AND ("${IOX_TARGET}" STREQUAL "posh_moduletests"))
target_compile_definitions(${IOX_TARGET} PRIVATE USE_SYSTEMD_TEST=1)
message(STATUS "[i] Configuring ${IOX_TARGET} with systemd support.")
endif ()

if ( IOX_STACK_SIZE )
if(APPLE)
# @todo iox-#1287 not yet supported
Expand Down Expand Up @@ -341,7 +346,7 @@ Macro(iox_add_library)

if ( LINUX )
if(USE_SYSTEMD AND ("${IOX_TARGET}" STREQUAL "iceoryx_posh_roudi"))
message(STATUS "[i] Configuring iceoryx_posh_roudi with systemd support.")
message(STATUS "[i] Configuring ${IOX_TARGET} with systemd support.")
target_compile_definitions(${IOX_TARGET} PRIVATE USE_SYSTEMD=1)
target_link_libraries(${IOX_TARGET} PUBLIC ${IOX_PUBLIC_LIBS_LINUX} PRIVATE ${IOX_PRIVATE_LIBS_LINUX} systemd)
else()
Expand Down
28 changes: 21 additions & 7 deletions iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@
#include <cstdint>
#include <thread>

#if defined(_WIN32) || defined(_WIN64)
// Windows include here
#elif defined(__linux__)
#ifdef USE_SYSTEMD
#include <systemd/sd-daemon.h>
#else
// MacOS and other non-Windows, non-Linux include here
#endif

#ifdef USE_SYSTEMD
Expand Down Expand Up @@ -144,8 +140,26 @@ class ServiceManagementSystemd final : public ServiceManagement
* @param state SDNotify state to be sent
* @return True if signal sending is successful, otherwise false
**/
bool sendSDNotifySignalHelper(const std::string_view state) final;

#ifdef USE_SYSTEMD
bool sendSDNotifySignalHelper(const std::string_view state) final
{
auto result = IOX_POSIX_CALL(sd_notify)(0, state.data()).successReturnValue(1).evaluate();
if (result.has_error())
{
IOX_LOG(ERROR,
"Failed to send " << state.data()
<< " signal. Error: " << result.get_error().getHumanReadableErrnum());
return false;
}
return true;
}
#else
bool sendSDNotifySignalHelper([[maybe_unused]] const std::string_view state) final
{
// empty implementation
return true;
}
#endif
/**
* @brief Function to manage the watchdog loop
**/
Expand Down
11 changes: 0 additions & 11 deletions iceoryx_posh/source/roudi/roudi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,17 +681,6 @@ void ServiceManagementSystemd::processNotify()
}
}

bool ServiceManagementSystemd::sendSDNotifySignalHelper(const std::string_view state)
{
auto result = IOX_POSIX_CALL(sd_notify)(0, state.data()).successReturnValue(1).evaluate();
if (result.has_error())
{
IOX_LOG(ERROR,
"Failed to send " << state.data() << " signal. Error: " << result.get_error().getHumanReadableErrnum());
return false;
}
return true;
}

} // namespace service_management
} // namespace roudi
Expand Down
28 changes: 28 additions & 0 deletions iceoryx_posh/test/moduletests/test_roudi_system_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@
#define GTEST_SKIP_FOR_WINDOWS() (void)0
#endif

#ifdef USE_SYSTEMD_TEST
#define GTEST_SKIP_NOT_SUPPORT_SYSTEMD() (void)0
#else
#define GTEST_SKIP_NOT_SUPPORT_SYSTEMD() GTEST_SKIP() << "Skipping this test when systemd is not use."
#endif


TEST(RoudiSystemD, CreateObject)
{
::testing::Test::RecordProperty("TEST_ID", "aa77b5f6-ffb3-4267-982d-dfe85da384ca");
GTEST_SKIP_NOT_SUPPORT_SYSTEMD();
std::unique_ptr<SendMessageServiceManagement> roudiSendMessage;
ASSERT_NO_THROW(roudiSendMessage = std::make_unique<SendMessageServiceManagement>());
}

TEST(RoudiSystemD, CheckConstantsSizeThreadName)
{
::testing::Test::RecordProperty("TEST_ID", "9c39f45c-a63c-43ec-9606-e50c33247b3f");
GTEST_SKIP_NOT_SUPPORT_SYSTEMD();
std::unique_ptr<SendMessageServiceManagement> roudiSendMessage;
ASSERT_NO_THROW(roudiSendMessage = std::make_unique<SendMessageServiceManagement>());
ASSERT_EQ(roudiSendMessage->SIZE_THREAD_NAME, 15) << "Size thread must equal 15 simbols";
Expand All @@ -42,6 +51,7 @@ TEST(RoudiSystemD, CheckConstantsSizeThreadName)
TEST(RoudiSystemD, CheckConstantsSizeString)
{
::testing::Test::RecordProperty("TEST_ID", "0b3e3058-6052-49cc-8a67-723f3775a745");
GTEST_SKIP_NOT_SUPPORT_SYSTEMD();
std::unique_ptr<SendMessageServiceManagement> roudiSendMessage;
ASSERT_NO_THROW(roudiSendMessage = std::make_unique<SendMessageServiceManagement>());
ASSERT_EQ(roudiSendMessage->SIZE_STRING, 4096) << "Size string must equal 4096 simbols";
Expand All @@ -51,19 +61,27 @@ TEST(RoudiSystemD, SetThreadNameHelper)
{
::testing::Test::RecordProperty("TEST_ID", "b9ff9e83-9dde-4221-bd1e-c1016ec2d5ff");
GTEST_SKIP_FOR_WINDOWS();
GTEST_SKIP_NOT_SUPPORT_SYSTEMD();
#ifdef USE_SYSTEMD_TEST
std::unique_ptr<SendMessageServiceManagement> roudiSendMessage;
bool result = true;

ASSERT_NO_THROW(roudiSendMessage = std::make_unique<SendMessageServiceManagement>());
iox::string<SendMessageServiceManagement::SIZE_THREAD_NAME> nameThread = "test";
ASSERT_NO_THROW(result = roudiSendMessage->setThreadNameHelper(nameThread));
ASSERT_EQ(result, true) << "Can not change name thread";
#else
/* need add test (other OS) */
ASSERT_EQ(true, true);
#endif
}

TEST(RoudiSystemD, GetEnvironmentVariableReturnsCorrectValue)
{
::testing::Test::RecordProperty("TEST_ID", "12dfa746-d1f1-4b4e-864d-2cb28ee49f70");
GTEST_SKIP_FOR_WINDOWS();
GTEST_SKIP_NOT_SUPPORT_SYSTEMD();
#ifdef USE_SYSTEMD_TEST
const char* const env_var_name = "TEST_ENV_VAR";
const char* const env_var_value = "test_value";

Expand All @@ -81,12 +99,18 @@ TEST(RoudiSystemD, GetEnvironmentVariableReturnsCorrectValue)
{
EXPECT_EQ(result, "no implement");
}
#else
/* need add test (other OS) */
ASSERT_EQ(true, true);
#endif
}

TEST(RoudiSystemD, GetEnvironmentVariableHandlesNonExistentVar)
{
::testing::Test::RecordProperty("TEST_ID", "9595728f-a504-46e3-8672-b074696326a4");
GTEST_SKIP_FOR_WINDOWS();
GTEST_SKIP_NOT_SUPPORT_SYSTEMD();
#ifdef USE_SYSTEMD_TEST
SendMessageServiceManagement sut;

std::string result = sut.getEnvironmentVariable("NON_EXISTENT_VAR");
Expand All @@ -98,4 +122,8 @@ TEST(RoudiSystemD, GetEnvironmentVariableHandlesNonExistentVar)
{
EXPECT_EQ(result, "no implement");
}
#else
/* need add test (other OS) */
ASSERT_EQ(true, true);
#endif
}
62 changes: 62 additions & 0 deletions tools/ci/build-test-ubuntu-support-systemd-integrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

# This script builds iceoryx_hoofs und iceoryx_posh and executes all tests

set -e

if [ "$USER" != "root" ]; then
echo "Please run this as root or with sudo"
exit 1
fi

msg() {
printf "\033[1;32m%s: %s\033[0m\n" ${FUNCNAME[1]} "$1"
}

msg "Create unit file"
echo -e "[Unit]\nDescription=Test application roudi\n\n[Service]\nType=notify\nRestartSec=10\nRestart=always\nExecStart=/usr/local/bin/iox-roudi\nTimeoutStartSec=10\nWatchdogSec=5\n\n[Install]\nWantedBy=multi-user.target" | tee /usr/lib/systemd/system/test_iox.service > /dev/null

msg "Show unit"
cat /usr/lib/systemd/system/test_iox.service

msg "Daemon reload"
systemctl daemon-reload

msg "Check status"
systemctl status test_iox || true

msg "Start roudi"
systemctl start test_iox || (echo "Failed to start service"; sudo journalctl -u test_iox -n 50; exit 1)

msg "Wait for 30 seconds"
sleep 30

msg "Check roudi"
systemctl status test_iox || (echo "Failed to start service"; sudo journalctl -u test_iox -n 50; exit 1)

msg "Stop roudi"
systemctl stop test_iox

msg "Show journal"
journalctl -u test_iox -n 100

msg "Start test (integration) posh with systemd"
cd build/posh/test && ./posh_integrationtests

msg "Start test (module) posh with systemd"
cd build/posh/test && ./posh_moduletests
48 changes: 48 additions & 0 deletions tools/ci/build-test-ubuntu-support-systemd-unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

# This script builds iceoryx_hoofs und iceoryx_posh and executes all tests

set -e

if [ "$USER" != "root" ]; then
echo "Please run this as root or with sudo"
exit 1
fi

msg() {
printf "\033[1;32m%s: %s\033[0m\n" ${FUNCNAME[1]} "$1"
}

WORKSPACE=$(git rev-parse --show-toplevel)
cd ${WORKSPACE}

msg "Install libsystemd-dev"
apt install -y libsystemd-dev

msg "compiler versions:
$(gcc --version)
$(clang --version)"

msg "building sources"
./tools/iceoryx_build_test.sh systemd build-shared build-test

msg "running all tests"
cd ./build
./tools/run_tests.sh all
cd -

8 changes: 8 additions & 0 deletions tools/iceoryx_build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ COMPONENTS="iceoryx_platform iceoryx_hoofs iceoryx_posh iceoryx_introspection ic
TOOLCHAIN_FILE=""
CMAKE_C_FLAGS=""
CMAKE_CXX_FLAGS=""
USE_SYSTEMD_FLAGS=""

while (( "$#" )); do
case "$1" in
Expand Down Expand Up @@ -228,6 +229,11 @@ while (( "$#" )); do
CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -malign-double"
shift 1
;;
"systemd")
echo " [i] Build with support systemd"
USE_SYSTEMD_FLAGS="ON"
shift 1
;;
"help")
echo "Build script for iceoryx."
echo "By default, iceoryx with C-Binding and TOML-config is built."
Expand Down Expand Up @@ -266,6 +272,7 @@ while (( "$#" )); do
echo " roudi-env Build the roudi environment"
echo " 32-bit-x86 Build as 32 bit library for x64"
echo " 32-bit-arm Build as 32 bit library for arm"
echo " systemd Build with support systemd"
echo ""
echo "e.g. iceoryx_build_test.sh -b ./build-scripted clean test"
echo "for gcov report: iceoryx_build_test.sh clean -c unit"
Expand Down Expand Up @@ -342,6 +349,7 @@ if [ "$NO_BUILD" == false ]; then
-DTEST_WITH_HUGE_PAYLOAD=$TEST_HUGE_PAYLOAD \
-DCMAKE_C_FLAGS="$CMAKE_C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" \
-DUSE_SYSTEMD="$USE_SYSTEMD_FLAGS" \
"$WORKSPACE"/iceoryx_meta

cmake --build . --target install -- -j$NUM_JOBS
Expand Down

0 comments on commit aa06475

Please sign in to comment.