Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 1 | #include <sys/stat.h> |
| 2 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 3 | #include "absl/strings/str_format.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 4 | #include "aos/events/event_loop.h" |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 5 | #include "aos/events/logging/log_reader.h" |
Austin Schuh | b06f03b | 2021-02-17 22:00:37 -0800 | [diff] [blame] | 6 | #include "aos/events/logging/log_writer.h" |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 7 | #include "aos/events/logging/snappy_encoder.h" |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 8 | #include "aos/events/message_counter.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 9 | #include "aos/events/ping_lib.h" |
| 10 | #include "aos/events/pong_lib.h" |
| 11 | #include "aos/events/simulated_event_loop.h" |
Austin Schuh | 0de30f3 | 2020-12-06 12:44:28 -0800 | [diff] [blame] | 12 | #include "aos/network/remote_message_generated.h" |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 13 | #include "aos/network/testing_time_converter.h" |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 14 | #include "aos/network/timestamp_generated.h" |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 15 | #include "aos/testing/path.h" |
Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 16 | #include "aos/testing/tmpdir.h" |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 17 | #include "aos/util/file.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 18 | #include "glog/logging.h" |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 19 | #include "gmock/gmock.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 20 | #include "gtest/gtest.h" |
| 21 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 22 | #ifdef LZMA |
| 23 | #include "aos/events/logging/lzma_encoder.h" |
| 24 | #endif |
| 25 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 26 | namespace aos { |
| 27 | namespace logger { |
| 28 | namespace testing { |
| 29 | |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 30 | using aos::testing::ArtifactPath; |
| 31 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 32 | namespace chrono = std::chrono; |
Austin Schuh | 0de30f3 | 2020-12-06 12:44:28 -0800 | [diff] [blame] | 33 | using aos::message_bridge::RemoteMessage; |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 34 | using aos::testing::MessageCounter; |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 35 | |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 36 | constexpr std::string_view kSingleConfigSha256( |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 37 | "bbe1b563139273b23a5405eebc2f2740cefcda5f96681acd0a84b8ff9ab93ea4"); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 38 | |
Austin Schuh | b06f03b | 2021-02-17 22:00:37 -0800 | [diff] [blame] | 39 | std::vector<std::vector<std::string>> ToLogReaderVector( |
| 40 | const std::vector<LogFile> &log_files) { |
| 41 | std::vector<std::vector<std::string>> result; |
| 42 | for (const LogFile &log_file : log_files) { |
| 43 | for (const LogParts &log_parts : log_file.parts) { |
| 44 | std::vector<std::string> parts; |
| 45 | for (const std::string &part : log_parts.parts) { |
| 46 | parts.emplace_back(part); |
| 47 | } |
| 48 | result.emplace_back(std::move(parts)); |
| 49 | } |
| 50 | } |
| 51 | return result; |
| 52 | } |
| 53 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 54 | class LoggerTest : public ::testing::Test { |
| 55 | public: |
| 56 | LoggerTest() |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 57 | : config_(aos::configuration::ReadConfig( |
| 58 | ArtifactPath("aos/events/pingpong_config.json"))), |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 59 | event_loop_factory_(&config_.message()), |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 60 | ping_event_loop_(event_loop_factory_.MakeEventLoop("ping")), |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 61 | ping_(ping_event_loop_.get()), |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 62 | pong_event_loop_(event_loop_factory_.MakeEventLoop("pong")), |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 63 | pong_(pong_event_loop_.get()) {} |
| 64 | |
| 65 | // Config and factory. |
| 66 | aos::FlatbufferDetachedBuffer<aos::Configuration> config_; |
| 67 | SimulatedEventLoopFactory event_loop_factory_; |
| 68 | |
| 69 | // Event loop and app for Ping |
| 70 | std::unique_ptr<EventLoop> ping_event_loop_; |
| 71 | Ping ping_; |
| 72 | |
| 73 | // Event loop and app for Pong |
| 74 | std::unique_ptr<EventLoop> pong_event_loop_; |
| 75 | Pong pong_; |
| 76 | }; |
| 77 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 78 | using LoggerDeathTest = LoggerTest; |
| 79 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 80 | // Tests that we can startup at all. This confirms that the channels are all in |
| 81 | // the config. |
| 82 | TEST_F(LoggerTest, Starts) { |
Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 83 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 84 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 85 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 86 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 87 | const ::std::string logfile = base_name + "_data.part0.bfbs"; |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 88 | // Remove it. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 89 | unlink(config.c_str()); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 90 | unlink(logfile.c_str()); |
| 91 | |
| 92 | LOG(INFO) << "Logging data to " << logfile; |
| 93 | |
| 94 | { |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 95 | std::unique_ptr<EventLoop> logger_event_loop = |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 96 | event_loop_factory_.MakeEventLoop("logger"); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 97 | |
| 98 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 99 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 100 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 101 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 102 | logger.set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 103 | logger.StartLoggingOnRun(base_name); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 104 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 105 | } |
| 106 | |
James Kuszmaul | c7bbb3e | 2020-01-03 20:01:00 -0800 | [diff] [blame] | 107 | // Even though it doesn't make any difference here, exercise the logic for |
| 108 | // passing in a separate config. |
| 109 | LogReader reader(logfile, &config_.message()); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 110 | |
James Kuszmaul | c7bbb3e | 2020-01-03 20:01:00 -0800 | [diff] [blame] | 111 | // Confirm that we can remap logged channels to point to new buses. |
| 112 | reader.RemapLoggedChannel<aos::examples::Ping>("/test", "/original"); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 113 | |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 114 | // This sends out the fetched messages and advances time to the start of the |
| 115 | // log file. |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 116 | reader.Register(); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 117 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 118 | EXPECT_THAT(reader.LoggedNodes(), ::testing::ElementsAre(nullptr)); |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 119 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 120 | std::unique_ptr<EventLoop> test_event_loop = |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 121 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 122 | |
| 123 | int ping_count = 10; |
| 124 | int pong_count = 10; |
| 125 | |
James Kuszmaul | c7bbb3e | 2020-01-03 20:01:00 -0800 | [diff] [blame] | 126 | // Confirm that the ping value matches in the remapped channel location. |
| 127 | test_event_loop->MakeWatcher("/original/test", |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 128 | [&ping_count](const examples::Ping &ping) { |
| 129 | EXPECT_EQ(ping.value(), ping_count + 1); |
| 130 | ++ping_count; |
| 131 | }); |
| 132 | // Confirm that the ping and pong counts both match, and the value also |
| 133 | // matches. |
| 134 | test_event_loop->MakeWatcher( |
| 135 | "/test", [&pong_count, &ping_count](const examples::Pong &pong) { |
| 136 | EXPECT_EQ(pong.value(), pong_count + 1); |
| 137 | ++pong_count; |
| 138 | EXPECT_EQ(ping_count, pong_count); |
| 139 | }); |
| 140 | |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 141 | reader.event_loop_factory()->RunFor(std::chrono::seconds(100)); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 142 | EXPECT_EQ(ping_count, 2010); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 145 | // Tests calling StartLogging twice. |
| 146 | TEST_F(LoggerDeathTest, ExtraStart) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 147 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 148 | const ::std::string base_name1 = tmpdir + "/logfile1"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 149 | const ::std::string config1 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 150 | absl::StrCat(base_name1, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 151 | const ::std::string logfile1 = base_name1 + "_data.part0.bfbs"; |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 152 | const ::std::string base_name2 = tmpdir + "/logfile2"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 153 | const ::std::string config2 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 154 | absl::StrCat(base_name2, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 155 | const ::std::string logfile2 = base_name2 + "_data.part0.bfbs"; |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 156 | unlink(logfile1.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 157 | unlink(config1.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 158 | unlink(logfile2.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 159 | unlink(config2.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 160 | |
| 161 | LOG(INFO) << "Logging data to " << logfile1 << " then " << logfile2; |
| 162 | |
| 163 | { |
| 164 | std::unique_ptr<EventLoop> logger_event_loop = |
| 165 | event_loop_factory_.MakeEventLoop("logger"); |
| 166 | |
| 167 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 168 | |
| 169 | Logger logger(logger_event_loop.get()); |
| 170 | logger.set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 171 | logger_event_loop->OnRun( |
| 172 | [base_name1, base_name2, &logger_event_loop, &logger]() { |
| 173 | logger.StartLogging(std::make_unique<MultiNodeLogNamer>( |
| 174 | base_name1, logger_event_loop->configuration(), |
| 175 | logger_event_loop.get(), logger_event_loop->node())); |
| 176 | EXPECT_DEATH(logger.StartLogging(std::make_unique<MultiNodeLogNamer>( |
| 177 | base_name2, logger_event_loop->configuration(), |
| 178 | logger_event_loop.get(), logger_event_loop->node())), |
| 179 | "Already logging"); |
| 180 | }); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 181 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 182 | } |
| 183 | } |
| 184 | |
James Kuszmaul | 94ca513 | 2022-07-19 09:11:08 -0700 | [diff] [blame] | 185 | // Tests that we die if the replayer attempts to send on a logged channel. |
| 186 | TEST_F(LoggerDeathTest, DieOnDuplicateReplayChannels) { |
| 187 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 188 | aos::configuration::ReadConfig( |
| 189 | ArtifactPath("aos/events/pingpong_config.json")); |
| 190 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 191 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
| 192 | const ::std::string base_name = tmpdir + "/logfile"; |
| 193 | const ::std::string config_file = |
| 194 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 195 | const ::std::string logfile = base_name + "_data.part0.bfbs"; |
James Kuszmaul | 94ca513 | 2022-07-19 09:11:08 -0700 | [diff] [blame] | 196 | // Remove the log file. |
| 197 | unlink(config_file.c_str()); |
| 198 | unlink(logfile.c_str()); |
| 199 | |
| 200 | LOG(INFO) << "Logging data to " << logfile; |
| 201 | |
| 202 | { |
| 203 | std::unique_ptr<EventLoop> logger_event_loop = |
| 204 | event_loop_factory.MakeEventLoop("logger"); |
| 205 | |
| 206 | Logger logger(logger_event_loop.get()); |
| 207 | logger.set_separate_config(false); |
| 208 | logger.set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 209 | logger.StartLoggingOnRun(base_name); |
James Kuszmaul | 94ca513 | 2022-07-19 09:11:08 -0700 | [diff] [blame] | 210 | |
| 211 | event_loop_factory.RunFor(chrono::seconds(2)); |
| 212 | } |
| 213 | |
| 214 | LogReader reader(logfile); |
| 215 | |
| 216 | reader.Register(); |
| 217 | |
| 218 | std::unique_ptr<EventLoop> test_event_loop = |
| 219 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
| 220 | |
| 221 | EXPECT_DEATH(test_event_loop->MakeSender<examples::Ping>("/test"), |
| 222 | "exclusive channel.*examples.Ping"); |
| 223 | } |
| 224 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 225 | // Tests calling StopLogging twice. |
| 226 | TEST_F(LoggerDeathTest, ExtraStop) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 227 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 228 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 229 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 230 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 231 | const ::std::string logfile = base_name + ".part0.bfbs"; |
| 232 | // Remove it. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 233 | unlink(config.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 234 | unlink(logfile.c_str()); |
| 235 | |
| 236 | LOG(INFO) << "Logging data to " << logfile; |
| 237 | |
| 238 | { |
| 239 | std::unique_ptr<EventLoop> logger_event_loop = |
| 240 | event_loop_factory_.MakeEventLoop("logger"); |
| 241 | |
| 242 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 243 | |
| 244 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 245 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 246 | logger.set_polling_period(std::chrono::milliseconds(100)); |
| 247 | logger_event_loop->OnRun([base_name, &logger_event_loop, &logger]() { |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 248 | logger.StartLogging(std::make_unique<MultiNodeLogNamer>( |
| 249 | base_name, logger_event_loop->configuration(), |
| 250 | logger_event_loop.get(), logger_event_loop->node())); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 251 | logger.StopLogging(aos::monotonic_clock::min_time); |
| 252 | EXPECT_DEATH(logger.StopLogging(aos::monotonic_clock::min_time), |
| 253 | "Not logging right now"); |
| 254 | }); |
| 255 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | // Tests that we can startup twice. |
| 260 | TEST_F(LoggerTest, StartsTwice) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 261 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 262 | const ::std::string base_name1 = tmpdir + "/logfile1"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 263 | const ::std::string config1 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 264 | absl::StrCat(base_name1, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 265 | const ::std::string logfile1 = base_name1 + "_data.part0.bfbs"; |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 266 | const ::std::string base_name2 = tmpdir + "/logfile2"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 267 | const ::std::string config2 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 268 | absl::StrCat(base_name2, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 269 | const ::std::string logfile2 = base_name2 + "_data.part0.bfbs"; |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 270 | unlink(logfile1.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 271 | unlink(config1.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 272 | unlink(logfile2.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 273 | unlink(config2.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 274 | |
| 275 | LOG(INFO) << "Logging data to " << logfile1 << " then " << logfile2; |
| 276 | |
| 277 | { |
| 278 | std::unique_ptr<EventLoop> logger_event_loop = |
| 279 | event_loop_factory_.MakeEventLoop("logger"); |
| 280 | |
| 281 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 282 | |
| 283 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 284 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 285 | logger.set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 286 | logger.StartLogging(std::make_unique<MultiNodeLogNamer>( |
| 287 | base_name1, logger_event_loop->configuration(), logger_event_loop.get(), |
| 288 | logger_event_loop->node())); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 289 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 290 | logger.StopLogging(logger_event_loop->monotonic_now()); |
| 291 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 292 | logger.StartLogging(std::make_unique<MultiNodeLogNamer>( |
| 293 | base_name2, logger_event_loop->configuration(), logger_event_loop.get(), |
| 294 | logger_event_loop->node())); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 295 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 296 | } |
| 297 | |
| 298 | for (const auto &logfile : |
| 299 | {std::make_tuple(logfile1, 10), std::make_tuple(logfile2, 2010)}) { |
| 300 | SCOPED_TRACE(std::get<0>(logfile)); |
| 301 | LogReader reader(std::get<0>(logfile)); |
| 302 | reader.Register(); |
| 303 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 304 | EXPECT_THAT(reader.LoggedNodes(), ::testing::ElementsAre(nullptr)); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 305 | |
| 306 | std::unique_ptr<EventLoop> test_event_loop = |
| 307 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
| 308 | |
| 309 | int ping_count = std::get<1>(logfile); |
| 310 | int pong_count = std::get<1>(logfile); |
| 311 | |
| 312 | // Confirm that the ping and pong counts both match, and the value also |
| 313 | // matches. |
| 314 | test_event_loop->MakeWatcher("/test", |
| 315 | [&ping_count](const examples::Ping &ping) { |
| 316 | EXPECT_EQ(ping.value(), ping_count + 1); |
| 317 | ++ping_count; |
| 318 | }); |
| 319 | test_event_loop->MakeWatcher( |
| 320 | "/test", [&pong_count, &ping_count](const examples::Pong &pong) { |
| 321 | EXPECT_EQ(pong.value(), pong_count + 1); |
| 322 | ++pong_count; |
| 323 | EXPECT_EQ(ping_count, pong_count); |
| 324 | }); |
| 325 | |
| 326 | reader.event_loop_factory()->RunFor(std::chrono::seconds(100)); |
| 327 | EXPECT_EQ(ping_count, std::get<1>(logfile) + 1000); |
| 328 | } |
| 329 | } |
| 330 | |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 331 | // Tests that we can read and write rotated log files. |
| 332 | TEST_F(LoggerTest, RotatedLogFile) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 333 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 334 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 335 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 336 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 337 | const ::std::string logfile0 = base_name + "_data.part0.bfbs"; |
| 338 | const ::std::string logfile1 = base_name + "_data.part1.bfbs"; |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 339 | // Remove it. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 340 | unlink(config.c_str()); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 341 | unlink(logfile0.c_str()); |
| 342 | unlink(logfile1.c_str()); |
| 343 | |
| 344 | LOG(INFO) << "Logging data to " << logfile0 << " and " << logfile1; |
| 345 | |
| 346 | { |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 347 | std::unique_ptr<EventLoop> logger_event_loop = |
| 348 | event_loop_factory_.MakeEventLoop("logger"); |
| 349 | |
| 350 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 351 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 352 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 353 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 354 | logger.set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 355 | logger.StartLoggingOnRun(base_name); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 356 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 357 | logger.Rotate(); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 358 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 359 | } |
| 360 | |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 361 | { |
| 362 | // Confirm that the UUIDs match for both the parts and the logger, and the |
| 363 | // parts_index increments. |
Austin Schuh | add6eb3 | 2020-11-09 21:24:26 -0800 | [diff] [blame] | 364 | std::vector<SizePrefixedFlatbufferVector<LogFileHeader>> log_header; |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 365 | for (std::string_view f : {logfile0, logfile1}) { |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 366 | log_header.emplace_back(ReadHeader(f).value()); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Brian Silverman | ae7c033 | 2020-09-30 16:58:23 -0700 | [diff] [blame] | 369 | EXPECT_EQ(log_header[0].message().log_event_uuid()->string_view(), |
| 370 | log_header[1].message().log_event_uuid()->string_view()); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 371 | EXPECT_EQ(log_header[0].message().parts_uuid()->string_view(), |
| 372 | log_header[1].message().parts_uuid()->string_view()); |
| 373 | |
| 374 | EXPECT_EQ(log_header[0].message().parts_index(), 0); |
| 375 | EXPECT_EQ(log_header[1].message().parts_index(), 1); |
| 376 | } |
| 377 | |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 378 | // Even though it doesn't make any difference here, exercise the logic for |
| 379 | // passing in a separate config. |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 380 | LogReader reader(SortParts({logfile0, logfile1}), &config_.message()); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 381 | |
| 382 | // Confirm that we can remap logged channels to point to new buses. |
| 383 | reader.RemapLoggedChannel<aos::examples::Ping>("/test", "/original"); |
| 384 | |
| 385 | // This sends out the fetched messages and advances time to the start of the |
| 386 | // log file. |
| 387 | reader.Register(); |
| 388 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 389 | EXPECT_THAT(reader.LoggedNodes(), ::testing::ElementsAre(nullptr)); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 390 | |
| 391 | std::unique_ptr<EventLoop> test_event_loop = |
| 392 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
| 393 | |
| 394 | int ping_count = 10; |
| 395 | int pong_count = 10; |
| 396 | |
| 397 | // Confirm that the ping value matches in the remapped channel location. |
| 398 | test_event_loop->MakeWatcher("/original/test", |
| 399 | [&ping_count](const examples::Ping &ping) { |
| 400 | EXPECT_EQ(ping.value(), ping_count + 1); |
| 401 | ++ping_count; |
| 402 | }); |
| 403 | // Confirm that the ping and pong counts both match, and the value also |
| 404 | // matches. |
| 405 | test_event_loop->MakeWatcher( |
| 406 | "/test", [&pong_count, &ping_count](const examples::Pong &pong) { |
| 407 | EXPECT_EQ(pong.value(), pong_count + 1); |
| 408 | ++pong_count; |
| 409 | EXPECT_EQ(ping_count, pong_count); |
| 410 | }); |
| 411 | |
| 412 | reader.event_loop_factory()->RunFor(std::chrono::seconds(100)); |
| 413 | EXPECT_EQ(ping_count, 2010); |
| 414 | } |
| 415 | |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 416 | // Tests that a large number of messages per second doesn't overwhelm writev. |
| 417 | TEST_F(LoggerTest, ManyMessages) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 418 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 419 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 420 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 421 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 422 | const ::std::string logfile = base_name + ".part0.bfbs"; |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 423 | // Remove the log file. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 424 | unlink(config.c_str()); |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 425 | unlink(logfile.c_str()); |
| 426 | |
| 427 | LOG(INFO) << "Logging data to " << logfile; |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 428 | ping_.set_quiet(true); |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 429 | |
| 430 | { |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 431 | std::unique_ptr<EventLoop> logger_event_loop = |
| 432 | event_loop_factory_.MakeEventLoop("logger"); |
| 433 | |
| 434 | std::unique_ptr<EventLoop> ping_spammer_event_loop = |
| 435 | event_loop_factory_.MakeEventLoop("ping_spammer"); |
| 436 | aos::Sender<examples::Ping> ping_sender = |
| 437 | ping_spammer_event_loop->MakeSender<examples::Ping>("/test"); |
| 438 | |
| 439 | aos::TimerHandler *timer_handler = |
| 440 | ping_spammer_event_loop->AddTimer([&ping_sender]() { |
| 441 | aos::Sender<examples::Ping>::Builder builder = |
| 442 | ping_sender.MakeBuilder(); |
| 443 | examples::Ping::Builder ping_builder = |
| 444 | builder.MakeBuilder<examples::Ping>(); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 445 | CHECK_EQ(builder.Send(ping_builder.Finish()), RawSender::Error::kOk); |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 446 | }); |
| 447 | |
| 448 | // 100 ms / 0.05 ms -> 2000 messages. Should be enough to crash it. |
| 449 | ping_spammer_event_loop->OnRun([&ping_spammer_event_loop, timer_handler]() { |
| 450 | timer_handler->Setup(ping_spammer_event_loop->monotonic_now(), |
| 451 | chrono::microseconds(50)); |
| 452 | }); |
| 453 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 454 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 455 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 456 | logger.set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 457 | logger.StartLoggingOnRun(base_name); |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 458 | |
| 459 | event_loop_factory_.RunFor(chrono::milliseconds(1000)); |
| 460 | } |
| 461 | } |
| 462 | |
James Kuszmaul | 890c249 | 2022-04-06 14:59:31 -0700 | [diff] [blame] | 463 | // Tests that we can read a logfile that has channels which were sent too fast. |
| 464 | TEST(SingleNodeLoggerNoFixtureTest, ReadTooFast) { |
| 465 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 466 | aos::configuration::ReadConfig( |
| 467 | ArtifactPath("aos/events/pingpong_config.json")); |
| 468 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 469 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
| 470 | const ::std::string base_name = tmpdir + "/logfile"; |
| 471 | const ::std::string config_file = |
| 472 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 473 | const ::std::string logfile = base_name + "_data.part0.bfbs"; |
James Kuszmaul | 890c249 | 2022-04-06 14:59:31 -0700 | [diff] [blame] | 474 | // Remove the log file. |
| 475 | unlink(config_file.c_str()); |
| 476 | unlink(logfile.c_str()); |
| 477 | |
| 478 | LOG(INFO) << "Logging data to " << logfile; |
| 479 | |
| 480 | int sent_messages = 0; |
| 481 | |
| 482 | { |
| 483 | std::unique_ptr<EventLoop> logger_event_loop = |
| 484 | event_loop_factory.MakeEventLoop("logger"); |
| 485 | |
| 486 | std::unique_ptr<EventLoop> ping_spammer_event_loop = |
| 487 | event_loop_factory.GetNodeEventLoopFactory(nullptr)->MakeEventLoop( |
| 488 | "ping_spammer", {NodeEventLoopFactory::CheckSentTooFast::kNo, |
James Kuszmaul | 94ca513 | 2022-07-19 09:11:08 -0700 | [diff] [blame] | 489 | NodeEventLoopFactory::ExclusiveSenders::kNo, |
| 490 | {}}); |
James Kuszmaul | 890c249 | 2022-04-06 14:59:31 -0700 | [diff] [blame] | 491 | aos::Sender<examples::Ping> ping_sender = |
| 492 | ping_spammer_event_loop->MakeSender<examples::Ping>("/test"); |
| 493 | |
| 494 | aos::TimerHandler *timer_handler = |
| 495 | ping_spammer_event_loop->AddTimer([&ping_sender, &sent_messages]() { |
| 496 | aos::Sender<examples::Ping>::Builder builder = |
| 497 | ping_sender.MakeBuilder(); |
| 498 | examples::Ping::Builder ping_builder = |
| 499 | builder.MakeBuilder<examples::Ping>(); |
| 500 | CHECK_EQ(builder.Send(ping_builder.Finish()), RawSender::Error::kOk); |
| 501 | ++sent_messages; |
| 502 | }); |
| 503 | |
| 504 | constexpr std::chrono::microseconds kSendPeriod{10}; |
| 505 | const int max_legal_messages = |
| 506 | ping_sender.channel()->frequency() * |
| 507 | event_loop_factory.configuration()->channel_storage_duration() / |
| 508 | 1000000000; |
| 509 | |
| 510 | ping_spammer_event_loop->OnRun( |
| 511 | [&ping_spammer_event_loop, kSendPeriod, timer_handler]() { |
| 512 | timer_handler->Setup( |
| 513 | ping_spammer_event_loop->monotonic_now() + kSendPeriod / 2, |
| 514 | kSendPeriod); |
| 515 | }); |
| 516 | |
| 517 | Logger logger(logger_event_loop.get()); |
| 518 | logger.set_separate_config(false); |
| 519 | logger.set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 1171769 | 2022-10-16 17:11:28 -0700 | [diff] [blame] | 520 | logger.StartLoggingOnRun(base_name); |
James Kuszmaul | 890c249 | 2022-04-06 14:59:31 -0700 | [diff] [blame] | 521 | |
| 522 | event_loop_factory.RunFor(kSendPeriod * max_legal_messages * 2); |
| 523 | } |
| 524 | |
| 525 | LogReader reader(logfile); |
| 526 | |
| 527 | reader.Register(); |
| 528 | |
| 529 | std::unique_ptr<EventLoop> test_event_loop = |
| 530 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
| 531 | |
| 532 | int replay_count = 0; |
| 533 | |
| 534 | test_event_loop->MakeWatcher( |
| 535 | "/test", [&replay_count](const examples::Ping &) { ++replay_count; }); |
| 536 | |
| 537 | reader.event_loop_factory()->Run(); |
| 538 | EXPECT_EQ(replay_count, sent_messages); |
| 539 | } |
| 540 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 541 | struct CompressionParams { |
| 542 | std::string_view extension; |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 543 | std::function<std::unique_ptr<DataEncoder>(size_t max_message_size)> |
| 544 | encoder_factory; |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 545 | }; |
| 546 | |
| 547 | std::ostream &operator<<(std::ostream &ostream, |
| 548 | const CompressionParams ¶ms) { |
| 549 | ostream << "\"" << params.extension << "\""; |
| 550 | return ostream; |
| 551 | } |
| 552 | |
| 553 | std::vector<CompressionParams> SupportedCompressionAlgorithms() { |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 554 | return {{"", |
| 555 | [](size_t max_message_size) { |
| 556 | return std::make_unique<DummyEncoder>(max_message_size); |
| 557 | }}, |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 558 | {SnappyDecoder::kExtension, |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 559 | [](size_t max_message_size) { |
| 560 | return std::make_unique<SnappyEncoder>(max_message_size); |
| 561 | }}, |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 562 | #ifdef LZMA |
| 563 | {LzmaDecoder::kExtension, |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 564 | [](size_t max_message_size) { |
| 565 | return std::make_unique<LzmaEncoder>(max_message_size, 3); |
| 566 | }} |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 567 | #endif // LZMA |
| 568 | }; |
| 569 | } |
| 570 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 571 | // Parameters to run all the tests with. |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 572 | struct ConfigParams { |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 573 | // The config file to use. |
| 574 | std::string config; |
| 575 | // If true, the RemoteMessage channel should be shared between all the remote |
| 576 | // channels. If false, there will be 1 RemoteMessage channel per remote |
| 577 | // channel. |
| 578 | bool shared; |
| 579 | // sha256 of the config. |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 580 | std::string_view sha256; |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 581 | // sha256 of the relogged config |
| 582 | std::string_view relogged_sha256; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 583 | }; |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 584 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 585 | std::ostream &operator<<(std::ostream &ostream, const ConfigParams ¶ms) { |
| 586 | ostream << "{config: \"" << params.config << "\", shared: " << params.shared |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 587 | << ", sha256: \"" << params.sha256 << "\", relogged_sha256: \"" |
| 588 | << params.relogged_sha256 << "\"}"; |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 589 | return ostream; |
| 590 | } |
| 591 | |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 592 | struct LoggerState { |
| 593 | static LoggerState MakeLogger(NodeEventLoopFactory *node, |
| 594 | SimulatedEventLoopFactory *factory, |
| 595 | CompressionParams params, |
| 596 | const Configuration *configuration = nullptr) { |
| 597 | if (configuration == nullptr) { |
| 598 | configuration = factory->configuration(); |
| 599 | } |
| 600 | return {node->MakeEventLoop("logger"), |
| 601 | {}, |
| 602 | configuration, |
| 603 | configuration::GetNode(configuration, node->node()), |
| 604 | nullptr, |
| 605 | params}; |
| 606 | } |
| 607 | |
| 608 | void StartLogger(std::string logfile_base) { |
| 609 | CHECK(!logfile_base.empty()); |
| 610 | |
| 611 | logger = std::make_unique<Logger>(event_loop.get(), configuration); |
| 612 | logger->set_polling_period(std::chrono::milliseconds(100)); |
| 613 | logger->set_name( |
| 614 | absl::StrCat("name_prefix_", event_loop->node()->name()->str())); |
Austin Schuh | fa71268 | 2022-05-11 16:43:42 -0700 | [diff] [blame] | 615 | logger->set_logger_sha1( |
| 616 | absl::StrCat("logger_sha1_", event_loop->node()->name()->str())); |
| 617 | logger->set_logger_version( |
| 618 | absl::StrCat("logger_version_", event_loop->node()->name()->str())); |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 619 | event_loop->OnRun([this, logfile_base]() { |
| 620 | std::unique_ptr<MultiNodeLogNamer> namer = |
| 621 | std::make_unique<MultiNodeLogNamer>(logfile_base, configuration, |
| 622 | event_loop.get(), node); |
| 623 | namer->set_extension(params.extension); |
| 624 | namer->set_encoder_factory(params.encoder_factory); |
| 625 | log_namer = namer.get(); |
| 626 | |
| 627 | logger->StartLogging(std::move(namer)); |
| 628 | }); |
| 629 | } |
| 630 | |
| 631 | std::unique_ptr<EventLoop> event_loop; |
| 632 | std::unique_ptr<Logger> logger; |
| 633 | const Configuration *configuration; |
| 634 | const Node *node; |
| 635 | MultiNodeLogNamer *log_namer; |
| 636 | CompressionParams params; |
| 637 | |
| 638 | void AppendAllFilenames(std::vector<std::string> *filenames) { |
| 639 | for (const std::string &file : log_namer->all_filenames()) { |
| 640 | const std::string_view separator = |
| 641 | log_namer->base_name().back() == '/' ? "" : "_"; |
| 642 | filenames->emplace_back( |
| 643 | absl::StrCat(log_namer->base_name(), separator, file)); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | ~LoggerState() { |
| 648 | if (logger) { |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 649 | std::vector<std::string> filenames; |
| 650 | AppendAllFilenames(&filenames); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 651 | std::sort(filenames.begin(), filenames.end()); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 652 | for (const std::string &file : filenames) { |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 653 | LOG(INFO) << "Wrote to " << file; |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 654 | auto x = ReadHeader(file); |
| 655 | if (x) { |
| 656 | VLOG(1) << aos::FlatbufferToJson(x.value()); |
| 657 | } |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
| 661 | }; |
| 662 | |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 663 | std::vector<std::pair<std::vector<realtime_clock::time_point>, |
| 664 | std::vector<realtime_clock::time_point>>> |
| 665 | ConfirmReadable( |
| 666 | const std::vector<std::string> &files, |
| 667 | realtime_clock::time_point start_time = realtime_clock::min_time, |
| 668 | realtime_clock::time_point end_time = realtime_clock::max_time) { |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 669 | { |
| 670 | LogReader reader(SortParts(files)); |
| 671 | |
| 672 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 673 | reader.Register(&log_reader_factory); |
| 674 | |
| 675 | log_reader_factory.Run(); |
| 676 | |
| 677 | reader.Deregister(); |
| 678 | } |
| 679 | { |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 680 | std::vector<std::pair<std::vector<realtime_clock::time_point>, |
| 681 | std::vector<realtime_clock::time_point>>> |
| 682 | result; |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 683 | LogReader reader(SortParts(files)); |
| 684 | |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 685 | reader.SetStartTime(start_time); |
| 686 | reader.SetEndTime(end_time); |
| 687 | |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 688 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 689 | reader.RegisterWithoutStarting(&log_reader_factory); |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 690 | result.resize( |
| 691 | configuration::NodesCount(log_reader_factory.configuration())); |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 692 | if (configuration::MultiNode(log_reader_factory.configuration())) { |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 693 | size_t i = 0; |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 694 | for (const aos::Node *node : |
| 695 | *log_reader_factory.configuration()->nodes()) { |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 696 | LOG(INFO) << "Registering start"; |
| 697 | reader.OnStart(node, [node, &log_reader_factory, &result, |
| 698 | node_index = i]() { |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 699 | LOG(INFO) << "Starting " << node->name()->string_view(); |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 700 | result[node_index].first.push_back( |
| 701 | log_reader_factory.GetNodeEventLoopFactory(node)->realtime_now()); |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 702 | }); |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 703 | reader.OnEnd(node, [node, &log_reader_factory, &result, |
| 704 | node_index = i]() { |
| 705 | LOG(INFO) << "Ending " << node->name()->string_view(); |
| 706 | result[node_index].second.push_back( |
| 707 | log_reader_factory.GetNodeEventLoopFactory(node)->realtime_now()); |
| 708 | }); |
| 709 | ++i; |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 710 | } |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 711 | } else { |
| 712 | reader.OnStart([&log_reader_factory, &result]() { |
| 713 | LOG(INFO) << "Starting"; |
| 714 | result[0].first.push_back( |
| 715 | log_reader_factory.GetNodeEventLoopFactory(nullptr) |
| 716 | ->realtime_now()); |
| 717 | }); |
| 718 | reader.OnEnd([&log_reader_factory, &result]() { |
| 719 | LOG(INFO) << "Ending"; |
| 720 | result[0].second.push_back( |
| 721 | log_reader_factory.GetNodeEventLoopFactory(nullptr) |
| 722 | ->realtime_now()); |
| 723 | }); |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | log_reader_factory.Run(); |
| 727 | |
| 728 | reader.Deregister(); |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 729 | |
| 730 | for (auto x : result) { |
| 731 | for (auto y : x.first) { |
| 732 | VLOG(1) << "Start " << y; |
| 733 | } |
| 734 | for (auto y : x.second) { |
| 735 | VLOG(1) << "End " << y; |
| 736 | } |
| 737 | } |
| 738 | return result; |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 742 | class MultinodeLoggerTest : public ::testing::TestWithParam< |
| 743 | std::tuple<ConfigParams, CompressionParams>> { |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 744 | public: |
| 745 | MultinodeLoggerTest() |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 746 | : config_(aos::configuration::ReadConfig(ArtifactPath(absl::StrCat( |
| 747 | "aos/events/logging/", std::get<0>(GetParam()).config)))), |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 748 | time_converter_(configuration::NodesCount(&config_.message())), |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 749 | event_loop_factory_(&config_.message()), |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 750 | pi1_(event_loop_factory_.GetNodeEventLoopFactory("pi1")), |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 751 | pi1_index_(configuration::GetNodeIndex( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 752 | event_loop_factory_.configuration(), pi1_->node())), |
| 753 | pi2_(event_loop_factory_.GetNodeEventLoopFactory("pi2")), |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 754 | pi2_index_(configuration::GetNodeIndex( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 755 | event_loop_factory_.configuration(), pi2_->node())), |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 756 | tmp_dir_(aos::testing::TestTmpDir()), |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 757 | logfile_base1_(tmp_dir_ + "/multi_logfile1"), |
| 758 | logfile_base2_(tmp_dir_ + "/multi_logfile2"), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 759 | pi1_reboot_logfiles_(MakePi1RebootLogfiles()), |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 760 | logfiles_(MakeLogFiles(logfile_base1_, logfile_base2_)), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 761 | pi1_single_direction_logfiles_(MakePi1SingleDirectionLogfiles()), |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 762 | structured_logfiles_(StructureLogFiles()) { |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 763 | LOG(INFO) << "Config " << std::get<0>(GetParam()).config; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 764 | event_loop_factory_.SetTimeConverter(&time_converter_); |
| 765 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 766 | // Go through and remove the logfiles if they already exist. |
Austin Schuh | 268586b | 2021-03-31 22:24:39 -0700 | [diff] [blame] | 767 | for (const auto &file : logfiles_) { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 768 | unlink(file.c_str()); |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 769 | unlink((file + ".xz").c_str()); |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 770 | } |
| 771 | |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 772 | for (const auto &file : MakeLogFiles(tmp_dir_ + "/relogged1", |
| 773 | tmp_dir_ + "/relogged2", 3, 3, true)) { |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 774 | unlink(file.c_str()); |
| 775 | } |
| 776 | |
Austin Schuh | 268586b | 2021-03-31 22:24:39 -0700 | [diff] [blame] | 777 | for (const auto &file : pi1_reboot_logfiles_) { |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 778 | unlink(file.c_str()); |
| 779 | } |
| 780 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 781 | LOG(INFO) << "Logging data to " << logfiles_[0] << ", " << logfiles_[1] |
| 782 | << " and " << logfiles_[2]; |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 783 | |
| 784 | pi1_->OnStartup([this]() { pi1_->AlwaysStart<Ping>("ping"); }); |
| 785 | pi2_->OnStartup([this]() { pi2_->AlwaysStart<Pong>("pong"); }); |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 786 | } |
| 787 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 788 | bool shared() const { return std::get<0>(GetParam()).shared; } |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 789 | |
| 790 | std::vector<std::string> MakeLogFiles(std::string logfile_base1, |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 791 | std::string logfile_base2, |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 792 | size_t pi1_data_count = 3, |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 793 | size_t pi2_data_count = 3, |
| 794 | bool relogged_config = false) { |
| 795 | std::string_view sha256 = relogged_config |
| 796 | ? std::get<0>(GetParam()).relogged_sha256 |
| 797 | : std::get<0>(GetParam()).sha256; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 798 | std::vector<std::string> result; |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 799 | result.emplace_back(absl::StrCat(logfile_base1, "_", sha256, Extension())); |
| 800 | result.emplace_back(absl::StrCat(logfile_base2, "_", sha256, Extension())); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 801 | for (size_t i = 0; i < pi1_data_count; ++i) { |
| 802 | result.emplace_back( |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 803 | absl::StrCat(logfile_base1, "_pi1_data.part", i, Extension())); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 804 | } |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 805 | result.emplace_back(logfile_base1 + |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 806 | "_pi2_data/test/aos.examples.Pong.part0" + Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 807 | result.emplace_back(logfile_base1 + |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 808 | "_pi2_data/test/aos.examples.Pong.part1" + Extension()); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 809 | for (size_t i = 0; i < pi2_data_count; ++i) { |
| 810 | result.emplace_back( |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 811 | absl::StrCat(logfile_base2, "_pi2_data.part", i, Extension())); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 812 | } |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 813 | result.emplace_back(logfile_base2 + |
| 814 | "_pi1_data/pi1/aos/aos.message_bridge.Timestamp.part0" + |
| 815 | Extension()); |
| 816 | result.emplace_back(logfile_base2 + |
| 817 | "_pi1_data/pi1/aos/aos.message_bridge.Timestamp.part1" + |
| 818 | Extension()); |
| 819 | result.emplace_back(logfile_base1 + |
| 820 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part0" + |
| 821 | Extension()); |
| 822 | result.emplace_back(logfile_base1 + |
| 823 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part1" + |
| 824 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 825 | if (shared()) { |
| 826 | result.emplace_back(logfile_base1 + |
| 827 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 828 | "aos.message_bridge.RemoteMessage.part0" + |
| 829 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 830 | result.emplace_back(logfile_base1 + |
| 831 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 832 | "aos.message_bridge.RemoteMessage.part1" + |
| 833 | Extension()); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 834 | result.emplace_back(logfile_base1 + |
| 835 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 836 | "aos.message_bridge.RemoteMessage.part2" + |
| 837 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 838 | result.emplace_back(logfile_base2 + |
| 839 | "_timestamps/pi2/aos/remote_timestamps/pi1/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 840 | "aos.message_bridge.RemoteMessage.part0" + |
| 841 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 842 | result.emplace_back(logfile_base2 + |
| 843 | "_timestamps/pi2/aos/remote_timestamps/pi1/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 844 | "aos.message_bridge.RemoteMessage.part1" + |
| 845 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 846 | } else { |
| 847 | result.emplace_back(logfile_base1 + |
| 848 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 849 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 850 | "aos.message_bridge.RemoteMessage.part0" + |
| 851 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 852 | result.emplace_back(logfile_base1 + |
| 853 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 854 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 855 | "aos.message_bridge.RemoteMessage.part1" + |
| 856 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 857 | result.emplace_back(logfile_base2 + |
| 858 | "_timestamps/pi2/aos/remote_timestamps/pi1/pi2/aos/" |
| 859 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 860 | "aos.message_bridge.RemoteMessage.part0" + |
| 861 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 862 | result.emplace_back(logfile_base2 + |
| 863 | "_timestamps/pi2/aos/remote_timestamps/pi1/pi2/aos/" |
| 864 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 865 | "aos.message_bridge.RemoteMessage.part1" + |
| 866 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 867 | result.emplace_back(logfile_base1 + |
| 868 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 869 | "aos-examples-Ping/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 870 | "aos.message_bridge.RemoteMessage.part0" + |
| 871 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 872 | result.emplace_back(logfile_base1 + |
| 873 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 874 | "aos-examples-Ping/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 875 | "aos.message_bridge.RemoteMessage.part1" + |
| 876 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | return result; |
| 880 | } |
| 881 | |
| 882 | std::vector<std::string> MakePi1RebootLogfiles() { |
| 883 | std::vector<std::string> result; |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 884 | result.emplace_back(logfile_base1_ + "_pi1_data.part0" + Extension()); |
| 885 | result.emplace_back(logfile_base1_ + "_pi1_data.part1" + Extension()); |
| 886 | result.emplace_back(logfile_base1_ + "_pi1_data.part2" + Extension()); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 887 | result.emplace_back(logfile_base1_ + "_pi1_data.part3" + Extension()); |
| 888 | result.emplace_back(logfile_base1_ + "_pi1_data.part4" + Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 889 | result.emplace_back(logfile_base1_ + |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 890 | "_pi2_data/test/aos.examples.Pong.part0" + Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 891 | result.emplace_back(logfile_base1_ + |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 892 | "_pi2_data/test/aos.examples.Pong.part1" + Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 893 | result.emplace_back(logfile_base1_ + |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 894 | "_pi2_data/test/aos.examples.Pong.part2" + Extension()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 895 | result.emplace_back(logfile_base1_ + |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 896 | "_pi2_data/test/aos.examples.Pong.part3" + Extension()); |
| 897 | result.emplace_back(logfile_base1_ + |
| 898 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part0" + |
| 899 | Extension()); |
| 900 | result.emplace_back(logfile_base1_ + |
| 901 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part1" + |
| 902 | Extension()); |
| 903 | result.emplace_back(logfile_base1_ + |
| 904 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part2" + |
| 905 | Extension()); |
| 906 | result.emplace_back(logfile_base1_ + |
| 907 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part3" + |
| 908 | Extension()); |
| 909 | result.emplace_back(absl::StrCat( |
| 910 | logfile_base1_, "_", std::get<0>(GetParam()).sha256, Extension())); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 911 | if (shared()) { |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 912 | for (size_t i = 0; i < 6; ++i) { |
| 913 | result.emplace_back( |
| 914 | absl::StrCat(logfile_base1_, |
| 915 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 916 | "aos.message_bridge.RemoteMessage.part", |
| 917 | i, Extension())); |
| 918 | } |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 919 | } else { |
| 920 | result.emplace_back(logfile_base1_ + |
| 921 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 922 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 923 | "aos.message_bridge.RemoteMessage.part0" + |
| 924 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 925 | result.emplace_back(logfile_base1_ + |
| 926 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 927 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 928 | "aos.message_bridge.RemoteMessage.part1" + |
| 929 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 930 | result.emplace_back(logfile_base1_ + |
| 931 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 932 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 933 | "aos.message_bridge.RemoteMessage.part2" + |
| 934 | Extension()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 935 | result.emplace_back(logfile_base1_ + |
| 936 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 937 | "aos-message_bridge-Timestamp/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 938 | "aos.message_bridge.RemoteMessage.part3" + |
| 939 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 940 | |
| 941 | result.emplace_back(logfile_base1_ + |
| 942 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 943 | "aos-examples-Ping/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 944 | "aos.message_bridge.RemoteMessage.part0" + |
| 945 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 946 | result.emplace_back(logfile_base1_ + |
| 947 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 948 | "aos-examples-Ping/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 949 | "aos.message_bridge.RemoteMessage.part1" + |
| 950 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 951 | result.emplace_back(logfile_base1_ + |
| 952 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 953 | "aos-examples-Ping/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 954 | "aos.message_bridge.RemoteMessage.part2" + |
| 955 | Extension()); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 956 | result.emplace_back(logfile_base1_ + |
| 957 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 958 | "aos-examples-Ping/" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 959 | "aos.message_bridge.RemoteMessage.part3" + |
| 960 | Extension()); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 961 | } |
| 962 | return result; |
| 963 | } |
| 964 | |
| 965 | std::vector<std::string> MakePi1SingleDirectionLogfiles() { |
| 966 | std::vector<std::string> result; |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 967 | result.emplace_back(logfile_base1_ + "_pi1_data.part0" + Extension()); |
| 968 | result.emplace_back(logfile_base1_ + "_pi1_data.part1" + Extension()); |
| 969 | result.emplace_back(logfile_base1_ + |
| 970 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part0" + |
| 971 | Extension()); |
| 972 | result.emplace_back(absl::StrCat( |
| 973 | logfile_base1_, "_", std::get<0>(GetParam()).sha256, Extension())); |
Austin Schuh | 510dc62 | 2021-08-06 18:47:30 -0700 | [diff] [blame] | 974 | return result; |
| 975 | } |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 976 | |
Austin Schuh | 510dc62 | 2021-08-06 18:47:30 -0700 | [diff] [blame] | 977 | std::vector<std::string> MakePi1DeadNodeLogfiles() { |
| 978 | std::vector<std::string> result; |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 979 | result.emplace_back(logfile_base1_ + "_pi1_data.part0" + Extension()); |
| 980 | result.emplace_back(absl::StrCat( |
| 981 | logfile_base1_, "_", std::get<0>(GetParam()).sha256, Extension())); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 982 | return result; |
| 983 | } |
| 984 | |
| 985 | std::vector<std::vector<std::string>> StructureLogFiles() { |
| 986 | std::vector<std::vector<std::string>> result{ |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 987 | std::vector<std::string>{logfiles_[2], logfiles_[3], logfiles_[4]}, |
| 988 | std::vector<std::string>{logfiles_[5], logfiles_[6]}, |
| 989 | std::vector<std::string>{logfiles_[7], logfiles_[8], logfiles_[9]}, |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 990 | std::vector<std::string>{logfiles_[10], logfiles_[11]}, |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 991 | std::vector<std::string>{logfiles_[12], logfiles_[13]}}; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 992 | |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 993 | if (shared()) { |
| 994 | result.emplace_back(std::vector<std::string>{logfiles_[14], logfiles_[15], |
| 995 | logfiles_[16]}); |
| 996 | result.emplace_back( |
| 997 | std::vector<std::string>{logfiles_[17], logfiles_[18]}); |
| 998 | } else { |
| 999 | result.emplace_back( |
| 1000 | std::vector<std::string>{logfiles_[14], logfiles_[15]}); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1001 | result.emplace_back( |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1002 | std::vector<std::string>{logfiles_[16], logfiles_[17]}); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1003 | result.emplace_back( |
| 1004 | std::vector<std::string>{logfiles_[18], logfiles_[19]}); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | return result; |
| 1008 | } |
| 1009 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 1010 | std::string Extension() { |
| 1011 | return absl::StrCat(".bfbs", std::get<1>(GetParam()).extension); |
| 1012 | } |
| 1013 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 1014 | LoggerState MakeLogger(NodeEventLoopFactory *node, |
Austin Schuh | 5b728b7 | 2021-06-16 14:57:15 -0700 | [diff] [blame] | 1015 | SimulatedEventLoopFactory *factory = nullptr, |
| 1016 | const Configuration *configuration = nullptr) { |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1017 | if (factory == nullptr) { |
| 1018 | factory = &event_loop_factory_; |
| 1019 | } |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 1020 | return LoggerState::MakeLogger(node, factory, std::get<1>(GetParam()), |
| 1021 | configuration); |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 1024 | void StartLogger(LoggerState *logger, std::string logfile_base = "") { |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1025 | if (logfile_base.empty()) { |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1026 | if (logger->event_loop->node()->name()->string_view() == "pi1") { |
| 1027 | logfile_base = logfile_base1_; |
| 1028 | } else { |
| 1029 | logfile_base = logfile_base2_; |
| 1030 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1031 | } |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 1032 | logger->StartLogger(logfile_base); |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1033 | } |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1034 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1035 | void VerifyParts(const std::vector<LogFile> &sorted_parts, |
| 1036 | const std::vector<std::string> &corrupted_parts = {}) { |
| 1037 | EXPECT_EQ(sorted_parts.size(), 2u); |
| 1038 | |
| 1039 | // Count up the number of UUIDs and make sure they are what we expect as a |
| 1040 | // sanity check. |
| 1041 | std::set<std::string> log_event_uuids; |
| 1042 | std::set<std::string> parts_uuids; |
| 1043 | std::set<std::string> both_uuids; |
| 1044 | |
| 1045 | size_t missing_rt_count = 0; |
| 1046 | |
| 1047 | std::vector<std::string> logger_nodes; |
| 1048 | for (const LogFile &log_file : sorted_parts) { |
| 1049 | EXPECT_FALSE(log_file.log_event_uuid.empty()); |
| 1050 | log_event_uuids.insert(log_file.log_event_uuid); |
| 1051 | logger_nodes.emplace_back(log_file.logger_node); |
| 1052 | both_uuids.insert(log_file.log_event_uuid); |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1053 | EXPECT_TRUE(log_file.config); |
| 1054 | EXPECT_EQ(log_file.name, |
| 1055 | absl::StrCat("name_prefix_", log_file.logger_node)); |
Austin Schuh | fa71268 | 2022-05-11 16:43:42 -0700 | [diff] [blame] | 1056 | EXPECT_EQ(log_file.logger_sha1, |
| 1057 | absl::StrCat("logger_sha1_", log_file.logger_node)); |
| 1058 | EXPECT_EQ(log_file.logger_version, |
| 1059 | absl::StrCat("logger_version_", log_file.logger_node)); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1060 | |
| 1061 | for (const LogParts &part : log_file.parts) { |
| 1062 | EXPECT_NE(part.monotonic_start_time, aos::monotonic_clock::min_time) |
| 1063 | << ": " << part; |
| 1064 | missing_rt_count += |
| 1065 | part.realtime_start_time == aos::realtime_clock::min_time; |
| 1066 | |
| 1067 | EXPECT_TRUE(log_event_uuids.find(part.log_event_uuid) != |
| 1068 | log_event_uuids.end()); |
| 1069 | EXPECT_NE(part.node, ""); |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1070 | EXPECT_TRUE(log_file.config); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1071 | parts_uuids.insert(part.parts_uuid); |
| 1072 | both_uuids.insert(part.parts_uuid); |
| 1073 | } |
| 1074 | } |
| 1075 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1076 | // We won't have RT timestamps for 5 or 6 log files. We don't log the RT |
| 1077 | // start time on remote nodes because we don't know it and would be |
| 1078 | // guessing. And the log reader can actually do a better job. The number |
| 1079 | // depends on if we have the remote timestamps split across 2 files, or just |
| 1080 | // across 1, depending on if we are using a split or combined timestamp |
| 1081 | // channel config. |
| 1082 | EXPECT_EQ(missing_rt_count, shared() ? 5u : 6u); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1083 | |
| 1084 | EXPECT_EQ(log_event_uuids.size(), 2u); |
| 1085 | EXPECT_EQ(parts_uuids.size(), ToLogReaderVector(sorted_parts).size()); |
| 1086 | EXPECT_EQ(log_event_uuids.size() + parts_uuids.size(), both_uuids.size()); |
| 1087 | |
| 1088 | // Test that each list of parts is in order. Don't worry about the ordering |
| 1089 | // between part file lists though. |
| 1090 | // (inner vectors all need to be in order, but outer one doesn't matter). |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1091 | ASSERT_THAT(ToLogReaderVector(sorted_parts), |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1092 | ::testing::UnorderedElementsAreArray(structured_logfiles_)); |
| 1093 | |
| 1094 | EXPECT_THAT(logger_nodes, ::testing::UnorderedElementsAre("pi1", "pi2")); |
| 1095 | |
| 1096 | EXPECT_NE(sorted_parts[0].realtime_start_time, |
| 1097 | aos::realtime_clock::min_time); |
| 1098 | EXPECT_NE(sorted_parts[1].realtime_start_time, |
| 1099 | aos::realtime_clock::min_time); |
| 1100 | |
| 1101 | EXPECT_NE(sorted_parts[0].monotonic_start_time, |
| 1102 | aos::monotonic_clock::min_time); |
| 1103 | EXPECT_NE(sorted_parts[1].monotonic_start_time, |
| 1104 | aos::monotonic_clock::min_time); |
| 1105 | |
| 1106 | EXPECT_THAT(sorted_parts[0].corrupted, ::testing::Eq(corrupted_parts)); |
| 1107 | EXPECT_THAT(sorted_parts[1].corrupted, ::testing::Eq(corrupted_parts)); |
| 1108 | } |
| 1109 | |
| 1110 | void AddExtension(std::string_view extension) { |
| 1111 | std::transform(logfiles_.begin(), logfiles_.end(), logfiles_.begin(), |
| 1112 | [extension](const std::string &in) { |
| 1113 | return absl::StrCat(in, extension); |
| 1114 | }); |
| 1115 | |
| 1116 | std::transform(structured_logfiles_.begin(), structured_logfiles_.end(), |
| 1117 | structured_logfiles_.begin(), |
| 1118 | [extension](std::vector<std::string> in) { |
| 1119 | std::transform(in.begin(), in.end(), in.begin(), |
| 1120 | [extension](const std::string &in_str) { |
| 1121 | return absl::StrCat(in_str, extension); |
| 1122 | }); |
| 1123 | return in; |
| 1124 | }); |
| 1125 | } |
| 1126 | |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1127 | // Config and factory. |
| 1128 | aos::FlatbufferDetachedBuffer<aos::Configuration> config_; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1129 | message_bridge::TestingTimeConverter time_converter_; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1130 | SimulatedEventLoopFactory event_loop_factory_; |
| 1131 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 1132 | NodeEventLoopFactory *const pi1_; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1133 | const size_t pi1_index_; |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 1134 | NodeEventLoopFactory *const pi2_; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1135 | const size_t pi2_index_; |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1136 | |
| 1137 | std::string tmp_dir_; |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1138 | std::string logfile_base1_; |
| 1139 | std::string logfile_base2_; |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 1140 | std::vector<std::string> pi1_reboot_logfiles_; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1141 | std::vector<std::string> logfiles_; |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 1142 | std::vector<std::string> pi1_single_direction_logfiles_; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1143 | |
| 1144 | std::vector<std::vector<std::string>> structured_logfiles_; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1145 | }; |
| 1146 | |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1147 | // Counts the number of messages on a channel. Returns (channel name, channel |
| 1148 | // type, count) for every message matching matcher() |
| 1149 | std::vector<std::tuple<std::string, std::string, int>> CountChannelsMatching( |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 1150 | std::shared_ptr<const aos::Configuration> config, std::string_view filename, |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 1151 | std::function<bool(const UnpackedMessageHeader *)> matcher) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1152 | MessageReader message_reader(filename); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1153 | std::vector<int> counts(config->channels()->size(), 0); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1154 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1155 | while (true) { |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 1156 | std::shared_ptr<UnpackedMessageHeader> msg = message_reader.ReadMessage(); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1157 | if (!msg) { |
| 1158 | break; |
| 1159 | } |
| 1160 | |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 1161 | if (matcher(msg.get())) { |
| 1162 | counts[msg->channel_index]++; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1166 | std::vector<std::tuple<std::string, std::string, int>> result; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1167 | int channel = 0; |
| 1168 | for (size_t i = 0; i < counts.size(); ++i) { |
| 1169 | if (counts[i] != 0) { |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1170 | const Channel *channel = config->channels()->Get(i); |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1171 | result.push_back(std::make_tuple(channel->name()->str(), |
| 1172 | channel->type()->str(), counts[i])); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1173 | } |
| 1174 | ++channel; |
| 1175 | } |
| 1176 | |
| 1177 | return result; |
| 1178 | } |
| 1179 | |
| 1180 | // Counts the number of messages (channel, count) for all data messages. |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1181 | std::vector<std::tuple<std::string, std::string, int>> CountChannelsData( |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1182 | std::shared_ptr<const aos::Configuration> config, |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1183 | std::string_view filename) { |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 1184 | return CountChannelsMatching( |
| 1185 | config, filename, [](const UnpackedMessageHeader *msg) { |
| 1186 | if (msg->span.data() != nullptr) { |
| 1187 | CHECK(!msg->monotonic_remote_time.has_value()); |
| 1188 | CHECK(!msg->realtime_remote_time.has_value()); |
| 1189 | CHECK(!msg->remote_queue_index.has_value()); |
| 1190 | return true; |
| 1191 | } |
| 1192 | return false; |
| 1193 | }); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | // Counts the number of messages (channel, count) for all timestamp messages. |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1197 | std::vector<std::tuple<std::string, std::string, int>> CountChannelsTimestamp( |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1198 | std::shared_ptr<const aos::Configuration> config, |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1199 | std::string_view filename) { |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 1200 | return CountChannelsMatching( |
| 1201 | config, filename, [](const UnpackedMessageHeader *msg) { |
| 1202 | if (msg->span.data() == nullptr) { |
| 1203 | CHECK(msg->monotonic_remote_time.has_value()); |
| 1204 | CHECK(msg->realtime_remote_time.has_value()); |
| 1205 | CHECK(msg->remote_queue_index.has_value()); |
| 1206 | return true; |
| 1207 | } |
| 1208 | return false; |
| 1209 | }); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1212 | // Tests that we can write and read simple multi-node log files. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1213 | TEST_P(MultinodeLoggerTest, SimpleMultiNode) { |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1214 | std::vector<std::string> actual_filenames; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1215 | time_converter_.StartEqual(); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1216 | |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1217 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1218 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1219 | LoggerState pi2_logger = MakeLogger(pi2_); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1220 | |
| 1221 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1222 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1223 | StartLogger(&pi1_logger); |
| 1224 | StartLogger(&pi2_logger); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1225 | |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1226 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1227 | pi1_logger.AppendAllFilenames(&actual_filenames); |
| 1228 | pi2_logger.AppendAllFilenames(&actual_filenames); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1231 | ASSERT_THAT(actual_filenames, |
| 1232 | ::testing::UnorderedElementsAreArray(logfiles_)); |
| 1233 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1234 | { |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1235 | std::set<std::string> logfile_uuids; |
| 1236 | std::set<std::string> parts_uuids; |
| 1237 | // Confirm that we have the expected number of UUIDs for both the logfile |
| 1238 | // UUIDs and parts UUIDs. |
Austin Schuh | add6eb3 | 2020-11-09 21:24:26 -0800 | [diff] [blame] | 1239 | std::vector<SizePrefixedFlatbufferVector<LogFileHeader>> log_header; |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1240 | for (std::string_view f : logfiles_) { |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1241 | log_header.emplace_back(ReadHeader(f).value()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1242 | if (!log_header.back().message().has_configuration()) { |
| 1243 | logfile_uuids.insert( |
| 1244 | log_header.back().message().log_event_uuid()->str()); |
| 1245 | parts_uuids.insert(log_header.back().message().parts_uuid()->str()); |
| 1246 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1247 | } |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1248 | |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1249 | EXPECT_EQ(logfile_uuids.size(), 2u); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1250 | if (shared()) { |
| 1251 | EXPECT_EQ(parts_uuids.size(), 7u); |
| 1252 | } else { |
| 1253 | EXPECT_EQ(parts_uuids.size(), 8u); |
| 1254 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1255 | |
| 1256 | // And confirm everything is on the correct node. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1257 | EXPECT_EQ(log_header[2].message().node()->name()->string_view(), "pi1"); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1258 | EXPECT_EQ(log_header[3].message().node()->name()->string_view(), "pi1"); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1259 | EXPECT_EQ(log_header[4].message().node()->name()->string_view(), "pi1"); |
| 1260 | |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1261 | EXPECT_EQ(log_header[5].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1262 | EXPECT_EQ(log_header[6].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1263 | |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1264 | EXPECT_EQ(log_header[7].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1265 | EXPECT_EQ(log_header[8].message().node()->name()->string_view(), "pi2"); |
| 1266 | EXPECT_EQ(log_header[9].message().node()->name()->string_view(), "pi2"); |
| 1267 | |
| 1268 | EXPECT_EQ(log_header[10].message().node()->name()->string_view(), "pi1"); |
| 1269 | EXPECT_EQ(log_header[11].message().node()->name()->string_view(), "pi1"); |
| 1270 | |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1271 | EXPECT_EQ(log_header[12].message().node()->name()->string_view(), "pi2"); |
| 1272 | EXPECT_EQ(log_header[13].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1273 | |
| 1274 | if (shared()) { |
| 1275 | EXPECT_EQ(log_header[14].message().node()->name()->string_view(), "pi2"); |
| 1276 | EXPECT_EQ(log_header[15].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1277 | EXPECT_EQ(log_header[16].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1278 | |
| 1279 | EXPECT_EQ(log_header[17].message().node()->name()->string_view(), "pi1"); |
| 1280 | EXPECT_EQ(log_header[18].message().node()->name()->string_view(), "pi1"); |
| 1281 | } else { |
| 1282 | EXPECT_EQ(log_header[14].message().node()->name()->string_view(), "pi2"); |
| 1283 | EXPECT_EQ(log_header[15].message().node()->name()->string_view(), "pi2"); |
| 1284 | |
| 1285 | EXPECT_EQ(log_header[16].message().node()->name()->string_view(), "pi1"); |
| 1286 | EXPECT_EQ(log_header[17].message().node()->name()->string_view(), "pi1"); |
| 1287 | |
| 1288 | EXPECT_EQ(log_header[18].message().node()->name()->string_view(), "pi2"); |
| 1289 | EXPECT_EQ(log_header[19].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1290 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1291 | |
| 1292 | // And the parts index matches. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1293 | EXPECT_EQ(log_header[2].message().parts_index(), 0); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1294 | EXPECT_EQ(log_header[3].message().parts_index(), 1); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1295 | EXPECT_EQ(log_header[4].message().parts_index(), 2); |
| 1296 | |
| 1297 | EXPECT_EQ(log_header[5].message().parts_index(), 0); |
| 1298 | EXPECT_EQ(log_header[6].message().parts_index(), 1); |
| 1299 | |
| 1300 | EXPECT_EQ(log_header[7].message().parts_index(), 0); |
| 1301 | EXPECT_EQ(log_header[8].message().parts_index(), 1); |
| 1302 | EXPECT_EQ(log_header[9].message().parts_index(), 2); |
| 1303 | |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1304 | EXPECT_EQ(log_header[10].message().parts_index(), 0); |
| 1305 | EXPECT_EQ(log_header[11].message().parts_index(), 1); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1306 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1307 | EXPECT_EQ(log_header[12].message().parts_index(), 0); |
| 1308 | EXPECT_EQ(log_header[13].message().parts_index(), 1); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1309 | |
| 1310 | if (shared()) { |
| 1311 | EXPECT_EQ(log_header[14].message().parts_index(), 0); |
| 1312 | EXPECT_EQ(log_header[15].message().parts_index(), 1); |
| 1313 | EXPECT_EQ(log_header[16].message().parts_index(), 2); |
| 1314 | |
| 1315 | EXPECT_EQ(log_header[17].message().parts_index(), 0); |
| 1316 | EXPECT_EQ(log_header[18].message().parts_index(), 1); |
| 1317 | } else { |
| 1318 | EXPECT_EQ(log_header[14].message().parts_index(), 0); |
| 1319 | EXPECT_EQ(log_header[15].message().parts_index(), 1); |
| 1320 | |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1321 | EXPECT_EQ(log_header[16].message().parts_index(), 0); |
| 1322 | EXPECT_EQ(log_header[17].message().parts_index(), 1); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1323 | |
| 1324 | EXPECT_EQ(log_header[18].message().parts_index(), 0); |
| 1325 | EXPECT_EQ(log_header[19].message().parts_index(), 1); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1326 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1329 | const std::vector<LogFile> sorted_log_files = SortParts(logfiles_); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1330 | { |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1331 | using ::testing::UnorderedElementsAre; |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1332 | std::shared_ptr<const aos::Configuration> config = |
| 1333 | sorted_log_files[0].config; |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1334 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1335 | // Timing reports, pings |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 1336 | EXPECT_THAT(CountChannelsData(config, logfiles_[2]), |
| 1337 | UnorderedElementsAre( |
| 1338 | std::make_tuple("/pi1/aos", |
| 1339 | "aos.message_bridge.ServerStatistics", 1), |
| 1340 | std::make_tuple("/test", "aos.examples.Ping", 1))) |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1341 | << " : " << logfiles_[2]; |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 1342 | { |
| 1343 | std::vector<std::tuple<std::string, std::string, int>> channel_counts = { |
| 1344 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 1), |
| 1345 | std::make_tuple("/pi1/aos", "aos.message_bridge.ClientStatistics", |
| 1346 | 1)}; |
| 1347 | if (!std::get<0>(GetParam()).shared) { |
| 1348 | channel_counts.push_back( |
| 1349 | std::make_tuple("/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 1350 | "aos-message_bridge-Timestamp", |
| 1351 | "aos.message_bridge.RemoteMessage", 1)); |
| 1352 | } |
| 1353 | EXPECT_THAT(CountChannelsData(config, logfiles_[3]), |
| 1354 | ::testing::UnorderedElementsAreArray(channel_counts)) |
| 1355 | << " : " << logfiles_[3]; |
| 1356 | } |
| 1357 | { |
| 1358 | std::vector<std::tuple<std::string, std::string, int>> channel_counts = { |
| 1359 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 199), |
| 1360 | std::make_tuple("/pi1/aos", "aos.message_bridge.ServerStatistics", |
| 1361 | 20), |
| 1362 | std::make_tuple("/pi1/aos", "aos.message_bridge.ClientStatistics", |
| 1363 | 199), |
| 1364 | std::make_tuple("/pi1/aos", "aos.timing.Report", 40), |
| 1365 | std::make_tuple("/test", "aos.examples.Ping", 2000)}; |
| 1366 | if (!std::get<0>(GetParam()).shared) { |
| 1367 | channel_counts.push_back( |
| 1368 | std::make_tuple("/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 1369 | "aos-message_bridge-Timestamp", |
| 1370 | "aos.message_bridge.RemoteMessage", 199)); |
| 1371 | } |
| 1372 | EXPECT_THAT(CountChannelsData(config, logfiles_[4]), |
| 1373 | ::testing::UnorderedElementsAreArray(channel_counts)) |
| 1374 | << " : " << logfiles_[4]; |
| 1375 | } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1376 | // Timestamps for pong |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1377 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[2]), |
| 1378 | UnorderedElementsAre()) |
| 1379 | << " : " << logfiles_[2]; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1380 | EXPECT_THAT( |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1381 | CountChannelsTimestamp(config, logfiles_[3]), |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1382 | UnorderedElementsAre(std::make_tuple("/test", "aos.examples.Pong", 1))) |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1383 | << " : " << logfiles_[3]; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1384 | EXPECT_THAT( |
| 1385 | CountChannelsTimestamp(config, logfiles_[4]), |
| 1386 | UnorderedElementsAre( |
| 1387 | std::make_tuple("/test", "aos.examples.Pong", 2000), |
| 1388 | std::make_tuple("/pi2/aos", "aos.message_bridge.Timestamp", 200))) |
| 1389 | << " : " << logfiles_[4]; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1390 | |
| 1391 | // Pong data. |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1392 | EXPECT_THAT( |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1393 | CountChannelsData(config, logfiles_[5]), |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1394 | UnorderedElementsAre(std::make_tuple("/test", "aos.examples.Pong", 91))) |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1395 | << " : " << logfiles_[5]; |
| 1396 | EXPECT_THAT(CountChannelsData(config, logfiles_[6]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1397 | UnorderedElementsAre( |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1398 | std::make_tuple("/test", "aos.examples.Pong", 1910))) |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1399 | << " : " << logfiles_[6]; |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1400 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1401 | // No timestamps |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1402 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[5]), |
| 1403 | UnorderedElementsAre()) |
| 1404 | << " : " << logfiles_[5]; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1405 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[6]), |
| 1406 | UnorderedElementsAre()) |
| 1407 | << " : " << logfiles_[6]; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1408 | |
| 1409 | // Timing reports and pongs. |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1410 | EXPECT_THAT(CountChannelsData(config, logfiles_[7]), |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1411 | UnorderedElementsAre(std::make_tuple( |
| 1412 | "/pi2/aos", "aos.message_bridge.ServerStatistics", 1))) |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1413 | << " : " << logfiles_[7]; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1414 | EXPECT_THAT( |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1415 | CountChannelsData(config, logfiles_[8]), |
| 1416 | UnorderedElementsAre(std::make_tuple("/test", "aos.examples.Pong", 1))) |
| 1417 | << " : " << logfiles_[8]; |
| 1418 | EXPECT_THAT( |
| 1419 | CountChannelsData(config, logfiles_[9]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1420 | UnorderedElementsAre( |
| 1421 | std::make_tuple("/pi2/aos", "aos.message_bridge.Timestamp", 200), |
James Kuszmaul | 4f106fb | 2021-01-05 20:53:02 -0800 | [diff] [blame] | 1422 | std::make_tuple("/pi2/aos", "aos.message_bridge.ServerStatistics", |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1423 | 20), |
James Kuszmaul | 4f106fb | 2021-01-05 20:53:02 -0800 | [diff] [blame] | 1424 | std::make_tuple("/pi2/aos", "aos.message_bridge.ClientStatistics", |
| 1425 | 200), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1426 | std::make_tuple("/pi2/aos", "aos.timing.Report", 40), |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1427 | std::make_tuple("/test", "aos.examples.Pong", 2000))) |
| 1428 | << " : " << logfiles_[9]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1429 | // And ping timestamps. |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1430 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[7]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1431 | UnorderedElementsAre()) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1432 | << " : " << logfiles_[7]; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1433 | EXPECT_THAT( |
| 1434 | CountChannelsTimestamp(config, logfiles_[8]), |
| 1435 | UnorderedElementsAre(std::make_tuple("/test", "aos.examples.Ping", 1))) |
| 1436 | << " : " << logfiles_[8]; |
| 1437 | EXPECT_THAT( |
| 1438 | CountChannelsTimestamp(config, logfiles_[9]), |
| 1439 | UnorderedElementsAre( |
| 1440 | std::make_tuple("/test", "aos.examples.Ping", 2000), |
| 1441 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 200))) |
| 1442 | << " : " << logfiles_[9]; |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1443 | |
| 1444 | // And then test that the remotely logged timestamp data files only have |
| 1445 | // timestamps in them. |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1446 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[10]), |
| 1447 | UnorderedElementsAre()) |
| 1448 | << " : " << logfiles_[10]; |
| 1449 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[11]), |
| 1450 | UnorderedElementsAre()) |
| 1451 | << " : " << logfiles_[11]; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1452 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[12]), |
| 1453 | UnorderedElementsAre()) |
| 1454 | << " : " << logfiles_[12]; |
| 1455 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[13]), |
| 1456 | UnorderedElementsAre()) |
| 1457 | << " : " << logfiles_[13]; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1458 | |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1459 | EXPECT_THAT(CountChannelsData(config, logfiles_[10]), |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1460 | UnorderedElementsAre(std::make_tuple( |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1461 | "/pi1/aos", "aos.message_bridge.Timestamp", 9))) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1462 | << " : " << logfiles_[10]; |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1463 | EXPECT_THAT(CountChannelsData(config, logfiles_[11]), |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1464 | UnorderedElementsAre(std::make_tuple( |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1465 | "/pi1/aos", "aos.message_bridge.Timestamp", 191))) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1466 | << " : " << logfiles_[11]; |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1467 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1468 | EXPECT_THAT(CountChannelsData(config, logfiles_[12]), |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1469 | UnorderedElementsAre(std::make_tuple( |
| 1470 | "/pi2/aos", "aos.message_bridge.Timestamp", 9))) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1471 | << " : " << logfiles_[12]; |
| 1472 | EXPECT_THAT(CountChannelsData(config, logfiles_[13]), |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1473 | UnorderedElementsAre(std::make_tuple( |
| 1474 | "/pi2/aos", "aos.message_bridge.Timestamp", 191))) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1475 | << " : " << logfiles_[13]; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1476 | |
| 1477 | // Timestamps from pi2 on pi1, and the other way. |
| 1478 | if (shared()) { |
| 1479 | EXPECT_THAT(CountChannelsData(config, logfiles_[14]), |
| 1480 | UnorderedElementsAre()) |
| 1481 | << " : " << logfiles_[14]; |
| 1482 | EXPECT_THAT(CountChannelsData(config, logfiles_[15]), |
| 1483 | UnorderedElementsAre()) |
| 1484 | << " : " << logfiles_[15]; |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1485 | EXPECT_THAT(CountChannelsData(config, logfiles_[16]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1486 | UnorderedElementsAre()) |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1487 | << " : " << logfiles_[16]; |
| 1488 | EXPECT_THAT(CountChannelsData(config, logfiles_[17]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1489 | UnorderedElementsAre()) |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1490 | << " : " << logfiles_[17]; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1491 | EXPECT_THAT(CountChannelsData(config, logfiles_[18]), |
| 1492 | UnorderedElementsAre()) |
| 1493 | << " : " << logfiles_[18]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1494 | |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1495 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[14]), |
| 1496 | UnorderedElementsAre( |
| 1497 | std::make_tuple("/test", "aos.examples.Ping", 1))) |
| 1498 | << " : " << logfiles_[14]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1499 | EXPECT_THAT( |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1500 | CountChannelsTimestamp(config, logfiles_[15]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1501 | UnorderedElementsAre( |
| 1502 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 9), |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1503 | std::make_tuple("/test", "aos.examples.Ping", 90))) |
| 1504 | << " : " << logfiles_[15]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1505 | EXPECT_THAT( |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1506 | CountChannelsTimestamp(config, logfiles_[16]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1507 | UnorderedElementsAre( |
| 1508 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 191), |
| 1509 | std::make_tuple("/test", "aos.examples.Ping", 1910))) |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1510 | << " : " << logfiles_[16]; |
| 1511 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[17]), |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1512 | UnorderedElementsAre(std::make_tuple( |
| 1513 | "/pi2/aos", "aos.message_bridge.Timestamp", 9))) |
| 1514 | << " : " << logfiles_[17]; |
| 1515 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[18]), |
| 1516 | UnorderedElementsAre(std::make_tuple( |
| 1517 | "/pi2/aos", "aos.message_bridge.Timestamp", 191))) |
| 1518 | << " : " << logfiles_[18]; |
| 1519 | } else { |
| 1520 | EXPECT_THAT(CountChannelsData(config, logfiles_[14]), |
| 1521 | UnorderedElementsAre()) |
| 1522 | << " : " << logfiles_[14]; |
| 1523 | EXPECT_THAT(CountChannelsData(config, logfiles_[15]), |
| 1524 | UnorderedElementsAre()) |
| 1525 | << " : " << logfiles_[15]; |
| 1526 | EXPECT_THAT(CountChannelsData(config, logfiles_[16]), |
| 1527 | UnorderedElementsAre()) |
| 1528 | << " : " << logfiles_[16]; |
| 1529 | EXPECT_THAT(CountChannelsData(config, logfiles_[17]), |
| 1530 | UnorderedElementsAre()) |
| 1531 | << " : " << logfiles_[17]; |
| 1532 | EXPECT_THAT(CountChannelsData(config, logfiles_[18]), |
| 1533 | UnorderedElementsAre()) |
| 1534 | << " : " << logfiles_[18]; |
| 1535 | EXPECT_THAT(CountChannelsData(config, logfiles_[19]), |
| 1536 | UnorderedElementsAre()) |
| 1537 | << " : " << logfiles_[19]; |
| 1538 | |
| 1539 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[14]), |
| 1540 | UnorderedElementsAre(std::make_tuple( |
| 1541 | "/pi1/aos", "aos.message_bridge.Timestamp", 9))) |
| 1542 | << " : " << logfiles_[14]; |
| 1543 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[15]), |
| 1544 | UnorderedElementsAre(std::make_tuple( |
| 1545 | "/pi1/aos", "aos.message_bridge.Timestamp", 191))) |
| 1546 | << " : " << logfiles_[15]; |
| 1547 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[16]), |
| 1548 | UnorderedElementsAre(std::make_tuple( |
| 1549 | "/pi2/aos", "aos.message_bridge.Timestamp", 9))) |
| 1550 | << " : " << logfiles_[16]; |
| 1551 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[17]), |
| 1552 | UnorderedElementsAre(std::make_tuple( |
| 1553 | "/pi2/aos", "aos.message_bridge.Timestamp", 191))) |
| 1554 | << " : " << logfiles_[17]; |
| 1555 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[18]), |
| 1556 | UnorderedElementsAre( |
| 1557 | std::make_tuple("/test", "aos.examples.Ping", 91))) |
| 1558 | << " : " << logfiles_[18]; |
| 1559 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[19]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1560 | UnorderedElementsAre( |
| 1561 | std::make_tuple("/test", "aos.examples.Ping", 1910))) |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1562 | << " : " << logfiles_[19]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1563 | } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1564 | } |
| 1565 | |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1566 | LogReader reader(sorted_log_files); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1567 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1568 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
Austin Schuh | 6331ef9 | 2020-01-07 18:28:09 -0800 | [diff] [blame] | 1569 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1570 | |
| 1571 | // This sends out the fetched messages and advances time to the start of the |
| 1572 | // log file. |
Austin Schuh | 6331ef9 | 2020-01-07 18:28:09 -0800 | [diff] [blame] | 1573 | reader.Register(&log_reader_factory); |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 1574 | |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 1575 | const Node *pi1 = |
| 1576 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1577 | const Node *pi2 = |
| 1578 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 1579 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1580 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi1) << " pi1"; |
| 1581 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi2) << " pi2"; |
| 1582 | LOG(INFO) << "now pi1 " |
| 1583 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now(); |
| 1584 | LOG(INFO) << "now pi2 " |
| 1585 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now(); |
| 1586 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 1587 | EXPECT_THAT(reader.LoggedNodes(), |
| 1588 | ::testing::ElementsAre( |
| 1589 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 1590 | configuration::GetNode(reader.logged_configuration(), pi2))); |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 1591 | |
| 1592 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1593 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1594 | std::unique_ptr<EventLoop> pi1_event_loop = |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 1595 | log_reader_factory.MakeEventLoop("test", pi1); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1596 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1597 | log_reader_factory.MakeEventLoop("test", pi2); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1598 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1599 | int pi1_ping_count = 10; |
| 1600 | int pi2_ping_count = 10; |
| 1601 | int pi1_pong_count = 10; |
| 1602 | int pi2_pong_count = 10; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1603 | |
| 1604 | // Confirm that the ping value matches. |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1605 | pi1_event_loop->MakeWatcher( |
| 1606 | "/test", [&pi1_ping_count, &pi1_event_loop](const examples::Ping &ping) { |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1607 | VLOG(1) << "Pi1 ping " << FlatbufferToJson(&ping) << " at " |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1608 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1609 | << pi1_event_loop->context().monotonic_event_time; |
| 1610 | EXPECT_EQ(ping.value(), pi1_ping_count + 1); |
| 1611 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time, |
| 1612 | pi1_ping_count * chrono::milliseconds(10) + |
| 1613 | monotonic_clock::epoch()); |
| 1614 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time, |
| 1615 | pi1_ping_count * chrono::milliseconds(10) + |
| 1616 | realtime_clock::epoch()); |
| 1617 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time, |
| 1618 | pi1_event_loop->context().monotonic_event_time); |
| 1619 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time, |
| 1620 | pi1_event_loop->context().realtime_event_time); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1621 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1622 | ++pi1_ping_count; |
| 1623 | }); |
| 1624 | pi2_event_loop->MakeWatcher( |
| 1625 | "/test", [&pi2_ping_count, &pi2_event_loop](const examples::Ping &ping) { |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1626 | VLOG(1) << "Pi2 ping " << FlatbufferToJson(&ping) << " at " |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1627 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1628 | << pi2_event_loop->context().monotonic_event_time; |
| 1629 | EXPECT_EQ(ping.value(), pi2_ping_count + 1); |
| 1630 | |
| 1631 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time, |
| 1632 | pi2_ping_count * chrono::milliseconds(10) + |
| 1633 | monotonic_clock::epoch()); |
| 1634 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time, |
| 1635 | pi2_ping_count * chrono::milliseconds(10) + |
| 1636 | realtime_clock::epoch()); |
| 1637 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time + |
| 1638 | chrono::microseconds(150), |
| 1639 | pi2_event_loop->context().monotonic_event_time); |
| 1640 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time + |
| 1641 | chrono::microseconds(150), |
| 1642 | pi2_event_loop->context().realtime_event_time); |
| 1643 | ++pi2_ping_count; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1644 | }); |
| 1645 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1646 | constexpr ssize_t kQueueIndexOffset = -9; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1647 | // Confirm that the ping and pong counts both match, and the value also |
| 1648 | // matches. |
| 1649 | pi1_event_loop->MakeWatcher( |
| 1650 | "/test", [&pi1_event_loop, &pi1_ping_count, |
| 1651 | &pi1_pong_count](const examples::Pong &pong) { |
| 1652 | VLOG(1) << "Pi1 pong " << FlatbufferToJson(&pong) << " at " |
| 1653 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1654 | << pi1_event_loop->context().monotonic_event_time; |
| 1655 | |
| 1656 | EXPECT_EQ(pi1_event_loop->context().remote_queue_index, |
| 1657 | pi1_pong_count + kQueueIndexOffset); |
| 1658 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time, |
| 1659 | chrono::microseconds(200) + |
| 1660 | pi1_pong_count * chrono::milliseconds(10) + |
| 1661 | monotonic_clock::epoch()); |
| 1662 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time, |
| 1663 | chrono::microseconds(200) + |
| 1664 | pi1_pong_count * chrono::milliseconds(10) + |
| 1665 | realtime_clock::epoch()); |
| 1666 | |
| 1667 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time + |
| 1668 | chrono::microseconds(150), |
| 1669 | pi1_event_loop->context().monotonic_event_time); |
| 1670 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time + |
| 1671 | chrono::microseconds(150), |
| 1672 | pi1_event_loop->context().realtime_event_time); |
| 1673 | |
| 1674 | EXPECT_EQ(pong.value(), pi1_pong_count + 1); |
| 1675 | ++pi1_pong_count; |
| 1676 | EXPECT_EQ(pi1_ping_count, pi1_pong_count); |
| 1677 | }); |
| 1678 | pi2_event_loop->MakeWatcher( |
| 1679 | "/test", [&pi2_event_loop, &pi2_ping_count, |
| 1680 | &pi2_pong_count](const examples::Pong &pong) { |
| 1681 | VLOG(1) << "Pi2 pong " << FlatbufferToJson(&pong) << " at " |
| 1682 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1683 | << pi2_event_loop->context().monotonic_event_time; |
| 1684 | |
| 1685 | EXPECT_EQ(pi2_event_loop->context().remote_queue_index, |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1686 | pi2_pong_count + kQueueIndexOffset); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1687 | |
| 1688 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time, |
| 1689 | chrono::microseconds(200) + |
| 1690 | pi2_pong_count * chrono::milliseconds(10) + |
| 1691 | monotonic_clock::epoch()); |
| 1692 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time, |
| 1693 | chrono::microseconds(200) + |
| 1694 | pi2_pong_count * chrono::milliseconds(10) + |
| 1695 | realtime_clock::epoch()); |
| 1696 | |
| 1697 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time, |
| 1698 | pi2_event_loop->context().monotonic_event_time); |
| 1699 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time, |
| 1700 | pi2_event_loop->context().realtime_event_time); |
| 1701 | |
| 1702 | EXPECT_EQ(pong.value(), pi2_pong_count + 1); |
| 1703 | ++pi2_pong_count; |
| 1704 | EXPECT_EQ(pi2_ping_count, pi2_pong_count); |
| 1705 | }); |
| 1706 | |
| 1707 | log_reader_factory.Run(); |
| 1708 | EXPECT_EQ(pi1_ping_count, 2010); |
| 1709 | EXPECT_EQ(pi2_ping_count, 2010); |
| 1710 | EXPECT_EQ(pi1_pong_count, 2010); |
| 1711 | EXPECT_EQ(pi2_pong_count, 2010); |
Austin Schuh | 6331ef9 | 2020-01-07 18:28:09 -0800 | [diff] [blame] | 1712 | |
| 1713 | reader.Deregister(); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1714 | } |
| 1715 | |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1716 | typedef MultinodeLoggerTest MultinodeLoggerDeathTest; |
| 1717 | |
| 1718 | // Test that if we feed the replay with a mismatched node list that we die on |
| 1719 | // the LogReader constructor. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1720 | TEST_P(MultinodeLoggerDeathTest, MultiNodeBadReplayConfig) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1721 | time_converter_.StartEqual(); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1722 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1723 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1724 | LoggerState pi2_logger = MakeLogger(pi2_); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1725 | |
| 1726 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1727 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1728 | StartLogger(&pi1_logger); |
| 1729 | StartLogger(&pi2_logger); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1730 | |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1731 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 1732 | } |
| 1733 | |
| 1734 | // Test that, if we add an additional node to the replay config that the |
| 1735 | // logger complains about the mismatch in number of nodes. |
| 1736 | FlatbufferDetachedBuffer<Configuration> extra_nodes_config = |
| 1737 | configuration::MergeWithConfig(&config_.message(), R"({ |
| 1738 | "nodes": [ |
| 1739 | { |
| 1740 | "name": "extra-node" |
| 1741 | } |
| 1742 | ] |
| 1743 | } |
| 1744 | )"); |
| 1745 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 1746 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
| 1747 | EXPECT_DEATH(LogReader(sorted_parts, &extra_nodes_config.message()), |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1748 | "Log file and replay config need to have matching nodes lists."); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1751 | // Tests that we can read log files where they don't start at the same monotonic |
| 1752 | // time. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1753 | TEST_P(MultinodeLoggerTest, StaggeredStart) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1754 | time_converter_.StartEqual(); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1755 | std::vector<std::string> actual_filenames; |
| 1756 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1757 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1758 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1759 | LoggerState pi2_logger = MakeLogger(pi2_); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1760 | |
| 1761 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1762 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1763 | StartLogger(&pi1_logger); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1764 | |
| 1765 | event_loop_factory_.RunFor(chrono::milliseconds(200)); |
| 1766 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1767 | StartLogger(&pi2_logger); |
| 1768 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1769 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1770 | pi1_logger.AppendAllFilenames(&actual_filenames); |
| 1771 | pi2_logger.AppendAllFilenames(&actual_filenames); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1772 | } |
| 1773 | |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 1774 | // Since we delay starting pi2, it already knows about all the timestamps so |
| 1775 | // we don't end up with extra parts. |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 1776 | LogReader reader(SortParts(actual_filenames)); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1777 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1778 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1779 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 1780 | |
| 1781 | // This sends out the fetched messages and advances time to the start of the |
| 1782 | // log file. |
| 1783 | reader.Register(&log_reader_factory); |
| 1784 | |
| 1785 | const Node *pi1 = |
| 1786 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 1787 | const Node *pi2 = |
| 1788 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 1789 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 1790 | EXPECT_THAT(reader.LoggedNodes(), |
| 1791 | ::testing::ElementsAre( |
| 1792 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 1793 | configuration::GetNode(reader.logged_configuration(), pi2))); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1794 | |
| 1795 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
| 1796 | |
| 1797 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 1798 | log_reader_factory.MakeEventLoop("test", pi1); |
| 1799 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1800 | log_reader_factory.MakeEventLoop("test", pi2); |
| 1801 | |
| 1802 | int pi1_ping_count = 30; |
| 1803 | int pi2_ping_count = 30; |
| 1804 | int pi1_pong_count = 30; |
| 1805 | int pi2_pong_count = 30; |
| 1806 | |
| 1807 | // Confirm that the ping value matches. |
| 1808 | pi1_event_loop->MakeWatcher( |
| 1809 | "/test", [&pi1_ping_count, &pi1_event_loop](const examples::Ping &ping) { |
| 1810 | VLOG(1) << "Pi1 ping " << FlatbufferToJson(&ping) |
| 1811 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1812 | << pi1_event_loop->context().monotonic_event_time; |
| 1813 | EXPECT_EQ(ping.value(), pi1_ping_count + 1); |
| 1814 | |
| 1815 | ++pi1_ping_count; |
| 1816 | }); |
| 1817 | pi2_event_loop->MakeWatcher( |
| 1818 | "/test", [&pi2_ping_count, &pi2_event_loop](const examples::Ping &ping) { |
| 1819 | VLOG(1) << "Pi2 ping " << FlatbufferToJson(&ping) |
| 1820 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1821 | << pi2_event_loop->context().monotonic_event_time; |
| 1822 | EXPECT_EQ(ping.value(), pi2_ping_count + 1); |
| 1823 | |
| 1824 | ++pi2_ping_count; |
| 1825 | }); |
| 1826 | |
| 1827 | // Confirm that the ping and pong counts both match, and the value also |
| 1828 | // matches. |
| 1829 | pi1_event_loop->MakeWatcher( |
| 1830 | "/test", [&pi1_event_loop, &pi1_ping_count, |
| 1831 | &pi1_pong_count](const examples::Pong &pong) { |
| 1832 | VLOG(1) << "Pi1 pong " << FlatbufferToJson(&pong) << " at " |
| 1833 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1834 | << pi1_event_loop->context().monotonic_event_time; |
| 1835 | |
| 1836 | EXPECT_EQ(pong.value(), pi1_pong_count + 1); |
| 1837 | ++pi1_pong_count; |
| 1838 | EXPECT_EQ(pi1_ping_count, pi1_pong_count); |
| 1839 | }); |
| 1840 | pi2_event_loop->MakeWatcher( |
| 1841 | "/test", [&pi2_event_loop, &pi2_ping_count, |
| 1842 | &pi2_pong_count](const examples::Pong &pong) { |
| 1843 | VLOG(1) << "Pi2 pong " << FlatbufferToJson(&pong) << " at " |
| 1844 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1845 | << pi2_event_loop->context().monotonic_event_time; |
| 1846 | |
| 1847 | EXPECT_EQ(pong.value(), pi2_pong_count + 1); |
| 1848 | ++pi2_pong_count; |
| 1849 | EXPECT_EQ(pi2_ping_count, pi2_pong_count); |
| 1850 | }); |
| 1851 | |
| 1852 | log_reader_factory.Run(); |
| 1853 | EXPECT_EQ(pi1_ping_count, 2030); |
| 1854 | EXPECT_EQ(pi2_ping_count, 2030); |
| 1855 | EXPECT_EQ(pi1_pong_count, 2030); |
| 1856 | EXPECT_EQ(pi2_pong_count, 2030); |
| 1857 | |
| 1858 | reader.Deregister(); |
| 1859 | } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1860 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1861 | // Tests that we can read log files where the monotonic clocks drift and don't |
| 1862 | // match correctly. While we are here, also test that different ending times |
| 1863 | // also is readable. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1864 | TEST_P(MultinodeLoggerTest, MismatchedClocks) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1865 | // TODO(austin): Negate... |
| 1866 | const chrono::nanoseconds initial_pi2_offset = chrono::seconds(1000); |
| 1867 | |
Austin Schuh | 6616884 | 2021-08-17 19:42:21 -0700 | [diff] [blame] | 1868 | time_converter_.AddMonotonic( |
| 1869 | {BootTimestamp::epoch(), BootTimestamp::epoch() + initial_pi2_offset}); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1870 | // Wait for 95 ms, (~0.1 seconds - 1/2 of the ping/pong period), and set the |
| 1871 | // skew to be 200 uS/s |
| 1872 | const chrono::nanoseconds startup_sleep1 = time_converter_.AddMonotonic( |
| 1873 | {chrono::milliseconds(95), |
| 1874 | chrono::milliseconds(95) - chrono::nanoseconds(200) * 95}); |
| 1875 | // Run another 200 ms to have one logger start first. |
| 1876 | const chrono::nanoseconds startup_sleep2 = time_converter_.AddMonotonic( |
| 1877 | {chrono::milliseconds(200), chrono::milliseconds(200)}); |
| 1878 | // Slew one way then the other at the same 200 uS/S slew rate. Make sure we |
| 1879 | // go far enough to cause problems if this isn't accounted for. |
| 1880 | const chrono::nanoseconds logger_run1 = time_converter_.AddMonotonic( |
| 1881 | {chrono::milliseconds(20000), |
| 1882 | chrono::milliseconds(20000) - chrono::nanoseconds(200) * 20000}); |
| 1883 | const chrono::nanoseconds logger_run2 = time_converter_.AddMonotonic( |
| 1884 | {chrono::milliseconds(40000), |
| 1885 | chrono::milliseconds(40000) + chrono::nanoseconds(200) * 40000}); |
| 1886 | const chrono::nanoseconds logger_run3 = time_converter_.AddMonotonic( |
| 1887 | {chrono::milliseconds(400), chrono::milliseconds(400)}); |
| 1888 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1889 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1890 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 1891 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 1892 | LOG(INFO) << "pi2 times: " << pi2_->monotonic_now() << " " |
| 1893 | << pi2_->realtime_now() << " distributed " |
| 1894 | << pi2_->ToDistributedClock(pi2_->monotonic_now()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1895 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 1896 | LOG(INFO) << "pi2_ times: " << pi2_->monotonic_now() << " " |
| 1897 | << pi2_->realtime_now() << " distributed " |
| 1898 | << pi2_->ToDistributedClock(pi2_->monotonic_now()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1899 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1900 | event_loop_factory_.RunFor(startup_sleep1); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1901 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1902 | StartLogger(&pi2_logger); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1903 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1904 | event_loop_factory_.RunFor(startup_sleep2); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1905 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1906 | { |
| 1907 | // Run pi1's logger for only part of the time. |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1908 | LoggerState pi1_logger = MakeLogger(pi1_); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1909 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1910 | StartLogger(&pi1_logger); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1911 | event_loop_factory_.RunFor(logger_run1); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1912 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1913 | // Make sure we slewed time far enough so that the difference is greater |
| 1914 | // than the network delay. This confirms that if we sort incorrectly, it |
| 1915 | // would show in the results. |
| 1916 | EXPECT_LT( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 1917 | (pi2_->monotonic_now() - pi1_->monotonic_now()) - initial_pi2_offset, |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1918 | -event_loop_factory_.send_delay() - |
| 1919 | event_loop_factory_.network_delay()); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1920 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1921 | event_loop_factory_.RunFor(logger_run2); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1922 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1923 | // And now check that we went far enough the other way to make sure we |
| 1924 | // cover both problems. |
| 1925 | EXPECT_GT( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 1926 | (pi2_->monotonic_now() - pi1_->monotonic_now()) - initial_pi2_offset, |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1927 | event_loop_factory_.send_delay() + |
| 1928 | event_loop_factory_.network_delay()); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | // And log a bit more on pi2. |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1932 | event_loop_factory_.RunFor(logger_run3); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1933 | } |
| 1934 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 1935 | LogReader reader( |
| 1936 | SortParts(MakeLogFiles(logfile_base1_, logfile_base2_, 3, 2))); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1937 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1938 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1939 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 1940 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1941 | const Node *pi1 = |
| 1942 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 1943 | const Node *pi2 = |
| 1944 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 1945 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1946 | // This sends out the fetched messages and advances time to the start of the |
| 1947 | // log file. |
| 1948 | reader.Register(&log_reader_factory); |
| 1949 | |
| 1950 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi1) << " pi1"; |
| 1951 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi2) << " pi2"; |
| 1952 | LOG(INFO) << "now pi1 " |
| 1953 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now(); |
| 1954 | LOG(INFO) << "now pi2 " |
| 1955 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now(); |
| 1956 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1957 | LOG(INFO) << "Done registering (pi1) " |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1958 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now() |
| 1959 | << " " |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1960 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->realtime_now(); |
| 1961 | LOG(INFO) << "Done registering (pi2) " |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1962 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now() |
| 1963 | << " " |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1964 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->realtime_now(); |
| 1965 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 1966 | EXPECT_THAT(reader.LoggedNodes(), |
| 1967 | ::testing::ElementsAre( |
| 1968 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 1969 | configuration::GetNode(reader.logged_configuration(), pi2))); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1970 | |
| 1971 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
| 1972 | |
| 1973 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 1974 | log_reader_factory.MakeEventLoop("test", pi1); |
| 1975 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1976 | log_reader_factory.MakeEventLoop("test", pi2); |
| 1977 | |
| 1978 | int pi1_ping_count = 30; |
| 1979 | int pi2_ping_count = 30; |
| 1980 | int pi1_pong_count = 30; |
| 1981 | int pi2_pong_count = 30; |
| 1982 | |
| 1983 | // Confirm that the ping value matches. |
| 1984 | pi1_event_loop->MakeWatcher( |
| 1985 | "/test", [&pi1_ping_count, &pi1_event_loop](const examples::Ping &ping) { |
| 1986 | VLOG(1) << "Pi1 ping " << FlatbufferToJson(&ping) |
| 1987 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1988 | << pi1_event_loop->context().monotonic_event_time; |
| 1989 | EXPECT_EQ(ping.value(), pi1_ping_count + 1); |
| 1990 | |
| 1991 | ++pi1_ping_count; |
| 1992 | }); |
| 1993 | pi2_event_loop->MakeWatcher( |
| 1994 | "/test", [&pi2_ping_count, &pi2_event_loop](const examples::Ping &ping) { |
| 1995 | VLOG(1) << "Pi2 ping " << FlatbufferToJson(&ping) |
| 1996 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1997 | << pi2_event_loop->context().monotonic_event_time; |
| 1998 | EXPECT_EQ(ping.value(), pi2_ping_count + 1); |
| 1999 | |
| 2000 | ++pi2_ping_count; |
| 2001 | }); |
| 2002 | |
| 2003 | // Confirm that the ping and pong counts both match, and the value also |
| 2004 | // matches. |
| 2005 | pi1_event_loop->MakeWatcher( |
| 2006 | "/test", [&pi1_event_loop, &pi1_ping_count, |
| 2007 | &pi1_pong_count](const examples::Pong &pong) { |
| 2008 | VLOG(1) << "Pi1 pong " << FlatbufferToJson(&pong) << " at " |
| 2009 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 2010 | << pi1_event_loop->context().monotonic_event_time; |
| 2011 | |
| 2012 | EXPECT_EQ(pong.value(), pi1_pong_count + 1); |
| 2013 | ++pi1_pong_count; |
| 2014 | EXPECT_EQ(pi1_ping_count, pi1_pong_count); |
| 2015 | }); |
| 2016 | pi2_event_loop->MakeWatcher( |
| 2017 | "/test", [&pi2_event_loop, &pi2_ping_count, |
| 2018 | &pi2_pong_count](const examples::Pong &pong) { |
| 2019 | VLOG(1) << "Pi2 pong " << FlatbufferToJson(&pong) << " at " |
| 2020 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 2021 | << pi2_event_loop->context().monotonic_event_time; |
| 2022 | |
| 2023 | EXPECT_EQ(pong.value(), pi2_pong_count + 1); |
| 2024 | ++pi2_pong_count; |
| 2025 | EXPECT_EQ(pi2_ping_count, pi2_pong_count); |
| 2026 | }); |
| 2027 | |
| 2028 | log_reader_factory.Run(); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 2029 | EXPECT_EQ(pi1_ping_count, 6030); |
| 2030 | EXPECT_EQ(pi2_ping_count, 6030); |
| 2031 | EXPECT_EQ(pi1_pong_count, 6030); |
| 2032 | EXPECT_EQ(pi2_pong_count, 6030); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 2033 | |
| 2034 | reader.Deregister(); |
| 2035 | } |
| 2036 | |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 2037 | // Tests that we can sort a bunch of parts into the pre-determined sorted parts. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2038 | TEST_P(MultinodeLoggerTest, SortParts) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2039 | time_converter_.StartEqual(); |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 2040 | // Make a bunch of parts. |
| 2041 | { |
| 2042 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2043 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2044 | |
| 2045 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2046 | |
| 2047 | StartLogger(&pi1_logger); |
| 2048 | StartLogger(&pi2_logger); |
| 2049 | |
| 2050 | event_loop_factory_.RunFor(chrono::milliseconds(2000)); |
| 2051 | } |
| 2052 | |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 2053 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2054 | VerifyParts(sorted_parts); |
| 2055 | } |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 2056 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2057 | // Tests that we can sort a bunch of parts with an empty part. We should ignore |
| 2058 | // it and remove it from the sorted list. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2059 | TEST_P(MultinodeLoggerTest, SortEmptyParts) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2060 | time_converter_.StartEqual(); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2061 | // Make a bunch of parts. |
| 2062 | { |
| 2063 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2064 | LoggerState pi2_logger = MakeLogger(pi2_); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 2065 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2066 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 2067 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2068 | StartLogger(&pi1_logger); |
| 2069 | StartLogger(&pi2_logger); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 2070 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2071 | event_loop_factory_.RunFor(chrono::milliseconds(2000)); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2074 | // TODO(austin): Should we flip out if the file can't open? |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 2075 | const std::string kEmptyFile("foobarinvalidfiledoesnotexist" + Extension()); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 2076 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2077 | aos::util::WriteStringToFileOrDie(kEmptyFile, ""); |
| 2078 | logfiles_.emplace_back(kEmptyFile); |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 2079 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2080 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
| 2081 | VerifyParts(sorted_parts, {kEmptyFile}); |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 2084 | // Tests that we can sort a bunch of parts with the end missing off a |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2085 | // file. We should use the part we can read. |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 2086 | TEST_P(MultinodeLoggerTest, SortTruncatedParts) { |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2087 | std::vector<std::string> actual_filenames; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2088 | time_converter_.StartEqual(); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2089 | // Make a bunch of parts. |
| 2090 | { |
| 2091 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2092 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2093 | |
| 2094 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2095 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 2096 | StartLogger(&pi1_logger); |
| 2097 | StartLogger(&pi2_logger); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2098 | |
| 2099 | event_loop_factory_.RunFor(chrono::milliseconds(2000)); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2100 | |
| 2101 | pi1_logger.AppendAllFilenames(&actual_filenames); |
| 2102 | pi2_logger.AppendAllFilenames(&actual_filenames); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2103 | } |
| 2104 | |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2105 | ASSERT_THAT(actual_filenames, |
| 2106 | ::testing::UnorderedElementsAreArray(logfiles_)); |
| 2107 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2108 | // Strip off the end of one of the files. Pick one with a lot of data. |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame] | 2109 | // For snappy, needs to have enough data to be >1 chunk of compressed data so |
| 2110 | // that we don't corrupt the entire log part. |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2111 | ::std::string compressed_contents = |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2112 | aos::util::ReadFileToStringOrDie(logfiles_[4]); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2113 | |
| 2114 | aos::util::WriteStringToFileOrDie( |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2115 | logfiles_[4], |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2116 | compressed_contents.substr(0, compressed_contents.size() - 100)); |
| 2117 | |
| 2118 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
| 2119 | VerifyParts(sorted_parts); |
| 2120 | } |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 2121 | |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 2122 | // Tests that if we remap a remapped channel, it shows up correctly. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2123 | TEST_P(MultinodeLoggerTest, RemapLoggedChannel) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2124 | time_converter_.StartEqual(); |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 2125 | { |
| 2126 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2127 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2128 | |
| 2129 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2130 | |
| 2131 | StartLogger(&pi1_logger); |
| 2132 | StartLogger(&pi2_logger); |
| 2133 | |
| 2134 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 2135 | } |
| 2136 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 2137 | LogReader reader(SortParts(logfiles_)); |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 2138 | |
| 2139 | // Remap just on pi1. |
| 2140 | reader.RemapLoggedChannel<aos::timing::Report>( |
| 2141 | "/aos", configuration::GetNode(reader.configuration(), "pi1")); |
| 2142 | |
| 2143 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 2144 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 2145 | |
Austin Schuh | 1c22735 | 2021-09-17 12:53:54 -0700 | [diff] [blame] | 2146 | std::vector<const Channel *> remapped_channels = reader.RemappedChannels(); |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 2147 | // Note: An extra channel gets remapped automatically due to a timestamp |
| 2148 | // channel being LOCAL_LOGGER'd. |
| 2149 | ASSERT_EQ(remapped_channels.size(), std::get<0>(GetParam()).shared ? 1u : 2u); |
Austin Schuh | 1c22735 | 2021-09-17 12:53:54 -0700 | [diff] [blame] | 2150 | EXPECT_EQ(remapped_channels[0]->name()->string_view(), "/original/pi1/aos"); |
| 2151 | EXPECT_EQ(remapped_channels[0]->type()->string_view(), "aos.timing.Report"); |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 2152 | if (!std::get<0>(GetParam()).shared) { |
| 2153 | EXPECT_EQ(remapped_channels[1]->name()->string_view(), |
| 2154 | "/original/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 2155 | "aos-message_bridge-Timestamp"); |
| 2156 | EXPECT_EQ(remapped_channels[1]->type()->string_view(), |
| 2157 | "aos.message_bridge.RemoteMessage"); |
| 2158 | } |
Austin Schuh | 1c22735 | 2021-09-17 12:53:54 -0700 | [diff] [blame] | 2159 | |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 2160 | reader.Register(&log_reader_factory); |
| 2161 | |
| 2162 | const Node *pi1 = |
| 2163 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 2164 | const Node *pi2 = |
| 2165 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 2166 | |
| 2167 | // Confirm we can read the data on the remapped channel, just for pi1. Nothing |
| 2168 | // else should have moved. |
| 2169 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 2170 | log_reader_factory.MakeEventLoop("test", pi1); |
| 2171 | pi1_event_loop->SkipTimingReport(); |
| 2172 | std::unique_ptr<EventLoop> full_pi1_event_loop = |
| 2173 | log_reader_factory.MakeEventLoop("test", pi1); |
| 2174 | full_pi1_event_loop->SkipTimingReport(); |
| 2175 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 2176 | log_reader_factory.MakeEventLoop("test", pi2); |
| 2177 | pi2_event_loop->SkipTimingReport(); |
| 2178 | |
| 2179 | MessageCounter<aos::timing::Report> pi1_timing_report(pi1_event_loop.get(), |
| 2180 | "/aos"); |
| 2181 | MessageCounter<aos::timing::Report> full_pi1_timing_report( |
| 2182 | full_pi1_event_loop.get(), "/pi1/aos"); |
| 2183 | MessageCounter<aos::timing::Report> pi1_original_timing_report( |
| 2184 | pi1_event_loop.get(), "/original/aos"); |
| 2185 | MessageCounter<aos::timing::Report> full_pi1_original_timing_report( |
| 2186 | full_pi1_event_loop.get(), "/original/pi1/aos"); |
| 2187 | MessageCounter<aos::timing::Report> pi2_timing_report(pi2_event_loop.get(), |
| 2188 | "/aos"); |
| 2189 | |
| 2190 | log_reader_factory.Run(); |
| 2191 | |
| 2192 | EXPECT_EQ(pi1_timing_report.count(), 0u); |
| 2193 | EXPECT_EQ(full_pi1_timing_report.count(), 0u); |
| 2194 | EXPECT_NE(pi1_original_timing_report.count(), 0u); |
| 2195 | EXPECT_NE(full_pi1_original_timing_report.count(), 0u); |
| 2196 | EXPECT_NE(pi2_timing_report.count(), 0u); |
| 2197 | |
| 2198 | reader.Deregister(); |
| 2199 | } |
| 2200 | |
Austin Schuh | 006a9f5 | 2021-04-07 16:24:18 -0700 | [diff] [blame] | 2201 | // Tests that we can remap a forwarded channel as well. |
| 2202 | TEST_P(MultinodeLoggerTest, RemapForwardedLoggedChannel) { |
| 2203 | time_converter_.StartEqual(); |
| 2204 | { |
| 2205 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2206 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2207 | |
| 2208 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2209 | |
| 2210 | StartLogger(&pi1_logger); |
| 2211 | StartLogger(&pi2_logger); |
| 2212 | |
| 2213 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 2214 | } |
| 2215 | |
| 2216 | LogReader reader(SortParts(logfiles_)); |
| 2217 | |
| 2218 | reader.RemapLoggedChannel<examples::Ping>("/test"); |
| 2219 | |
| 2220 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 2221 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 2222 | |
| 2223 | reader.Register(&log_reader_factory); |
| 2224 | |
| 2225 | const Node *pi1 = |
| 2226 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 2227 | const Node *pi2 = |
| 2228 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 2229 | |
| 2230 | // Confirm we can read the data on the remapped channel, just for pi1. Nothing |
| 2231 | // else should have moved. |
| 2232 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 2233 | log_reader_factory.MakeEventLoop("test", pi1); |
| 2234 | pi1_event_loop->SkipTimingReport(); |
| 2235 | std::unique_ptr<EventLoop> full_pi1_event_loop = |
| 2236 | log_reader_factory.MakeEventLoop("test", pi1); |
| 2237 | full_pi1_event_loop->SkipTimingReport(); |
| 2238 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 2239 | log_reader_factory.MakeEventLoop("test", pi2); |
| 2240 | pi2_event_loop->SkipTimingReport(); |
| 2241 | |
| 2242 | MessageCounter<examples::Ping> pi1_ping(pi1_event_loop.get(), "/test"); |
| 2243 | MessageCounter<examples::Ping> pi2_ping(pi2_event_loop.get(), "/test"); |
| 2244 | MessageCounter<examples::Ping> pi1_original_ping(pi1_event_loop.get(), |
| 2245 | "/original/test"); |
| 2246 | MessageCounter<examples::Ping> pi2_original_ping(pi2_event_loop.get(), |
| 2247 | "/original/test"); |
| 2248 | |
| 2249 | std::unique_ptr<MessageCounter<message_bridge::RemoteMessage>> |
| 2250 | pi1_original_ping_timestamp; |
| 2251 | std::unique_ptr<MessageCounter<message_bridge::RemoteMessage>> |
| 2252 | pi1_ping_timestamp; |
| 2253 | if (!shared()) { |
| 2254 | pi1_original_ping_timestamp = |
| 2255 | std::make_unique<MessageCounter<message_bridge::RemoteMessage>>( |
| 2256 | pi1_event_loop.get(), |
| 2257 | "/pi1/aos/remote_timestamps/pi2/original/test/aos-examples-Ping"); |
| 2258 | pi1_ping_timestamp = |
| 2259 | std::make_unique<MessageCounter<message_bridge::RemoteMessage>>( |
| 2260 | pi1_event_loop.get(), |
| 2261 | "/pi1/aos/remote_timestamps/pi2/test/aos-examples-Ping"); |
| 2262 | } |
| 2263 | |
| 2264 | log_reader_factory.Run(); |
| 2265 | |
| 2266 | EXPECT_EQ(pi1_ping.count(), 0u); |
| 2267 | EXPECT_EQ(pi2_ping.count(), 0u); |
| 2268 | EXPECT_NE(pi1_original_ping.count(), 0u); |
| 2269 | EXPECT_NE(pi2_original_ping.count(), 0u); |
| 2270 | if (!shared()) { |
| 2271 | EXPECT_NE(pi1_original_ping_timestamp->count(), 0u); |
| 2272 | EXPECT_EQ(pi1_ping_timestamp->count(), 0u); |
| 2273 | } |
| 2274 | |
| 2275 | reader.Deregister(); |
| 2276 | } |
| 2277 | |
James Kuszmaul | 0963242 | 2022-05-25 15:56:19 -0700 | [diff] [blame] | 2278 | // Tests that we observe all the same events in log replay (for a given node) |
| 2279 | // whether we just register an event loop for that node or if we register a full |
| 2280 | // event loop factory. |
| 2281 | TEST_P(MultinodeLoggerTest, SingleNodeReplay) { |
| 2282 | time_converter_.StartEqual(); |
| 2283 | constexpr chrono::milliseconds kStartupDelay(95); |
| 2284 | { |
| 2285 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2286 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2287 | |
| 2288 | event_loop_factory_.RunFor(kStartupDelay); |
| 2289 | |
| 2290 | StartLogger(&pi1_logger); |
| 2291 | StartLogger(&pi2_logger); |
| 2292 | |
| 2293 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 2294 | } |
| 2295 | |
| 2296 | LogReader full_reader(SortParts(logfiles_)); |
| 2297 | LogReader single_node_reader(SortParts(logfiles_)); |
| 2298 | |
| 2299 | SimulatedEventLoopFactory full_factory(full_reader.configuration()); |
| 2300 | SimulatedEventLoopFactory single_node_factory( |
| 2301 | single_node_reader.configuration()); |
James Kuszmaul | 94ca513 | 2022-07-19 09:11:08 -0700 | [diff] [blame] | 2302 | single_node_factory.SkipTimingReport(); |
| 2303 | single_node_factory.DisableStatistics(); |
James Kuszmaul | 0963242 | 2022-05-25 15:56:19 -0700 | [diff] [blame] | 2304 | std::unique_ptr<EventLoop> replay_event_loop = |
| 2305 | single_node_factory.GetNodeEventLoopFactory("pi1")->MakeEventLoop( |
| 2306 | "log_reader"); |
| 2307 | |
| 2308 | full_reader.Register(&full_factory); |
| 2309 | single_node_reader.Register(replay_event_loop.get()); |
James Kuszmaul | 0963242 | 2022-05-25 15:56:19 -0700 | [diff] [blame] | 2310 | |
| 2311 | const Node *full_pi1 = |
| 2312 | configuration::GetNode(full_factory.configuration(), "pi1"); |
| 2313 | |
| 2314 | // Confirm we can read the data on the remapped channel, just for pi1. Nothing |
| 2315 | // else should have moved. |
| 2316 | std::unique_ptr<EventLoop> full_event_loop = |
| 2317 | full_factory.MakeEventLoop("test", full_pi1); |
| 2318 | full_event_loop->SkipTimingReport(); |
| 2319 | full_event_loop->SkipAosLog(); |
| 2320 | // maps are indexed on channel index. |
| 2321 | // observed_messages: {channel_index: [(message_sent_time, was_fetched),...]} |
| 2322 | std::map<size_t, std::vector<std::pair<monotonic_clock::time_point, bool>>> |
| 2323 | observed_messages; |
| 2324 | std::map<size_t, std::unique_ptr<RawFetcher>> fetchers; |
| 2325 | for (size_t ii = 0; ii < full_event_loop->configuration()->channels()->size(); |
| 2326 | ++ii) { |
| 2327 | const Channel *channel = |
| 2328 | full_event_loop->configuration()->channels()->Get(ii); |
| 2329 | // We currently don't support replaying remote timestamp channels in |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 2330 | // realtime replay (unless the remote timestamp channel was not NOT_LOGGED, |
| 2331 | // in which case it gets auto-remapped and replayed on a /original channel). |
James Kuszmaul | 0963242 | 2022-05-25 15:56:19 -0700 | [diff] [blame] | 2332 | if (channel->name()->string_view().find("remote_timestamp") != |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 2333 | std::string_view::npos && |
| 2334 | channel->name()->string_view().find("/original") == |
| 2335 | std::string_view::npos) { |
James Kuszmaul | 0963242 | 2022-05-25 15:56:19 -0700 | [diff] [blame] | 2336 | continue; |
| 2337 | } |
| 2338 | if (configuration::ChannelIsReadableOnNode(channel, full_pi1)) { |
| 2339 | observed_messages[ii] = {}; |
| 2340 | fetchers[ii] = full_event_loop->MakeRawFetcher(channel); |
| 2341 | full_event_loop->OnRun([ii, &observed_messages, &fetchers]() { |
| 2342 | if (fetchers[ii]->Fetch()) { |
| 2343 | observed_messages[ii].push_back(std::make_pair( |
| 2344 | fetchers[ii]->context().monotonic_event_time, true)); |
| 2345 | } |
| 2346 | }); |
| 2347 | full_event_loop->MakeRawNoArgWatcher( |
| 2348 | channel, [ii, &observed_messages](const Context &context) { |
| 2349 | observed_messages[ii].push_back( |
| 2350 | std::make_pair(context.monotonic_event_time, false)); |
| 2351 | }); |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | full_factory.Run(); |
| 2356 | fetchers.clear(); |
| 2357 | full_reader.Deregister(); |
| 2358 | |
| 2359 | const Node *single_node_pi1 = |
| 2360 | configuration::GetNode(single_node_factory.configuration(), "pi1"); |
| 2361 | std::map<size_t, std::unique_ptr<RawFetcher>> single_node_fetchers; |
| 2362 | |
| 2363 | std::unique_ptr<EventLoop> single_node_event_loop = |
| 2364 | single_node_factory.MakeEventLoop("test", single_node_pi1); |
| 2365 | single_node_event_loop->SkipTimingReport(); |
| 2366 | single_node_event_loop->SkipAosLog(); |
| 2367 | for (size_t ii = 0; |
| 2368 | ii < single_node_event_loop->configuration()->channels()->size(); ++ii) { |
| 2369 | const Channel *channel = |
| 2370 | single_node_event_loop->configuration()->channels()->Get(ii); |
| 2371 | single_node_factory.DisableForwarding(channel); |
| 2372 | if (configuration::ChannelIsReadableOnNode(channel, single_node_pi1)) { |
| 2373 | single_node_fetchers[ii] = |
| 2374 | single_node_event_loop->MakeRawFetcher(channel); |
| 2375 | single_node_event_loop->OnRun([channel, ii, &single_node_fetchers]() { |
| 2376 | EXPECT_FALSE(single_node_fetchers[ii]->Fetch()) |
| 2377 | << "Single EventLoop replay doesn't support pre-loading fetchers. " |
| 2378 | << configuration::StrippedChannelToString(channel); |
| 2379 | }); |
| 2380 | single_node_event_loop->MakeRawNoArgWatcher( |
| 2381 | channel, [ii, &observed_messages, channel, |
| 2382 | kStartupDelay](const Context &context) { |
| 2383 | if (observed_messages[ii].empty()) { |
| 2384 | FAIL() << "Observed extra message at " |
| 2385 | << context.monotonic_event_time << " on " |
| 2386 | << configuration::StrippedChannelToString(channel); |
| 2387 | return; |
| 2388 | } |
| 2389 | const std::pair<monotonic_clock::time_point, bool> &message = |
| 2390 | observed_messages[ii].front(); |
| 2391 | if (message.second) { |
| 2392 | EXPECT_LE(message.first, |
| 2393 | context.monotonic_event_time + kStartupDelay) |
| 2394 | << "Mismatched message times " << context.monotonic_event_time |
| 2395 | << " and " << message.first << " on " |
| 2396 | << configuration::StrippedChannelToString(channel); |
| 2397 | } else { |
| 2398 | EXPECT_EQ(message.first, |
| 2399 | context.monotonic_event_time + kStartupDelay) |
| 2400 | << "Mismatched message times " << context.monotonic_event_time |
| 2401 | << " and " << message.first << " on " |
| 2402 | << configuration::StrippedChannelToString(channel); |
| 2403 | } |
| 2404 | observed_messages[ii].erase(observed_messages[ii].begin()); |
| 2405 | }); |
| 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | single_node_factory.Run(); |
| 2410 | |
| 2411 | single_node_fetchers.clear(); |
| 2412 | |
| 2413 | single_node_reader.Deregister(); |
| 2414 | |
| 2415 | for (const auto &pair : observed_messages) { |
| 2416 | EXPECT_TRUE(pair.second.empty()) |
| 2417 | << "Missed " << pair.second.size() << " messages on " |
| 2418 | << configuration::StrippedChannelToString( |
| 2419 | single_node_event_loop->configuration()->channels()->Get( |
| 2420 | pair.first)); |
| 2421 | } |
| 2422 | } |
| 2423 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2424 | // Tests that we properly recreate forwarded timestamps when replaying a log. |
| 2425 | // This should be enough that we can then re-run the logger and get a valid log |
| 2426 | // back. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2427 | TEST_P(MultinodeLoggerTest, MessageHeader) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2428 | time_converter_.StartEqual(); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2429 | { |
| 2430 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2431 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2432 | |
| 2433 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2434 | |
| 2435 | StartLogger(&pi1_logger); |
| 2436 | StartLogger(&pi2_logger); |
| 2437 | |
| 2438 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 2439 | } |
| 2440 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 2441 | LogReader reader(SortParts(logfiles_)); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2442 | |
| 2443 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 2444 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 2445 | |
| 2446 | // This sends out the fetched messages and advances time to the start of the |
| 2447 | // log file. |
| 2448 | reader.Register(&log_reader_factory); |
| 2449 | |
| 2450 | const Node *pi1 = |
| 2451 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 2452 | const Node *pi2 = |
| 2453 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 2454 | |
| 2455 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi1) << " pi1"; |
| 2456 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi2) << " pi2"; |
| 2457 | LOG(INFO) << "now pi1 " |
| 2458 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now(); |
| 2459 | LOG(INFO) << "now pi2 " |
| 2460 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now(); |
| 2461 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 2462 | EXPECT_THAT(reader.LoggedNodes(), |
| 2463 | ::testing::ElementsAre( |
| 2464 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 2465 | configuration::GetNode(reader.logged_configuration(), pi2))); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2466 | |
| 2467 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
| 2468 | |
| 2469 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 2470 | log_reader_factory.MakeEventLoop("test", pi1); |
| 2471 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 2472 | log_reader_factory.MakeEventLoop("test", pi2); |
| 2473 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2474 | aos::Fetcher<message_bridge::Timestamp> pi1_timestamp_on_pi1_fetcher = |
| 2475 | pi1_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi1/aos"); |
| 2476 | aos::Fetcher<message_bridge::Timestamp> pi1_timestamp_on_pi2_fetcher = |
| 2477 | pi2_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi1/aos"); |
| 2478 | |
| 2479 | aos::Fetcher<examples::Ping> ping_on_pi1_fetcher = |
| 2480 | pi1_event_loop->MakeFetcher<examples::Ping>("/test"); |
| 2481 | aos::Fetcher<examples::Ping> ping_on_pi2_fetcher = |
| 2482 | pi2_event_loop->MakeFetcher<examples::Ping>("/test"); |
| 2483 | |
| 2484 | aos::Fetcher<message_bridge::Timestamp> pi2_timestamp_on_pi2_fetcher = |
| 2485 | pi2_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi2/aos"); |
| 2486 | aos::Fetcher<message_bridge::Timestamp> pi2_timestamp_on_pi1_fetcher = |
| 2487 | pi1_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi2/aos"); |
| 2488 | |
| 2489 | aos::Fetcher<examples::Pong> pong_on_pi2_fetcher = |
| 2490 | pi2_event_loop->MakeFetcher<examples::Pong>("/test"); |
| 2491 | aos::Fetcher<examples::Pong> pong_on_pi1_fetcher = |
| 2492 | pi1_event_loop->MakeFetcher<examples::Pong>("/test"); |
| 2493 | |
| 2494 | const size_t pi1_timestamp_channel = configuration::ChannelIndex( |
| 2495 | pi1_event_loop->configuration(), pi1_timestamp_on_pi1_fetcher.channel()); |
| 2496 | const size_t ping_timestamp_channel = configuration::ChannelIndex( |
| 2497 | pi2_event_loop->configuration(), ping_on_pi2_fetcher.channel()); |
| 2498 | |
| 2499 | const size_t pi2_timestamp_channel = configuration::ChannelIndex( |
| 2500 | pi2_event_loop->configuration(), pi2_timestamp_on_pi2_fetcher.channel()); |
| 2501 | const size_t pong_timestamp_channel = configuration::ChannelIndex( |
| 2502 | pi1_event_loop->configuration(), pong_on_pi1_fetcher.channel()); |
| 2503 | |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 2504 | const chrono::nanoseconds network_delay = event_loop_factory_.network_delay(); |
Austin Schuh | 816e5d6 | 2021-01-05 23:42:20 -0800 | [diff] [blame] | 2505 | const chrono::nanoseconds send_delay = event_loop_factory_.send_delay(); |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 2506 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2507 | for (std::pair<int, std::string> channel : |
| 2508 | shared() |
| 2509 | ? std::vector< |
| 2510 | std::pair<int, std::string>>{{-1, |
| 2511 | "/aos/remote_timestamps/pi2"}} |
| 2512 | : std::vector<std::pair<int, std::string>>{ |
| 2513 | {pi1_timestamp_channel, |
| 2514 | "/aos/remote_timestamps/pi2/pi1/aos/" |
| 2515 | "aos-message_bridge-Timestamp"}, |
| 2516 | {ping_timestamp_channel, |
| 2517 | "/aos/remote_timestamps/pi2/test/aos-examples-Ping"}}) { |
| 2518 | pi1_event_loop->MakeWatcher( |
| 2519 | channel.second, |
| 2520 | [&pi1_event_loop, &pi2_event_loop, pi1_timestamp_channel, |
| 2521 | ping_timestamp_channel, &pi1_timestamp_on_pi1_fetcher, |
| 2522 | &pi1_timestamp_on_pi2_fetcher, &ping_on_pi1_fetcher, |
| 2523 | &ping_on_pi2_fetcher, network_delay, send_delay, |
| 2524 | channel_index = channel.first](const RemoteMessage &header) { |
| 2525 | const aos::monotonic_clock::time_point header_monotonic_sent_time( |
| 2526 | chrono::nanoseconds(header.monotonic_sent_time())); |
| 2527 | const aos::realtime_clock::time_point header_realtime_sent_time( |
| 2528 | chrono::nanoseconds(header.realtime_sent_time())); |
| 2529 | const aos::monotonic_clock::time_point header_monotonic_remote_time( |
| 2530 | chrono::nanoseconds(header.monotonic_remote_time())); |
| 2531 | const aos::realtime_clock::time_point header_realtime_remote_time( |
| 2532 | chrono::nanoseconds(header.realtime_remote_time())); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2533 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2534 | if (channel_index != -1) { |
| 2535 | ASSERT_EQ(channel_index, header.channel_index()); |
| 2536 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2537 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2538 | const Context *pi1_context = nullptr; |
| 2539 | const Context *pi2_context = nullptr; |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2540 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2541 | if (header.channel_index() == pi1_timestamp_channel) { |
| 2542 | ASSERT_TRUE(pi1_timestamp_on_pi1_fetcher.FetchNext()); |
| 2543 | ASSERT_TRUE(pi1_timestamp_on_pi2_fetcher.FetchNext()); |
| 2544 | pi1_context = &pi1_timestamp_on_pi1_fetcher.context(); |
| 2545 | pi2_context = &pi1_timestamp_on_pi2_fetcher.context(); |
| 2546 | } else if (header.channel_index() == ping_timestamp_channel) { |
| 2547 | ASSERT_TRUE(ping_on_pi1_fetcher.FetchNext()); |
| 2548 | ASSERT_TRUE(ping_on_pi2_fetcher.FetchNext()); |
| 2549 | pi1_context = &ping_on_pi1_fetcher.context(); |
| 2550 | pi2_context = &ping_on_pi2_fetcher.context(); |
| 2551 | } else { |
| 2552 | LOG(FATAL) << "Unknown channel " << FlatbufferToJson(&header) << " " |
| 2553 | << configuration::CleanedChannelToString( |
| 2554 | pi1_event_loop->configuration()->channels()->Get( |
| 2555 | header.channel_index())); |
| 2556 | } |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2557 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2558 | ASSERT_TRUE(header.has_boot_uuid()); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 2559 | EXPECT_EQ(UUID::FromVector(header.boot_uuid()), |
| 2560 | pi2_event_loop->boot_uuid()); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2561 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2562 | EXPECT_EQ(pi1_context->queue_index, header.remote_queue_index()); |
| 2563 | EXPECT_EQ(pi2_context->remote_queue_index, |
| 2564 | header.remote_queue_index()); |
| 2565 | EXPECT_EQ(pi2_context->queue_index, header.queue_index()); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2566 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2567 | EXPECT_EQ(pi2_context->monotonic_event_time, |
| 2568 | header_monotonic_sent_time); |
| 2569 | EXPECT_EQ(pi2_context->realtime_event_time, |
| 2570 | header_realtime_sent_time); |
| 2571 | EXPECT_EQ(pi2_context->realtime_remote_time, |
| 2572 | header_realtime_remote_time); |
| 2573 | EXPECT_EQ(pi2_context->monotonic_remote_time, |
| 2574 | header_monotonic_remote_time); |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 2575 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2576 | EXPECT_EQ(pi1_context->realtime_event_time, |
| 2577 | header_realtime_remote_time); |
| 2578 | EXPECT_EQ(pi1_context->monotonic_event_time, |
| 2579 | header_monotonic_remote_time); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2580 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2581 | // Time estimation isn't perfect, but we know the clocks were |
| 2582 | // identical when logged, so we know when this should have come back. |
| 2583 | // Confirm we got it when we expected. |
| 2584 | EXPECT_EQ(pi1_event_loop->context().monotonic_event_time, |
| 2585 | pi1_context->monotonic_event_time + 2 * network_delay + |
| 2586 | send_delay); |
| 2587 | }); |
| 2588 | } |
| 2589 | for (std::pair<int, std::string> channel : |
| 2590 | shared() |
| 2591 | ? std::vector< |
| 2592 | std::pair<int, std::string>>{{-1, |
| 2593 | "/aos/remote_timestamps/pi1"}} |
| 2594 | : std::vector<std::pair<int, std::string>>{ |
| 2595 | {pi2_timestamp_channel, |
| 2596 | "/aos/remote_timestamps/pi1/pi2/aos/" |
| 2597 | "aos-message_bridge-Timestamp"}}) { |
| 2598 | pi2_event_loop->MakeWatcher( |
| 2599 | channel.second, |
| 2600 | [&pi2_event_loop, &pi1_event_loop, pi2_timestamp_channel, |
| 2601 | pong_timestamp_channel, &pi2_timestamp_on_pi2_fetcher, |
| 2602 | &pi2_timestamp_on_pi1_fetcher, &pong_on_pi2_fetcher, |
| 2603 | &pong_on_pi1_fetcher, network_delay, send_delay, |
| 2604 | channel_index = channel.first](const RemoteMessage &header) { |
| 2605 | const aos::monotonic_clock::time_point header_monotonic_sent_time( |
| 2606 | chrono::nanoseconds(header.monotonic_sent_time())); |
| 2607 | const aos::realtime_clock::time_point header_realtime_sent_time( |
| 2608 | chrono::nanoseconds(header.realtime_sent_time())); |
| 2609 | const aos::monotonic_clock::time_point header_monotonic_remote_time( |
| 2610 | chrono::nanoseconds(header.monotonic_remote_time())); |
| 2611 | const aos::realtime_clock::time_point header_realtime_remote_time( |
| 2612 | chrono::nanoseconds(header.realtime_remote_time())); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2613 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2614 | if (channel_index != -1) { |
| 2615 | ASSERT_EQ(channel_index, header.channel_index()); |
| 2616 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2617 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2618 | const Context *pi2_context = nullptr; |
| 2619 | const Context *pi1_context = nullptr; |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2620 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2621 | if (header.channel_index() == pi2_timestamp_channel) { |
| 2622 | ASSERT_TRUE(pi2_timestamp_on_pi2_fetcher.FetchNext()); |
| 2623 | ASSERT_TRUE(pi2_timestamp_on_pi1_fetcher.FetchNext()); |
| 2624 | pi2_context = &pi2_timestamp_on_pi2_fetcher.context(); |
| 2625 | pi1_context = &pi2_timestamp_on_pi1_fetcher.context(); |
| 2626 | } else if (header.channel_index() == pong_timestamp_channel) { |
| 2627 | ASSERT_TRUE(pong_on_pi2_fetcher.FetchNext()); |
| 2628 | ASSERT_TRUE(pong_on_pi1_fetcher.FetchNext()); |
| 2629 | pi2_context = &pong_on_pi2_fetcher.context(); |
| 2630 | pi1_context = &pong_on_pi1_fetcher.context(); |
| 2631 | } else { |
| 2632 | LOG(FATAL) << "Unknown channel " << FlatbufferToJson(&header) << " " |
| 2633 | << configuration::CleanedChannelToString( |
| 2634 | pi2_event_loop->configuration()->channels()->Get( |
| 2635 | header.channel_index())); |
| 2636 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2637 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2638 | ASSERT_TRUE(header.has_boot_uuid()); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 2639 | EXPECT_EQ(UUID::FromVector(header.boot_uuid()), |
| 2640 | pi1_event_loop->boot_uuid()); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2641 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2642 | EXPECT_EQ(pi2_context->queue_index, header.remote_queue_index()); |
| 2643 | EXPECT_EQ(pi1_context->remote_queue_index, |
| 2644 | header.remote_queue_index()); |
| 2645 | EXPECT_EQ(pi1_context->queue_index, header.queue_index()); |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 2646 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2647 | EXPECT_EQ(pi1_context->monotonic_event_time, |
| 2648 | header_monotonic_sent_time); |
| 2649 | EXPECT_EQ(pi1_context->realtime_event_time, |
| 2650 | header_realtime_sent_time); |
| 2651 | EXPECT_EQ(pi1_context->realtime_remote_time, |
| 2652 | header_realtime_remote_time); |
| 2653 | EXPECT_EQ(pi1_context->monotonic_remote_time, |
| 2654 | header_monotonic_remote_time); |
| 2655 | |
| 2656 | EXPECT_EQ(pi2_context->realtime_event_time, |
| 2657 | header_realtime_remote_time); |
| 2658 | EXPECT_EQ(pi2_context->monotonic_event_time, |
| 2659 | header_monotonic_remote_time); |
| 2660 | |
| 2661 | // Time estimation isn't perfect, but we know the clocks were |
| 2662 | // identical when logged, so we know when this should have come back. |
| 2663 | // Confirm we got it when we expected. |
| 2664 | EXPECT_EQ(pi2_event_loop->context().monotonic_event_time, |
| 2665 | pi2_context->monotonic_event_time + 2 * network_delay + |
| 2666 | send_delay); |
| 2667 | }); |
| 2668 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2669 | |
| 2670 | // And confirm we can re-create a log again, while checking the contents. |
| 2671 | { |
| 2672 | LoggerState pi1_logger = MakeLogger( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2673 | log_reader_factory.GetNodeEventLoopFactory("pi1"), &log_reader_factory); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2674 | LoggerState pi2_logger = MakeLogger( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2675 | log_reader_factory.GetNodeEventLoopFactory("pi2"), &log_reader_factory); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2676 | |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 2677 | StartLogger(&pi1_logger, tmp_dir_ + "/relogged1"); |
| 2678 | StartLogger(&pi2_logger, tmp_dir_ + "/relogged2"); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2679 | |
| 2680 | log_reader_factory.Run(); |
| 2681 | } |
| 2682 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2683 | reader.Deregister(); |
James Kuszmaul | 4f106fb | 2021-01-05 20:53:02 -0800 | [diff] [blame] | 2684 | |
| 2685 | // And verify that we can run the LogReader over the relogged files without |
| 2686 | // hitting any fatal errors. |
| 2687 | { |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 2688 | LogReader relogged_reader(SortParts(MakeLogFiles( |
| 2689 | tmp_dir_ + "/relogged1", tmp_dir_ + "/relogged2", 3, 3, true))); |
| 2690 | relogged_reader.Register(); |
| 2691 | |
| 2692 | relogged_reader.event_loop_factory()->Run(); |
| 2693 | } |
| 2694 | // And confirm that we can read the logged file using the reader's |
| 2695 | // configuration. |
| 2696 | { |
| 2697 | LogReader relogged_reader( |
| 2698 | SortParts(MakeLogFiles(tmp_dir_ + "/relogged1", tmp_dir_ + "/relogged2", |
| 2699 | 3, 3, true)), |
| 2700 | reader.configuration()); |
James Kuszmaul | 4f106fb | 2021-01-05 20:53:02 -0800 | [diff] [blame] | 2701 | relogged_reader.Register(); |
| 2702 | |
| 2703 | relogged_reader.event_loop_factory()->Run(); |
| 2704 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2707 | // Tests that we properly populate and extract the logger_start time by setting |
| 2708 | // up a clock difference between 2 nodes and looking at the resulting parts. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2709 | TEST_P(MultinodeLoggerTest, LoggerStartTime) { |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 2710 | std::vector<std::string> actual_filenames; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2711 | time_converter_.AddMonotonic( |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 2712 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(1000)}); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2713 | { |
| 2714 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2715 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2716 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2717 | StartLogger(&pi1_logger); |
| 2718 | StartLogger(&pi2_logger); |
| 2719 | |
| 2720 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 2721 | |
| 2722 | pi1_logger.AppendAllFilenames(&actual_filenames); |
| 2723 | pi2_logger.AppendAllFilenames(&actual_filenames); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2724 | } |
| 2725 | |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 2726 | ASSERT_THAT(actual_filenames, |
| 2727 | ::testing::UnorderedElementsAreArray(logfiles_)); |
| 2728 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2729 | for (const LogFile &log_file : SortParts(logfiles_)) { |
| 2730 | for (const LogParts &log_part : log_file.parts) { |
| 2731 | if (log_part.node == log_file.logger_node) { |
| 2732 | EXPECT_EQ(log_part.logger_monotonic_start_time, |
| 2733 | aos::monotonic_clock::min_time); |
| 2734 | EXPECT_EQ(log_part.logger_realtime_start_time, |
| 2735 | aos::realtime_clock::min_time); |
| 2736 | } else { |
| 2737 | const chrono::seconds offset = log_file.logger_node == "pi1" |
| 2738 | ? -chrono::seconds(1000) |
| 2739 | : chrono::seconds(1000); |
| 2740 | EXPECT_EQ(log_part.logger_monotonic_start_time, |
| 2741 | log_part.monotonic_start_time + offset); |
| 2742 | EXPECT_EQ(log_part.logger_realtime_start_time, |
| 2743 | log_file.realtime_start_time + |
| 2744 | (log_part.logger_monotonic_start_time - |
| 2745 | log_file.monotonic_start_time)); |
| 2746 | } |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 2751 | // Test that renaming the base, renames the folder. |
Austin Schuh | 9f2a74b | 2021-12-08 12:10:50 -0800 | [diff] [blame] | 2752 | TEST_P(MultinodeLoggerTest, LoggerRenameFolder) { |
Austin Schuh | 9733ae5 | 2021-07-30 18:25:52 -0700 | [diff] [blame] | 2753 | util::UnlinkRecursive(tmp_dir_ + "/renamefolder"); |
| 2754 | util::UnlinkRecursive(tmp_dir_ + "/new-good"); |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 2755 | time_converter_.AddMonotonic( |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 2756 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(1000)}); |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 2757 | logfile_base1_ = tmp_dir_ + "/renamefolder/multi_logfile1"; |
| 2758 | logfile_base2_ = tmp_dir_ + "/renamefolder/multi_logfile2"; |
| 2759 | logfiles_ = MakeLogFiles(logfile_base1_, logfile_base2_); |
| 2760 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2761 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2762 | |
| 2763 | StartLogger(&pi1_logger); |
| 2764 | StartLogger(&pi2_logger); |
| 2765 | |
| 2766 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2767 | logfile_base1_ = tmp_dir_ + "/new-good/multi_logfile1"; |
| 2768 | logfile_base2_ = tmp_dir_ + "/new-good/multi_logfile2"; |
| 2769 | logfiles_ = MakeLogFiles(logfile_base1_, logfile_base2_); |
| 2770 | ASSERT_TRUE(pi1_logger.logger->RenameLogBase(logfile_base1_)); |
| 2771 | ASSERT_TRUE(pi2_logger.logger->RenameLogBase(logfile_base2_)); |
| 2772 | for (auto &file : logfiles_) { |
| 2773 | struct stat s; |
| 2774 | EXPECT_EQ(0, stat(file.c_str(), &s)); |
| 2775 | } |
| 2776 | } |
| 2777 | |
| 2778 | // Test that renaming the file base dies. |
| 2779 | TEST_P(MultinodeLoggerDeathTest, LoggerRenameFile) { |
| 2780 | time_converter_.AddMonotonic( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2781 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(1000)}); |
Austin Schuh | 9733ae5 | 2021-07-30 18:25:52 -0700 | [diff] [blame] | 2782 | util::UnlinkRecursive(tmp_dir_ + "/renamefile"); |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 2783 | logfile_base1_ = tmp_dir_ + "/renamefile/multi_logfile1"; |
| 2784 | logfile_base2_ = tmp_dir_ + "/renamefile/multi_logfile2"; |
| 2785 | logfiles_ = MakeLogFiles(logfile_base1_, logfile_base2_); |
| 2786 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2787 | StartLogger(&pi1_logger); |
| 2788 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2789 | logfile_base1_ = tmp_dir_ + "/new-renamefile/new_multi_logfile1"; |
| 2790 | EXPECT_DEATH({ pi1_logger.logger->RenameLogBase(logfile_base1_); }, |
| 2791 | "Rename of file base from"); |
| 2792 | } |
| 2793 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 2794 | // TODO(austin): We can write a test which recreates a logfile and confirms that |
| 2795 | // we get it back. That is the ultimate test. |
| 2796 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2797 | // Tests that we properly recreate forwarded timestamps when replaying a log. |
| 2798 | // This should be enough that we can then re-run the logger and get a valid log |
| 2799 | // back. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2800 | TEST_P(MultinodeLoggerTest, RemoteReboot) { |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2801 | std::vector<std::string> actual_filenames; |
| 2802 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2803 | const UUID pi1_boot0 = UUID::Random(); |
| 2804 | const UUID pi2_boot0 = UUID::Random(); |
| 2805 | const UUID pi2_boot1 = UUID::Random(); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2806 | { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2807 | CHECK_EQ(pi1_index_, 0u); |
| 2808 | CHECK_EQ(pi2_index_, 1u); |
| 2809 | |
| 2810 | time_converter_.set_boot_uuid(pi1_index_, 0, pi1_boot0); |
| 2811 | time_converter_.set_boot_uuid(pi2_index_, 0, pi2_boot0); |
| 2812 | time_converter_.set_boot_uuid(pi2_index_, 1, pi2_boot1); |
| 2813 | |
| 2814 | time_converter_.AddNextTimestamp( |
| 2815 | distributed_clock::epoch(), |
| 2816 | {BootTimestamp::epoch(), BootTimestamp::epoch()}); |
| 2817 | const chrono::nanoseconds reboot_time = chrono::milliseconds(10100); |
| 2818 | time_converter_.AddNextTimestamp( |
| 2819 | distributed_clock::epoch() + reboot_time, |
| 2820 | {BootTimestamp::epoch() + reboot_time, |
| 2821 | BootTimestamp{ |
| 2822 | .boot = 1, |
| 2823 | .time = monotonic_clock::epoch() + chrono::milliseconds(1323)}}); |
| 2824 | } |
| 2825 | |
| 2826 | { |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2827 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2828 | |
| 2829 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2830 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi1")->boot_uuid(), |
| 2831 | pi1_boot0); |
| 2832 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi2")->boot_uuid(), |
| 2833 | pi2_boot0); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2834 | |
| 2835 | StartLogger(&pi1_logger); |
| 2836 | |
| 2837 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2838 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2839 | VLOG(1) << "Reboot now!"; |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2840 | |
| 2841 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2842 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi1")->boot_uuid(), |
| 2843 | pi1_boot0); |
| 2844 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi2")->boot_uuid(), |
| 2845 | pi2_boot1); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2846 | |
| 2847 | pi1_logger.AppendAllFilenames(&actual_filenames); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2848 | } |
| 2849 | |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2850 | std::sort(actual_filenames.begin(), actual_filenames.end()); |
| 2851 | std::sort(pi1_reboot_logfiles_.begin(), pi1_reboot_logfiles_.end()); |
| 2852 | ASSERT_THAT(actual_filenames, |
| 2853 | ::testing::UnorderedElementsAreArray(pi1_reboot_logfiles_)); |
| 2854 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 2855 | // Confirm that our new oldest timestamps properly update as we reboot and |
| 2856 | // rotate. |
| 2857 | for (const std::string &file : pi1_reboot_logfiles_) { |
| 2858 | std::optional<SizePrefixedFlatbufferVector<LogFileHeader>> log_header = |
| 2859 | ReadHeader(file); |
| 2860 | CHECK(log_header); |
| 2861 | if (log_header->message().has_configuration()) { |
| 2862 | continue; |
| 2863 | } |
| 2864 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2865 | const monotonic_clock::time_point monotonic_start_time = |
| 2866 | monotonic_clock::time_point( |
| 2867 | chrono::nanoseconds(log_header->message().monotonic_start_time())); |
| 2868 | const UUID source_node_boot_uuid = UUID::FromString( |
| 2869 | log_header->message().source_node_boot_uuid()->string_view()); |
| 2870 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 2871 | if (log_header->message().node()->name()->string_view() != "pi1") { |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 2872 | // The remote message channel should rotate later and have more parts. |
| 2873 | // This only is true on the log files with shared remote messages. |
| 2874 | // |
| 2875 | // TODO(austin): I'm not the most thrilled with this test pattern... It |
| 2876 | // feels brittle in a different way. |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2877 | if (file.find("aos.message_bridge.RemoteMessage") == std::string::npos || |
| 2878 | !shared()) { |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 2879 | switch (log_header->message().parts_index()) { |
| 2880 | case 0: |
| 2881 | EXPECT_EQ(source_node_boot_uuid, pi2_boot0); |
| 2882 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
| 2883 | break; |
| 2884 | case 1: |
| 2885 | EXPECT_EQ(source_node_boot_uuid, pi2_boot0); |
| 2886 | ASSERT_EQ(monotonic_start_time, |
| 2887 | monotonic_clock::epoch() + chrono::seconds(1)); |
| 2888 | break; |
| 2889 | case 2: |
| 2890 | EXPECT_EQ(source_node_boot_uuid, pi2_boot1); |
| 2891 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time) << file; |
| 2892 | break; |
| 2893 | case 3: |
| 2894 | EXPECT_EQ(source_node_boot_uuid, pi2_boot1); |
| 2895 | ASSERT_EQ(monotonic_start_time, monotonic_clock::epoch() + |
| 2896 | chrono::nanoseconds(2322999462)) |
| 2897 | << " on " << file; |
| 2898 | break; |
| 2899 | default: |
| 2900 | FAIL(); |
| 2901 | break; |
| 2902 | } |
| 2903 | } else { |
| 2904 | switch (log_header->message().parts_index()) { |
| 2905 | case 0: |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2906 | case 1: |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 2907 | EXPECT_EQ(source_node_boot_uuid, pi2_boot0); |
| 2908 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
| 2909 | break; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2910 | case 2: |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 2911 | EXPECT_EQ(source_node_boot_uuid, pi2_boot0); |
| 2912 | ASSERT_EQ(monotonic_start_time, |
| 2913 | monotonic_clock::epoch() + chrono::seconds(1)); |
| 2914 | break; |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 2915 | case 3: |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2916 | case 4: |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 2917 | EXPECT_EQ(source_node_boot_uuid, pi2_boot1); |
| 2918 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time) << file; |
| 2919 | break; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2920 | case 5: |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 2921 | EXPECT_EQ(source_node_boot_uuid, pi2_boot1); |
| 2922 | ASSERT_EQ(monotonic_start_time, monotonic_clock::epoch() + |
| 2923 | chrono::nanoseconds(2322999462)) |
| 2924 | << " on " << file; |
| 2925 | break; |
| 2926 | default: |
| 2927 | FAIL(); |
| 2928 | break; |
| 2929 | } |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 2930 | } |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 2931 | continue; |
| 2932 | } |
| 2933 | SCOPED_TRACE(file); |
| 2934 | SCOPED_TRACE(aos::FlatbufferToJson( |
| 2935 | *log_header, {.multi_line = true, .max_vector_size = 100})); |
| 2936 | ASSERT_TRUE(log_header->message().has_oldest_remote_monotonic_timestamps()); |
| 2937 | ASSERT_EQ( |
| 2938 | log_header->message().oldest_remote_monotonic_timestamps()->size(), 2u); |
| 2939 | EXPECT_EQ( |
| 2940 | log_header->message().oldest_remote_monotonic_timestamps()->Get(0), |
| 2941 | monotonic_clock::max_time.time_since_epoch().count()); |
| 2942 | ASSERT_TRUE(log_header->message().has_oldest_local_monotonic_timestamps()); |
| 2943 | ASSERT_EQ(log_header->message().oldest_local_monotonic_timestamps()->size(), |
| 2944 | 2u); |
| 2945 | EXPECT_EQ(log_header->message().oldest_local_monotonic_timestamps()->Get(0), |
| 2946 | monotonic_clock::max_time.time_since_epoch().count()); |
| 2947 | ASSERT_TRUE(log_header->message() |
| 2948 | .has_oldest_remote_unreliable_monotonic_timestamps()); |
| 2949 | ASSERT_EQ(log_header->message() |
| 2950 | .oldest_remote_unreliable_monotonic_timestamps() |
| 2951 | ->size(), |
| 2952 | 2u); |
| 2953 | EXPECT_EQ(log_header->message() |
| 2954 | .oldest_remote_unreliable_monotonic_timestamps() |
| 2955 | ->Get(0), |
| 2956 | monotonic_clock::max_time.time_since_epoch().count()); |
| 2957 | ASSERT_TRUE(log_header->message() |
| 2958 | .has_oldest_local_unreliable_monotonic_timestamps()); |
| 2959 | ASSERT_EQ(log_header->message() |
| 2960 | .oldest_local_unreliable_monotonic_timestamps() |
| 2961 | ->size(), |
| 2962 | 2u); |
| 2963 | EXPECT_EQ(log_header->message() |
| 2964 | .oldest_local_unreliable_monotonic_timestamps() |
| 2965 | ->Get(0), |
| 2966 | monotonic_clock::max_time.time_since_epoch().count()); |
| 2967 | |
| 2968 | const monotonic_clock::time_point oldest_remote_monotonic_timestamps = |
| 2969 | monotonic_clock::time_point(chrono::nanoseconds( |
| 2970 | log_header->message().oldest_remote_monotonic_timestamps()->Get( |
| 2971 | 1))); |
| 2972 | const monotonic_clock::time_point oldest_local_monotonic_timestamps = |
| 2973 | monotonic_clock::time_point(chrono::nanoseconds( |
| 2974 | log_header->message().oldest_local_monotonic_timestamps()->Get(1))); |
| 2975 | const monotonic_clock::time_point |
| 2976 | oldest_remote_unreliable_monotonic_timestamps = |
| 2977 | monotonic_clock::time_point(chrono::nanoseconds( |
| 2978 | log_header->message() |
| 2979 | .oldest_remote_unreliable_monotonic_timestamps() |
| 2980 | ->Get(1))); |
| 2981 | const monotonic_clock::time_point |
| 2982 | oldest_local_unreliable_monotonic_timestamps = |
| 2983 | monotonic_clock::time_point(chrono::nanoseconds( |
| 2984 | log_header->message() |
| 2985 | .oldest_local_unreliable_monotonic_timestamps() |
| 2986 | ->Get(1))); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 2987 | const monotonic_clock::time_point |
| 2988 | oldest_remote_reliable_monotonic_timestamps = |
| 2989 | monotonic_clock::time_point(chrono::nanoseconds( |
| 2990 | log_header->message() |
| 2991 | .oldest_remote_reliable_monotonic_timestamps() |
| 2992 | ->Get(1))); |
| 2993 | const monotonic_clock::time_point |
| 2994 | oldest_local_reliable_monotonic_timestamps = |
| 2995 | monotonic_clock::time_point(chrono::nanoseconds( |
| 2996 | log_header->message() |
| 2997 | .oldest_local_reliable_monotonic_timestamps() |
| 2998 | ->Get(1))); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 2999 | const monotonic_clock::time_point |
| 3000 | oldest_logger_remote_unreliable_monotonic_timestamps = |
| 3001 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3002 | log_header->message() |
| 3003 | .oldest_logger_remote_unreliable_monotonic_timestamps() |
| 3004 | ->Get(0))); |
| 3005 | const monotonic_clock::time_point |
| 3006 | oldest_logger_local_unreliable_monotonic_timestamps = |
| 3007 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3008 | log_header->message() |
| 3009 | .oldest_logger_local_unreliable_monotonic_timestamps() |
| 3010 | ->Get(0))); |
| 3011 | EXPECT_EQ(oldest_logger_remote_unreliable_monotonic_timestamps, |
| 3012 | monotonic_clock::max_time); |
| 3013 | EXPECT_EQ(oldest_logger_local_unreliable_monotonic_timestamps, |
| 3014 | monotonic_clock::max_time); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 3015 | switch (log_header->message().parts_index()) { |
| 3016 | case 0: |
| 3017 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
| 3018 | monotonic_clock::max_time); |
| 3019 | EXPECT_EQ(oldest_local_monotonic_timestamps, monotonic_clock::max_time); |
| 3020 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3021 | monotonic_clock::max_time); |
| 3022 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3023 | monotonic_clock::max_time); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3024 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3025 | monotonic_clock::max_time); |
| 3026 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3027 | monotonic_clock::max_time); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 3028 | break; |
| 3029 | case 1: |
| 3030 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
| 3031 | monotonic_clock::time_point(chrono::microseconds(90200))); |
| 3032 | EXPECT_EQ(oldest_local_monotonic_timestamps, |
| 3033 | monotonic_clock::time_point(chrono::microseconds(90350))); |
| 3034 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3035 | monotonic_clock::time_point(chrono::microseconds(90200))); |
| 3036 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3037 | monotonic_clock::time_point(chrono::microseconds(90350))); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3038 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3039 | monotonic_clock::max_time); |
| 3040 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3041 | monotonic_clock::max_time); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 3042 | break; |
| 3043 | case 2: |
| 3044 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3045 | monotonic_clock::time_point(chrono::microseconds(90200))) |
| 3046 | << file; |
| 3047 | EXPECT_EQ(oldest_local_monotonic_timestamps, |
| 3048 | monotonic_clock::time_point(chrono::microseconds(90350))) |
| 3049 | << file; |
| 3050 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3051 | monotonic_clock::time_point(chrono::microseconds(90200))) |
| 3052 | << file; |
| 3053 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3054 | monotonic_clock::time_point(chrono::microseconds(90350))) |
| 3055 | << file; |
| 3056 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3057 | monotonic_clock::time_point(chrono::microseconds(100000))) |
| 3058 | << file; |
| 3059 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3060 | monotonic_clock::time_point(chrono::microseconds(100150))) |
| 3061 | << file; |
| 3062 | break; |
| 3063 | case 3: |
| 3064 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3065 | monotonic_clock::time_point(chrono::milliseconds(1323) + |
| 3066 | chrono::microseconds(200))); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 3067 | EXPECT_EQ(oldest_local_monotonic_timestamps, |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3068 | monotonic_clock::time_point(chrono::microseconds(10100350))); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 3069 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3070 | monotonic_clock::time_point(chrono::milliseconds(1323) + |
| 3071 | chrono::microseconds(200))); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 3072 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3073 | monotonic_clock::time_point(chrono::microseconds(10100350))); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3074 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3075 | monotonic_clock::max_time) |
| 3076 | << file; |
| 3077 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3078 | monotonic_clock::max_time) |
| 3079 | << file; |
| 3080 | break; |
| 3081 | case 4: |
| 3082 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
| 3083 | monotonic_clock::time_point(chrono::milliseconds(1323) + |
| 3084 | chrono::microseconds(200))); |
| 3085 | EXPECT_EQ(oldest_local_monotonic_timestamps, |
| 3086 | monotonic_clock::time_point(chrono::microseconds(10100350))); |
| 3087 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3088 | monotonic_clock::time_point(chrono::milliseconds(1323) + |
| 3089 | chrono::microseconds(200))); |
| 3090 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3091 | monotonic_clock::time_point(chrono::microseconds(10100350))); |
| 3092 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3093 | monotonic_clock::time_point(chrono::microseconds(1423000))) |
| 3094 | << file; |
| 3095 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3096 | monotonic_clock::time_point(chrono::microseconds(10200150))) |
| 3097 | << file; |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 3098 | break; |
| 3099 | default: |
| 3100 | FAIL(); |
| 3101 | break; |
| 3102 | } |
| 3103 | } |
| 3104 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 3105 | // Confirm that we refuse to replay logs with missing boot uuids. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3106 | { |
| 3107 | LogReader reader(SortParts(pi1_reboot_logfiles_)); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 3108 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3109 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 3110 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 3111 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3112 | // This sends out the fetched messages and advances time to the start of |
| 3113 | // the log file. |
| 3114 | reader.Register(&log_reader_factory); |
| 3115 | |
| 3116 | log_reader_factory.Run(); |
| 3117 | |
| 3118 | reader.Deregister(); |
| 3119 | } |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 3120 | } |
| 3121 | |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3122 | // Tests that we can sort a log which only has timestamps from the remote |
| 3123 | // because the local message_bridge_client failed to connect. |
| 3124 | TEST_P(MultinodeLoggerTest, RemoteRebootOnlyTimestamps) { |
| 3125 | const UUID pi1_boot0 = UUID::Random(); |
| 3126 | const UUID pi2_boot0 = UUID::Random(); |
| 3127 | const UUID pi2_boot1 = UUID::Random(); |
| 3128 | { |
| 3129 | CHECK_EQ(pi1_index_, 0u); |
| 3130 | CHECK_EQ(pi2_index_, 1u); |
| 3131 | |
| 3132 | time_converter_.set_boot_uuid(pi1_index_, 0, pi1_boot0); |
| 3133 | time_converter_.set_boot_uuid(pi2_index_, 0, pi2_boot0); |
| 3134 | time_converter_.set_boot_uuid(pi2_index_, 1, pi2_boot1); |
| 3135 | |
| 3136 | time_converter_.AddNextTimestamp( |
| 3137 | distributed_clock::epoch(), |
| 3138 | {BootTimestamp::epoch(), BootTimestamp::epoch()}); |
| 3139 | const chrono::nanoseconds reboot_time = chrono::milliseconds(10100); |
| 3140 | time_converter_.AddNextTimestamp( |
| 3141 | distributed_clock::epoch() + reboot_time, |
| 3142 | {BootTimestamp::epoch() + reboot_time, |
| 3143 | BootTimestamp{ |
| 3144 | .boot = 1, |
| 3145 | .time = monotonic_clock::epoch() + chrono::milliseconds(1323)}}); |
| 3146 | } |
| 3147 | pi2_->Disconnect(pi1_->node()); |
| 3148 | |
| 3149 | std::vector<std::string> filenames; |
| 3150 | { |
| 3151 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 3152 | |
| 3153 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 3154 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi1")->boot_uuid(), |
| 3155 | pi1_boot0); |
| 3156 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi2")->boot_uuid(), |
| 3157 | pi2_boot0); |
| 3158 | |
| 3159 | StartLogger(&pi1_logger); |
| 3160 | |
| 3161 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 3162 | |
| 3163 | VLOG(1) << "Reboot now!"; |
| 3164 | |
| 3165 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 3166 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi1")->boot_uuid(), |
| 3167 | pi1_boot0); |
| 3168 | EXPECT_EQ(event_loop_factory_.GetNodeEventLoopFactory("pi2")->boot_uuid(), |
| 3169 | pi2_boot1); |
| 3170 | pi1_logger.AppendAllFilenames(&filenames); |
| 3171 | } |
| 3172 | |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3173 | std::sort(filenames.begin(), filenames.end()); |
| 3174 | |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3175 | // Confirm that our new oldest timestamps properly update as we reboot and |
| 3176 | // rotate. |
| 3177 | size_t timestamp_file_count = 0; |
| 3178 | for (const std::string &file : filenames) { |
| 3179 | std::optional<SizePrefixedFlatbufferVector<LogFileHeader>> log_header = |
| 3180 | ReadHeader(file); |
| 3181 | CHECK(log_header); |
| 3182 | |
| 3183 | if (log_header->message().has_configuration()) { |
| 3184 | continue; |
| 3185 | } |
| 3186 | |
| 3187 | const monotonic_clock::time_point monotonic_start_time = |
| 3188 | monotonic_clock::time_point( |
| 3189 | chrono::nanoseconds(log_header->message().monotonic_start_time())); |
| 3190 | const UUID source_node_boot_uuid = UUID::FromString( |
| 3191 | log_header->message().source_node_boot_uuid()->string_view()); |
| 3192 | |
| 3193 | ASSERT_TRUE(log_header->message().has_oldest_remote_monotonic_timestamps()); |
| 3194 | ASSERT_EQ( |
| 3195 | log_header->message().oldest_remote_monotonic_timestamps()->size(), 2u); |
| 3196 | ASSERT_TRUE(log_header->message().has_oldest_local_monotonic_timestamps()); |
| 3197 | ASSERT_EQ(log_header->message().oldest_local_monotonic_timestamps()->size(), |
| 3198 | 2u); |
| 3199 | ASSERT_TRUE(log_header->message() |
| 3200 | .has_oldest_remote_unreliable_monotonic_timestamps()); |
| 3201 | ASSERT_EQ(log_header->message() |
| 3202 | .oldest_remote_unreliable_monotonic_timestamps() |
| 3203 | ->size(), |
| 3204 | 2u); |
| 3205 | ASSERT_TRUE(log_header->message() |
| 3206 | .has_oldest_local_unreliable_monotonic_timestamps()); |
| 3207 | ASSERT_EQ(log_header->message() |
| 3208 | .oldest_local_unreliable_monotonic_timestamps() |
| 3209 | ->size(), |
| 3210 | 2u); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3211 | ASSERT_TRUE(log_header->message() |
| 3212 | .has_oldest_remote_reliable_monotonic_timestamps()); |
| 3213 | ASSERT_EQ(log_header->message() |
| 3214 | .oldest_remote_reliable_monotonic_timestamps() |
| 3215 | ->size(), |
| 3216 | 2u); |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 3217 | ASSERT_TRUE( |
| 3218 | log_header->message().has_oldest_local_reliable_monotonic_timestamps()); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3219 | ASSERT_EQ(log_header->message() |
| 3220 | .oldest_local_reliable_monotonic_timestamps() |
| 3221 | ->size(), |
| 3222 | 2u); |
| 3223 | |
| 3224 | ASSERT_TRUE( |
| 3225 | log_header->message() |
| 3226 | .has_oldest_logger_remote_unreliable_monotonic_timestamps()); |
| 3227 | ASSERT_EQ(log_header->message() |
| 3228 | .oldest_logger_remote_unreliable_monotonic_timestamps() |
| 3229 | ->size(), |
| 3230 | 2u); |
| 3231 | ASSERT_TRUE(log_header->message() |
| 3232 | .has_oldest_logger_local_unreliable_monotonic_timestamps()); |
| 3233 | ASSERT_EQ(log_header->message() |
| 3234 | .oldest_logger_local_unreliable_monotonic_timestamps() |
| 3235 | ->size(), |
| 3236 | 2u); |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3237 | |
| 3238 | if (log_header->message().node()->name()->string_view() != "pi1") { |
| 3239 | ASSERT_TRUE(file.find("aos.message_bridge.RemoteMessage") != |
| 3240 | std::string::npos); |
| 3241 | |
| 3242 | const std::optional<SizePrefixedFlatbufferVector<MessageHeader>> msg = |
| 3243 | ReadNthMessage(file, 0); |
| 3244 | CHECK(msg); |
| 3245 | |
| 3246 | EXPECT_TRUE(msg->message().has_monotonic_sent_time()); |
| 3247 | EXPECT_TRUE(msg->message().has_monotonic_remote_time()); |
| 3248 | |
| 3249 | const monotonic_clock::time_point |
| 3250 | expected_oldest_local_monotonic_timestamps( |
| 3251 | chrono::nanoseconds(msg->message().monotonic_sent_time())); |
| 3252 | const monotonic_clock::time_point |
| 3253 | expected_oldest_remote_monotonic_timestamps( |
| 3254 | chrono::nanoseconds(msg->message().monotonic_remote_time())); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3255 | const monotonic_clock::time_point |
| 3256 | expected_oldest_timestamp_monotonic_timestamps( |
| 3257 | chrono::nanoseconds(msg->message().monotonic_timestamp_time())); |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3258 | |
| 3259 | EXPECT_NE(expected_oldest_local_monotonic_timestamps, |
| 3260 | monotonic_clock::min_time); |
| 3261 | EXPECT_NE(expected_oldest_remote_monotonic_timestamps, |
| 3262 | monotonic_clock::min_time); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3263 | EXPECT_NE(expected_oldest_timestamp_monotonic_timestamps, |
| 3264 | monotonic_clock::min_time); |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3265 | |
| 3266 | ++timestamp_file_count; |
| 3267 | // Since the log file is from the perspective of the other node, |
| 3268 | const monotonic_clock::time_point oldest_remote_monotonic_timestamps = |
| 3269 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3270 | log_header->message().oldest_remote_monotonic_timestamps()->Get( |
| 3271 | 0))); |
| 3272 | const monotonic_clock::time_point oldest_local_monotonic_timestamps = |
| 3273 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3274 | log_header->message().oldest_local_monotonic_timestamps()->Get( |
| 3275 | 0))); |
| 3276 | const monotonic_clock::time_point |
| 3277 | oldest_remote_unreliable_monotonic_timestamps = |
| 3278 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3279 | log_header->message() |
| 3280 | .oldest_remote_unreliable_monotonic_timestamps() |
| 3281 | ->Get(0))); |
| 3282 | const monotonic_clock::time_point |
| 3283 | oldest_local_unreliable_monotonic_timestamps = |
| 3284 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3285 | log_header->message() |
| 3286 | .oldest_local_unreliable_monotonic_timestamps() |
| 3287 | ->Get(0))); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3288 | const monotonic_clock::time_point |
| 3289 | oldest_remote_reliable_monotonic_timestamps = |
| 3290 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3291 | log_header->message() |
| 3292 | .oldest_remote_reliable_monotonic_timestamps() |
| 3293 | ->Get(0))); |
| 3294 | const monotonic_clock::time_point |
| 3295 | oldest_local_reliable_monotonic_timestamps = |
| 3296 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3297 | log_header->message() |
| 3298 | .oldest_local_reliable_monotonic_timestamps() |
| 3299 | ->Get(0))); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3300 | const monotonic_clock::time_point |
| 3301 | oldest_logger_remote_unreliable_monotonic_timestamps = |
| 3302 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3303 | log_header->message() |
| 3304 | .oldest_logger_remote_unreliable_monotonic_timestamps() |
| 3305 | ->Get(1))); |
| 3306 | const monotonic_clock::time_point |
| 3307 | oldest_logger_local_unreliable_monotonic_timestamps = |
| 3308 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3309 | log_header->message() |
| 3310 | .oldest_logger_local_unreliable_monotonic_timestamps() |
| 3311 | ->Get(1))); |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3312 | |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3313 | const Channel *channel = |
| 3314 | event_loop_factory_.configuration()->channels()->Get( |
| 3315 | msg->message().channel_index()); |
| 3316 | const Connection *connection = configuration::ConnectionToNode( |
| 3317 | channel, configuration::GetNode( |
| 3318 | event_loop_factory_.configuration(), |
| 3319 | log_header->message().node()->name()->string_view())); |
| 3320 | |
| 3321 | const bool reliable = connection->time_to_live() == 0; |
| 3322 | |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3323 | SCOPED_TRACE(file); |
| 3324 | SCOPED_TRACE(aos::FlatbufferToJson( |
| 3325 | *log_header, {.multi_line = true, .max_vector_size = 100})); |
| 3326 | |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3327 | if (shared()) { |
| 3328 | // Confirm that the oldest timestamps match what we expect. Based on |
| 3329 | // what we are doing, we know that the oldest time is the first |
| 3330 | // message's time. |
| 3331 | // |
| 3332 | // This makes the test robust to both the split and combined config |
| 3333 | // tests. |
| 3334 | switch (log_header->message().parts_index()) { |
| 3335 | case 0: |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3336 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
| 3337 | expected_oldest_remote_monotonic_timestamps); |
| 3338 | EXPECT_EQ(oldest_local_monotonic_timestamps, |
| 3339 | expected_oldest_local_monotonic_timestamps); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3340 | EXPECT_EQ(oldest_logger_remote_unreliable_monotonic_timestamps, |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 3341 | expected_oldest_local_monotonic_timestamps) |
| 3342 | << file; |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3343 | EXPECT_EQ(oldest_logger_local_unreliable_monotonic_timestamps, |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 3344 | expected_oldest_timestamp_monotonic_timestamps) |
| 3345 | << file; |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3346 | |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3347 | if (reliable) { |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3348 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3349 | expected_oldest_remote_monotonic_timestamps); |
| 3350 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3351 | expected_oldest_local_monotonic_timestamps); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3352 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3353 | monotonic_clock::max_time); |
| 3354 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3355 | monotonic_clock::max_time); |
| 3356 | } else { |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3357 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3358 | monotonic_clock::max_time); |
| 3359 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3360 | monotonic_clock::max_time); |
| 3361 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3362 | expected_oldest_remote_monotonic_timestamps); |
| 3363 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3364 | expected_oldest_local_monotonic_timestamps); |
| 3365 | } |
| 3366 | break; |
| 3367 | case 1: |
| 3368 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
| 3369 | monotonic_clock::epoch() + chrono::nanoseconds(90000000)); |
| 3370 | EXPECT_EQ(oldest_local_monotonic_timestamps, |
| 3371 | monotonic_clock::epoch() + chrono::nanoseconds(90150000)); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3372 | EXPECT_EQ(oldest_logger_remote_unreliable_monotonic_timestamps, |
| 3373 | monotonic_clock::epoch() + chrono::nanoseconds(90150000)); |
| 3374 | EXPECT_EQ(oldest_logger_local_unreliable_monotonic_timestamps, |
| 3375 | monotonic_clock::epoch() + chrono::nanoseconds(90250000)); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3376 | if (reliable) { |
| 3377 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3378 | expected_oldest_remote_monotonic_timestamps); |
| 3379 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3380 | expected_oldest_local_monotonic_timestamps); |
| 3381 | EXPECT_EQ( |
| 3382 | oldest_remote_unreliable_monotonic_timestamps, |
| 3383 | monotonic_clock::epoch() + chrono::nanoseconds(90000000)); |
| 3384 | EXPECT_EQ( |
| 3385 | oldest_local_unreliable_monotonic_timestamps, |
| 3386 | monotonic_clock::epoch() + chrono::nanoseconds(90150000)); |
| 3387 | } else { |
| 3388 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3389 | monotonic_clock::max_time); |
| 3390 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3391 | monotonic_clock::max_time); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3392 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3393 | expected_oldest_remote_monotonic_timestamps); |
| 3394 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3395 | expected_oldest_local_monotonic_timestamps); |
| 3396 | } |
| 3397 | break; |
| 3398 | case 2: |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3399 | EXPECT_EQ( |
| 3400 | oldest_remote_monotonic_timestamps, |
| 3401 | monotonic_clock::epoch() + chrono::nanoseconds(10000000000)); |
| 3402 | EXPECT_EQ( |
| 3403 | oldest_local_monotonic_timestamps, |
| 3404 | monotonic_clock::epoch() + chrono::nanoseconds(1323100000)); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3405 | EXPECT_EQ(oldest_logger_remote_unreliable_monotonic_timestamps, |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 3406 | expected_oldest_local_monotonic_timestamps) |
| 3407 | << file; |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3408 | EXPECT_EQ(oldest_logger_local_unreliable_monotonic_timestamps, |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 3409 | expected_oldest_timestamp_monotonic_timestamps) |
| 3410 | << file; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3411 | if (reliable) { |
| 3412 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3413 | expected_oldest_remote_monotonic_timestamps); |
| 3414 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3415 | expected_oldest_local_monotonic_timestamps); |
| 3416 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3417 | monotonic_clock::max_time); |
| 3418 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3419 | monotonic_clock::max_time); |
| 3420 | } else { |
| 3421 | EXPECT_EQ(oldest_remote_reliable_monotonic_timestamps, |
| 3422 | monotonic_clock::max_time); |
| 3423 | EXPECT_EQ(oldest_local_reliable_monotonic_timestamps, |
| 3424 | monotonic_clock::max_time); |
| 3425 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3426 | expected_oldest_remote_monotonic_timestamps); |
| 3427 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3428 | expected_oldest_local_monotonic_timestamps); |
| 3429 | } |
| 3430 | break; |
| 3431 | |
| 3432 | case 3: |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3433 | EXPECT_EQ( |
| 3434 | oldest_remote_monotonic_timestamps, |
| 3435 | monotonic_clock::epoch() + chrono::nanoseconds(10000000000)); |
| 3436 | EXPECT_EQ( |
| 3437 | oldest_local_monotonic_timestamps, |
| 3438 | monotonic_clock::epoch() + chrono::nanoseconds(1323100000)); |
| 3439 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3440 | expected_oldest_remote_monotonic_timestamps); |
| 3441 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3442 | expected_oldest_local_monotonic_timestamps); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3443 | EXPECT_EQ( |
| 3444 | oldest_logger_remote_unreliable_monotonic_timestamps, |
| 3445 | monotonic_clock::epoch() + chrono::nanoseconds(1323100000)); |
| 3446 | EXPECT_EQ( |
| 3447 | oldest_logger_local_unreliable_monotonic_timestamps, |
| 3448 | monotonic_clock::epoch() + chrono::nanoseconds(10100200000)); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3449 | break; |
| 3450 | default: |
| 3451 | FAIL(); |
| 3452 | break; |
| 3453 | } |
| 3454 | |
| 3455 | switch (log_header->message().parts_index()) { |
| 3456 | case 0: |
| 3457 | EXPECT_EQ(source_node_boot_uuid, pi2_boot0); |
| 3458 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
| 3459 | break; |
| 3460 | case 1: |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3461 | EXPECT_EQ(source_node_boot_uuid, pi2_boot0); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3462 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
| 3463 | break; |
| 3464 | case 2: |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3465 | EXPECT_EQ(source_node_boot_uuid, pi2_boot1); |
| 3466 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
| 3467 | break; |
| 3468 | case 3: |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3469 | if (shared()) { |
| 3470 | EXPECT_EQ(source_node_boot_uuid, pi2_boot1); |
| 3471 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3472 | break; |
| 3473 | } |
| 3474 | [[fallthrough]]; |
| 3475 | default: |
| 3476 | FAIL(); |
| 3477 | break; |
| 3478 | } |
| 3479 | } else { |
| 3480 | switch (log_header->message().parts_index()) { |
| 3481 | case 0: |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3482 | if (reliable) { |
| 3483 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3484 | monotonic_clock::max_time); |
| 3485 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3486 | monotonic_clock::max_time); |
| 3487 | EXPECT_EQ( |
| 3488 | oldest_logger_remote_unreliable_monotonic_timestamps, |
| 3489 | monotonic_clock::epoch() + chrono::nanoseconds(100150000)) |
| 3490 | << file; |
| 3491 | EXPECT_EQ( |
| 3492 | oldest_logger_local_unreliable_monotonic_timestamps, |
| 3493 | monotonic_clock::epoch() + chrono::nanoseconds(100250000)) |
| 3494 | << file; |
| 3495 | } else { |
| 3496 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3497 | expected_oldest_remote_monotonic_timestamps); |
| 3498 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3499 | expected_oldest_local_monotonic_timestamps); |
| 3500 | EXPECT_EQ( |
| 3501 | oldest_logger_remote_unreliable_monotonic_timestamps, |
| 3502 | monotonic_clock::epoch() + chrono::nanoseconds(90150000)) |
| 3503 | << file; |
| 3504 | EXPECT_EQ( |
| 3505 | oldest_logger_local_unreliable_monotonic_timestamps, |
| 3506 | monotonic_clock::epoch() + chrono::nanoseconds(90250000)) |
| 3507 | << file; |
| 3508 | } |
| 3509 | break; |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3510 | case 1: |
| 3511 | if (reliable) { |
| 3512 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3513 | monotonic_clock::max_time); |
| 3514 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3515 | monotonic_clock::max_time); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3516 | EXPECT_EQ( |
| 3517 | oldest_logger_remote_unreliable_monotonic_timestamps, |
| 3518 | monotonic_clock::epoch() + chrono::nanoseconds(1323100000)); |
| 3519 | EXPECT_EQ( |
| 3520 | oldest_logger_local_unreliable_monotonic_timestamps, |
| 3521 | monotonic_clock::epoch() + chrono::nanoseconds(10100200000)); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3522 | } else { |
| 3523 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3524 | expected_oldest_remote_monotonic_timestamps); |
| 3525 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3526 | expected_oldest_local_monotonic_timestamps); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 3527 | EXPECT_EQ( |
| 3528 | oldest_logger_remote_unreliable_monotonic_timestamps, |
| 3529 | monotonic_clock::epoch() + chrono::nanoseconds(1323150000)); |
| 3530 | EXPECT_EQ( |
| 3531 | oldest_logger_local_unreliable_monotonic_timestamps, |
| 3532 | monotonic_clock::epoch() + chrono::nanoseconds(10100250000)); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3533 | } |
| 3534 | break; |
| 3535 | default: |
| 3536 | FAIL(); |
| 3537 | break; |
| 3538 | } |
| 3539 | |
| 3540 | switch (log_header->message().parts_index()) { |
| 3541 | case 0: |
| 3542 | EXPECT_EQ(source_node_boot_uuid, pi2_boot0); |
| 3543 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
| 3544 | break; |
| 3545 | case 1: |
| 3546 | EXPECT_EQ(source_node_boot_uuid, pi2_boot1); |
| 3547 | EXPECT_EQ(monotonic_start_time, monotonic_clock::min_time); |
| 3548 | break; |
| 3549 | default: |
| 3550 | FAIL(); |
| 3551 | break; |
| 3552 | } |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | continue; |
| 3556 | } |
| 3557 | EXPECT_EQ( |
| 3558 | log_header->message().oldest_remote_monotonic_timestamps()->Get(0), |
| 3559 | monotonic_clock::max_time.time_since_epoch().count()); |
| 3560 | EXPECT_EQ(log_header->message().oldest_local_monotonic_timestamps()->Get(0), |
| 3561 | monotonic_clock::max_time.time_since_epoch().count()); |
| 3562 | EXPECT_EQ(log_header->message() |
| 3563 | .oldest_remote_unreliable_monotonic_timestamps() |
| 3564 | ->Get(0), |
| 3565 | monotonic_clock::max_time.time_since_epoch().count()); |
| 3566 | EXPECT_EQ(log_header->message() |
| 3567 | .oldest_local_unreliable_monotonic_timestamps() |
| 3568 | ->Get(0), |
| 3569 | monotonic_clock::max_time.time_since_epoch().count()); |
| 3570 | |
| 3571 | const monotonic_clock::time_point oldest_remote_monotonic_timestamps = |
| 3572 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3573 | log_header->message().oldest_remote_monotonic_timestamps()->Get( |
| 3574 | 1))); |
| 3575 | const monotonic_clock::time_point oldest_local_monotonic_timestamps = |
| 3576 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3577 | log_header->message().oldest_local_monotonic_timestamps()->Get(1))); |
| 3578 | const monotonic_clock::time_point |
| 3579 | oldest_remote_unreliable_monotonic_timestamps = |
| 3580 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3581 | log_header->message() |
| 3582 | .oldest_remote_unreliable_monotonic_timestamps() |
| 3583 | ->Get(1))); |
| 3584 | const monotonic_clock::time_point |
| 3585 | oldest_local_unreliable_monotonic_timestamps = |
| 3586 | monotonic_clock::time_point(chrono::nanoseconds( |
| 3587 | log_header->message() |
| 3588 | .oldest_local_unreliable_monotonic_timestamps() |
| 3589 | ->Get(1))); |
| 3590 | switch (log_header->message().parts_index()) { |
| 3591 | case 0: |
| 3592 | EXPECT_EQ(oldest_remote_monotonic_timestamps, |
| 3593 | monotonic_clock::max_time); |
| 3594 | EXPECT_EQ(oldest_local_monotonic_timestamps, monotonic_clock::max_time); |
| 3595 | EXPECT_EQ(oldest_remote_unreliable_monotonic_timestamps, |
| 3596 | monotonic_clock::max_time); |
| 3597 | EXPECT_EQ(oldest_local_unreliable_monotonic_timestamps, |
| 3598 | monotonic_clock::max_time); |
| 3599 | break; |
| 3600 | default: |
| 3601 | FAIL(); |
| 3602 | break; |
| 3603 | } |
| 3604 | } |
| 3605 | |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3606 | if (shared()) { |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 3607 | EXPECT_EQ(timestamp_file_count, 4u); |
Austin Schuh | 01f3b39 | 2022-01-25 20:03:09 -0800 | [diff] [blame] | 3608 | } else { |
| 3609 | EXPECT_EQ(timestamp_file_count, 4u); |
| 3610 | } |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3611 | |
Austin Schuh | e2373e2 | 2022-01-21 12:25:17 -0800 | [diff] [blame] | 3612 | // Confirm that we can actually sort the resulting log and read it. |
| 3613 | { |
| 3614 | LogReader reader(SortParts(filenames)); |
| 3615 | |
| 3616 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 3617 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 3618 | |
| 3619 | // This sends out the fetched messages and advances time to the start of |
| 3620 | // the log file. |
| 3621 | reader.Register(&log_reader_factory); |
| 3622 | |
| 3623 | log_reader_factory.Run(); |
| 3624 | |
| 3625 | reader.Deregister(); |
| 3626 | } |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 3627 | } |
| 3628 | |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 3629 | // Tests that we properly handle one direction of message_bridge being |
| 3630 | // unavailable. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 3631 | TEST_P(MultinodeLoggerTest, OneDirectionWithNegativeSlope) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3632 | pi1_->Disconnect(pi2_->node()); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 3633 | time_converter_.AddMonotonic( |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 3634 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(1000)}); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 3635 | |
| 3636 | time_converter_.AddMonotonic( |
| 3637 | {chrono::milliseconds(10000), |
| 3638 | chrono::milliseconds(10000) - chrono::milliseconds(1)}); |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 3639 | { |
| 3640 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 3641 | |
| 3642 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 3643 | |
| 3644 | StartLogger(&pi1_logger); |
| 3645 | |
| 3646 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 3647 | } |
| 3648 | |
| 3649 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 3650 | // to confirm the right thing happened. |
| 3651 | ConfirmReadable(pi1_single_direction_logfiles_); |
| 3652 | } |
| 3653 | |
| 3654 | // Tests that we properly handle one direction of message_bridge being |
| 3655 | // unavailable. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 3656 | TEST_P(MultinodeLoggerTest, OneDirectionWithPositiveSlope) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3657 | pi1_->Disconnect(pi2_->node()); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 3658 | time_converter_.AddMonotonic( |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 3659 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(500)}); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 3660 | |
| 3661 | time_converter_.AddMonotonic( |
| 3662 | {chrono::milliseconds(10000), |
| 3663 | chrono::milliseconds(10000) + chrono::milliseconds(1)}); |
| 3664 | { |
| 3665 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 3666 | |
| 3667 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 3668 | |
| 3669 | StartLogger(&pi1_logger); |
| 3670 | |
| 3671 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 3672 | } |
| 3673 | |
| 3674 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 3675 | // to confirm the right thing happened. |
| 3676 | ConfirmReadable(pi1_single_direction_logfiles_); |
| 3677 | } |
| 3678 | |
Austin Schuh | e9f0023 | 2021-09-16 18:04:23 -0700 | [diff] [blame] | 3679 | // Tests that we explode if someone passes in a part file twice with a better |
| 3680 | // error than an out of order error. |
| 3681 | TEST_P(MultinodeLoggerTest, DuplicateLogFiles) { |
| 3682 | time_converter_.AddMonotonic( |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 3683 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(1000)}); |
Austin Schuh | e9f0023 | 2021-09-16 18:04:23 -0700 | [diff] [blame] | 3684 | { |
| 3685 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 3686 | |
| 3687 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 3688 | |
| 3689 | StartLogger(&pi1_logger); |
| 3690 | |
| 3691 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 3692 | } |
| 3693 | |
| 3694 | std::vector<std::string> duplicates; |
| 3695 | for (const std::string &f : pi1_single_direction_logfiles_) { |
| 3696 | duplicates.emplace_back(f); |
| 3697 | duplicates.emplace_back(f); |
| 3698 | } |
| 3699 | EXPECT_DEATH({ SortParts(duplicates); }, "Found duplicate parts in"); |
| 3700 | } |
| 3701 | |
Austin Schuh | 22cf786 | 2022-09-19 19:09:42 -0700 | [diff] [blame] | 3702 | // Tests that we explode if someone loses a part out of the middle of a log. |
| 3703 | TEST_P(MultinodeLoggerTest, MissingPartsFromMiddle) { |
| 3704 | time_converter_.AddMonotonic( |
| 3705 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(1000)}); |
| 3706 | { |
| 3707 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 3708 | |
| 3709 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 3710 | |
| 3711 | |
| 3712 | StartLogger(&pi1_logger); |
| 3713 | aos::monotonic_clock::time_point last_rotation_time = |
| 3714 | pi1_logger.event_loop->monotonic_now(); |
| 3715 | pi1_logger.logger->set_on_logged_period([&] { |
| 3716 | const auto now = pi1_logger.event_loop->monotonic_now(); |
| 3717 | if (now > last_rotation_time + std::chrono::seconds(5)) { |
| 3718 | pi1_logger.logger->Rotate(); |
| 3719 | last_rotation_time = now; |
| 3720 | } |
| 3721 | }); |
| 3722 | |
| 3723 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 3724 | } |
| 3725 | |
| 3726 | std::vector<std::string> missing_parts; |
| 3727 | |
| 3728 | missing_parts.emplace_back(logfile_base1_ + "_pi1_data.part0" + Extension()); |
| 3729 | missing_parts.emplace_back(logfile_base1_ + "_pi1_data.part2" + Extension()); |
| 3730 | missing_parts.emplace_back(absl::StrCat( |
| 3731 | logfile_base1_, "_", std::get<0>(GetParam()).sha256, Extension())); |
| 3732 | |
| 3733 | EXPECT_DEATH({ SortParts(missing_parts); }, |
| 3734 | "Broken log, missing part files between"); |
| 3735 | } |
| 3736 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 3737 | // Tests that we properly handle a dead node. Do this by just disconnecting it |
| 3738 | // and only using one nodes of logs. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 3739 | TEST_P(MultinodeLoggerTest, DeadNode) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3740 | pi1_->Disconnect(pi2_->node()); |
| 3741 | pi2_->Disconnect(pi1_->node()); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 3742 | time_converter_.AddMonotonic( |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 3743 | {BootTimestamp::epoch(), BootTimestamp::epoch() + chrono::seconds(1000)}); |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 3744 | { |
| 3745 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 3746 | |
| 3747 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 3748 | |
| 3749 | StartLogger(&pi1_logger); |
| 3750 | |
| 3751 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 3752 | } |
| 3753 | |
| 3754 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 3755 | // to confirm the right thing happened. |
Austin Schuh | 510dc62 | 2021-08-06 18:47:30 -0700 | [diff] [blame] | 3756 | ConfirmReadable(MakePi1DeadNodeLogfiles()); |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 3757 | } |
| 3758 | |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 3759 | constexpr std::string_view kCombinedConfigSha1( |
James Kuszmaul | 65541cb | 2022-11-08 14:53:47 -0800 | [diff] [blame^] | 3760 | "5d73fe35bacaa59d24f8f0c1a806fe10b783b0fcc80809ee30a9db824e82538b"); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 3761 | constexpr std::string_view kSplitConfigSha1( |
James Kuszmaul | 65541cb | 2022-11-08 14:53:47 -0800 | [diff] [blame^] | 3762 | "f25e8f6f90d61f41c41517e652300566228b077e44cd86f1af2af4a9bed31ad4"); |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 3763 | constexpr std::string_view kReloggedSplitConfigSha1( |
James Kuszmaul | 65541cb | 2022-11-08 14:53:47 -0800 | [diff] [blame^] | 3764 | "f1fabd629bdf8735c3d81bc791d7a454e8e636951c26cba6426545cbc97f911f"); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 3765 | |
James Kuszmaul | f4bf9fe | 2021-05-10 22:58:24 -0700 | [diff] [blame] | 3766 | INSTANTIATE_TEST_SUITE_P( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 3767 | All, MultinodeLoggerTest, |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 3768 | ::testing::Combine( |
| 3769 | ::testing::Values( |
| 3770 | ConfigParams{"multinode_pingpong_combined_config.json", true, |
| 3771 | kCombinedConfigSha1, kCombinedConfigSha1}, |
| 3772 | ConfigParams{"multinode_pingpong_split_config.json", false, |
| 3773 | kSplitConfigSha1, kReloggedSplitConfigSha1}), |
| 3774 | ::testing::ValuesIn(SupportedCompressionAlgorithms()))); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 3775 | |
James Kuszmaul | f4bf9fe | 2021-05-10 22:58:24 -0700 | [diff] [blame] | 3776 | INSTANTIATE_TEST_SUITE_P( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 3777 | All, MultinodeLoggerDeathTest, |
James Kuszmaul | 53da7f3 | 2022-09-11 11:11:55 -0700 | [diff] [blame] | 3778 | ::testing::Combine( |
| 3779 | ::testing::Values( |
| 3780 | ConfigParams{"multinode_pingpong_combined_config.json", true, |
| 3781 | kCombinedConfigSha1, kCombinedConfigSha1}, |
| 3782 | ConfigParams{"multinode_pingpong_split_config.json", false, |
| 3783 | kSplitConfigSha1, kReloggedSplitConfigSha1}), |
| 3784 | ::testing::ValuesIn(SupportedCompressionAlgorithms()))); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 3785 | |
Austin Schuh | 5b728b7 | 2021-06-16 14:57:15 -0700 | [diff] [blame] | 3786 | // Tests that we can relog with a different config. This makes most sense when |
| 3787 | // you are trying to edit a log and want to use channel renaming + the original |
| 3788 | // config in the new log. |
| 3789 | TEST_P(MultinodeLoggerTest, LogDifferentConfig) { |
| 3790 | time_converter_.StartEqual(); |
| 3791 | { |
| 3792 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 3793 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 3794 | |
| 3795 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 3796 | |
| 3797 | StartLogger(&pi1_logger); |
| 3798 | StartLogger(&pi2_logger); |
| 3799 | |
| 3800 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 3801 | } |
| 3802 | |
| 3803 | LogReader reader(SortParts(logfiles_)); |
| 3804 | reader.RemapLoggedChannel<aos::examples::Ping>("/test", "/original"); |
| 3805 | |
| 3806 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 3807 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 3808 | |
| 3809 | // This sends out the fetched messages and advances time to the start of the |
| 3810 | // log file. |
| 3811 | reader.Register(&log_reader_factory); |
| 3812 | |
| 3813 | const Node *pi1 = |
| 3814 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 3815 | const Node *pi2 = |
| 3816 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 3817 | |
| 3818 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi1) << " pi1"; |
| 3819 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi2) << " pi2"; |
| 3820 | LOG(INFO) << "now pi1 " |
| 3821 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now(); |
| 3822 | LOG(INFO) << "now pi2 " |
| 3823 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now(); |
| 3824 | |
| 3825 | EXPECT_THAT(reader.LoggedNodes(), |
| 3826 | ::testing::ElementsAre( |
| 3827 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 3828 | configuration::GetNode(reader.logged_configuration(), pi2))); |
| 3829 | |
| 3830 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
| 3831 | |
| 3832 | // And confirm we can re-create a log again, while checking the contents. |
| 3833 | std::vector<std::string> log_files; |
| 3834 | { |
| 3835 | LoggerState pi1_logger = |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3836 | MakeLogger(log_reader_factory.GetNodeEventLoopFactory("pi1"), |
Austin Schuh | 5b728b7 | 2021-06-16 14:57:15 -0700 | [diff] [blame] | 3837 | &log_reader_factory, reader.logged_configuration()); |
| 3838 | LoggerState pi2_logger = |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 3839 | MakeLogger(log_reader_factory.GetNodeEventLoopFactory("pi2"), |
Austin Schuh | 5b728b7 | 2021-06-16 14:57:15 -0700 | [diff] [blame] | 3840 | &log_reader_factory, reader.logged_configuration()); |
| 3841 | |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 3842 | pi1_logger.StartLogger(tmp_dir_ + "/relogged1"); |
| 3843 | pi2_logger.StartLogger(tmp_dir_ + "/relogged2"); |
Austin Schuh | 5b728b7 | 2021-06-16 14:57:15 -0700 | [diff] [blame] | 3844 | |
| 3845 | log_reader_factory.Run(); |
| 3846 | |
| 3847 | for (auto &x : pi1_logger.log_namer->all_filenames()) { |
| 3848 | log_files.emplace_back(absl::StrCat(tmp_dir_, "/relogged1_", x)); |
| 3849 | } |
| 3850 | for (auto &x : pi2_logger.log_namer->all_filenames()) { |
| 3851 | log_files.emplace_back(absl::StrCat(tmp_dir_, "/relogged2_", x)); |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | reader.Deregister(); |
| 3856 | |
| 3857 | // And verify that we can run the LogReader over the relogged files without |
| 3858 | // hitting any fatal errors. |
| 3859 | { |
| 3860 | LogReader relogged_reader(SortParts(log_files)); |
| 3861 | relogged_reader.Register(); |
| 3862 | |
| 3863 | relogged_reader.event_loop_factory()->Run(); |
| 3864 | } |
| 3865 | } |
Austin Schuh | a04efed | 2021-01-24 18:04:20 -0800 | [diff] [blame] | 3866 | |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 3867 | // Tests that we properly replay a log where the start time for a node is before |
| 3868 | // any data on the node. This can happen if the logger starts before data is |
| 3869 | // published. While the scenario below is a bit convoluted, we have seen logs |
| 3870 | // like this generated out in the wild. |
| 3871 | TEST(MultinodeRebootLoggerTest, StartTimeBeforeData) { |
| 3872 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 3873 | aos::configuration::ReadConfig(ArtifactPath( |
| 3874 | "aos/events/logging/multinode_pingpong_split3_config.json")); |
| 3875 | message_bridge::TestingTimeConverter time_converter( |
| 3876 | configuration::NodesCount(&config.message())); |
| 3877 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 3878 | event_loop_factory.SetTimeConverter(&time_converter); |
| 3879 | NodeEventLoopFactory *const pi1 = |
| 3880 | event_loop_factory.GetNodeEventLoopFactory("pi1"); |
| 3881 | const size_t pi1_index = configuration::GetNodeIndex( |
| 3882 | event_loop_factory.configuration(), pi1->node()); |
| 3883 | NodeEventLoopFactory *const pi2 = |
| 3884 | event_loop_factory.GetNodeEventLoopFactory("pi2"); |
| 3885 | const size_t pi2_index = configuration::GetNodeIndex( |
| 3886 | event_loop_factory.configuration(), pi2->node()); |
| 3887 | NodeEventLoopFactory *const pi3 = |
| 3888 | event_loop_factory.GetNodeEventLoopFactory("pi3"); |
| 3889 | const size_t pi3_index = configuration::GetNodeIndex( |
| 3890 | event_loop_factory.configuration(), pi3->node()); |
| 3891 | |
| 3892 | const std::string kLogfile1_1 = |
| 3893 | aos::testing::TestTmpDir() + "/multi_logfile1/"; |
| 3894 | const std::string kLogfile2_1 = |
| 3895 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 3896 | const std::string kLogfile2_2 = |
| 3897 | aos::testing::TestTmpDir() + "/multi_logfile2.2/"; |
| 3898 | const std::string kLogfile3_1 = |
| 3899 | aos::testing::TestTmpDir() + "/multi_logfile3/"; |
| 3900 | util::UnlinkRecursive(kLogfile1_1); |
| 3901 | util::UnlinkRecursive(kLogfile2_1); |
| 3902 | util::UnlinkRecursive(kLogfile2_2); |
| 3903 | util::UnlinkRecursive(kLogfile3_1); |
| 3904 | const UUID pi1_boot0 = UUID::Random(); |
| 3905 | const UUID pi2_boot0 = UUID::Random(); |
| 3906 | const UUID pi2_boot1 = UUID::Random(); |
| 3907 | const UUID pi3_boot0 = UUID::Random(); |
| 3908 | { |
| 3909 | CHECK_EQ(pi1_index, 0u); |
| 3910 | CHECK_EQ(pi2_index, 1u); |
| 3911 | CHECK_EQ(pi3_index, 2u); |
| 3912 | |
| 3913 | time_converter.set_boot_uuid(pi1_index, 0, pi1_boot0); |
| 3914 | time_converter.set_boot_uuid(pi2_index, 0, pi2_boot0); |
| 3915 | time_converter.set_boot_uuid(pi2_index, 1, pi2_boot1); |
| 3916 | time_converter.set_boot_uuid(pi3_index, 0, pi3_boot0); |
| 3917 | |
| 3918 | time_converter.AddNextTimestamp( |
| 3919 | distributed_clock::epoch(), |
| 3920 | {BootTimestamp::epoch(), BootTimestamp::epoch(), |
| 3921 | BootTimestamp::epoch()}); |
| 3922 | const chrono::nanoseconds reboot_time = chrono::milliseconds(20000); |
| 3923 | time_converter.AddNextTimestamp( |
| 3924 | distributed_clock::epoch() + reboot_time, |
| 3925 | {BootTimestamp::epoch() + reboot_time, |
| 3926 | BootTimestamp{ |
| 3927 | .boot = 1, |
| 3928 | .time = monotonic_clock::epoch() + chrono::milliseconds(1323)}, |
| 3929 | BootTimestamp::epoch() + reboot_time}); |
| 3930 | } |
| 3931 | |
| 3932 | // Make everything perfectly quiet. |
| 3933 | event_loop_factory.SkipTimingReport(); |
| 3934 | event_loop_factory.DisableStatistics(); |
| 3935 | |
| 3936 | std::vector<std::string> filenames; |
| 3937 | { |
| 3938 | LoggerState pi1_logger = LoggerState::MakeLogger( |
| 3939 | pi1, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 3940 | LoggerState pi3_logger = LoggerState::MakeLogger( |
| 3941 | pi3, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 3942 | { |
| 3943 | // And now start the logger. |
| 3944 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 3945 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 3946 | |
| 3947 | event_loop_factory.RunFor(chrono::milliseconds(1000)); |
| 3948 | |
| 3949 | pi1_logger.StartLogger(kLogfile1_1); |
| 3950 | pi3_logger.StartLogger(kLogfile3_1); |
| 3951 | pi2_logger.StartLogger(kLogfile2_1); |
| 3952 | |
| 3953 | event_loop_factory.RunFor(chrono::milliseconds(10000)); |
| 3954 | |
| 3955 | // Now that we've got a start time in the past, turn on data. |
| 3956 | event_loop_factory.EnableStatistics(); |
| 3957 | std::unique_ptr<aos::EventLoop> ping_event_loop = |
| 3958 | pi1->MakeEventLoop("ping"); |
| 3959 | Ping ping(ping_event_loop.get()); |
| 3960 | |
| 3961 | pi2->AlwaysStart<Pong>("pong"); |
| 3962 | |
| 3963 | event_loop_factory.RunFor(chrono::milliseconds(3000)); |
| 3964 | |
| 3965 | pi2_logger.AppendAllFilenames(&filenames); |
| 3966 | |
| 3967 | // Stop logging on pi2 before rebooting and completely shut off all |
| 3968 | // messages on pi2. |
| 3969 | pi2->DisableStatistics(); |
| 3970 | pi1->Disconnect(pi2->node()); |
| 3971 | pi2->Disconnect(pi1->node()); |
| 3972 | } |
| 3973 | event_loop_factory.RunFor(chrono::milliseconds(7000)); |
| 3974 | // pi2 now reboots. |
| 3975 | { |
| 3976 | event_loop_factory.RunFor(chrono::milliseconds(1000)); |
| 3977 | |
| 3978 | // Start logging again on pi2 after it is up. |
| 3979 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 3980 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 3981 | pi2_logger.StartLogger(kLogfile2_2); |
| 3982 | |
| 3983 | event_loop_factory.RunFor(chrono::milliseconds(10000)); |
| 3984 | // And, now that we have a start time in the log, turn data back on. |
| 3985 | pi2->EnableStatistics(); |
| 3986 | pi1->Connect(pi2->node()); |
| 3987 | pi2->Connect(pi1->node()); |
| 3988 | |
| 3989 | pi2->AlwaysStart<Pong>("pong"); |
| 3990 | std::unique_ptr<aos::EventLoop> ping_event_loop = |
| 3991 | pi1->MakeEventLoop("ping"); |
| 3992 | Ping ping(ping_event_loop.get()); |
| 3993 | |
| 3994 | event_loop_factory.RunFor(chrono::milliseconds(3000)); |
| 3995 | |
| 3996 | pi2_logger.AppendAllFilenames(&filenames); |
| 3997 | } |
| 3998 | |
| 3999 | pi1_logger.AppendAllFilenames(&filenames); |
| 4000 | pi3_logger.AppendAllFilenames(&filenames); |
| 4001 | } |
| 4002 | |
| 4003 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 4004 | // to confirm the right thing happened. |
| 4005 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 4006 | auto result = ConfirmReadable(filenames); |
| 4007 | EXPECT_THAT(result[0].first, ::testing::ElementsAre(realtime_clock::epoch() + |
| 4008 | chrono::seconds(1))); |
| 4009 | EXPECT_THAT(result[0].second, |
| 4010 | ::testing::ElementsAre(realtime_clock::epoch() + |
| 4011 | chrono::microseconds(34990350))); |
| 4012 | |
| 4013 | EXPECT_THAT(result[1].first, |
| 4014 | ::testing::ElementsAre( |
| 4015 | realtime_clock::epoch() + chrono::seconds(1), |
| 4016 | realtime_clock::epoch() + chrono::microseconds(3323000))); |
| 4017 | EXPECT_THAT(result[1].second, |
| 4018 | ::testing::ElementsAre( |
| 4019 | realtime_clock::epoch() + chrono::microseconds(13990200), |
| 4020 | realtime_clock::epoch() + chrono::microseconds(16313200))); |
| 4021 | |
| 4022 | EXPECT_THAT(result[2].first, ::testing::ElementsAre(realtime_clock::epoch() + |
| 4023 | chrono::seconds(1))); |
| 4024 | EXPECT_THAT(result[2].second, |
| 4025 | ::testing::ElementsAre(realtime_clock::epoch() + |
| 4026 | chrono::microseconds(34900150))); |
Austin Schuh | 3e20c69 | 2021-11-16 20:43:16 -0800 | [diff] [blame] | 4027 | } |
| 4028 | |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 4029 | // Tests that local data before remote data after reboot is properly replayed. |
| 4030 | // We only trigger a reboot in the timestamp interpolation function when solving |
| 4031 | // the timestamp problem when we actually have a point in the function. This |
| 4032 | // originally only happened when a point passes the noncausal filter. At the |
| 4033 | // start of time for the second boot, if we aren't careful, we will have |
| 4034 | // messages which need to be published at times before the boot. This happens |
| 4035 | // when a local message is in the log before a forwarded message, so there is no |
| 4036 | // point in the interpolation function. This delays the reboot. So, we need to |
| 4037 | // recreate that situation and make sure it doesn't come back. |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 4038 | TEST(MultinodeRebootLoggerTest, |
| 4039 | LocalMessageBeforeRemoteBeforeStartAfterReboot) { |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 4040 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 4041 | aos::configuration::ReadConfig(ArtifactPath( |
| 4042 | "aos/events/logging/multinode_pingpong_split3_config.json")); |
| 4043 | message_bridge::TestingTimeConverter time_converter( |
| 4044 | configuration::NodesCount(&config.message())); |
| 4045 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 4046 | event_loop_factory.SetTimeConverter(&time_converter); |
| 4047 | NodeEventLoopFactory *const pi1 = |
| 4048 | event_loop_factory.GetNodeEventLoopFactory("pi1"); |
| 4049 | const size_t pi1_index = configuration::GetNodeIndex( |
| 4050 | event_loop_factory.configuration(), pi1->node()); |
| 4051 | NodeEventLoopFactory *const pi2 = |
| 4052 | event_loop_factory.GetNodeEventLoopFactory("pi2"); |
| 4053 | const size_t pi2_index = configuration::GetNodeIndex( |
| 4054 | event_loop_factory.configuration(), pi2->node()); |
| 4055 | NodeEventLoopFactory *const pi3 = |
| 4056 | event_loop_factory.GetNodeEventLoopFactory("pi3"); |
| 4057 | const size_t pi3_index = configuration::GetNodeIndex( |
| 4058 | event_loop_factory.configuration(), pi3->node()); |
| 4059 | |
| 4060 | const std::string kLogfile1_1 = |
| 4061 | aos::testing::TestTmpDir() + "/multi_logfile1/"; |
| 4062 | const std::string kLogfile2_1 = |
| 4063 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 4064 | const std::string kLogfile2_2 = |
| 4065 | aos::testing::TestTmpDir() + "/multi_logfile2.2/"; |
| 4066 | const std::string kLogfile3_1 = |
| 4067 | aos::testing::TestTmpDir() + "/multi_logfile3/"; |
| 4068 | util::UnlinkRecursive(kLogfile1_1); |
| 4069 | util::UnlinkRecursive(kLogfile2_1); |
| 4070 | util::UnlinkRecursive(kLogfile2_2); |
| 4071 | util::UnlinkRecursive(kLogfile3_1); |
| 4072 | const UUID pi1_boot0 = UUID::Random(); |
| 4073 | const UUID pi2_boot0 = UUID::Random(); |
| 4074 | const UUID pi2_boot1 = UUID::Random(); |
| 4075 | const UUID pi3_boot0 = UUID::Random(); |
| 4076 | { |
| 4077 | CHECK_EQ(pi1_index, 0u); |
| 4078 | CHECK_EQ(pi2_index, 1u); |
| 4079 | CHECK_EQ(pi3_index, 2u); |
| 4080 | |
| 4081 | time_converter.set_boot_uuid(pi1_index, 0, pi1_boot0); |
| 4082 | time_converter.set_boot_uuid(pi2_index, 0, pi2_boot0); |
| 4083 | time_converter.set_boot_uuid(pi2_index, 1, pi2_boot1); |
| 4084 | time_converter.set_boot_uuid(pi3_index, 0, pi3_boot0); |
| 4085 | |
| 4086 | time_converter.AddNextTimestamp( |
| 4087 | distributed_clock::epoch(), |
| 4088 | {BootTimestamp::epoch(), BootTimestamp::epoch(), |
| 4089 | BootTimestamp::epoch()}); |
| 4090 | const chrono::nanoseconds reboot_time = chrono::milliseconds(5000); |
| 4091 | time_converter.AddNextTimestamp( |
| 4092 | distributed_clock::epoch() + reboot_time, |
| 4093 | {BootTimestamp::epoch() + reboot_time, |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 4094 | BootTimestamp{.boot = 1, |
| 4095 | .time = monotonic_clock::epoch() + reboot_time + |
| 4096 | chrono::seconds(100)}, |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 4097 | BootTimestamp::epoch() + reboot_time}); |
| 4098 | } |
| 4099 | |
| 4100 | std::vector<std::string> filenames; |
| 4101 | { |
| 4102 | LoggerState pi1_logger = LoggerState::MakeLogger( |
| 4103 | pi1, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4104 | LoggerState pi3_logger = LoggerState::MakeLogger( |
| 4105 | pi3, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4106 | { |
| 4107 | // And now start the logger. |
| 4108 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4109 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4110 | |
| 4111 | pi1_logger.StartLogger(kLogfile1_1); |
| 4112 | pi3_logger.StartLogger(kLogfile3_1); |
| 4113 | pi2_logger.StartLogger(kLogfile2_1); |
| 4114 | |
| 4115 | event_loop_factory.RunFor(chrono::milliseconds(1005)); |
| 4116 | |
| 4117 | // Now that we've got a start time in the past, turn on data. |
| 4118 | std::unique_ptr<aos::EventLoop> ping_event_loop = |
| 4119 | pi1->MakeEventLoop("ping"); |
| 4120 | Ping ping(ping_event_loop.get()); |
| 4121 | |
| 4122 | pi2->AlwaysStart<Pong>("pong"); |
| 4123 | |
| 4124 | event_loop_factory.RunFor(chrono::milliseconds(3000)); |
| 4125 | |
| 4126 | pi2_logger.AppendAllFilenames(&filenames); |
| 4127 | |
| 4128 | // Disable any remote messages on pi2. |
| 4129 | pi1->Disconnect(pi2->node()); |
| 4130 | pi2->Disconnect(pi1->node()); |
| 4131 | } |
| 4132 | event_loop_factory.RunFor(chrono::milliseconds(995)); |
| 4133 | // pi2 now reboots at 5 seconds. |
| 4134 | { |
| 4135 | event_loop_factory.RunFor(chrono::milliseconds(1000)); |
| 4136 | |
| 4137 | // Make local stuff happen before we start logging and connect the remote. |
| 4138 | pi2->AlwaysStart<Pong>("pong"); |
| 4139 | std::unique_ptr<aos::EventLoop> ping_event_loop = |
| 4140 | pi1->MakeEventLoop("ping"); |
| 4141 | Ping ping(ping_event_loop.get()); |
| 4142 | event_loop_factory.RunFor(chrono::milliseconds(1005)); |
| 4143 | |
| 4144 | // Start logging again on pi2 after it is up. |
| 4145 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4146 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4147 | pi2_logger.StartLogger(kLogfile2_2); |
| 4148 | |
| 4149 | // And allow remote messages now that we have some local ones. |
| 4150 | pi1->Connect(pi2->node()); |
| 4151 | pi2->Connect(pi1->node()); |
| 4152 | |
| 4153 | event_loop_factory.RunFor(chrono::milliseconds(1000)); |
| 4154 | |
| 4155 | event_loop_factory.RunFor(chrono::milliseconds(3000)); |
| 4156 | |
| 4157 | pi2_logger.AppendAllFilenames(&filenames); |
| 4158 | } |
| 4159 | |
| 4160 | pi1_logger.AppendAllFilenames(&filenames); |
| 4161 | pi3_logger.AppendAllFilenames(&filenames); |
| 4162 | } |
| 4163 | |
| 4164 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 4165 | // to confirm the right thing happened. |
| 4166 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 4167 | auto result = ConfirmReadable(filenames); |
| 4168 | |
| 4169 | EXPECT_THAT(result[0].first, ::testing::ElementsAre(realtime_clock::epoch())); |
| 4170 | EXPECT_THAT(result[0].second, |
| 4171 | ::testing::ElementsAre(realtime_clock::epoch() + |
| 4172 | chrono::microseconds(11000350))); |
| 4173 | |
| 4174 | EXPECT_THAT(result[1].first, |
| 4175 | ::testing::ElementsAre( |
| 4176 | realtime_clock::epoch(), |
| 4177 | realtime_clock::epoch() + chrono::microseconds(107005000))); |
| 4178 | EXPECT_THAT(result[1].second, |
| 4179 | ::testing::ElementsAre( |
| 4180 | realtime_clock::epoch() + chrono::microseconds(4000150), |
| 4181 | realtime_clock::epoch() + chrono::microseconds(111000200))); |
| 4182 | |
| 4183 | EXPECT_THAT(result[2].first, ::testing::ElementsAre(realtime_clock::epoch())); |
| 4184 | EXPECT_THAT(result[2].second, |
| 4185 | ::testing::ElementsAre(realtime_clock::epoch() + |
| 4186 | chrono::microseconds(11000150))); |
| 4187 | |
| 4188 | auto start_stop_result = ConfirmReadable( |
| 4189 | filenames, realtime_clock::epoch() + chrono::milliseconds(2000), |
| 4190 | realtime_clock::epoch() + chrono::milliseconds(3000)); |
| 4191 | |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 4192 | EXPECT_THAT( |
| 4193 | start_stop_result[0].first, |
| 4194 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(2))); |
| 4195 | EXPECT_THAT( |
| 4196 | start_stop_result[0].second, |
| 4197 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(3))); |
| 4198 | EXPECT_THAT( |
| 4199 | start_stop_result[1].first, |
| 4200 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(2))); |
| 4201 | EXPECT_THAT( |
| 4202 | start_stop_result[1].second, |
| 4203 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(3))); |
| 4204 | EXPECT_THAT( |
| 4205 | start_stop_result[2].first, |
| 4206 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(2))); |
| 4207 | EXPECT_THAT( |
| 4208 | start_stop_result[2].second, |
| 4209 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(3))); |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 4210 | } |
| 4211 | |
Austin Schuh | e33c08d | 2022-02-03 18:15:21 -0800 | [diff] [blame] | 4212 | // Tests that setting the start and stop flags across a reboot works as |
| 4213 | // expected. |
| 4214 | TEST(MultinodeRebootLoggerTest, RebootStartStopTimes) { |
| 4215 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 4216 | aos::configuration::ReadConfig(ArtifactPath( |
| 4217 | "aos/events/logging/multinode_pingpong_split3_config.json")); |
| 4218 | message_bridge::TestingTimeConverter time_converter( |
| 4219 | configuration::NodesCount(&config.message())); |
| 4220 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 4221 | event_loop_factory.SetTimeConverter(&time_converter); |
| 4222 | NodeEventLoopFactory *const pi1 = |
| 4223 | event_loop_factory.GetNodeEventLoopFactory("pi1"); |
| 4224 | const size_t pi1_index = configuration::GetNodeIndex( |
| 4225 | event_loop_factory.configuration(), pi1->node()); |
| 4226 | NodeEventLoopFactory *const pi2 = |
| 4227 | event_loop_factory.GetNodeEventLoopFactory("pi2"); |
| 4228 | const size_t pi2_index = configuration::GetNodeIndex( |
| 4229 | event_loop_factory.configuration(), pi2->node()); |
| 4230 | NodeEventLoopFactory *const pi3 = |
| 4231 | event_loop_factory.GetNodeEventLoopFactory("pi3"); |
| 4232 | const size_t pi3_index = configuration::GetNodeIndex( |
| 4233 | event_loop_factory.configuration(), pi3->node()); |
| 4234 | |
| 4235 | const std::string kLogfile1_1 = |
| 4236 | aos::testing::TestTmpDir() + "/multi_logfile1/"; |
| 4237 | const std::string kLogfile2_1 = |
| 4238 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 4239 | const std::string kLogfile2_2 = |
| 4240 | aos::testing::TestTmpDir() + "/multi_logfile2.2/"; |
| 4241 | const std::string kLogfile3_1 = |
| 4242 | aos::testing::TestTmpDir() + "/multi_logfile3/"; |
| 4243 | util::UnlinkRecursive(kLogfile1_1); |
| 4244 | util::UnlinkRecursive(kLogfile2_1); |
| 4245 | util::UnlinkRecursive(kLogfile2_2); |
| 4246 | util::UnlinkRecursive(kLogfile3_1); |
| 4247 | { |
| 4248 | CHECK_EQ(pi1_index, 0u); |
| 4249 | CHECK_EQ(pi2_index, 1u); |
| 4250 | CHECK_EQ(pi3_index, 2u); |
| 4251 | |
| 4252 | time_converter.AddNextTimestamp( |
| 4253 | distributed_clock::epoch(), |
| 4254 | {BootTimestamp::epoch(), BootTimestamp::epoch(), |
| 4255 | BootTimestamp::epoch()}); |
| 4256 | const chrono::nanoseconds reboot_time = chrono::milliseconds(5000); |
| 4257 | time_converter.AddNextTimestamp( |
| 4258 | distributed_clock::epoch() + reboot_time, |
| 4259 | {BootTimestamp::epoch() + reboot_time, |
| 4260 | BootTimestamp{.boot = 1, |
| 4261 | .time = monotonic_clock::epoch() + reboot_time}, |
| 4262 | BootTimestamp::epoch() + reboot_time}); |
| 4263 | } |
| 4264 | |
| 4265 | std::vector<std::string> filenames; |
| 4266 | { |
| 4267 | LoggerState pi1_logger = LoggerState::MakeLogger( |
| 4268 | pi1, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4269 | LoggerState pi3_logger = LoggerState::MakeLogger( |
| 4270 | pi3, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4271 | { |
| 4272 | // And now start the logger. |
| 4273 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4274 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4275 | |
| 4276 | pi1_logger.StartLogger(kLogfile1_1); |
| 4277 | pi3_logger.StartLogger(kLogfile3_1); |
| 4278 | pi2_logger.StartLogger(kLogfile2_1); |
| 4279 | |
| 4280 | event_loop_factory.RunFor(chrono::milliseconds(1005)); |
| 4281 | |
| 4282 | // Now that we've got a start time in the past, turn on data. |
| 4283 | std::unique_ptr<aos::EventLoop> ping_event_loop = |
| 4284 | pi1->MakeEventLoop("ping"); |
| 4285 | Ping ping(ping_event_loop.get()); |
| 4286 | |
| 4287 | pi2->AlwaysStart<Pong>("pong"); |
| 4288 | |
| 4289 | event_loop_factory.RunFor(chrono::milliseconds(3000)); |
| 4290 | |
| 4291 | pi2_logger.AppendAllFilenames(&filenames); |
| 4292 | } |
| 4293 | event_loop_factory.RunFor(chrono::milliseconds(995)); |
| 4294 | // pi2 now reboots at 5 seconds. |
| 4295 | { |
| 4296 | event_loop_factory.RunFor(chrono::milliseconds(1000)); |
| 4297 | |
| 4298 | // Make local stuff happen before we start logging and connect the remote. |
| 4299 | pi2->AlwaysStart<Pong>("pong"); |
| 4300 | std::unique_ptr<aos::EventLoop> ping_event_loop = |
| 4301 | pi1->MakeEventLoop("ping"); |
| 4302 | Ping ping(ping_event_loop.get()); |
| 4303 | event_loop_factory.RunFor(chrono::milliseconds(5)); |
| 4304 | |
| 4305 | // Start logging again on pi2 after it is up. |
| 4306 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4307 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4308 | pi2_logger.StartLogger(kLogfile2_2); |
| 4309 | |
| 4310 | event_loop_factory.RunFor(chrono::milliseconds(5000)); |
| 4311 | |
| 4312 | pi2_logger.AppendAllFilenames(&filenames); |
| 4313 | } |
| 4314 | |
| 4315 | pi1_logger.AppendAllFilenames(&filenames); |
| 4316 | pi3_logger.AppendAllFilenames(&filenames); |
| 4317 | } |
| 4318 | |
| 4319 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
| 4320 | auto result = ConfirmReadable(filenames); |
| 4321 | |
| 4322 | EXPECT_THAT(result[0].first, ::testing::ElementsAre(realtime_clock::epoch())); |
| 4323 | EXPECT_THAT(result[0].second, |
| 4324 | ::testing::ElementsAre(realtime_clock::epoch() + |
| 4325 | chrono::microseconds(11000350))); |
| 4326 | |
| 4327 | EXPECT_THAT(result[1].first, |
| 4328 | ::testing::ElementsAre( |
| 4329 | realtime_clock::epoch(), |
| 4330 | realtime_clock::epoch() + chrono::microseconds(6005000))); |
| 4331 | EXPECT_THAT(result[1].second, |
| 4332 | ::testing::ElementsAre( |
| 4333 | realtime_clock::epoch() + chrono::microseconds(4900150), |
| 4334 | realtime_clock::epoch() + chrono::microseconds(11000200))); |
| 4335 | |
| 4336 | EXPECT_THAT(result[2].first, ::testing::ElementsAre(realtime_clock::epoch())); |
| 4337 | EXPECT_THAT(result[2].second, |
| 4338 | ::testing::ElementsAre(realtime_clock::epoch() + |
| 4339 | chrono::microseconds(11000150))); |
| 4340 | |
| 4341 | // Confirm we observed the correct start and stop times. We should see the |
| 4342 | // reboot here. |
| 4343 | auto start_stop_result = ConfirmReadable( |
| 4344 | filenames, realtime_clock::epoch() + chrono::milliseconds(2000), |
| 4345 | realtime_clock::epoch() + chrono::milliseconds(8000)); |
| 4346 | |
| 4347 | EXPECT_THAT( |
| 4348 | start_stop_result[0].first, |
| 4349 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(2))); |
| 4350 | EXPECT_THAT( |
| 4351 | start_stop_result[0].second, |
| 4352 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(8))); |
| 4353 | EXPECT_THAT(start_stop_result[1].first, |
| 4354 | ::testing::ElementsAre( |
| 4355 | realtime_clock::epoch() + chrono::seconds(2), |
| 4356 | realtime_clock::epoch() + chrono::microseconds(6005000))); |
| 4357 | EXPECT_THAT(start_stop_result[1].second, |
| 4358 | ::testing::ElementsAre( |
| 4359 | realtime_clock::epoch() + chrono::microseconds(4900150), |
| 4360 | realtime_clock::epoch() + chrono::seconds(8))); |
| 4361 | EXPECT_THAT( |
| 4362 | start_stop_result[2].first, |
| 4363 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(2))); |
| 4364 | EXPECT_THAT( |
| 4365 | start_stop_result[2].second, |
| 4366 | ::testing::ElementsAre(realtime_clock::epoch() + chrono::seconds(8))); |
| 4367 | } |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 4368 | |
Austin Schuh | 5c770fa | 2022-03-11 06:57:22 -0800 | [diff] [blame] | 4369 | // Tests that we properly handle one direction being down. |
| 4370 | TEST(MissingDirectionTest, OneDirection) { |
| 4371 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 4372 | aos::configuration::ReadConfig(ArtifactPath( |
| 4373 | "aos/events/logging/multinode_pingpong_split4_config.json")); |
| 4374 | message_bridge::TestingTimeConverter time_converter( |
| 4375 | configuration::NodesCount(&config.message())); |
| 4376 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 4377 | event_loop_factory.SetTimeConverter(&time_converter); |
| 4378 | |
| 4379 | NodeEventLoopFactory *const pi1 = |
| 4380 | event_loop_factory.GetNodeEventLoopFactory("pi1"); |
| 4381 | const size_t pi1_index = configuration::GetNodeIndex( |
| 4382 | event_loop_factory.configuration(), pi1->node()); |
| 4383 | NodeEventLoopFactory *const pi2 = |
| 4384 | event_loop_factory.GetNodeEventLoopFactory("pi2"); |
| 4385 | const size_t pi2_index = configuration::GetNodeIndex( |
| 4386 | event_loop_factory.configuration(), pi2->node()); |
| 4387 | std::vector<std::string> filenames; |
| 4388 | |
| 4389 | { |
| 4390 | CHECK_EQ(pi1_index, 0u); |
| 4391 | CHECK_EQ(pi2_index, 1u); |
| 4392 | |
| 4393 | time_converter.AddNextTimestamp( |
| 4394 | distributed_clock::epoch(), |
| 4395 | {BootTimestamp::epoch(), BootTimestamp::epoch()}); |
| 4396 | |
| 4397 | const chrono::nanoseconds reboot_time = chrono::milliseconds(5000); |
| 4398 | time_converter.AddNextTimestamp( |
| 4399 | distributed_clock::epoch() + reboot_time, |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 4400 | {BootTimestamp{.boot = 1, .time = monotonic_clock::epoch()}, |
Austin Schuh | 5c770fa | 2022-03-11 06:57:22 -0800 | [diff] [blame] | 4401 | BootTimestamp::epoch() + reboot_time}); |
| 4402 | } |
| 4403 | |
| 4404 | const std::string kLogfile2_1 = |
| 4405 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 4406 | const std::string kLogfile1_1 = |
| 4407 | aos::testing::TestTmpDir() + "/multi_logfile1.1/"; |
| 4408 | util::UnlinkRecursive(kLogfile2_1); |
| 4409 | util::UnlinkRecursive(kLogfile1_1); |
| 4410 | |
| 4411 | pi2->Disconnect(pi1->node()); |
| 4412 | |
| 4413 | pi1->AlwaysStart<Ping>("ping"); |
| 4414 | pi2->AlwaysStart<Pong>("pong"); |
| 4415 | |
| 4416 | { |
| 4417 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4418 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4419 | |
| 4420 | event_loop_factory.RunFor(chrono::milliseconds(95)); |
| 4421 | |
| 4422 | pi2_logger.StartLogger(kLogfile2_1); |
| 4423 | |
| 4424 | event_loop_factory.RunFor(chrono::milliseconds(6000)); |
| 4425 | |
| 4426 | pi2->Connect(pi1->node()); |
| 4427 | |
| 4428 | LoggerState pi1_logger = LoggerState::MakeLogger( |
| 4429 | pi1, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4430 | pi1_logger.StartLogger(kLogfile1_1); |
| 4431 | |
| 4432 | event_loop_factory.RunFor(chrono::milliseconds(5000)); |
| 4433 | pi1_logger.AppendAllFilenames(&filenames); |
| 4434 | pi2_logger.AppendAllFilenames(&filenames); |
| 4435 | } |
| 4436 | |
| 4437 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
| 4438 | ConfirmReadable(filenames); |
| 4439 | } |
| 4440 | |
Austin Schuh | c1ee1b6 | 2022-03-22 17:09:52 -0700 | [diff] [blame] | 4441 | // Tests that we properly handle only one direction ever existing after a |
| 4442 | // reboot. |
| 4443 | TEST(MissingDirectionTest, OneDirectionAfterReboot) { |
| 4444 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 4445 | aos::configuration::ReadConfig(ArtifactPath( |
| 4446 | "aos/events/logging/multinode_pingpong_split4_config.json")); |
| 4447 | message_bridge::TestingTimeConverter time_converter( |
| 4448 | configuration::NodesCount(&config.message())); |
| 4449 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 4450 | event_loop_factory.SetTimeConverter(&time_converter); |
| 4451 | |
| 4452 | NodeEventLoopFactory *const pi1 = |
| 4453 | event_loop_factory.GetNodeEventLoopFactory("pi1"); |
| 4454 | const size_t pi1_index = configuration::GetNodeIndex( |
| 4455 | event_loop_factory.configuration(), pi1->node()); |
| 4456 | NodeEventLoopFactory *const pi2 = |
| 4457 | event_loop_factory.GetNodeEventLoopFactory("pi2"); |
| 4458 | const size_t pi2_index = configuration::GetNodeIndex( |
| 4459 | event_loop_factory.configuration(), pi2->node()); |
| 4460 | std::vector<std::string> filenames; |
| 4461 | |
| 4462 | { |
| 4463 | CHECK_EQ(pi1_index, 0u); |
| 4464 | CHECK_EQ(pi2_index, 1u); |
| 4465 | |
| 4466 | time_converter.AddNextTimestamp( |
| 4467 | distributed_clock::epoch(), |
| 4468 | {BootTimestamp::epoch(), BootTimestamp::epoch()}); |
| 4469 | |
| 4470 | const chrono::nanoseconds reboot_time = chrono::milliseconds(5000); |
| 4471 | time_converter.AddNextTimestamp( |
| 4472 | distributed_clock::epoch() + reboot_time, |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 4473 | {BootTimestamp{.boot = 1, .time = monotonic_clock::epoch()}, |
Austin Schuh | c1ee1b6 | 2022-03-22 17:09:52 -0700 | [diff] [blame] | 4474 | BootTimestamp::epoch() + reboot_time}); |
| 4475 | } |
| 4476 | |
| 4477 | const std::string kLogfile2_1 = |
| 4478 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 4479 | util::UnlinkRecursive(kLogfile2_1); |
| 4480 | |
Austin Schuh | 4b8b45b | 2022-04-13 17:05:44 -0700 | [diff] [blame] | 4481 | pi1->AlwaysStart<Ping>("ping"); |
| 4482 | |
| 4483 | // Pi1 sends to pi2. Reboot pi1, but don't let pi2 connect to pi1. This |
| 4484 | // makes it such that we will only get timestamps from pi1 -> pi2 on the |
| 4485 | // second boot. |
| 4486 | { |
| 4487 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4488 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4489 | |
| 4490 | event_loop_factory.RunFor(chrono::milliseconds(95)); |
| 4491 | |
| 4492 | pi2_logger.StartLogger(kLogfile2_1); |
| 4493 | |
| 4494 | event_loop_factory.RunFor(chrono::milliseconds(4000)); |
| 4495 | |
| 4496 | pi2->Disconnect(pi1->node()); |
| 4497 | |
| 4498 | event_loop_factory.RunFor(chrono::milliseconds(1000)); |
| 4499 | pi1->AlwaysStart<Ping>("ping"); |
| 4500 | |
| 4501 | event_loop_factory.RunFor(chrono::milliseconds(5000)); |
| 4502 | pi2_logger.AppendAllFilenames(&filenames); |
| 4503 | } |
| 4504 | |
| 4505 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
| 4506 | ConfirmReadable(filenames); |
| 4507 | } |
| 4508 | |
| 4509 | // Tests that we properly handle only one direction ever existing after a reboot |
| 4510 | // with only reliable data. |
| 4511 | TEST(MissingDirectionTest, OneDirectionAfterRebootReliable) { |
| 4512 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 4513 | aos::configuration::ReadConfig(ArtifactPath( |
| 4514 | "aos/events/logging/multinode_pingpong_split4_reliable_config.json")); |
| 4515 | message_bridge::TestingTimeConverter time_converter( |
| 4516 | configuration::NodesCount(&config.message())); |
| 4517 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 4518 | event_loop_factory.SetTimeConverter(&time_converter); |
| 4519 | |
| 4520 | NodeEventLoopFactory *const pi1 = |
| 4521 | event_loop_factory.GetNodeEventLoopFactory("pi1"); |
| 4522 | const size_t pi1_index = configuration::GetNodeIndex( |
| 4523 | event_loop_factory.configuration(), pi1->node()); |
| 4524 | NodeEventLoopFactory *const pi2 = |
| 4525 | event_loop_factory.GetNodeEventLoopFactory("pi2"); |
| 4526 | const size_t pi2_index = configuration::GetNodeIndex( |
| 4527 | event_loop_factory.configuration(), pi2->node()); |
| 4528 | std::vector<std::string> filenames; |
| 4529 | |
| 4530 | { |
| 4531 | CHECK_EQ(pi1_index, 0u); |
| 4532 | CHECK_EQ(pi2_index, 1u); |
| 4533 | |
| 4534 | time_converter.AddNextTimestamp( |
| 4535 | distributed_clock::epoch(), |
| 4536 | {BootTimestamp::epoch(), BootTimestamp::epoch()}); |
| 4537 | |
| 4538 | const chrono::nanoseconds reboot_time = chrono::milliseconds(5000); |
| 4539 | time_converter.AddNextTimestamp( |
| 4540 | distributed_clock::epoch() + reboot_time, |
| 4541 | {BootTimestamp{.boot = 1, .time = monotonic_clock::epoch()}, |
| 4542 | BootTimestamp::epoch() + reboot_time}); |
| 4543 | } |
| 4544 | |
| 4545 | const std::string kLogfile2_1 = |
| 4546 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 4547 | util::UnlinkRecursive(kLogfile2_1); |
Austin Schuh | c1ee1b6 | 2022-03-22 17:09:52 -0700 | [diff] [blame] | 4548 | |
| 4549 | pi1->AlwaysStart<Ping>("ping"); |
| 4550 | |
| 4551 | // Pi1 sends to pi2. Reboot pi1, but don't let pi2 connect to pi1. This |
| 4552 | // makes it such that we will only get timestamps from pi1 -> pi2 on the |
| 4553 | // second boot. |
| 4554 | { |
| 4555 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4556 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4557 | |
| 4558 | event_loop_factory.RunFor(chrono::milliseconds(95)); |
| 4559 | |
| 4560 | pi2_logger.StartLogger(kLogfile2_1); |
| 4561 | |
| 4562 | event_loop_factory.RunFor(chrono::milliseconds(4000)); |
| 4563 | |
| 4564 | pi2->Disconnect(pi1->node()); |
| 4565 | |
| 4566 | event_loop_factory.RunFor(chrono::milliseconds(1000)); |
| 4567 | pi1->AlwaysStart<Ping>("ping"); |
| 4568 | |
| 4569 | event_loop_factory.RunFor(chrono::milliseconds(5000)); |
| 4570 | pi2_logger.AppendAllFilenames(&filenames); |
| 4571 | } |
| 4572 | |
| 4573 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
| 4574 | ConfirmReadable(filenames); |
| 4575 | } |
| 4576 | |
Austin Schuh | efba96d | 2022-06-24 13:22:18 -0700 | [diff] [blame] | 4577 | // Tests that we properly handle what used to be a time violation in one |
| 4578 | // direction. This can occur when one direction goes down after sending some |
| 4579 | // data, but the other keeps working. The down direction ends up resolving to a |
| 4580 | // straight line in the noncausal filter, where the direction which is still up |
| 4581 | // can cross that line. Really, time progressed along just fine but we assumed |
| 4582 | // that the offset was a line when it could have deviated by up to 1ms/second. |
| 4583 | TEST_P(MultinodeLoggerTest, OneDirectionTimeDrift) { |
| 4584 | std::vector<std::string> filenames; |
| 4585 | |
| 4586 | CHECK_EQ(pi1_index_, 0u); |
| 4587 | CHECK_EQ(pi2_index_, 1u); |
| 4588 | |
| 4589 | time_converter_.AddNextTimestamp( |
| 4590 | distributed_clock::epoch(), |
| 4591 | {BootTimestamp::epoch(), BootTimestamp::epoch()}); |
| 4592 | |
| 4593 | const chrono::nanoseconds before_disconnect_duration = |
| 4594 | time_converter_.AddMonotonic( |
| 4595 | {chrono::milliseconds(1000), chrono::milliseconds(1000)}); |
| 4596 | |
| 4597 | const chrono::nanoseconds test_duration = |
| 4598 | time_converter_.AddMonotonic( |
| 4599 | {chrono::milliseconds(1000), chrono::milliseconds(1000)}) + |
| 4600 | time_converter_.AddMonotonic( |
| 4601 | {chrono::milliseconds(10000), |
| 4602 | chrono::milliseconds(10000) - chrono::milliseconds(5)}) + |
| 4603 | time_converter_.AddMonotonic( |
| 4604 | {chrono::milliseconds(10000), |
| 4605 | chrono::milliseconds(10000) + chrono::milliseconds(5)}); |
| 4606 | |
| 4607 | const std::string kLogfile = |
| 4608 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 4609 | util::UnlinkRecursive(kLogfile); |
| 4610 | |
| 4611 | { |
| 4612 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 4613 | pi2_logger.StartLogger(kLogfile); |
| 4614 | event_loop_factory_.RunFor(before_disconnect_duration); |
| 4615 | |
| 4616 | pi2_->Disconnect(pi1_->node()); |
| 4617 | |
| 4618 | event_loop_factory_.RunFor(test_duration); |
| 4619 | pi2_->Connect(pi1_->node()); |
| 4620 | |
| 4621 | event_loop_factory_.RunFor(chrono::milliseconds(5000)); |
| 4622 | pi2_logger.AppendAllFilenames(&filenames); |
| 4623 | } |
| 4624 | |
| 4625 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
| 4626 | ConfirmReadable(filenames); |
| 4627 | } |
| 4628 | |
James Kuszmaul | 86e86c3 | 2022-07-21 17:39:47 -0700 | [diff] [blame] | 4629 | // Tests that we can replay a logfile that has timestamps such that at least one |
| 4630 | // node's epoch is at a positive distributed_clock (and thus will have to be |
| 4631 | // booted after the other node(s)). |
| 4632 | TEST_P(MultinodeLoggerTest, StartOneNodeBeforeOther) { |
| 4633 | std::vector<std::string> filenames; |
| 4634 | |
| 4635 | CHECK_EQ(pi1_index_, 0u); |
| 4636 | CHECK_EQ(pi2_index_, 1u); |
| 4637 | |
| 4638 | time_converter_.AddNextTimestamp( |
| 4639 | distributed_clock::epoch(), |
| 4640 | {BootTimestamp::epoch(), BootTimestamp::epoch()}); |
| 4641 | |
| 4642 | const chrono::nanoseconds before_reboot_duration = chrono::milliseconds(1000); |
| 4643 | time_converter_.RebootAt( |
| 4644 | 0, distributed_clock::time_point(before_reboot_duration)); |
| 4645 | |
| 4646 | const chrono::nanoseconds test_duration = time_converter_.AddMonotonic( |
| 4647 | {chrono::milliseconds(10000), chrono::milliseconds(10000)}); |
| 4648 | |
| 4649 | const std::string kLogfile = |
| 4650 | aos::testing::TestTmpDir() + "/multi_logfile2.1/"; |
| 4651 | util::UnlinkRecursive(kLogfile); |
| 4652 | |
| 4653 | pi2_->Disconnect(pi1_->node()); |
| 4654 | pi1_->Disconnect(pi2_->node()); |
| 4655 | |
| 4656 | { |
| 4657 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 4658 | |
| 4659 | pi2_logger.StartLogger(kLogfile); |
| 4660 | event_loop_factory_.RunFor(before_reboot_duration); |
| 4661 | |
| 4662 | pi2_->Connect(pi1_->node()); |
| 4663 | pi1_->Connect(pi2_->node()); |
| 4664 | |
| 4665 | event_loop_factory_.RunFor(test_duration); |
| 4666 | |
| 4667 | pi2_logger.AppendAllFilenames(&filenames); |
| 4668 | } |
| 4669 | |
| 4670 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
| 4671 | ConfirmReadable(filenames); |
| 4672 | |
| 4673 | { |
| 4674 | LogReader reader(sorted_parts); |
| 4675 | SimulatedEventLoopFactory replay_factory(reader.configuration()); |
| 4676 | reader.RegisterWithoutStarting(&replay_factory); |
| 4677 | |
| 4678 | NodeEventLoopFactory *const replay_node = |
| 4679 | reader.event_loop_factory()->GetNodeEventLoopFactory("pi1"); |
| 4680 | |
| 4681 | std::unique_ptr<EventLoop> test_event_loop = |
| 4682 | replay_node->MakeEventLoop("test_reader"); |
| 4683 | replay_node->OnStartup([replay_node]() { |
| 4684 | // Check that we didn't boot until at least t=0. |
| 4685 | CHECK_LE(monotonic_clock::epoch(), replay_node->monotonic_now()); |
| 4686 | }); |
| 4687 | test_event_loop->OnRun([&test_event_loop]() { |
| 4688 | // Check that we didn't boot until at least t=0. |
| 4689 | EXPECT_LE(monotonic_clock::epoch(), test_event_loop->monotonic_now()); |
| 4690 | }); |
| 4691 | reader.event_loop_factory()->Run(); |
| 4692 | reader.Deregister(); |
| 4693 | } |
| 4694 | } |
| 4695 | |
Austin Schuh | 79b21d6 | 2022-08-16 13:54:49 -0700 | [diff] [blame] | 4696 | // Tests that when we have a loop without all the logs at all points in time, we |
| 4697 | // can sort it properly. |
Austin Schuh | eb595a6 | 2022-08-26 19:24:32 -0700 | [diff] [blame] | 4698 | TEST(MultinodeLoggerLoopTest, Loop) { |
Austin Schuh | 79b21d6 | 2022-08-16 13:54:49 -0700 | [diff] [blame] | 4699 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 4700 | aos::configuration::ReadConfig(ArtifactPath( |
| 4701 | "aos/events/logging/multinode_pingpong_triangle_split_config.json")); |
| 4702 | message_bridge::TestingTimeConverter time_converter( |
| 4703 | configuration::NodesCount(&config.message())); |
| 4704 | SimulatedEventLoopFactory event_loop_factory(&config.message()); |
| 4705 | event_loop_factory.SetTimeConverter(&time_converter); |
| 4706 | |
| 4707 | NodeEventLoopFactory *const pi1 = |
| 4708 | event_loop_factory.GetNodeEventLoopFactory("pi1"); |
| 4709 | NodeEventLoopFactory *const pi2 = |
| 4710 | event_loop_factory.GetNodeEventLoopFactory("pi2"); |
| 4711 | NodeEventLoopFactory *const pi3 = |
| 4712 | event_loop_factory.GetNodeEventLoopFactory("pi3"); |
| 4713 | |
| 4714 | const std::string kLogfile1_1 = |
| 4715 | aos::testing::TestTmpDir() + "/multi_logfile1/"; |
| 4716 | const std::string kLogfile2_1 = |
| 4717 | aos::testing::TestTmpDir() + "/multi_logfile2/"; |
| 4718 | const std::string kLogfile3_1 = |
| 4719 | aos::testing::TestTmpDir() + "/multi_logfile3/"; |
| 4720 | util::UnlinkRecursive(kLogfile1_1); |
| 4721 | util::UnlinkRecursive(kLogfile2_1); |
| 4722 | util::UnlinkRecursive(kLogfile3_1); |
| 4723 | |
| 4724 | { |
| 4725 | // Make pi1 boot before everything else. |
| 4726 | time_converter.AddNextTimestamp( |
| 4727 | distributed_clock::epoch(), |
| 4728 | {BootTimestamp::epoch(), |
| 4729 | BootTimestamp::epoch() - chrono::milliseconds(100), |
| 4730 | BootTimestamp::epoch() - chrono::milliseconds(300)}); |
| 4731 | } |
| 4732 | |
| 4733 | // We want to setup a situation such that 2 of the 3 legs of the loop are very |
| 4734 | // confident about time being X, and the third leg is pulling the average off |
| 4735 | // to one side. |
| 4736 | // |
| 4737 | // It's easiest to visualize this in timestamp_plotter. |
| 4738 | |
| 4739 | std::vector<std::string> filenames; |
| 4740 | { |
| 4741 | // Have pi1 send out a reliable message at startup. This sets up a long |
| 4742 | // forwarding time message at the start to bias time. |
| 4743 | std::unique_ptr<EventLoop> pi1_event_loop = pi1->MakeEventLoop("ping"); |
| 4744 | { |
| 4745 | aos::Sender<examples::Ping> ping_sender = |
| 4746 | pi1_event_loop->MakeSender<examples::Ping>("/reliable"); |
| 4747 | |
| 4748 | aos::Sender<examples::Ping>::Builder builder = ping_sender.MakeBuilder(); |
| 4749 | examples::Ping::Builder ping_builder = |
| 4750 | builder.MakeBuilder<examples::Ping>(); |
| 4751 | CHECK_EQ(builder.Send(ping_builder.Finish()), RawSender::Error::kOk); |
| 4752 | } |
| 4753 | |
| 4754 | // Wait a while so there's enough data to let the worst case be rather off. |
| 4755 | event_loop_factory.RunFor(chrono::seconds(1000)); |
| 4756 | |
| 4757 | // Now start a receiving node first. This sets up 2 tight bounds between 2 |
| 4758 | // of the nodes. |
| 4759 | LoggerState pi2_logger = LoggerState::MakeLogger( |
| 4760 | pi2, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4761 | pi2_logger.StartLogger(kLogfile2_1); |
| 4762 | |
| 4763 | event_loop_factory.RunFor(chrono::seconds(100)); |
| 4764 | |
| 4765 | // And now start the third leg. |
| 4766 | LoggerState pi3_logger = LoggerState::MakeLogger( |
| 4767 | pi3, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4768 | pi3_logger.StartLogger(kLogfile3_1); |
| 4769 | |
| 4770 | LoggerState pi1_logger = LoggerState::MakeLogger( |
| 4771 | pi1, &event_loop_factory, SupportedCompressionAlgorithms()[0]); |
| 4772 | pi1_logger.StartLogger(kLogfile1_1); |
| 4773 | |
| 4774 | event_loop_factory.RunFor(chrono::seconds(100)); |
| 4775 | |
| 4776 | pi1_logger.AppendAllFilenames(&filenames); |
| 4777 | pi2_logger.AppendAllFilenames(&filenames); |
| 4778 | pi3_logger.AppendAllFilenames(&filenames); |
| 4779 | } |
| 4780 | |
| 4781 | // Make sure we can read this. |
| 4782 | const std::vector<LogFile> sorted_parts = SortParts(filenames); |
| 4783 | auto result = ConfirmReadable(filenames); |
| 4784 | } |
| 4785 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 4786 | } // namespace testing |
| 4787 | } // namespace logger |
| 4788 | } // namespace aos |