Eric Schmiedeberg | e279b53 | 2023-04-19 16:36:02 -0600 | [diff] [blame^] | 1 | #include "aos/events/logging/config_remapper.h" |
| 2 | |
| 3 | #include "gmock/gmock.h" |
| 4 | #include "gtest/gtest.h" |
| 5 | |
| 6 | #include "aos/events/event_loop_generated.h" |
| 7 | #include "aos/events/logging/log_reader.h" |
| 8 | #include "aos/events/logging/multinode_logger_test_lib.h" |
| 9 | #include "aos/events/message_counter.h" |
| 10 | #include "aos/events/ping_lib.h" |
| 11 | #include "aos/events/pong_lib.h" |
| 12 | #include "aos/network/remote_message_generated.h" |
| 13 | #include "aos/network/timestamp_generated.h" |
| 14 | #include "aos/testing/tmpdir.h" |
| 15 | #include "multinode_logger_test_lib.h" |
| 16 | |
| 17 | namespace aos { |
| 18 | namespace testing { |
| 19 | using namespace logger::testing; |
| 20 | using namespace logger; |
| 21 | namespace chrono = std::chrono; |
| 22 | |
| 23 | using ConfigRemapperTest = MultinodeLoggerTest; |
| 24 | |
| 25 | INSTANTIATE_TEST_SUITE_P( |
| 26 | All, ConfigRemapperTest, |
| 27 | ::testing::Combine( |
| 28 | ::testing::Values( |
| 29 | ConfigParams{"multinode_pingpong_combined_config.json", true, |
| 30 | kCombinedConfigSha1(), kCombinedConfigSha1()}, |
| 31 | ConfigParams{"multinode_pingpong_split_config.json", false, |
| 32 | kSplitConfigSha1(), kReloggedSplitConfigSha1()}), |
| 33 | ::testing::ValuesIn(SupportedCompressionAlgorithms()))); |
| 34 | |
| 35 | // Tests that we can read a config and remap a channel |
| 36 | TEST_P(ConfigRemapperTest, RemapOriginalChannel) { |
| 37 | ConfigRemapper remapper(&config_.message()); |
| 38 | |
| 39 | remapper.RemapOriginalChannel<examples::Ping>("/test"); |
| 40 | |
| 41 | const Channel *channel = configuration::GetChannel<examples::Ping>( |
| 42 | remapper.remapped_configuration(), "/original/test", "pi1", nullptr); |
| 43 | EXPECT_NE(channel, nullptr); |
| 44 | EXPECT_EQ(channel->name()->string_view(), "/original/test"); |
| 45 | EXPECT_EQ(channel->type()->string_view(), "aos.examples.Ping"); |
| 46 | } |
| 47 | |
| 48 | // Tests that we can read a config and rename a channel |
| 49 | TEST_P(ConfigRemapperTest, RenameOriginalChannel) { |
| 50 | ConfigRemapper remapper(&config_.message()); |
| 51 | |
| 52 | remapper.RenameOriginalChannel<examples::Ping>("/test", "/original/test"); |
| 53 | |
| 54 | const Channel *channel = configuration::GetChannel<examples::Ping>( |
| 55 | remapper.remapped_configuration(), "/original/test", "pi1", nullptr); |
| 56 | EXPECT_NE(channel, nullptr); |
| 57 | EXPECT_EQ(channel->name()->string_view(), "/original/test"); |
| 58 | EXPECT_EQ(channel->type()->string_view(), "aos.examples.Ping"); |
| 59 | } |
| 60 | |
| 61 | // Tests that we can remap a channel specifying a certain node |
| 62 | TEST_P(ConfigRemapperTest, RemapOriginalChannelWithNode) { |
| 63 | ConfigRemapper remapper(&config_.message()); |
| 64 | |
| 65 | const Node *node = |
| 66 | configuration::GetNode(remapper.remapped_configuration(), "pi1"); |
| 67 | |
| 68 | // Remap just on pi1. |
| 69 | remapper.RemapOriginalChannel<aos::timing::Report>("/aos", node); |
| 70 | |
| 71 | const Channel *channel = configuration::GetChannel<aos::timing::Report>( |
| 72 | remapper.remapped_configuration(), "/original/pi1/aos", "pi1", node); |
| 73 | EXPECT_NE(channel, nullptr); |
| 74 | EXPECT_EQ(channel->name()->string_view(), "/original/pi1/aos"); |
| 75 | EXPECT_EQ(channel->type()->string_view(), "aos.timing.Report"); |
| 76 | } |
| 77 | |
| 78 | // Tests that we can rename a channel specifying a certain node |
| 79 | TEST_P(ConfigRemapperTest, RenameOriginalChannelWithNode) { |
| 80 | ConfigRemapper remapper(&config_.message()); |
| 81 | |
| 82 | const Node *node = |
| 83 | configuration::GetNode(remapper.remapped_configuration(), "pi1"); |
| 84 | |
| 85 | // Rename just on pi1. |
| 86 | remapper.RenameOriginalChannel<aos::timing::Report>("/aos", node, |
| 87 | "/original/pi1/aos"); |
| 88 | |
| 89 | const Channel *channel = configuration::GetChannel<aos::timing::Report>( |
| 90 | remapper.remapped_configuration(), "/original/pi1/aos", "pi1", node); |
| 91 | EXPECT_NE(channel, nullptr); |
| 92 | EXPECT_EQ(channel->name()->string_view(), "/original/pi1/aos"); |
| 93 | EXPECT_EQ(channel->type()->string_view(), "aos.timing.Report"); |
| 94 | } |
| 95 | |
| 96 | } // namespace testing |
| 97 | } // namespace aos |