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 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 17 | namespace aos::testing { |
Eric Schmiedeberg | e279b53 | 2023-04-19 16:36:02 -0600 | [diff] [blame] | 18 | using namespace logger::testing; |
| 19 | using namespace logger; |
| 20 | namespace chrono = std::chrono; |
| 21 | |
| 22 | using ConfigRemapperTest = MultinodeLoggerTest; |
| 23 | |
| 24 | INSTANTIATE_TEST_SUITE_P( |
| 25 | All, ConfigRemapperTest, |
| 26 | ::testing::Combine( |
| 27 | ::testing::Values( |
| 28 | ConfigParams{"multinode_pingpong_combined_config.json", true, |
Austin Schuh | 6ecfe90 | 2023-08-04 22:44:37 -0700 | [diff] [blame] | 29 | kCombinedConfigSha1(), kCombinedConfigSha1(), |
Austin Schuh | 6309726 | 2023-08-16 17:04:29 -0700 | [diff] [blame] | 30 | FileStrategy::kCombine, |
| 31 | ForceTimestampBuffering::kForceBufferTimestamps}, |
Eric Schmiedeberg | e279b53 | 2023-04-19 16:36:02 -0600 | [diff] [blame] | 32 | ConfigParams{"multinode_pingpong_split_config.json", false, |
Austin Schuh | 6ecfe90 | 2023-08-04 22:44:37 -0700 | [diff] [blame] | 33 | kSplitConfigSha1(), kReloggedSplitConfigSha1(), |
Austin Schuh | 6309726 | 2023-08-16 17:04:29 -0700 | [diff] [blame] | 34 | FileStrategy::kCombine, |
| 35 | ForceTimestampBuffering::kForceBufferTimestamps}), |
Eric Schmiedeberg | e279b53 | 2023-04-19 16:36:02 -0600 | [diff] [blame] | 36 | ::testing::ValuesIn(SupportedCompressionAlgorithms()))); |
| 37 | |
| 38 | // Tests that we can read a config and remap a channel |
| 39 | TEST_P(ConfigRemapperTest, RemapOriginalChannel) { |
| 40 | ConfigRemapper remapper(&config_.message()); |
| 41 | |
| 42 | remapper.RemapOriginalChannel<examples::Ping>("/test"); |
| 43 | |
| 44 | const Channel *channel = configuration::GetChannel<examples::Ping>( |
| 45 | remapper.remapped_configuration(), "/original/test", "pi1", nullptr); |
| 46 | EXPECT_NE(channel, nullptr); |
| 47 | EXPECT_EQ(channel->name()->string_view(), "/original/test"); |
| 48 | EXPECT_EQ(channel->type()->string_view(), "aos.examples.Ping"); |
| 49 | } |
| 50 | |
| 51 | // Tests that we can read a config and rename a channel |
| 52 | TEST_P(ConfigRemapperTest, RenameOriginalChannel) { |
| 53 | ConfigRemapper remapper(&config_.message()); |
| 54 | |
| 55 | remapper.RenameOriginalChannel<examples::Ping>("/test", "/original/test"); |
| 56 | |
| 57 | const Channel *channel = configuration::GetChannel<examples::Ping>( |
| 58 | remapper.remapped_configuration(), "/original/test", "pi1", nullptr); |
| 59 | EXPECT_NE(channel, nullptr); |
| 60 | EXPECT_EQ(channel->name()->string_view(), "/original/test"); |
| 61 | EXPECT_EQ(channel->type()->string_view(), "aos.examples.Ping"); |
| 62 | } |
| 63 | |
| 64 | // Tests that we can remap a channel specifying a certain node |
| 65 | TEST_P(ConfigRemapperTest, RemapOriginalChannelWithNode) { |
| 66 | ConfigRemapper remapper(&config_.message()); |
| 67 | |
| 68 | const Node *node = |
| 69 | configuration::GetNode(remapper.remapped_configuration(), "pi1"); |
| 70 | |
| 71 | // Remap just on pi1. |
| 72 | remapper.RemapOriginalChannel<aos::timing::Report>("/aos", node); |
| 73 | |
| 74 | const Channel *channel = configuration::GetChannel<aos::timing::Report>( |
| 75 | remapper.remapped_configuration(), "/original/pi1/aos", "pi1", node); |
| 76 | EXPECT_NE(channel, nullptr); |
| 77 | EXPECT_EQ(channel->name()->string_view(), "/original/pi1/aos"); |
| 78 | EXPECT_EQ(channel->type()->string_view(), "aos.timing.Report"); |
| 79 | } |
| 80 | |
| 81 | // Tests that we can rename a channel specifying a certain node |
| 82 | TEST_P(ConfigRemapperTest, RenameOriginalChannelWithNode) { |
| 83 | ConfigRemapper remapper(&config_.message()); |
| 84 | |
| 85 | const Node *node = |
| 86 | configuration::GetNode(remapper.remapped_configuration(), "pi1"); |
| 87 | |
| 88 | // Rename just on pi1. |
| 89 | remapper.RenameOriginalChannel<aos::timing::Report>("/aos", node, |
| 90 | "/original/pi1/aos"); |
| 91 | |
| 92 | const Channel *channel = configuration::GetChannel<aos::timing::Report>( |
| 93 | remapper.remapped_configuration(), "/original/pi1/aos", "pi1", node); |
| 94 | EXPECT_NE(channel, nullptr); |
| 95 | EXPECT_EQ(channel->name()->string_view(), "/original/pi1/aos"); |
| 96 | EXPECT_EQ(channel->type()->string_view(), "aos.timing.Report"); |
| 97 | } |
| 98 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 99 | } // namespace aos::testing |