diff --git a/doc/design/draft/named-segments.md b/doc/design/draft/named-segments.md index 15f53dd0a9f..90401a8228a 100644 --- a/doc/design/draft/named-segments.md +++ b/doc/design/draft/named-segments.md @@ -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 diff --git a/iceoryx_examples/iceperf/roudi_main_static_config.cpp b/iceoryx_examples/iceperf/roudi_main_static_config.cpp index ef9de3c3f3b..9ca449dbf56 100644 --- a/iceoryx_examples/iceperf/roudi_main_static_config.cpp +++ b/iceoryx_examples/iceperf/roudi_main_static_config.cpp @@ -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. @@ -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. diff --git a/iceoryx_posh/include/iceoryx_posh/mepoo/segment_config.hpp b/iceoryx_posh/include/iceoryx_posh/mepoo/segment_config.hpp index ef27a85e731..2ee117bfcb6 100644 --- a/iceoryx_posh/include/iceoryx_posh/mepoo/segment_config.hpp +++ b/iceoryx_posh/include/iceoryx_posh/mepoo/segment_config.hpp @@ -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. @@ -31,11 +32,13 @@ 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) @@ -43,6 +46,7 @@ struct SegmentConfig { } + ShmName_t m_name; PosixGroup::groupName_t m_readerGroup; PosixGroup::groupName_t m_writerGroup; MePooConfig m_mempoolConfig; diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_config_file_provider.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_config_file_provider.hpp index 114d4ae3534..8b5a1806f4c 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_config_file_provider.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_config_file_provider.hpp @@ -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. @@ -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, @@ -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", @@ -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 diff --git a/iceoryx_posh/roudi_env/source/minimal_roudi_config.cpp b/iceoryx_posh/roudi_env/source/minimal_roudi_config.cpp index 32442f3085e..b3e81815f4b 100644 --- a/iceoryx_posh/roudi_env/source/minimal_roudi_config.cpp +++ b/iceoryx_posh/roudi_env/source/minimal_roudi_config.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2023 by Mathias Kraus . 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. @@ -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; diff --git a/iceoryx_posh/source/mepoo/segment_config.cpp b/iceoryx_posh/source/mepoo/segment_config.cpp index b7cb7ec8389..05157f1fbc2 100644 --- a/iceoryx_posh/source/mepoo/segment_config.cpp +++ b/iceoryx_posh/source/mepoo/segment_config.cpp @@ -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. @@ -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; } diff --git a/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp b/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp index ef124146696..13bfb3504c2 100644 --- a/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp +++ b/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp @@ -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. @@ -108,7 +109,7 @@ TomlRouDiConfigFileProvider::parse(std::istream& stream) noexcept return iox::err(iox::roudi::RouDiConfigFileParseError::NO_GENERAL_SECTION); } auto configFileVersion = general->get_as("version"); - if (!configFileVersion || *configFileVersion != 1) + if (!configFileVersion || *configFileVersion == 0 || *configFileVersion > 2U) { return iox::err(iox::roudi::RouDiConfigFileParseError::INVALID_CONFIG_FILE_VERSION); } @@ -128,6 +129,12 @@ TomlRouDiConfigFileProvider::parse(std::istream& stream) noexcept iox::RouDiConfig_t parsedConfig; for (auto segment : *segments) { + auto maybe_name = segment->get_as("name"); + if (maybe_name && *configFileVersion == 1U) + { + return iox::err(iox::roudi::RouDiConfigFileParseError::NAMED_SEGMENT_IN_V1_CONFIG); + } + auto name = maybe_name.value_or(into(groupOfCurrentProcess)); auto writer = segment->get_as("writer").value_or(into(groupOfCurrentProcess)); auto reader = segment->get_as("reader").value_or(into(groupOfCurrentProcess)); iox::mepoo::MePooConfig mempoolConfig; @@ -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); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp index 736cc9bf214..25d51ab43da 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp @@ -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. @@ -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; } @@ -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; } diff --git a/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp b/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp index f1a1093dacd..8ccdd8e9f76 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp @@ -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. @@ -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"); @@ -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(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 = @@ -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, @@ -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) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index ee0ad415abb..b88c7f954a7 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -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. @@ -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);