Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1030 Add builder for minimal 'RouDiConfig_t'
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 5, 2023
1 parent 0471df8 commit 7299cd1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "iceoryx_posh/popo/publisher.hpp"
#include "iceoryx_posh/popo/subscriber.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
#include "iceoryx_posh/testing/roudi_environment/minimal_roudi_config.hpp"
#include "iceoryx_posh/testing/roudi_gtest.hpp"
#include "iox/optional.hpp"
#include "iox/stack.hpp"
Expand All @@ -38,6 +39,7 @@ using namespace ::testing;
using namespace iox;
using namespace iox::popo;
using namespace iox::cxx;
using namespace iox::testing;

template <typename T>
struct ComplexDataType
Expand All @@ -49,6 +51,11 @@ struct ComplexDataType
class PublisherSubscriberCommunication_test : public RouDi_GTest
{
public:
PublisherSubscriberCommunication_test()
: RouDi_GTest(MinimalRouDiConfigBuilder().chunk_size(512).chunk_count(10).create())
{
}

void SetUp()
{
runtime::PoshRuntime::initRuntime("PublisherSubscriberCommunication_test");
Expand Down Expand Up @@ -463,7 +470,7 @@ TEST_F(PublisherSubscriberCommunication_test, SendingComplexDataType_string)
TEST_F(PublisherSubscriberCommunication_test, SendingComplexDataType_vector)
{
::testing::Test::RecordProperty("TEST_ID", "fdfe4d05-c61a-4a99-b0b7-5e79da2700d5");
using Type_t = ComplexDataType<vector<string<128>, 20>>;
using Type_t = ComplexDataType<vector<string<64>, 5>>;
auto publisher = createPublisher<Type_t>();
auto subscriber = createSubscriber<Type_t>();

Expand Down Expand Up @@ -491,7 +498,7 @@ TEST_F(PublisherSubscriberCommunication_test, SendingComplexDataType_vector)
TEST_F(PublisherSubscriberCommunication_test, SendingComplexDataType_variant)
{
::testing::Test::RecordProperty("TEST_ID", "0b5688ff-2367-4c76-93a2-6e447403c5ed");
using Type_t = ComplexDataType<vector<variant<string<128>, int>, 20>>;
using Type_t = ComplexDataType<vector<variant<string<64>, int>, 5>>;
auto publisher = createPublisher<Type_t>();
auto subscriber = createSubscriber<Type_t>();

Expand Down
1 change: 1 addition & 0 deletions iceoryx_posh/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if(ROUDI_ENVIRONMENT OR BUILD_TEST)
iceoryx_posh::iceoryx_posh_roudi
iceoryx_hoofs_testing::iceoryx_hoofs_testing
FILES
roudi_environment/minimal_roudi_config.cpp
roudi_environment/runtime_test_interface.cpp
roudi_environment/roudi_environment.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 by Mathias Kraus <elboberido@m-hias.de>. 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

#ifndef IOX_POSH_ROUDI_ENVIRONMENT_MINIMAL_ROUDI_CONFIG_HPP
#define IOX_POSH_ROUDI_ENVIRONMENT_MINIMAL_ROUDI_CONFIG_HPP

#include "iceoryx_posh/iceoryx_posh_config.hpp"
#include "iox/builder.hpp"

namespace iox
{
namespace testing
{
/// @brief Builder for a minimal RouDiConfig_t with only one MemPool. This significantly speeds up tests which create a
/// shared memory.
class MinimalRouDiConfigBuilder
{
/// @brief Set the chunk size. Default = 128
IOX_BUILDER_PARAMETER(uint32_t, chunk_size, 128)
/// @brief Set the chunk count. Default = 10
IOX_BUILDER_PARAMETER(uint32_t, chunk_count, 10)

public:
/// @brief creates the previously configured RouDiConfig_t
RouDiConfig_t create() const noexcept;
};
} // namespace testing
} // namespace iox

#endif // IOX_POSH_ROUDI_ENVIRONMENT_MINIMAL_ROUDI_CONFIG_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RouDi_GTest : public iox::roudi::RouDiEnvironment, public Test
{
public:
RouDi_GTest() = default;
RouDi_GTest(iox::RouDiConfig_t& roudiConfig)
RouDi_GTest(const iox::RouDiConfig_t& roudiConfig)
: iox::roudi::RouDiEnvironment(roudiConfig)
{
}
Expand Down
33 changes: 33 additions & 0 deletions iceoryx_posh/testing/roudi_environment/minimal_roudi_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023 by Mathias Kraus <elboberido@m-hias.de>. 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

#include "iceoryx_posh/testing/roudi_environment/minimal_roudi_config.hpp"

namespace iox
{
namespace testing
{
RouDiConfig_t MinimalRouDiConfigBuilder::create() const noexcept
{
RouDiConfig_t roudiConfig;
mepoo::MePooConfig mepooConfig;
mepooConfig.addMemPool({m_chunk_size, m_chunk_count});
auto currentGroup = iox::posix::PosixGroup::getGroupOfCurrentProcess();
roudiConfig.m_sharedMemorySegments.push_back({currentGroup.getName(), currentGroup.getName(), mepooConfig});
return roudiConfig;
}
} // namespace testing
} // namespace iox

0 comments on commit 7299cd1

Please sign in to comment.