Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2128 Support configuring shm segment names
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Palmer committed Jan 9, 2024
1 parent 53ad6ab commit 8783545
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 28 deletions.
2 changes: 1 addition & 1 deletion doc/design/draft/named-segments.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ In order to determine which segments to map:

## Development Roadmap

- [ ] Extend the RouDi config to support specifying segment names to be added to the `SegmentConfig`
- [x] Extend the RouDi config to support specifying segment names to be added to the `SegmentConfig`
- [ ] Update the `SegmentManager` to use the name in the `SegmentConfig` instead of the writer group
- [ ] Add the name to the `MePooSegment` data structure and populate it based on the `SegmentConfig`
- [ ] Update producer options structs to include segment names
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_examples/iceperf/roudi_main_static_config.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 @@ -53,7 +54,7 @@ int main(int argc, char* argv[])
auto currentGroup = iox::PosixGroup::getGroupOfCurrentProcess();

/// Create an Entry for a new Shared Memory Segment from the MempoolConfig and add it to the RouDiConfig
roudiConfig.m_sharedMemorySegments.push_back({currentGroup.getName(), currentGroup.getName(), mepooConfig});
roudiConfig.m_sharedMemorySegments.emplace_back(currentGroup.getName(), currentGroup.getName(), currentGroup.getName(), mepooConfig);

/// For the case that you want to give accessrights to the shm segments, you need to set groupnames as fixed string.
/// These names defines groups whose members are either to read/write from/to the respective shared memory segment.
Expand Down
8 changes: 6 additions & 2 deletions iceoryx_posh/include/iceoryx_posh/mepoo/segment_config.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2023 by Latitude AI. 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 @@ -31,18 +32,21 @@ struct SegmentConfig
{
struct SegmentEntry
{
SegmentEntry(const PosixGroup::groupName_t& readerGroup,
SegmentEntry(const ShmName_t& name,
const PosixGroup::groupName_t& readerGroup,
const PosixGroup::groupName_t& writerGroup,
const MePooConfig& memPoolConfig,
iox::mepoo::MemoryInfo memoryInfo = iox::mepoo::MemoryInfo()) noexcept
: m_readerGroup(readerGroup)
: m_name(name)
, m_readerGroup(readerGroup)
, m_writerGroup(writerGroup)
, m_mempoolConfig(memPoolConfig)
, m_memoryInfo(memoryInfo)

{
}

ShmName_t m_name;
PosixGroup::groupName_t m_readerGroup;
PosixGroup::groupName_t m_writerGroup;
MePooConfig m_mempoolConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 @@ -35,6 +36,8 @@ namespace roudi
/// MAX_NUMBER_OF_MEMPOOLS_PER_SEGMENT_EXCEEDED - the max number of mempools per segment is exceeded
/// MEMPOOL_WITHOUT_CHUNK_SIZE - chunk size not specified for the mempool
/// MEMPOOL_WITHOUT_CHUNK_COUNT - chunk count not specified for the mempool
/// EXCEPTION_IN_PARSER - An exception occurred in the toml file parsing library
/// NAMED_SEGMENT_IN_V1_CONFIG - A segment name was specified in a v1 config
enum class RouDiConfigFileParseError
{
FILE_OPEN_FAILED,
Expand All @@ -46,7 +49,8 @@ enum class RouDiConfigFileParseError
MAX_NUMBER_OF_MEMPOOLS_PER_SEGMENT_EXCEEDED,
MEMPOOL_WITHOUT_CHUNK_SIZE,
MEMPOOL_WITHOUT_CHUNK_COUNT,
EXCEPTION_IN_PARSER
EXCEPTION_IN_PARSER,
NAMED_SEGMENT_IN_V1_CONFIG,
};

constexpr const char* ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS[] = {"FILE_OPEN_FAILED",
Expand All @@ -58,7 +62,8 @@ constexpr const char* ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS[] = {"FILE_OPEN_FAIL
"MAX_NUMBER_OF_MEMPOOLS_PER_SEGMENT_EXCEEDED",
"MEMPOOL_WITHOUT_CHUNK_SIZE",
"MEMPOOL_WITHOUT_CHUNK_COUNT",
"EXCEPTION_IN_PARSER"};
"EXCEPTION_IN_PARSER",
"NAMED_SEGMENT_IN_V1_CONFIG"};

/// @brief Base class for a config file provider.
class RouDiConfigFileProvider
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_posh/roudi_env/source/minimal_roudi_config.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2023 by Mathias Kraus <[email protected]>. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 @@ -26,7 +27,7 @@ RouDiConfig_t MinimalRouDiConfigBuilder::create() const noexcept
mepoo::MePooConfig mepooConfig;
mepooConfig.addMemPool({m_payloadChunkSize, m_payloadChunkCount});
auto currentGroup = PosixGroup::getGroupOfCurrentProcess();
roudiConfig.m_sharedMemorySegments.push_back({currentGroup.getName(), currentGroup.getName(), mepooConfig});
roudiConfig.m_sharedMemorySegments.emplace_back(currentGroup.getName(), currentGroup.getName(), currentGroup.getName(), mepooConfig);

roudiConfig.introspectionChunkCount = m_introspectionChunkCount;
roudiConfig.discoveryChunkCount = m_discoveryChunkCount;
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_posh/source/mepoo/segment_config.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 All @@ -24,7 +25,7 @@ namespace mepoo
SegmentConfig& SegmentConfig::setDefaults() noexcept
{
auto groupName = PosixGroup::getGroupOfCurrentProcess().getName();
m_sharedMemorySegments.push_back({groupName, groupName, MePooConfig().setDefaults()});
m_sharedMemorySegments.emplace_back(groupName, groupName, groupName, MePooConfig().setDefaults());
return *this;
}

Expand Down
18 changes: 13 additions & 5 deletions iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2022 by Apex AI Inc. All rights reserved.
// Copyright (c) 2022 by NXP. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 @@ -108,7 +109,7 @@ TomlRouDiConfigFileProvider::parse(std::istream& stream) noexcept
return iox::err(iox::roudi::RouDiConfigFileParseError::NO_GENERAL_SECTION);
}
auto configFileVersion = general->get_as<uint32_t>("version");
if (!configFileVersion || *configFileVersion != 1)
if (!configFileVersion || *configFileVersion == 0 || *configFileVersion > 2U)
{
return iox::err(iox::roudi::RouDiConfigFileParseError::INVALID_CONFIG_FILE_VERSION);
}
Expand All @@ -128,6 +129,12 @@ TomlRouDiConfigFileProvider::parse(std::istream& stream) noexcept
iox::RouDiConfig_t parsedConfig;
for (auto segment : *segments)
{
auto maybe_name = segment->get_as<std::string>("name");
if (maybe_name && *configFileVersion == 1U)
{
return iox::err(iox::roudi::RouDiConfigFileParseError::NAMED_SEGMENT_IN_V1_CONFIG);
}
auto name = maybe_name.value_or(into<std::string>(groupOfCurrentProcess));
auto writer = segment->get_as<std::string>("writer").value_or(into<std::string>(groupOfCurrentProcess));
auto reader = segment->get_as<std::string>("reader").value_or(into<std::string>(groupOfCurrentProcess));
iox::mepoo::MePooConfig mempoolConfig;
Expand Down Expand Up @@ -156,10 +163,11 @@ TomlRouDiConfigFileProvider::parse(std::istream& stream) noexcept
}
mempoolConfig.addMemPool({*chunkSize, *chunkCount});
}
parsedConfig.m_sharedMemorySegments.push_back(
{PosixGroup::groupName_t(iox::TruncateToCapacity, reader.c_str(), reader.size()),
PosixGroup::groupName_t(iox::TruncateToCapacity, writer.c_str(), writer.size()),
mempoolConfig});
parsedConfig.m_sharedMemorySegments.emplace_back(
ShmName_t(iox::TruncateToCapacity, name.c_str(), name.size()),
PosixGroup::groupName_t(iox::TruncateToCapacity, reader.c_str(), reader.size()),
PosixGroup::groupName_t(iox::TruncateToCapacity, writer.c_str(), writer.size()),
mempoolConfig);
}

return iox::ok(parsedConfig);
Expand Down
11 changes: 6 additions & 5 deletions iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 @@ -68,16 +69,16 @@ class SegmentManager_test : public Test
SegmentConfig getSegmentConfig()
{
SegmentConfig config;
config.m_sharedMemorySegments.push_back({"iox_roudi_test1", "iox_roudi_test2", mepooConfig});
config.m_sharedMemorySegments.push_back({"iox_roudi_test2", "iox_roudi_test3", mepooConfig});
config.m_sharedMemorySegments.emplace_back("segment_name1", "iox_roudi_test1", "iox_roudi_test2", mepooConfig);
config.m_sharedMemorySegments.emplace_back("segment_name2", "iox_roudi_test2", "iox_roudi_test3", mepooConfig);
return config;
}

SegmentConfig getInvalidSegmentConfig()
{
SegmentConfig config;
config.m_sharedMemorySegments.push_back({"iox_roudi_test1", "iox_roudi_test1", mepooConfig});
config.m_sharedMemorySegments.push_back({"iox_roudi_test3", "iox_roudi_test1", mepooConfig});
config.m_sharedMemorySegments.emplace_back("segment_name1", "iox_roudi_test1", "iox_roudi_test1", mepooConfig);
config.m_sharedMemorySegments.emplace_back("segment_name2", "iox_roudi_test3", "iox_roudi_test1", mepooConfig);
return config;
}

Expand All @@ -86,7 +87,7 @@ class SegmentManager_test : public Test
SegmentConfig config;
for (uint64_t i = 0U; i < iox::MAX_SHM_SEGMENTS; ++i)
{
config.m_sharedMemorySegments.push_back({"iox_roudi_test1", "iox_roudi_test1", mepooConfig});
config.m_sharedMemorySegments.emplace_back("segment_name1", "iox_roudi_test1", "iox_roudi_test1", mepooConfig);
}
return config;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2021 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 @@ -67,7 +68,20 @@ TEST_F(RoudiConfigTomlFileProvider_test, InvalidPathResultsInError)
[](const auto& error) { EXPECT_THAT(error, Eq(iox::roudi::RouDiConfigFileParseError::FILE_OPEN_FAILED)); });
}

TEST_F(RoudiConfigTomlFileProvider_test, ParsingFileIsSuccessful)
constexpr const char* CONFIG_V1_SIMPLE = R"(
[general]
version = 1
[[segment]]
writer = "writer"
reader = "reader"
[[segment.mempool]]
size = 128
count = 1
)";

TEST_F(RoudiConfigTomlFileProvider_test, ParsingV1FileIsSuccessful)
{
::testing::Test::RecordProperty("TEST_ID", "37f5a397-a289-4bc1-86a7-d95851a5ab47");

Expand All @@ -76,15 +90,44 @@ TEST_F(RoudiConfigTomlFileProvider_test, ParsingFileIsSuccessful)

std::fstream tempFile{tempFilePath, std::ios_base::trunc | std::ios_base::out};
ASSERT_TRUE(tempFile.is_open());
tempFile << R"([general]
version = 1
tempFile << CONFIG_V1_SIMPLE;
tempFile.close();

[[segment]]
cmdLineArgs.configFilePath =
iox::roudi::ConfigFilePathString_t(iox::TruncateToCapacity, tempFilePath.u8string().c_str());

[[segment.mempool]]
size = 128
count = 1
)";
iox::config::TomlRouDiConfigFileProvider sut(cmdLineArgs);

sut.parse().and_then([](const auto&) { GTEST_SUCCEED() << "We got a config!"; }).or_else([](const auto& error) {
GTEST_FAIL() << "Expected a config but got error: "
<< iox::roudi::ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS[static_cast<uint64_t>(error)];
});
}

constexpr const char* CONFIG_V2_SIMPLE = R"(
[general]
version = 2
[[segment]]
name = "name"
writer = "writer"
reader = "reader"
[[segment.mempool]]
size = 128
count = 1
)";

TEST_F(RoudiConfigTomlFileProvider_test, ParsingV2FileIsSuccessful)
{
::testing::Test::RecordProperty("TEST_ID", "f1a7517e-7612-4eb8-84ad-3ff934f64efd");

auto tempFilePath = std::filesystem::temp_directory_path();
tempFilePath.append("test_roudi_config.toml");

std::fstream tempFile{tempFilePath, std::ios_base::trunc | std::ios_base::out};
ASSERT_TRUE(tempFile.is_open());
tempFile << CONFIG_V2_SIMPLE;
tempFile.close();

cmdLineArgs.configFilePath =
Expand Down Expand Up @@ -183,6 +226,18 @@ constexpr const char* CONFIG_MEMPOOL_WITHOUT_CHUNK_COUNT = R"(

constexpr const char* CONFIG_EXCEPTION_IN_PARSER = R"(🐔)";

constexpr const char* CONFIG_NAMED_SEGMENT_IN_V1_CONFIG = R"(
[general]
version = 1
[[segment]]
name = "name"
[[segment.mempool]]
size = 128
count = 1
)";

INSTANTIATE_TEST_SUITE_P(
ParseAllMalformedInputConfigFiles,
RoudiConfigTomlFileProvider_test,
Expand All @@ -201,7 +256,9 @@ INSTANTIATE_TEST_SUITE_P(
ParseErrorInputFile_t{iox::roudi::RouDiConfigFileParseError::MEMPOOL_WITHOUT_CHUNK_COUNT,
CONFIG_MEMPOOL_WITHOUT_CHUNK_COUNT},
ParseErrorInputFile_t{iox::roudi::RouDiConfigFileParseError::EXCEPTION_IN_PARSER,
CONFIG_EXCEPTION_IN_PARSER}));
CONFIG_EXCEPTION_IN_PARSER},
ParseErrorInputFile_t{iox::roudi::RouDiConfigFileParseError::NAMED_SEGMENT_IN_V1_CONFIG,
CONFIG_NAMED_SEGMENT_IN_V1_CONFIG}));


TEST_P(RoudiConfigTomlFileProvider_test, ParseMalformedInputFileCausesError)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2021 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI. All rights reserved.
// Copyright (c) 2024 by Latitude AI. 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 @@ -249,7 +250,7 @@ TEST_F(IceoryxRoudiApp_test, VerifyConstructorUsingConfigWithSegmentWithoutMemPo

iox::RouDiConfig_t roudiConfig;

roudiConfig.m_sharedMemorySegments.push_back({currentGroup.getName(), currentGroup.getName(), mempoolConfig});
roudiConfig.m_sharedMemorySegments.emplace_back("segment_name1", currentGroup.getName(), currentGroup.getName(), mempoolConfig);

IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), roudiConfig);

Expand Down

0 comments on commit 8783545

Please sign in to comment.