Skip to content

Commit

Permalink
Merge branch 'eclipse-iceoryx:master' into iox-692-move-thread-saniti…
Browse files Browse the repository at this point in the history
…zer-job-to-pr-ci
  • Loading branch information
ibrhmkuru authored Feb 15, 2023
2 parents d239fbc + b093d24 commit d58e0d2
Show file tree
Hide file tree
Showing 82 changed files with 1,015 additions and 611 deletions.
11 changes: 5 additions & 6 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
./iceoryx_hoofs/test/moduletests/test_cxx*
./iceoryx_hoofs/source/cxx/*

./iceoryx_hoofs/include/iceoryx_hoofs/internal/units/*
./iceoryx_hoofs/test/moduletests/test_unit*
./iceoryx_hoofs/source/units/*

./iceoryx_hoofs/include/iceoryx_hoofs/internal/memory/*
./iceoryx_hoofs/include/iceoryx_hoofs/memory/*
./iceoryx_hoofs/test/moduletests/test_relative_pointer*
Expand All @@ -28,14 +24,14 @@
./iceoryx_hoofs/test/moduletests/test_log*
./iceoryx_hoofs/test/moduletests/test_console_logger*
./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/logger_mock.hpp
./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure*
./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/testing_logger.hpp
./iceoryx_hoofs/testing/logger.cpp
./iceoryx_hoofs/testing/testing_logger.cpp

./iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/*
./iceoryx_hoofs/source/posix_wrapper/*
./iceoryx_hoofs/source/posix_wrapper/shared_memory_object/*
./iceoryx_hoofs/test/moduletests/test_posix*
./iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/builder.hpp
./iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/polymorphic_handler.hpp
./iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/static_lifetime_guard.hpp

Expand Down Expand Up @@ -67,6 +63,9 @@
./iceoryx_hoofs/buffer/**/*
./iceoryx_hoofs/test/moduletests/test_buffer_*

./iceoryx_hoofs/filesystem/**/*
./iceoryx_hoofs/test/moduletests/test_filesystem_*

# IMPORTANT:
# after the first # everything is considered a comment, add new files and
# directories only at the top of this file
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Build & Test](https://github.com/eclipse-iceoryx/iceoryx/workflows/Build%20&%20Test/badge.svg?branch=master)](https://github.com/eclipse-iceoryx/iceoryx/actions)
[![Integrationtests](https://github.com/eclipse-iceoryx/iceoryx/workflows/Iceoryx%20Integrationtests/badge.svg?branch=master)](https://github.com/eclipse-iceoryx/iceoryx/actions)
[![Gitter](https://badges.gitter.im/eclipse-iceoryx/iceoryx.svg)](https://gitter.im/eclipse/iceoryx)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Codecov](https://codecov.io/gh/eclipse-iceoryx/iceoryx/branch/master/graph/badge.svg?branch=master)](https://codecov.io/gh/eclipse-iceoryx/iceoryx?branch=master)
[![Sanitize](https://github.com/eclipse/iceoryx/workflows/Sanitize/badge.svg?branch=master)](https://github.com/eclipse/iceoryx/actions?query=workflow%3ASanitize)

Expand Down
17 changes: 17 additions & 0 deletions doc/design/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,23 @@ auto errorFunc = [](Error& error) {
func(arg).and_then(successFunc).or_else(errorFunc);
```
### Testing fatal error
For fatal errors the error handler will terminate the execution of the binary. In order to test these paths the
`iox::testing::IOX_EXPECT_FATAL_FAILURE` function should be used instead of the `EXPECT_DEATH` gTest macro.
The `EXPECT_DEATH` gTest macro forks the process which slows down the test execution (especially with the ThreadSanitizer enabled)
and causes issues with running thread. The `IOX_EXPECT_FATAL_FAILURE` registers a temporary error handler and runs the provided
function in a separate thread. When the error handler is called `longjmp` is used to prevent the termination and instead ensures
to gracefully shutdown the thread.
```cpp
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
TEST(MyTest, valueOnNulloptIsFatal) {
iox::optional<bool> sut;
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { sut.value(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED);
}
```

## Open points

### Centralized error handling
Expand Down
23 changes: 12 additions & 11 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
- Move `cxx::static_storage` from `iceoryx_hoofs` to `iceoryx_dust` [\#1732](https://github.com/eclipse-iceoryx/iceoryx/issues/1732)
- Remove `algorithm::uniqueMergeSortedContainers` from `algorithm.hpp`
- Move `std::string` conversion function to `iceoryx_dust` [\#1612](https://github.com/eclipse-iceoryx/iceoryx/issues/1612)
- The posix call `unlink` is directly used in `UnixDomainSocket` [\#1622](https://github.com/eclipse-iceoryx/iceoryx/issues/1622)

**Workflow:**

Expand Down Expand Up @@ -143,7 +144,7 @@
.memorySizeInBytes(16)
.accessMode(iox::posix::AccessMode::READ_WRITE)
.openMode(iox::posix::OpenMode::PURGE_AND_CREATE)
.permissions(cxx::perms::owner_all)
.permissions(perms::owner_all)
.create();
```

Expand Down Expand Up @@ -192,7 +193,7 @@
auto result = iox::posix::NamedSemaphoreBuilder()
.name("mySemaphoreName")
.openMode(iox::posix::OpenMode::OPEN_OR_CREATE)
.permissions(iox::cxx::perms::owner_all)
.permissions(iox::perms::owner_all)
.initialValue(0U)
.create(semaphore);
```
Expand Down Expand Up @@ -268,7 +269,7 @@
// after
auto fileLock = iox::posix::FileLockBuilder().name("lockFileName")
.path("/Now/I/Can/Add/A/Path")
.permission(iox::cxx::perms::owner_all)
.permission(iox::perms::owner_all)
.create()
.expect("Oh no I couldn't create the lock file");
```
Expand Down Expand Up @@ -372,14 +373,14 @@
iox::cxx::isValidPathToFile(..);
iox::cxx::isValidPathToDirectory(..);
iox::cxx::doesEndWithPathSeparator(..);

// after
#include "iceoryx_hoofs/cxx/filesystem.hpp"
iox::cxx::isValidPathEntry(..);
iox::cxx::isValidFileName(..);
iox::cxx::isValidPathToFile(..);
iox::cxx::isValidPathToDirectory(..);
iox::cxx::doesEndWithPathSeparator(..);
#include "iox/filesystem.hpp"
iox::isValidPathEntry(..);
iox::isValidFileName(..);
iox::isValidPathToFile(..);
iox::isValidPathToDirectory(..);
iox::doesEndWithPathSeparator(..);
```

```cpp
Expand Down Expand Up @@ -994,7 +995,7 @@

std::string myStdString("foo");
// std::string to iox::string
iox::string<3> myIoxString = iox::into<iox::string<3>>(myStdString);
iox::string<3> myIoxString = iox::into<iox::lossy<iox::string<3>>>(myStdString);
// iox::string to std::string
std::string myConvertedIoxString = iox::into<std::string>(myIoxString);
```
Expand Down
14 changes: 4 additions & 10 deletions iceoryx_binding_c/source/c_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/cxx/requires.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"

using namespace iox;
Expand All @@ -26,16 +27,9 @@ extern "C" {

void iox_runtime_init(const char* const name)
{
if (name == nullptr)
{
LogError() << "Runtime name is a nullptr!";
std::terminate();
}
else if (strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) > MAX_RUNTIME_NAME_LENGTH)
{
LogError() << "Runtime name has more than 100 characters!";
std::terminate();
}
iox::cxx::Expects(name != nullptr && "Runtime name is a nullptr!");
iox::cxx::Expects(strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) <= MAX_RUNTIME_NAME_LENGTH
&& "Runtime name has more than 100 characters!");

PoshRuntime::initRuntime(RuntimeName_t(iox::TruncateToCapacity, name));
}
Expand Down
6 changes: 5 additions & 1 deletion iceoryx_binding_c/test/moduletests/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_binding_c/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_publisher.hpp"
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp"
#include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp"
#include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
Expand All @@ -37,6 +39,7 @@ extern "C" {
namespace
{
using namespace ::testing;
using namespace iox::testing;
using namespace iox::capro;
using namespace iox::cxx;
using namespace iox::mepoo;
Expand Down Expand Up @@ -137,7 +140,8 @@ TEST(iox_pub_test_DeathTest, initPublisherWithNotInitializedPublisherOptionsTerm
iox_pub_options_t options;
iox_pub_storage_t storage;

EXPECT_DEATH({ iox_pub_init(&storage, "a", "b", "c", &options); }, ".*");
IOX_EXPECT_FATAL_FAILURE<iox::CBindingError>([&] { iox_pub_init(&storage, "a", "b", "c", &options); },
iox::CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED);
}

TEST_F(iox_pub_test, initPublisherWithDefaultOptionsWorks)
Expand Down
13 changes: 11 additions & 2 deletions iceoryx_binding_c/test/moduletests/test_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ extern "C" {
#include "iceoryx_binding_c/runtime.h"
}

#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iceoryx_posh/testing/roudi_gtest.hpp"

namespace
{
using namespace iox;
using namespace iox::runtime;
using namespace iox::testing;

class BindingC_Runtime_test : public RouDi_GTest
{
Expand Down Expand Up @@ -69,13 +72,19 @@ TEST_F(BindingC_Runtime_test, RuntimeNameLengthIsOutOfLimit)
::testing::Test::RecordProperty("TEST_ID", "8fd6735d-f331-4c9c-9a91-3f06d3856d15");
std::string tooLongName(iox::MAX_RUNTIME_NAME_LENGTH + 1, 's');

EXPECT_DEATH({ iox_runtime_init(tooLongName.c_str()); }, ".*");
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>(
[&] {
iox_runtime_init(tooLongName.c_str());
;
},
iox::HoofsError::EXPECTS_ENSURES_FAILED);
}

TEST_F(BindingC_Runtime_test, RuntimeNameIsNullptr)
{
::testing::Test::RecordProperty("TEST_ID", "eb1b76c9-5420-42a9-88b3-db2e36e332de");
EXPECT_DEATH({ iox_runtime_init(nullptr); }, ".*");
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { iox_runtime_init(nullptr); },
iox::HoofsError::EXPECTS_ENSURES_FAILED);
}

TEST_F(BindingC_Runtime_test, GetInstanceNameIsNullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_posh/runtime/service_discovery.hpp"
#include "iceoryx_posh/testing/roudi_gtest.hpp"

using namespace iox;
using namespace iox::runtime;
using namespace iox::testing;

extern "C" {
#include "iceoryx_binding_c/publisher.h"
Expand Down Expand Up @@ -63,7 +66,8 @@ description_vector iox_service_discovery_test::searchResult;
TEST(iox_service_discovery_DeathTest, InitServiceDiscoveryWithNullptrForStorageTerminates)
{
::testing::Test::RecordProperty("TEST_ID", "be551a9e-7dcf-406a-a74c-7dcb1ee16c30");
EXPECT_DEATH({ iox_service_discovery_init(nullptr); }, ".*");
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { iox_service_discovery_init(nullptr); },
iox::HoofsError::EXPECTS_ENSURES_FAILED);
}

/// @note We test only if the arguments of iox_service_discovery_find_service are correctly passed to
Expand Down
9 changes: 6 additions & 3 deletions iceoryx_binding_c/test/moduletests/test_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_binding_c/error_handling/error_handling.hpp"
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp"
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_posh/internal/mepoo/memory_manager.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp"
Expand All @@ -28,6 +30,7 @@

using namespace iox;
using namespace iox::popo;
using namespace iox::testing;

extern "C" {
#include "iceoryx_binding_c/chunk.h"
Expand Down Expand Up @@ -130,14 +133,14 @@ TEST_F(iox_sub_test, initSubscriberWithNullptrForStorageReturnsNullptr)
EXPECT_EQ(iox_sub_init(nullptr, "all", "glory", "hypnotoad", &options), nullptr);
}

// this crashes if the fixture is used, therefore a test without a fixture
TEST(iox_sub_test_DeathTest, initSubscriberWithNotInitializedPublisherOptionsTerminates)
TEST_F(iox_sub_test, initSubscriberWithNotInitializedSubscriberOptionsTerminates)
{
::testing::Test::RecordProperty("TEST_ID", "6a33309e-fe21-45f6-815a-eebe0136c572");
iox_sub_options_t options;
iox_sub_storage_t storage;

EXPECT_DEATH({ iox_sub_init(&storage, "a", "b", "c", &options); }, ".*");
IOX_EXPECT_FATAL_FAILURE<iox::CBindingError>([&] { iox_sub_init(&storage, "a", "b", "c", &options); },
iox::CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED);
}

TEST_F(iox_sub_test, initSubscriberWithDefaultOptionsWorks)
Expand Down
8 changes: 7 additions & 1 deletion iceoryx_dust/include/iceoryx_dust/cxx/std_string_support.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2022 - 2023 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.
Expand Down Expand Up @@ -34,6 +34,12 @@ struct FromImpl<std::string, string<N>>
{
static string<N> fromImpl(const std::string& value) noexcept;
};

template <uint64_t N>
struct FromImpl<std::string, lossy<string<N>>>
{
static string<N> fromImpl(const std::string& value) noexcept;
};
} // namespace iox

#include "iceoryx_dust/internal/cxx/std_string_support.inl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inline T OptionManager::defineOption(T& referenceToMember,
{
constexpr bool IS_NO_SWITCH = false;
m_optionSet.addOption(OptionWithDetails{
{shortName, IS_NO_SWITCH, name, into<Argument_t>(cxx::convert::toString(defaultArgumentValue))},
{shortName, IS_NO_SWITCH, name, into<lossy<Argument_t>>(cxx::convert::toString(defaultArgumentValue))},
description,
optionType,
{cxx::TypeInfo<T>::NAME}});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2022 - 2023 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.
Expand Down Expand Up @@ -27,7 +27,17 @@ inline std::string FromImpl<string<N>, std::string>::fromImpl(const string<N>& v
}

template <uint64_t N>
inline string<N> FromImpl<std::string, string<N>>::fromImpl(const std::string& value) noexcept
inline string<N> FromImpl<std::string, string<N>>::fromImpl(const std::string&) noexcept
{
static_assert(cxx::always_false_v<std::string> && cxx::always_false_v<string<N>>, "\n \
The conversion from 'std::string' to 'iox::sring<N>' is potentially lossy!\n \
This happens when the size of source string exceeds the capacity of the destination string!\n \
Please use 'iox::into<iox::lossy<iox::string<N>>>' which returns a 'iox::string<N>' and truncates the\n \
source string if its size exceeds the capacity of the destination string");
}

template <uint64_t N>
inline string<N> FromImpl<std::string, lossy<string<N>>>::fromImpl(const std::string& value) noexcept
{
return string<N>(TruncateToCapacity, value.c_str(), value.size());
}
Expand Down
Loading

0 comments on commit d58e0d2

Please sign in to comment.