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