Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iox-#1613 Remove EXPECT_DEATH #2019

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/design/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ TEST(MyTest, valueOnNulloptIsFatal) {
}
```

In cases where the `IOX_EXPECT_FATAL_FAILURE` cannot be used, e.g. testing the `PoshRuntime` with its singleton, `EXPECT_DEATH`
shall be used with `GTEST_FLAG(death_test_style) = "threadsafe";`.

```cpp
GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_DEATH(bad_call(), ".*");
```

## Open points

### Centralized error handling
Expand Down
2 changes: 2 additions & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
- ServiceDescription `Interfaces` and `INTERFACE_NAMES` do not match [\#1977](https://github.com/eclipse-iceoryx/iceoryx/issues/1977)
- Implement and test nullptr check in c binding [\#1106](https://github.com/eclipse-iceoryx/iceoryx/issues/1106)
- Fix `expected<void, Error>` is unusable due to `final` [\#1976](https://github.com/eclipse-iceoryx/iceoryx/issues/1976)
- MacOS tests that use `EXPECT_DEATH` stuck [#898](https://github.com/eclipse-iceoryx/iceoryx/issues/898)
- Remove `EXPECT_DEATH` [#1613](https://github.com/eclipse-iceoryx/iceoryx/issues/1613)

**Refactoring:**

Expand Down
3 changes: 2 additions & 1 deletion iceoryx_posh/source/mepoo/mem_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ MemPool::MemPool(const greater_or_equal<uint32_t, CHUNK_MEMORY_ALIGNMENT> chunkS
else
{
IOX_LOG(FATAL) << "Chunk size must be multiple of '" << CHUNK_MEMORY_ALIGNMENT << "'! Requested size is "
<< chunkSize << " for " << numberOfChunks << " chunks!";
<< static_cast<uint32_t>(chunkSize) << " for " << static_cast<uint32_t>(numberOfChunks)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just discovered that the logger currently does not invoke implicit conversion of greater_or_equal<T> to T correctly due to SFINEA on LogStream& operator<<(const T value) for arithmetic typs. LogStream& operator<<(const bool value) does not have SFINEA so greater_or_equal<uint32> gets implicitly converted into bool. I guess we should replace the SFINEA implementation for arithmetic types with explicit methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elBoberido Can you please open an issue for this?

Copy link
Member Author

@elBoberido elBoberido Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FerdinandSpitzschnueffler I added a task to #1755

<< " chunks!";
errorHandler(PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ TEST(ShmCreatorDeathTest, AllocatingTooMuchMemoryLeadsToExitWithSIGBUS)
TEST_SHM_NAME, iox::posix::AccessMode::READ_WRITE, iox::posix::OpenMode::PURGE_AND_CREATE);
ASSERT_FALSE(badShmProvider.addMemoryBlock(&badmempools).has_error());

GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_DEATH(IOX_DISCARD_RESULT(badShmProvider.create()), ".*");
}

Expand Down
7 changes: 6 additions & 1 deletion iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_hoofs/testing/mocks/logger_mock.hpp"
#include "iceoryx_posh/internal/mepoo/memory_manager.hpp"
#include "iceoryx_posh/mepoo/mepoo_config.hpp"
Expand All @@ -24,6 +26,7 @@
namespace
{
using namespace ::testing;
using namespace iox::testing;

using iox::mepoo::ChunkHeader;
using iox::mepoo::ChunkSettings;
Expand Down Expand Up @@ -472,7 +475,9 @@ TEST_F(MemoryManager_test, addMemPoolWithChunkCountZeroShouldFail)
{
::testing::Test::RecordProperty("TEST_ID", "be653b65-a2d1-42eb-98b5-d161c6ba7c08");
mempoolconf.addMemPool({32, 0});
EXPECT_DEATH({ sut->configureMemoryManager(mempoolconf, *allocator, *allocator); }, ".*");

IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { sut->configureMemoryManager(mempoolconf, *allocator, *allocator); },
iox::HoofsError::EXPECTS_ENSURES_FAILED);
}

TEST(MemoryManagerEnumString_test, asStringLiteralConvertsEnumValuesToStrings)
Expand Down
32 changes: 24 additions & 8 deletions iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_posh/error_handling/error_handling.hpp"
#include "iceoryx_posh/internal/mepoo/mem_pool.hpp"
#include "iox/bump_allocator.hpp"
#include "test.hpp"
Expand All @@ -23,6 +26,7 @@ namespace
{
using namespace ::testing;
using namespace iox::mepoo;
using namespace iox::testing;

class MemPool_test : public Test
{
Expand Down Expand Up @@ -90,16 +94,21 @@ TEST_F(MemPool_test, MempoolCtorWhenChunkSizeIsSmallerThanChunkMemoryAlignmentGe
::testing::Test::RecordProperty("TEST_ID", "52df897a-0847-476c-9d2f-99cb16432199");
constexpr uint32_t CHUNK_SIZE_SMALLER_THAN_MEMORY_ALIGNMENT = iox::mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT - 1U;

EXPECT_DEATH(
{ iox::mepoo::MemPool sut(CHUNK_SIZE_SMALLER_THAN_MEMORY_ALIGNMENT, NUMBER_OF_CHUNKS, allocator, allocator); },
".*");
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>(
[&] {
iox::mepoo::MemPool sut(CHUNK_SIZE_SMALLER_THAN_MEMORY_ALIGNMENT, NUMBER_OF_CHUNKS, allocator, allocator);
},
iox::HoofsError::EXPECTS_ENSURES_FAILED);
}

TEST_F(MemPool_test, MempoolCtorWhenNumberOfChunksIsZeroGetsTerminated)
{
::testing::Test::RecordProperty("TEST_ID", "a5c43e1b-e5b5-4a69-8c4c-8b95752ade8e");
constexpr uint32_t INVALID_NUMBER_OF_CHUNKS = 0U;
EXPECT_DEATH({ iox::mepoo::MemPool sut(CHUNK_SIZE, INVALID_NUMBER_OF_CHUNKS, allocator, allocator); }, ".*");

IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>(
[&] { iox::mepoo::MemPool sut(CHUNK_SIZE, INVALID_NUMBER_OF_CHUNKS, allocator, allocator); },
iox::HoofsError::EXPECTS_ENSURES_FAILED);
}
TEST_F(MemPool_test, GetChunkMethodWhenAllTheChunksAreUsedReturnsNullPointer)
{
Expand Down Expand Up @@ -191,11 +200,12 @@ TEST_F(MemPool_test, FreeChunkMethodWhenSameChunkIsTriedToFreeTwiceReturnsError)
TEST_F(MemPool_test, FreeChunkMethodWhenTheChunkIndexIsInvalidReturnsError)
{
::testing::Test::RecordProperty("TEST_ID", "fb68953e-d47a-4658-8109-6b1974a8baab");
std::vector<uint8_t*> chunks;
iox::vector<uint8_t*, 10> chunks;
constexpr uint32_t INVALID_INDEX{1U};
chunks.push_back(reinterpret_cast<uint8_t*>(sut.getChunk()));

EXPECT_DEATH({ sut.freeChunk(chunks[INVALID_INDEX]); }, ".*");
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { sut.freeChunk(chunks[INVALID_INDEX]); },
iox::HoofsError::EXPECTS_ENSURES_FAILED);
}

TEST_F(MemPool_test, GetMinFreeMethodReturnsTheNumberOfFreeChunks)
Expand All @@ -212,13 +222,19 @@ TEST_F(MemPool_test, GetMinFreeMethodReturnsTheNumberOfFreeChunks)
TEST_F(MemPool_test, dieWhenMempoolChunkSizeIsSmallerThan32Bytes)
{
::testing::Test::RecordProperty("TEST_ID", "7704246e-42b5-46fd-8827-ebac200390e1");
EXPECT_DEATH({ iox::mepoo::MemPool sut(12, 10, allocator, allocator); }, ".*");

IOX_EXPECT_FATAL_FAILURE<iox::PoshError>(
[&] { iox::mepoo::MemPool sut(12, 10, allocator, allocator); },
iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT);
}

TEST_F(MemPool_test, dieWhenMempoolChunkSizeIsNotPowerOf32)
{
::testing::Test::RecordProperty("TEST_ID", "6a354976-235a-4a94-8af2-2bc872f705f4");
EXPECT_DEATH({ iox::mepoo::MemPool sut(333, 10, allocator, allocator); }, ".*");

IOX_EXPECT_FATAL_FAILURE<iox::PoshError>(
[&] { iox::mepoo::MemPool sut(333, 10, allocator, allocator); },
iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT);
}

} // namespace
5 changes: 5 additions & 0 deletions iceoryx_posh/test/moduletests/test_posh_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ TEST_F(PoshRuntime_test, NoAppName)
::testing::Test::RecordProperty("TEST_ID", "e053d114-c79c-4391-91e1-8fcfe90ee8e4");
const iox::RuntimeName_t invalidAppName("");

GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_DEATH({ PoshRuntime::initRuntime(invalidAppName); }, "");
}

Expand All @@ -161,6 +162,7 @@ TEST(PoshRuntime, RuntimeFailsWhenAppNameIsNotAFileName)
{
const iox::RuntimeName_t invalidAppName(iox::TruncateToCapacity, i);

GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_DEATH(PoshRuntime::initRuntime(invalidAppName), ".*");
}
}
Expand All @@ -171,6 +173,8 @@ TEST(PoshRuntime, RuntimeFailsWhenAppNameIsNotAFileName)
TEST(PoshRuntime, AppNameEmpty)
{
::testing::Test::RecordProperty("TEST_ID", "63900656-4fbb-466d-b6cc-f2139121092c");

GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_DEATH({ iox::runtime::PoshRuntime::getInstance(); }, ".*");
}

Expand Down Expand Up @@ -1138,6 +1142,7 @@ TEST(PoshRuntimeFactory_test, SetEmptyRuntimeFactoryFails)
auto mockRuntime = PoshRuntimeMock::create("hypnotoad");

// do not use the setRuntimeFactory in a test with a running RouDiEnvironment
GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_DEATH(
{
class FactoryAccess : public PoshRuntime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// SPDX-License-Identifier: Apache-2.0

#if !defined(_WIN32)
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_posh/error_handling/error_handling.hpp"
#include "iceoryx_posh/internal/runtime/ipc_interface_creator.hpp"

#include "test.hpp"
Expand All @@ -27,6 +29,7 @@ using namespace ::testing;
using namespace iox;
using namespace iox::posix;
using namespace iox::runtime;
using namespace iox::testing;

constexpr char goodName[] = "channel_test";
constexpr char anotherGoodName[] = "horst";
Expand Down Expand Up @@ -67,7 +70,9 @@ TEST_F(IpcInterfaceCreator_test, CreateWithSameNameLeadsToError)
{
::testing::Test::RecordProperty("TEST_ID", "2e8c15c8-1b7b-465b-aae5-6db24fc3c34a");
IpcInterfaceCreator m_sut{goodName};
EXPECT_DEATH({ IpcInterfaceCreator m_sut2{goodName}; }, ".*");

IOX_EXPECT_FATAL_FAILURE<iox::PoshError>([&] { IpcInterfaceCreator m_sut2{goodName}; },
iox::PoshError::IPC_INTERFACE__APP_WITH_SAME_NAME_STILL_RUNNING);
}

} // namespace
Expand Down
Loading