Skip to content

Commit

Permalink
iox-eclipse-iceoryx#624 adjusted port pool test to check its created …
Browse files Browse the repository at this point in the history
…products

Signed-off-by: Christian Eltzschig <me@elchris.org>
  • Loading branch information
elfenpiff committed Mar 23, 2021
1 parent a75490a commit 01bc772
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 32 deletions.
1 change: 1 addition & 0 deletions iceoryx_posh/test/moduletests/test_gw_channel.cpp
Expand Up @@ -55,4 +55,5 @@ TEST_F(ChannelTest, ReturnsEmptyOptionalIfObjectPoolExhausted)
{
auto channel = iox::gw::Channel<StubbedIceoryxTerminal, StubbedExternalTerminal>::create(
{"", "", ""}, StubbedIceoryxTerminal::Options());
EXPECT_FALSE(channel.has_error());
}
5 changes: 5 additions & 0 deletions iceoryx_posh/test/moduletests/test_mepoo_typed_mempool.cpp
Expand Up @@ -87,6 +87,7 @@ TEST_F(TypedMemPool_test, ReleaseChunkWhenGoingOutOfScope)
{
{
auto object = sut.createObject(1, 234);
EXPECT_FALSE(object.has_error());
EXPECT_THAT(sut.getUsedChunks(), Eq(1));
}
EXPECT_THAT(sut.getUsedChunks(), Eq(0));
Expand All @@ -99,6 +100,10 @@ TEST_F(TypedMemPool_test, OutOfChunksErrorWhenFull)
auto object3 = sut.createObject(0xaffe, 0xdead);
auto object4 = sut.createObject(0xaffe, 0xdead);

EXPECT_FALSE(object1.has_error());
EXPECT_FALSE(object2.has_error());
EXPECT_FALSE(object3.has_error());

EXPECT_THAT(object4.has_error(), Eq(true));
EXPECT_THAT(object4.get_error(), Eq(TypedMemPoolError::OutOfChunks));
}
Expand Down
3 changes: 3 additions & 0 deletions iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp
Expand Up @@ -511,10 +511,13 @@ TEST_F(PublisherPort_test, cleanupReleasesAllChunks)
// allocate some samples
auto maybeChunkHeader1 = m_sutWithHistoryUserSide.tryAllocateChunk(
sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT);
EXPECT_FALSE(maybeChunkHeader1.has_error());
auto maybeChunkHeader2 = m_sutWithHistoryUserSide.tryAllocateChunk(
sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT);
EXPECT_FALSE(maybeChunkHeader2.has_error());
auto maybeChunkHeader3 = m_sutWithHistoryUserSide.tryAllocateChunk(
sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT);
EXPECT_FALSE(maybeChunkHeader3.has_error());

m_sutWithHistoryRouDiSide.releaseAllChunks();

Expand Down
Expand Up @@ -26,7 +26,6 @@ namespace iox
{
namespace test
{

/// @brief This test file verifies that the BaseClass IceoryxRouDiMemoryManager is tested
class IceoryxRoudiMemoryManager_test : public Test
{
Expand All @@ -35,8 +34,8 @@ class IceoryxRoudiMemoryManager_test : public Test

void SetUp() override
{
auto config = iox::RouDiConfig_t().setDefaults();
m_roudiMemoryManagerTest = std::unique_ptr<IceOryxRouDiMemoryManager>(new IceOryxRouDiMemoryManager(config));
auto config = iox::RouDiConfig_t().setDefaults();
m_roudiMemoryManagerTest = std::unique_ptr<IceOryxRouDiMemoryManager>(new IceOryxRouDiMemoryManager(config));
}

void TearDown() override
Expand Down Expand Up @@ -112,6 +111,7 @@ TEST_F(IceoryxRoudiMemoryManager_test, AcquiringPortPoolAfterCreateAndAnnounceMe
TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryReturnNoError)
{
auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory();
EXPECT_FALSE(testResult.has_error());

auto result = m_roudiMemoryManagerTest->destroyMemory();

Expand All @@ -121,8 +121,10 @@ TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryReturnNoError)
TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryIntrospectionMemoryManagerReturnNullOpt)
{
auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory();
ASSERT_FALSE(testResult.has_error());

auto result = m_roudiMemoryManagerTest->destroyMemory();
ASSERT_FALSE(result.has_error());

auto res = m_roudiMemoryManagerTest->introspectionMemoryManager();
EXPECT_THAT(res, Eq(iox::cxx::nullopt_t()));
Expand All @@ -131,8 +133,10 @@ TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryIntrospectionMemoryManagerRe
TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemorySegmentManagerReturnNullOpt)
{
auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory();
ASSERT_FALSE(testResult.has_error());

auto result = m_roudiMemoryManagerTest->destroyMemory();
ASSERT_FALSE(result.has_error());

auto resultTest = m_roudiMemoryManagerTest->segmentManager();
EXPECT_THAT(resultTest, Eq(iox::cxx::nullopt_t()));
Expand All @@ -141,6 +145,7 @@ TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemorySegmentManagerReturnNullOpt)
TEST_F(IceoryxRoudiMemoryManager_test, CreateAndAnnouceMemoryFailingAfterCalledTwoTimes)
{
auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory();
ASSERT_FALSE(testResult.has_error());

auto result = m_roudiMemoryManagerTest->createAndAnnounceMemory();

Expand All @@ -151,13 +156,15 @@ TEST_F(IceoryxRoudiMemoryManager_test, CreateAndAnnouceMemoryFailingAfterCalledT
TEST_F(IceoryxRoudiMemoryManager_test, DestroyMemoryNotFailingAfterCalledTwoTimes)
{
auto testResult = m_roudiMemoryManagerTest->createAndAnnounceMemory();
ASSERT_FALSE(testResult.has_error());

auto result = m_roudiMemoryManagerTest->destroyMemory();
ASSERT_FALSE(result.has_error());

auto res = m_roudiMemoryManagerTest->destroyMemory();

EXPECT_THAT(res.has_error(), Eq(false));
}

} // namespace test
} // iox
} // namespace test
} // namespace iox
62 changes: 37 additions & 25 deletions iceoryx_posh/test/moduletests/test_roudi_portpool.cpp
Expand Up @@ -293,16 +293,7 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful)

TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError)
{
auto errorHandlerCalled{false};
Error errorHandlerType;
auto errorHandlerGuard =
ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function<void()>, const ErrorLevel) {
errorHandlerType = error;
errorHandlerCalled = true;
});

for (uint32_t i = 0U; i <= MAX_SUBSCRIBERS; ++i)
{
auto addSubscriberPort = [&](const uint32_t i) -> bool {
std::string service = "service" + std::to_string(i);
std::string instance = "instance" + std::to_string(i);
ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)};
Expand All @@ -312,15 +303,31 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError)
{IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)},
applicationName,
m_subscriberOptions);
return publisherPort.has_error();
};

for (uint32_t i = 0U; i < MAX_SUBSCRIBERS; ++i)
{
EXPECT_FALSE(addSubscriberPort(i));
}

auto errorHandlerCalled{false};
Error errorHandlerType;
auto errorHandlerGuard =
ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function<void()>, const ErrorLevel) {
errorHandlerType = error;
errorHandlerCalled = true;
});
EXPECT_TRUE(addSubscriberPort(MAX_SUBSCRIBERS));

EXPECT_TRUE(errorHandlerCalled);
EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW);
}

TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful)
{
auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions);
EXPECT_FALSE(subscriberPort.has_error());
auto subscriberPortDataList = sut.getSubscriberPortDataList();

ASSERT_EQ(subscriberPortDataList.size(), 1U);
Expand All @@ -345,6 +352,7 @@ TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful)
{IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)},
applicationName,
m_subscriberOptions);
EXPECT_FALSE(publisherPort.has_error());
}
auto subscriberPortDataList = sut.getSubscriberPortDataList();

Expand Down Expand Up @@ -383,18 +391,19 @@ TEST_F(PortPool_test, AddInterfacePortWithMaxCapacityIsSuccessful)

TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError)
{
for (uint32_t i = 0U; i < MAX_INTERFACE_NUMBER; ++i)
{
EXPECT_FALSE(sut.addInterfacePort(m_applicationName, Interfaces::INTERFACE_END).has_error());
}

auto errorHandlerCalled{false};
Error errorHandlerType;
auto errorHandlerGuard =
ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function<void()>, const ErrorLevel) {
errorHandlerType = error;
errorHandlerCalled = true;
});

for (uint32_t i = 0U; i <= MAX_INTERFACE_NUMBER; ++i)
{
auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL);
}
EXPECT_TRUE(sut.addInterfacePort(m_applicationName, Interfaces::INTERFACE_END).has_error());

EXPECT_TRUE(errorHandlerCalled);
EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW);
Expand All @@ -403,6 +412,7 @@ TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError)
TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful)
{
auto interfacePort = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL);
EXPECT_FALSE(interfacePort.has_error());
auto interfacePortDataList = sut.getInterfacePortDataList();

ASSERT_EQ(interfacePortDataList.size(), 1U);
Expand Down Expand Up @@ -458,18 +468,19 @@ TEST_F(PortPool_test, AddApplicationPortWithMaxCapacityIsSuccessful)

TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError)
{
for (uint32_t i = 0U; i < MAX_PROCESS_NUMBER; ++i)
{
EXPECT_FALSE(sut.addApplicationPort(m_applicationName).has_error());
}

auto errorHandlerCalled{false};
Error errorHandlerType;
auto errorHandlerGuard =
ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function<void()>, const ErrorLevel) {
errorHandlerType = error;
errorHandlerCalled = true;
});

for (uint32_t i = 0U; i <= MAX_PROCESS_NUMBER; ++i)
{
auto applicationData = sut.addApplicationPort(m_applicationName);
}
EXPECT_TRUE(sut.addApplicationPort(m_applicationName).has_error());

EXPECT_TRUE(errorHandlerCalled);
EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__APPLICATIONLIST_OVERFLOW);
Expand Down Expand Up @@ -533,18 +544,19 @@ TEST_F(PortPool_test, AddConditionVariableDataWithMaxCapacityIsSuccessful)

TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError)
{
for (uint32_t i = 0U; i < MAX_NUMBER_OF_CONDITION_VARIABLES; ++i)
{
EXPECT_FALSE(sut.addConditionVariableData(m_applicationName).has_error());
}

auto errorHandlerCalled{false};
Error errorHandlerType;
auto errorHandlerGuard =
ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function<void()>, const ErrorLevel) {
errorHandlerType = error;
errorHandlerCalled = true;
});

for (uint32_t i = 0U; i <= MAX_NUMBER_OF_CONDITION_VARIABLES; ++i)
{
auto conditionVariableData = sut.addConditionVariableData(m_applicationName);
}
EXPECT_TRUE(sut.addConditionVariableData(m_applicationName).has_error());

EXPECT_TRUE(errorHandlerCalled);
EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW);
Expand Down
13 changes: 12 additions & 1 deletion iceoryx_utils/include/iceoryx_utils/cxx/helplets.hpp
Expand Up @@ -257,8 +257,19 @@ using BestFittingType_t = typename BestFittingType<Value>::Type_t;
/// @endcode
#define IOX_DISCARD_RESULT(expr) static_cast<void>(expr) // NOLINT

// the __attribute__((warn_unused)) is even stronger than [[nodiscard]] therefore we prefer it
// whenever possible
#if defined(__GNUC__) || defined(__clang__)
#define IOX_NO_DISCARD __attribute__((warn_unused)) // NOLINT
#else
// on Mac OS and WIN32 we are using C++17 which makes the keyword [[nodiscard]] available
#if defined(__APPLE__) || defined(_WIN32)
#define IOX_NO_DISCARD [[nodiscard]] // NOLINT

// on an unknown platform we use for now nothing since we do not know what
#else
#define IOX_NO_DISCARD
#endif
#endif
/// @brief Returns info whether called on a 32-bit system
/// @return True if called on 32-bit, false if not 32-bit system
constexpr bool isCompiledOn32BitSystem()
Expand Down
12 changes: 12 additions & 0 deletions iceoryx_utils/test/moduletests/test_cxx_expected.cpp
Expand Up @@ -185,6 +185,7 @@ TEST_F(expected_test, CreateWithValueAndMoveCtorLeadsToInvalidState)
{
auto sut = expected<int, TestClass>::create_value(177);
auto movedValue{std::move(sut)};
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState()));
}
Expand All @@ -193,6 +194,7 @@ TEST_F(expected_test, CreateWithErrorAndMoveCtorLeadsToInvalidState)
{
auto sut = expected<int, TestClass>::create_error(22, 33);
auto movedValue{std::move(sut)};
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState()));
}
Expand All @@ -201,6 +203,7 @@ TEST_F(expected_test, CreateWithValueAndMoveAssignmentLeadsToInvalidState)
{
auto sut = expected<int, TestClass>::create_value(73);
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState()));
}
Expand All @@ -209,6 +212,7 @@ TEST_F(expected_test, CreateWithErrorAndMoveAssignmentLeadsToInvalidState)
{
auto sut = expected<int, TestClass>::create_error(44, 55);
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestClassAdapter::getInvalidState()));
}
Expand All @@ -217,6 +221,7 @@ TEST_F(expected_test, CreateInvalidExpectedAndCallGetErrorLeadsToInvalidState)
{
auto sut = expected<int, TestError>::create_error(TestError::ERROR1);
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE));
}
Expand All @@ -225,6 +230,7 @@ TEST_F(expected_test, ErrorTypeOnlyCreateInvalidExpectedAndCallGetErrorLeadsToIn
{
auto sut = expected<TestError>::create_error(TestError::ERROR2);
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE));
}
Expand Down Expand Up @@ -326,6 +332,7 @@ TEST_F(expected_test, ErrorTypeOnlyMoveCtorLeadsToInvalidState)
{
auto sut = expected<TestError>::create_error(TestError::ERROR2);
auto movedValue{std::move(sut)};
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE));
}
Expand All @@ -334,6 +341,7 @@ TEST_F(expected_test, ErrorTypeOnlyMoveAssignmentLeadsToInvalidState)
{
auto sut = expected<TestError>::create_error(TestError::ERROR1);
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
ASSERT_TRUE(sut.has_error());
EXPECT_THAT(sut.get_error(), Eq(TestError::INVALID_STATE));
}
Expand Down Expand Up @@ -440,6 +448,7 @@ TEST_F(expected_test, WhenHavingSuccessAndMoveAssignmentCallsOrElse)
{
expected<int, TestError> sut{success<int>(1143)};
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
TestError error{TestError::ERROR1};
sut.and_then([&](auto&) { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; });
EXPECT_THAT(error, Eq(TestError::INVALID_STATE));
Expand All @@ -449,6 +458,7 @@ TEST_F(expected_test, WhenHavingAnErrorAndMoveAssignmentCallsOrElse)
{
expected<int, TestError> sut{error<TestError>(TestError::ERROR1)};
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
TestError error{TestError::ERROR1};
sut.and_then([&](auto&) { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; });
EXPECT_THAT(error, Eq(TestError::INVALID_STATE));
Expand All @@ -458,6 +468,7 @@ TEST_F(expected_test, ErrorTypeOnlyWhenHavingSuccessAndMoveAssignmentCallsOrElse
{
expected<TestError> sut{success<>()};
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
TestError error{TestError::ERROR1};
sut.and_then([&]() { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; });
EXPECT_THAT(error, Eq(TestError::INVALID_STATE));
Expand All @@ -467,6 +478,7 @@ TEST_F(expected_test, ErrorTypeOnlyWhenHavingAnErrorAndMoveAssignmentCallsOrElse
{
expected<TestError> sut{error<TestError>(TestError::ERROR1)};
auto movedValue = std::move(sut);
IOX_DISCARD_RESULT(movedValue);
TestError error{TestError::ERROR1};
sut.and_then([&]() { error = TestError::ERROR2; }).or_else([&](auto& e) { error = e; });
EXPECT_THAT(error, Eq(TestError::INVALID_STATE));
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_utils/test/moduletests/test_posix_file_lock.cpp
Expand Up @@ -84,7 +84,7 @@ TEST_F(FileLock_test, SecondLockWithDifferentNameWorks)
TEST_F(FileLock_test, LockAndReleaseWorks)
{
{
auto sut1 = iox::posix::FileLock::create(ANOTHER_TEST_NAME);
IOX_DISCARD_RESULT(iox::posix::FileLock::create(ANOTHER_TEST_NAME));
}
auto sut2 = iox::posix::FileLock::create(ANOTHER_TEST_NAME);
ASSERT_FALSE(sut2.has_error());
Expand Down

0 comments on commit 01bc772

Please sign in to comment.