Austin Schuh | b06f03b | 2021-02-17 22:00:37 -0800 | [diff] [blame] | 1 | #include "aos/events/logging/log_reader.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 2 | |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame^] | 3 | #include <sys/stat.h> |
| 4 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 5 | #include "absl/strings/str_format.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 6 | #include "aos/events/event_loop.h" |
Austin Schuh | b06f03b | 2021-02-17 22:00:37 -0800 | [diff] [blame] | 7 | #include "aos/events/logging/log_writer.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 | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 15 | #include "aos/testing/tmpdir.h" |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 16 | #include "aos/util/file.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 17 | #include "glog/logging.h" |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 18 | #include "gmock/gmock.h" |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 19 | #include "gtest/gtest.h" |
| 20 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 21 | #ifdef LZMA |
| 22 | #include "aos/events/logging/lzma_encoder.h" |
| 23 | #endif |
| 24 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 25 | namespace aos { |
| 26 | namespace logger { |
| 27 | namespace testing { |
| 28 | |
| 29 | namespace chrono = std::chrono; |
Austin Schuh | 0de30f3 | 2020-12-06 12:44:28 -0800 | [diff] [blame] | 30 | using aos::message_bridge::RemoteMessage; |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 31 | using aos::testing::MessageCounter; |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 32 | |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 33 | constexpr std::string_view kSingleConfigSha256( |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 34 | "bc8c9c2e31589eae6f0e36d766f6a437643e861d9568b7483106841cf7504dea"); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 35 | |
Austin Schuh | b06f03b | 2021-02-17 22:00:37 -0800 | [diff] [blame] | 36 | std::vector<std::vector<std::string>> ToLogReaderVector( |
| 37 | const std::vector<LogFile> &log_files) { |
| 38 | std::vector<std::vector<std::string>> result; |
| 39 | for (const LogFile &log_file : log_files) { |
| 40 | for (const LogParts &log_parts : log_file.parts) { |
| 41 | std::vector<std::string> parts; |
| 42 | for (const std::string &part : log_parts.parts) { |
| 43 | parts.emplace_back(part); |
| 44 | } |
| 45 | result.emplace_back(std::move(parts)); |
| 46 | } |
| 47 | } |
| 48 | return result; |
| 49 | } |
| 50 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 51 | class LoggerTest : public ::testing::Test { |
| 52 | public: |
| 53 | LoggerTest() |
| 54 | : config_( |
| 55 | aos::configuration::ReadConfig("aos/events/pingpong_config.json")), |
| 56 | event_loop_factory_(&config_.message()), |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 57 | ping_event_loop_(event_loop_factory_.MakeEventLoop("ping")), |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 58 | ping_(ping_event_loop_.get()), |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 59 | pong_event_loop_(event_loop_factory_.MakeEventLoop("pong")), |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 60 | pong_(pong_event_loop_.get()) {} |
| 61 | |
| 62 | // Config and factory. |
| 63 | aos::FlatbufferDetachedBuffer<aos::Configuration> config_; |
| 64 | SimulatedEventLoopFactory event_loop_factory_; |
| 65 | |
| 66 | // Event loop and app for Ping |
| 67 | std::unique_ptr<EventLoop> ping_event_loop_; |
| 68 | Ping ping_; |
| 69 | |
| 70 | // Event loop and app for Pong |
| 71 | std::unique_ptr<EventLoop> pong_event_loop_; |
| 72 | Pong pong_; |
| 73 | }; |
| 74 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 75 | using LoggerDeathTest = LoggerTest; |
| 76 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 77 | // Tests that we can startup at all. This confirms that the channels are all in |
| 78 | // the config. |
| 79 | TEST_F(LoggerTest, Starts) { |
Austin Schuh | c243b42 | 2020-10-11 15:35:08 -0700 | [diff] [blame] | 80 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 81 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 82 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 83 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 84 | const ::std::string logfile = base_name + ".part0.bfbs"; |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 85 | // Remove it. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 86 | unlink(config.c_str()); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 87 | unlink(logfile.c_str()); |
| 88 | |
| 89 | LOG(INFO) << "Logging data to " << logfile; |
| 90 | |
| 91 | { |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 92 | std::unique_ptr<EventLoop> logger_event_loop = |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 93 | event_loop_factory_.MakeEventLoop("logger"); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 94 | |
| 95 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 96 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 97 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 98 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 99 | logger.set_polling_period(std::chrono::milliseconds(100)); |
| 100 | logger.StartLoggingLocalNamerOnRun(base_name); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 101 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 102 | } |
| 103 | |
James Kuszmaul | c7bbb3e | 2020-01-03 20:01:00 -0800 | [diff] [blame] | 104 | // Even though it doesn't make any difference here, exercise the logic for |
| 105 | // passing in a separate config. |
| 106 | LogReader reader(logfile, &config_.message()); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 107 | |
James Kuszmaul | c7bbb3e | 2020-01-03 20:01:00 -0800 | [diff] [blame] | 108 | // Confirm that we can remap logged channels to point to new buses. |
| 109 | reader.RemapLoggedChannel<aos::examples::Ping>("/test", "/original"); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 110 | |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 111 | // This sends out the fetched messages and advances time to the start of the |
| 112 | // log file. |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 113 | reader.Register(); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 114 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 115 | EXPECT_THAT(reader.LoggedNodes(), ::testing::ElementsAre(nullptr)); |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 116 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 117 | std::unique_ptr<EventLoop> test_event_loop = |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 118 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 119 | |
| 120 | int ping_count = 10; |
| 121 | int pong_count = 10; |
| 122 | |
James Kuszmaul | c7bbb3e | 2020-01-03 20:01:00 -0800 | [diff] [blame] | 123 | // Confirm that the ping value matches in the remapped channel location. |
| 124 | test_event_loop->MakeWatcher("/original/test", |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 125 | [&ping_count](const examples::Ping &ping) { |
| 126 | EXPECT_EQ(ping.value(), ping_count + 1); |
| 127 | ++ping_count; |
| 128 | }); |
| 129 | // Confirm that the ping and pong counts both match, and the value also |
| 130 | // matches. |
| 131 | test_event_loop->MakeWatcher( |
| 132 | "/test", [&pong_count, &ping_count](const examples::Pong &pong) { |
| 133 | EXPECT_EQ(pong.value(), pong_count + 1); |
| 134 | ++pong_count; |
| 135 | EXPECT_EQ(ping_count, pong_count); |
| 136 | }); |
| 137 | |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 138 | reader.event_loop_factory()->RunFor(std::chrono::seconds(100)); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 139 | EXPECT_EQ(ping_count, 2010); |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 142 | // Tests calling StartLogging twice. |
| 143 | TEST_F(LoggerDeathTest, ExtraStart) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 144 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 145 | const ::std::string base_name1 = tmpdir + "/logfile1"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 146 | const ::std::string config1 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 147 | absl::StrCat(base_name1, kSingleConfigSha256, ".bfbs"); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 148 | const ::std::string logfile1 = base_name1 + ".part0.bfbs"; |
| 149 | const ::std::string base_name2 = tmpdir + "/logfile2"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 150 | const ::std::string config2 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 151 | absl::StrCat(base_name2, kSingleConfigSha256, ".bfbs"); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 152 | const ::std::string logfile2 = base_name2 + ".part0.bfbs"; |
| 153 | unlink(logfile1.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 154 | unlink(config1.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 155 | unlink(logfile2.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 156 | unlink(config2.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 157 | |
| 158 | LOG(INFO) << "Logging data to " << logfile1 << " then " << logfile2; |
| 159 | |
| 160 | { |
| 161 | std::unique_ptr<EventLoop> logger_event_loop = |
| 162 | event_loop_factory_.MakeEventLoop("logger"); |
| 163 | |
| 164 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 165 | |
| 166 | Logger logger(logger_event_loop.get()); |
| 167 | logger.set_polling_period(std::chrono::milliseconds(100)); |
| 168 | logger_event_loop->OnRun( |
| 169 | [base_name1, base_name2, &logger_event_loop, &logger]() { |
| 170 | logger.StartLogging(std::make_unique<LocalLogNamer>( |
| 171 | base_name1, logger_event_loop->node())); |
| 172 | EXPECT_DEATH(logger.StartLogging(std::make_unique<LocalLogNamer>( |
| 173 | base_name2, logger_event_loop->node())), |
| 174 | "Already logging"); |
| 175 | }); |
| 176 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // Tests calling StopLogging twice. |
| 181 | TEST_F(LoggerDeathTest, ExtraStop) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 182 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 183 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 184 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 185 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 186 | const ::std::string logfile = base_name + ".part0.bfbs"; |
| 187 | // Remove it. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 188 | unlink(config.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 189 | unlink(logfile.c_str()); |
| 190 | |
| 191 | LOG(INFO) << "Logging data to " << logfile; |
| 192 | |
| 193 | { |
| 194 | std::unique_ptr<EventLoop> logger_event_loop = |
| 195 | event_loop_factory_.MakeEventLoop("logger"); |
| 196 | |
| 197 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 198 | |
| 199 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 200 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 201 | logger.set_polling_period(std::chrono::milliseconds(100)); |
| 202 | logger_event_loop->OnRun([base_name, &logger_event_loop, &logger]() { |
| 203 | logger.StartLogging(std::make_unique<LocalLogNamer>( |
| 204 | base_name, logger_event_loop->node())); |
| 205 | logger.StopLogging(aos::monotonic_clock::min_time); |
| 206 | EXPECT_DEATH(logger.StopLogging(aos::monotonic_clock::min_time), |
| 207 | "Not logging right now"); |
| 208 | }); |
| 209 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | // Tests that we can startup twice. |
| 214 | TEST_F(LoggerTest, StartsTwice) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 215 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 216 | const ::std::string base_name1 = tmpdir + "/logfile1"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 217 | const ::std::string config1 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 218 | absl::StrCat(base_name1, kSingleConfigSha256, ".bfbs"); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 219 | const ::std::string logfile1 = base_name1 + ".part0.bfbs"; |
| 220 | const ::std::string base_name2 = tmpdir + "/logfile2"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 221 | const ::std::string config2 = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 222 | absl::StrCat(base_name2, kSingleConfigSha256, ".bfbs"); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 223 | const ::std::string logfile2 = base_name2 + ".part0.bfbs"; |
| 224 | unlink(logfile1.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 225 | unlink(config1.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 226 | unlink(logfile2.c_str()); |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 227 | unlink(config2.c_str()); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 228 | |
| 229 | LOG(INFO) << "Logging data to " << logfile1 << " then " << logfile2; |
| 230 | |
| 231 | { |
| 232 | std::unique_ptr<EventLoop> logger_event_loop = |
| 233 | event_loop_factory_.MakeEventLoop("logger"); |
| 234 | |
| 235 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 236 | |
| 237 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 238 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 239 | logger.set_polling_period(std::chrono::milliseconds(100)); |
| 240 | logger.StartLogging( |
| 241 | std::make_unique<LocalLogNamer>(base_name1, logger_event_loop->node())); |
| 242 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 243 | logger.StopLogging(logger_event_loop->monotonic_now()); |
| 244 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 245 | logger.StartLogging( |
| 246 | std::make_unique<LocalLogNamer>(base_name2, logger_event_loop->node())); |
| 247 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 248 | } |
| 249 | |
| 250 | for (const auto &logfile : |
| 251 | {std::make_tuple(logfile1, 10), std::make_tuple(logfile2, 2010)}) { |
| 252 | SCOPED_TRACE(std::get<0>(logfile)); |
| 253 | LogReader reader(std::get<0>(logfile)); |
| 254 | reader.Register(); |
| 255 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 256 | EXPECT_THAT(reader.LoggedNodes(), ::testing::ElementsAre(nullptr)); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 257 | |
| 258 | std::unique_ptr<EventLoop> test_event_loop = |
| 259 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
| 260 | |
| 261 | int ping_count = std::get<1>(logfile); |
| 262 | int pong_count = std::get<1>(logfile); |
| 263 | |
| 264 | // Confirm that the ping and pong counts both match, and the value also |
| 265 | // matches. |
| 266 | test_event_loop->MakeWatcher("/test", |
| 267 | [&ping_count](const examples::Ping &ping) { |
| 268 | EXPECT_EQ(ping.value(), ping_count + 1); |
| 269 | ++ping_count; |
| 270 | }); |
| 271 | test_event_loop->MakeWatcher( |
| 272 | "/test", [&pong_count, &ping_count](const examples::Pong &pong) { |
| 273 | EXPECT_EQ(pong.value(), pong_count + 1); |
| 274 | ++pong_count; |
| 275 | EXPECT_EQ(ping_count, pong_count); |
| 276 | }); |
| 277 | |
| 278 | reader.event_loop_factory()->RunFor(std::chrono::seconds(100)); |
| 279 | EXPECT_EQ(ping_count, std::get<1>(logfile) + 1000); |
| 280 | } |
| 281 | } |
| 282 | |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 283 | // Tests that we can read and write rotated log files. |
| 284 | TEST_F(LoggerTest, RotatedLogFile) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 285 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 286 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 287 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 288 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 289 | const ::std::string logfile0 = base_name + ".part0.bfbs"; |
| 290 | const ::std::string logfile1 = base_name + ".part1.bfbs"; |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 291 | // Remove it. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 292 | unlink(config.c_str()); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 293 | unlink(logfile0.c_str()); |
| 294 | unlink(logfile1.c_str()); |
| 295 | |
| 296 | LOG(INFO) << "Logging data to " << logfile0 << " and " << logfile1; |
| 297 | |
| 298 | { |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 299 | std::unique_ptr<EventLoop> logger_event_loop = |
| 300 | event_loop_factory_.MakeEventLoop("logger"); |
| 301 | |
| 302 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 303 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 304 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 305 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 306 | logger.set_polling_period(std::chrono::milliseconds(100)); |
| 307 | logger.StartLoggingLocalNamerOnRun(base_name); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 308 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 309 | logger.Rotate(); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 310 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 311 | } |
| 312 | |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 313 | { |
| 314 | // Confirm that the UUIDs match for both the parts and the logger, and the |
| 315 | // parts_index increments. |
Austin Schuh | add6eb3 | 2020-11-09 21:24:26 -0800 | [diff] [blame] | 316 | std::vector<SizePrefixedFlatbufferVector<LogFileHeader>> log_header; |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 317 | for (std::string_view f : {logfile0, logfile1}) { |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 318 | log_header.emplace_back(ReadHeader(f).value()); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Brian Silverman | ae7c033 | 2020-09-30 16:58:23 -0700 | [diff] [blame] | 321 | EXPECT_EQ(log_header[0].message().log_event_uuid()->string_view(), |
| 322 | log_header[1].message().log_event_uuid()->string_view()); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 323 | EXPECT_EQ(log_header[0].message().parts_uuid()->string_view(), |
| 324 | log_header[1].message().parts_uuid()->string_view()); |
| 325 | |
| 326 | EXPECT_EQ(log_header[0].message().parts_index(), 0); |
| 327 | EXPECT_EQ(log_header[1].message().parts_index(), 1); |
| 328 | } |
| 329 | |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 330 | // Even though it doesn't make any difference here, exercise the logic for |
| 331 | // passing in a separate config. |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 332 | LogReader reader(SortParts({logfile0, logfile1}), &config_.message()); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 333 | |
| 334 | // Confirm that we can remap logged channels to point to new buses. |
| 335 | reader.RemapLoggedChannel<aos::examples::Ping>("/test", "/original"); |
| 336 | |
| 337 | // This sends out the fetched messages and advances time to the start of the |
| 338 | // log file. |
| 339 | reader.Register(); |
| 340 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 341 | EXPECT_THAT(reader.LoggedNodes(), ::testing::ElementsAre(nullptr)); |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 342 | |
| 343 | std::unique_ptr<EventLoop> test_event_loop = |
| 344 | reader.event_loop_factory()->MakeEventLoop("log_reader"); |
| 345 | |
| 346 | int ping_count = 10; |
| 347 | int pong_count = 10; |
| 348 | |
| 349 | // Confirm that the ping value matches in the remapped channel location. |
| 350 | test_event_loop->MakeWatcher("/original/test", |
| 351 | [&ping_count](const examples::Ping &ping) { |
| 352 | EXPECT_EQ(ping.value(), ping_count + 1); |
| 353 | ++ping_count; |
| 354 | }); |
| 355 | // Confirm that the ping and pong counts both match, and the value also |
| 356 | // matches. |
| 357 | test_event_loop->MakeWatcher( |
| 358 | "/test", [&pong_count, &ping_count](const examples::Pong &pong) { |
| 359 | EXPECT_EQ(pong.value(), pong_count + 1); |
| 360 | ++pong_count; |
| 361 | EXPECT_EQ(ping_count, pong_count); |
| 362 | }); |
| 363 | |
| 364 | reader.event_loop_factory()->RunFor(std::chrono::seconds(100)); |
| 365 | EXPECT_EQ(ping_count, 2010); |
| 366 | } |
| 367 | |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 368 | // Tests that a large number of messages per second doesn't overwhelm writev. |
| 369 | TEST_F(LoggerTest, ManyMessages) { |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 370 | const ::std::string tmpdir = aos::testing::TestTmpDir(); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 371 | const ::std::string base_name = tmpdir + "/logfile"; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 372 | const ::std::string config = |
Austin Schuh | ee4713b | 2021-03-21 19:25:17 -0700 | [diff] [blame] | 373 | absl::StrCat(base_name, kSingleConfigSha256, ".bfbs"); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 374 | const ::std::string logfile = base_name + ".part0.bfbs"; |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 375 | // Remove the log file. |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 376 | unlink(config.c_str()); |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 377 | unlink(logfile.c_str()); |
| 378 | |
| 379 | LOG(INFO) << "Logging data to " << logfile; |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 380 | ping_.set_quiet(true); |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 381 | |
| 382 | { |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 383 | std::unique_ptr<EventLoop> logger_event_loop = |
| 384 | event_loop_factory_.MakeEventLoop("logger"); |
| 385 | |
| 386 | std::unique_ptr<EventLoop> ping_spammer_event_loop = |
| 387 | event_loop_factory_.MakeEventLoop("ping_spammer"); |
| 388 | aos::Sender<examples::Ping> ping_sender = |
| 389 | ping_spammer_event_loop->MakeSender<examples::Ping>("/test"); |
| 390 | |
| 391 | aos::TimerHandler *timer_handler = |
| 392 | ping_spammer_event_loop->AddTimer([&ping_sender]() { |
| 393 | aos::Sender<examples::Ping>::Builder builder = |
| 394 | ping_sender.MakeBuilder(); |
| 395 | examples::Ping::Builder ping_builder = |
| 396 | builder.MakeBuilder<examples::Ping>(); |
| 397 | CHECK(builder.Send(ping_builder.Finish())); |
| 398 | }); |
| 399 | |
| 400 | // 100 ms / 0.05 ms -> 2000 messages. Should be enough to crash it. |
| 401 | ping_spammer_event_loop->OnRun([&ping_spammer_event_loop, timer_handler]() { |
| 402 | timer_handler->Setup(ping_spammer_event_loop->monotonic_now(), |
| 403 | chrono::microseconds(50)); |
| 404 | }); |
| 405 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 406 | Logger logger(logger_event_loop.get()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 407 | logger.set_separate_config(false); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 408 | logger.set_polling_period(std::chrono::milliseconds(100)); |
| 409 | logger.StartLoggingLocalNamerOnRun(base_name); |
Austin Schuh | 4c4e009 | 2019-12-22 16:18:03 -0800 | [diff] [blame] | 410 | |
| 411 | event_loop_factory_.RunFor(chrono::milliseconds(1000)); |
| 412 | } |
| 413 | } |
| 414 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 415 | // Parameters to run all the tests with. |
| 416 | struct Param { |
| 417 | // The config file to use. |
| 418 | std::string config; |
| 419 | // If true, the RemoteMessage channel should be shared between all the remote |
| 420 | // channels. If false, there will be 1 RemoteMessage channel per remote |
| 421 | // channel. |
| 422 | bool shared; |
| 423 | // sha256 of the config. |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 424 | std::string_view sha256; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 425 | }; |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 426 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 427 | class MultinodeLoggerTest : public ::testing::TestWithParam<struct Param> { |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 428 | public: |
| 429 | MultinodeLoggerTest() |
| 430 | : config_(aos::configuration::ReadConfig( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 431 | absl::StrCat("aos/events/logging/", GetParam().config))), |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 432 | time_converter_(configuration::NodesCount(&config_.message())), |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 433 | event_loop_factory_(&config_.message()), |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 434 | pi1_( |
| 435 | configuration::GetNode(event_loop_factory_.configuration(), "pi1")), |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 436 | pi1_index_(configuration::GetNodeIndex( |
| 437 | event_loop_factory_.configuration(), pi1_)), |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 438 | pi2_( |
| 439 | configuration::GetNode(event_loop_factory_.configuration(), "pi2")), |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 440 | pi2_index_(configuration::GetNodeIndex( |
| 441 | event_loop_factory_.configuration(), pi2_)), |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 442 | tmp_dir_(aos::testing::TestTmpDir()), |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 443 | logfile_base1_(tmp_dir_ + "/multi_logfile1"), |
| 444 | logfile_base2_(tmp_dir_ + "/multi_logfile2"), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 445 | pi1_reboot_logfiles_(MakePi1RebootLogfiles()), |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 446 | logfiles_(MakeLogFiles(logfile_base1_, logfile_base2_)), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 447 | pi1_single_direction_logfiles_(MakePi1SingleDirectionLogfiles()), |
| 448 | structured_logfiles_(StructureLogFiles()), |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 449 | ping_event_loop_(event_loop_factory_.MakeEventLoop("ping", pi1_)), |
| 450 | ping_(ping_event_loop_.get()), |
| 451 | pong_event_loop_(event_loop_factory_.MakeEventLoop("pong", pi2_)), |
| 452 | pong_(pong_event_loop_.get()) { |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 453 | LOG(INFO) << "Config " << GetParam().config; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 454 | event_loop_factory_.SetTimeConverter(&time_converter_); |
| 455 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 456 | // Go through and remove the logfiles if they already exist. |
| 457 | for (const auto file : logfiles_) { |
| 458 | unlink(file.c_str()); |
Austin Schuh | c6f8f1b | 2020-12-02 23:23:39 -0800 | [diff] [blame] | 459 | unlink((file + ".xz").c_str()); |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 462 | for (const auto file : |
| 463 | MakeLogFiles(tmp_dir_ + "/relogged1", tmp_dir_ + "/relogged2")) { |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 464 | unlink(file.c_str()); |
| 465 | } |
| 466 | |
| 467 | for (const auto file : pi1_reboot_logfiles_) { |
| 468 | unlink(file.c_str()); |
| 469 | } |
| 470 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 471 | LOG(INFO) << "Logging data to " << logfiles_[0] << ", " << logfiles_[1] |
| 472 | << " and " << logfiles_[2]; |
| 473 | } |
| 474 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 475 | bool shared() const { return GetParam().shared; } |
| 476 | |
| 477 | std::vector<std::string> MakeLogFiles(std::string logfile_base1, |
| 478 | std::string logfile_base2) { |
| 479 | std::vector<std::string> result; |
| 480 | result.emplace_back( |
| 481 | absl::StrCat(logfile_base1, "_", GetParam().sha256, ".bfbs")); |
| 482 | result.emplace_back( |
| 483 | absl::StrCat(logfile_base2, "_", GetParam().sha256, ".bfbs")); |
| 484 | result.emplace_back(logfile_base1 + "_pi1_data.part0.bfbs"); |
| 485 | result.emplace_back(logfile_base1 + |
| 486 | "_pi2_data/test/aos.examples.Pong.part0.bfbs"); |
| 487 | result.emplace_back(logfile_base1 + |
| 488 | "_pi2_data/test/aos.examples.Pong.part1.bfbs"); |
| 489 | result.emplace_back(logfile_base2 + "_pi2_data.part0.bfbs"); |
| 490 | result.emplace_back( |
| 491 | logfile_base2 + |
| 492 | "_pi1_data/pi1/aos/aos.message_bridge.Timestamp.part0.bfbs"); |
| 493 | result.emplace_back( |
| 494 | logfile_base2 + |
| 495 | "_pi1_data/pi1/aos/aos.message_bridge.Timestamp.part1.bfbs"); |
| 496 | result.emplace_back( |
| 497 | logfile_base1 + |
| 498 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part0.bfbs"); |
| 499 | result.emplace_back( |
| 500 | logfile_base1 + |
| 501 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part1.bfbs"); |
| 502 | if (shared()) { |
| 503 | result.emplace_back(logfile_base1 + |
| 504 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 505 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 506 | result.emplace_back(logfile_base1 + |
| 507 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 508 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 509 | result.emplace_back(logfile_base2 + |
| 510 | "_timestamps/pi2/aos/remote_timestamps/pi1/" |
| 511 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 512 | result.emplace_back(logfile_base2 + |
| 513 | "_timestamps/pi2/aos/remote_timestamps/pi1/" |
| 514 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 515 | } else { |
| 516 | result.emplace_back(logfile_base1 + |
| 517 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 518 | "aos-message_bridge-Timestamp/" |
| 519 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 520 | result.emplace_back(logfile_base1 + |
| 521 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 522 | "aos-message_bridge-Timestamp/" |
| 523 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 524 | result.emplace_back(logfile_base2 + |
| 525 | "_timestamps/pi2/aos/remote_timestamps/pi1/pi2/aos/" |
| 526 | "aos-message_bridge-Timestamp/" |
| 527 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 528 | result.emplace_back(logfile_base2 + |
| 529 | "_timestamps/pi2/aos/remote_timestamps/pi1/pi2/aos/" |
| 530 | "aos-message_bridge-Timestamp/" |
| 531 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 532 | result.emplace_back(logfile_base1 + |
| 533 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 534 | "aos-examples-Ping/" |
| 535 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 536 | result.emplace_back(logfile_base1 + |
| 537 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 538 | "aos-examples-Ping/" |
| 539 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 540 | } |
| 541 | |
| 542 | return result; |
| 543 | } |
| 544 | |
| 545 | std::vector<std::string> MakePi1RebootLogfiles() { |
| 546 | std::vector<std::string> result; |
| 547 | result.emplace_back(logfile_base1_ + "_pi1_data.part0.bfbs"); |
| 548 | result.emplace_back(logfile_base1_ + |
| 549 | "_pi2_data/test/aos.examples.Pong.part0.bfbs"); |
| 550 | result.emplace_back(logfile_base1_ + |
| 551 | "_pi2_data/test/aos.examples.Pong.part1.bfbs"); |
| 552 | result.emplace_back(logfile_base1_ + |
| 553 | "_pi2_data/test/aos.examples.Pong.part2.bfbs"); |
| 554 | result.emplace_back( |
| 555 | logfile_base1_ + |
| 556 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part0.bfbs"); |
| 557 | result.emplace_back( |
| 558 | logfile_base1_ + |
| 559 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part1.bfbs"); |
| 560 | result.emplace_back( |
| 561 | logfile_base1_ + |
| 562 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part2.bfbs"); |
| 563 | result.emplace_back( |
| 564 | absl::StrCat(logfile_base1_, "_", GetParam().sha256, ".bfbs")); |
| 565 | if (shared()) { |
| 566 | result.emplace_back(logfile_base1_ + |
| 567 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 568 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 569 | result.emplace_back(logfile_base1_ + |
| 570 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 571 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 572 | result.emplace_back(logfile_base1_ + |
| 573 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 574 | "aos.message_bridge.RemoteMessage.part2.bfbs"); |
| 575 | } else { |
| 576 | result.emplace_back(logfile_base1_ + |
| 577 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 578 | "aos-message_bridge-Timestamp/" |
| 579 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 580 | result.emplace_back(logfile_base1_ + |
| 581 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 582 | "aos-message_bridge-Timestamp/" |
| 583 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 584 | result.emplace_back(logfile_base1_ + |
| 585 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 586 | "aos-message_bridge-Timestamp/" |
| 587 | "aos.message_bridge.RemoteMessage.part2.bfbs"); |
| 588 | |
| 589 | result.emplace_back(logfile_base1_ + |
| 590 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 591 | "aos-examples-Ping/" |
| 592 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 593 | result.emplace_back(logfile_base1_ + |
| 594 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 595 | "aos-examples-Ping/" |
| 596 | "aos.message_bridge.RemoteMessage.part1.bfbs"); |
| 597 | result.emplace_back(logfile_base1_ + |
| 598 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 599 | "aos-examples-Ping/" |
| 600 | "aos.message_bridge.RemoteMessage.part2.bfbs"); |
| 601 | } |
| 602 | return result; |
| 603 | } |
| 604 | |
| 605 | std::vector<std::string> MakePi1SingleDirectionLogfiles() { |
| 606 | std::vector<std::string> result; |
| 607 | result.emplace_back(logfile_base1_ + "_pi1_data.part0.bfbs"); |
| 608 | result.emplace_back(logfile_base1_ + |
| 609 | "_pi2_data/test/aos.examples.Pong.part0.bfbs"); |
| 610 | result.emplace_back( |
| 611 | logfile_base1_ + |
| 612 | "_pi2_data/pi2/aos/aos.message_bridge.Timestamp.part0.bfbs"); |
| 613 | result.emplace_back( |
| 614 | absl::StrCat(logfile_base1_, "_", GetParam().sha256, ".bfbs")); |
| 615 | |
| 616 | if (shared()) { |
| 617 | result.emplace_back(logfile_base1_ + |
| 618 | "_timestamps/pi1/aos/remote_timestamps/pi2/" |
| 619 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 620 | } else { |
| 621 | result.emplace_back(logfile_base1_ + |
| 622 | "_timestamps/pi1/aos/remote_timestamps/pi2/pi1/aos/" |
| 623 | "aos-message_bridge-Timestamp/" |
| 624 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 625 | result.emplace_back(logfile_base1_ + |
| 626 | "_timestamps/pi1/aos/remote_timestamps/pi2/test/" |
| 627 | "aos-examples-Ping/" |
| 628 | "aos.message_bridge.RemoteMessage.part0.bfbs"); |
| 629 | } |
| 630 | return result; |
| 631 | } |
| 632 | |
| 633 | std::vector<std::vector<std::string>> StructureLogFiles() { |
| 634 | std::vector<std::vector<std::string>> result{ |
| 635 | std::vector<std::string>{logfiles_[2]}, |
| 636 | std::vector<std::string>{logfiles_[3], logfiles_[4]}, |
| 637 | std::vector<std::string>{logfiles_[5]}, |
| 638 | std::vector<std::string>{logfiles_[6], logfiles_[7]}, |
| 639 | std::vector<std::string>{logfiles_[8], logfiles_[9]}, |
| 640 | std::vector<std::string>{logfiles_[10], logfiles_[11]}, |
| 641 | std::vector<std::string>{logfiles_[12], logfiles_[13]}}; |
| 642 | |
| 643 | if (!shared()) { |
| 644 | result.emplace_back( |
| 645 | std::vector<std::string>{logfiles_[14], logfiles_[15]}); |
| 646 | } |
| 647 | |
| 648 | return result; |
| 649 | } |
| 650 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 651 | struct LoggerState { |
| 652 | std::unique_ptr<EventLoop> event_loop; |
| 653 | std::unique_ptr<Logger> logger; |
| 654 | }; |
| 655 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 656 | LoggerState MakeLogger(const Node *node, |
| 657 | SimulatedEventLoopFactory *factory = nullptr) { |
| 658 | if (factory == nullptr) { |
| 659 | factory = &event_loop_factory_; |
| 660 | } |
| 661 | return {factory->MakeEventLoop("logger", node), {}}; |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 664 | void StartLogger(LoggerState *logger, std::string logfile_base = "", |
| 665 | bool compress = false) { |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 666 | if (logfile_base.empty()) { |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 667 | if (logger->event_loop->node()->name()->string_view() == "pi1") { |
| 668 | logfile_base = logfile_base1_; |
| 669 | } else { |
| 670 | logfile_base = logfile_base2_; |
| 671 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 674 | logger->logger = std::make_unique<Logger>(logger->event_loop.get()); |
| 675 | logger->logger->set_polling_period(std::chrono::milliseconds(100)); |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 676 | logger->logger->set_name(absl::StrCat( |
| 677 | "name_prefix_", logger->event_loop->node()->name()->str())); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 678 | logger->event_loop->OnRun([logger, logfile_base, compress]() { |
| 679 | std::unique_ptr<MultiNodeLogNamer> namer = |
| 680 | std::make_unique<MultiNodeLogNamer>( |
| 681 | logfile_base, logger->event_loop->configuration(), |
| 682 | logger->event_loop->node()); |
| 683 | if (compress) { |
| 684 | #ifdef LZMA |
| 685 | namer->set_extension(".xz"); |
| 686 | namer->set_encoder_factory( |
| 687 | []() { return std::make_unique<aos::logger::LzmaEncoder>(3); }); |
| 688 | #else |
| 689 | LOG(FATAL) << "Compression unsupported"; |
| 690 | #endif |
| 691 | } |
| 692 | |
| 693 | logger->logger->StartLogging(std::move(namer)); |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 694 | }); |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 695 | } |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 696 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 697 | void VerifyParts(const std::vector<LogFile> &sorted_parts, |
| 698 | const std::vector<std::string> &corrupted_parts = {}) { |
| 699 | EXPECT_EQ(sorted_parts.size(), 2u); |
| 700 | |
| 701 | // Count up the number of UUIDs and make sure they are what we expect as a |
| 702 | // sanity check. |
| 703 | std::set<std::string> log_event_uuids; |
| 704 | std::set<std::string> parts_uuids; |
| 705 | std::set<std::string> both_uuids; |
| 706 | |
| 707 | size_t missing_rt_count = 0; |
| 708 | |
| 709 | std::vector<std::string> logger_nodes; |
| 710 | for (const LogFile &log_file : sorted_parts) { |
| 711 | EXPECT_FALSE(log_file.log_event_uuid.empty()); |
| 712 | log_event_uuids.insert(log_file.log_event_uuid); |
| 713 | logger_nodes.emplace_back(log_file.logger_node); |
| 714 | both_uuids.insert(log_file.log_event_uuid); |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 715 | EXPECT_TRUE(log_file.config); |
| 716 | EXPECT_EQ(log_file.name, |
| 717 | absl::StrCat("name_prefix_", log_file.logger_node)); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 718 | |
| 719 | for (const LogParts &part : log_file.parts) { |
| 720 | EXPECT_NE(part.monotonic_start_time, aos::monotonic_clock::min_time) |
| 721 | << ": " << part; |
| 722 | missing_rt_count += |
| 723 | part.realtime_start_time == aos::realtime_clock::min_time; |
| 724 | |
| 725 | EXPECT_TRUE(log_event_uuids.find(part.log_event_uuid) != |
| 726 | log_event_uuids.end()); |
| 727 | EXPECT_NE(part.node, ""); |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 728 | EXPECT_TRUE(log_file.config); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 729 | parts_uuids.insert(part.parts_uuid); |
| 730 | both_uuids.insert(part.parts_uuid); |
| 731 | } |
| 732 | } |
| 733 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 734 | // We won't have RT timestamps for 5 or 6 log files. We don't log the RT |
| 735 | // start time on remote nodes because we don't know it and would be |
| 736 | // guessing. And the log reader can actually do a better job. The number |
| 737 | // depends on if we have the remote timestamps split across 2 files, or just |
| 738 | // across 1, depending on if we are using a split or combined timestamp |
| 739 | // channel config. |
| 740 | EXPECT_EQ(missing_rt_count, shared() ? 5u : 6u); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 741 | |
| 742 | EXPECT_EQ(log_event_uuids.size(), 2u); |
| 743 | EXPECT_EQ(parts_uuids.size(), ToLogReaderVector(sorted_parts).size()); |
| 744 | EXPECT_EQ(log_event_uuids.size() + parts_uuids.size(), both_uuids.size()); |
| 745 | |
| 746 | // Test that each list of parts is in order. Don't worry about the ordering |
| 747 | // between part file lists though. |
| 748 | // (inner vectors all need to be in order, but outer one doesn't matter). |
| 749 | EXPECT_THAT(ToLogReaderVector(sorted_parts), |
| 750 | ::testing::UnorderedElementsAreArray(structured_logfiles_)); |
| 751 | |
| 752 | EXPECT_THAT(logger_nodes, ::testing::UnorderedElementsAre("pi1", "pi2")); |
| 753 | |
| 754 | EXPECT_NE(sorted_parts[0].realtime_start_time, |
| 755 | aos::realtime_clock::min_time); |
| 756 | EXPECT_NE(sorted_parts[1].realtime_start_time, |
| 757 | aos::realtime_clock::min_time); |
| 758 | |
| 759 | EXPECT_NE(sorted_parts[0].monotonic_start_time, |
| 760 | aos::monotonic_clock::min_time); |
| 761 | EXPECT_NE(sorted_parts[1].monotonic_start_time, |
| 762 | aos::monotonic_clock::min_time); |
| 763 | |
| 764 | EXPECT_THAT(sorted_parts[0].corrupted, ::testing::Eq(corrupted_parts)); |
| 765 | EXPECT_THAT(sorted_parts[1].corrupted, ::testing::Eq(corrupted_parts)); |
| 766 | } |
| 767 | |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 768 | void ConfirmReadable(const std::vector<std::string> &files) { |
| 769 | LogReader reader(SortParts(files)); |
| 770 | |
| 771 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 772 | reader.Register(&log_reader_factory); |
| 773 | |
| 774 | log_reader_factory.Run(); |
| 775 | |
| 776 | reader.Deregister(); |
| 777 | } |
| 778 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 779 | void AddExtension(std::string_view extension) { |
| 780 | std::transform(logfiles_.begin(), logfiles_.end(), logfiles_.begin(), |
| 781 | [extension](const std::string &in) { |
| 782 | return absl::StrCat(in, extension); |
| 783 | }); |
| 784 | |
| 785 | std::transform(structured_logfiles_.begin(), structured_logfiles_.end(), |
| 786 | structured_logfiles_.begin(), |
| 787 | [extension](std::vector<std::string> in) { |
| 788 | std::transform(in.begin(), in.end(), in.begin(), |
| 789 | [extension](const std::string &in_str) { |
| 790 | return absl::StrCat(in_str, extension); |
| 791 | }); |
| 792 | return in; |
| 793 | }); |
| 794 | } |
| 795 | |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 796 | // Config and factory. |
| 797 | aos::FlatbufferDetachedBuffer<aos::Configuration> config_; |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 798 | message_bridge::TestingTimeConverter time_converter_; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 799 | SimulatedEventLoopFactory event_loop_factory_; |
| 800 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 801 | const Node *const pi1_; |
| 802 | const size_t pi1_index_; |
| 803 | const Node *const pi2_; |
| 804 | const size_t pi2_index_; |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 805 | |
| 806 | std::string tmp_dir_; |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 807 | std::string logfile_base1_; |
| 808 | std::string logfile_base2_; |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 809 | std::vector<std::string> pi1_reboot_logfiles_; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 810 | std::vector<std::string> logfiles_; |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 811 | std::vector<std::string> pi1_single_direction_logfiles_; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 812 | |
| 813 | std::vector<std::vector<std::string>> structured_logfiles_; |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 814 | |
| 815 | std::unique_ptr<EventLoop> ping_event_loop_; |
| 816 | Ping ping_; |
| 817 | std::unique_ptr<EventLoop> pong_event_loop_; |
| 818 | Pong pong_; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 819 | }; |
| 820 | |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 821 | // Counts the number of messages on a channel. Returns (channel name, channel |
| 822 | // type, count) for every message matching matcher() |
| 823 | std::vector<std::tuple<std::string, std::string, int>> CountChannelsMatching( |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 824 | std::shared_ptr<const aos::Configuration> config, std::string_view filename, |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 825 | std::function<bool(const MessageHeader *)> matcher) { |
| 826 | MessageReader message_reader(filename); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 827 | std::vector<int> counts(config->channels()->size(), 0); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 828 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 829 | while (true) { |
Austin Schuh | add6eb3 | 2020-11-09 21:24:26 -0800 | [diff] [blame] | 830 | std::optional<SizePrefixedFlatbufferVector<MessageHeader>> msg = |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 831 | message_reader.ReadMessage(); |
| 832 | if (!msg) { |
| 833 | break; |
| 834 | } |
| 835 | |
| 836 | if (matcher(&msg.value().message())) { |
| 837 | counts[msg.value().message().channel_index()]++; |
| 838 | } |
| 839 | } |
| 840 | |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 841 | std::vector<std::tuple<std::string, std::string, int>> result; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 842 | int channel = 0; |
| 843 | for (size_t i = 0; i < counts.size(); ++i) { |
| 844 | if (counts[i] != 0) { |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 845 | const Channel *channel = config->channels()->Get(i); |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 846 | result.push_back(std::make_tuple(channel->name()->str(), |
| 847 | channel->type()->str(), counts[i])); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 848 | } |
| 849 | ++channel; |
| 850 | } |
| 851 | |
| 852 | return result; |
| 853 | } |
| 854 | |
| 855 | // Counts the number of messages (channel, count) for all data messages. |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 856 | std::vector<std::tuple<std::string, std::string, int>> CountChannelsData( |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 857 | std::shared_ptr<const aos::Configuration> config, |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 858 | std::string_view filename) { |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 859 | return CountChannelsMatching(config, filename, [](const MessageHeader *msg) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 860 | if (msg->has_data()) { |
| 861 | CHECK(!msg->has_monotonic_remote_time()); |
| 862 | CHECK(!msg->has_realtime_remote_time()); |
| 863 | CHECK(!msg->has_remote_queue_index()); |
| 864 | return true; |
| 865 | } |
| 866 | return false; |
| 867 | }); |
| 868 | } |
| 869 | |
| 870 | // Counts the number of messages (channel, count) for all timestamp messages. |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 871 | std::vector<std::tuple<std::string, std::string, int>> CountChannelsTimestamp( |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 872 | std::shared_ptr<const aos::Configuration> config, |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 873 | std::string_view filename) { |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 874 | return CountChannelsMatching(config, filename, [](const MessageHeader *msg) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 875 | if (!msg->has_data()) { |
| 876 | CHECK(msg->has_monotonic_remote_time()); |
| 877 | CHECK(msg->has_realtime_remote_time()); |
| 878 | CHECK(msg->has_remote_queue_index()); |
| 879 | return true; |
| 880 | } |
| 881 | return false; |
| 882 | }); |
| 883 | } |
| 884 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 885 | // Tests that we can write and read simple multi-node log files. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 886 | TEST_P(MultinodeLoggerTest, SimpleMultiNode) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 887 | time_converter_.StartEqual(); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 888 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 889 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 890 | LoggerState pi2_logger = MakeLogger(pi2_); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 891 | |
| 892 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 893 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 894 | StartLogger(&pi1_logger); |
| 895 | StartLogger(&pi2_logger); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 896 | |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 897 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 898 | } |
| 899 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 900 | { |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 901 | std::set<std::string> logfile_uuids; |
| 902 | std::set<std::string> parts_uuids; |
| 903 | // Confirm that we have the expected number of UUIDs for both the logfile |
| 904 | // UUIDs and parts UUIDs. |
Austin Schuh | add6eb3 | 2020-11-09 21:24:26 -0800 | [diff] [blame] | 905 | std::vector<SizePrefixedFlatbufferVector<LogFileHeader>> log_header; |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 906 | for (std::string_view f : logfiles_) { |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 907 | log_header.emplace_back(ReadHeader(f).value()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 908 | if (!log_header.back().message().has_configuration()) { |
| 909 | logfile_uuids.insert( |
| 910 | log_header.back().message().log_event_uuid()->str()); |
| 911 | parts_uuids.insert(log_header.back().message().parts_uuid()->str()); |
| 912 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 913 | } |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 914 | |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 915 | EXPECT_EQ(logfile_uuids.size(), 2u); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 916 | if (shared()) { |
| 917 | EXPECT_EQ(parts_uuids.size(), 7u); |
| 918 | } else { |
| 919 | EXPECT_EQ(parts_uuids.size(), 8u); |
| 920 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 921 | |
| 922 | // And confirm everything is on the correct node. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 923 | EXPECT_EQ(log_header[2].message().node()->name()->string_view(), "pi1"); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 924 | EXPECT_EQ(log_header[3].message().node()->name()->string_view(), "pi2"); |
| 925 | EXPECT_EQ(log_header[4].message().node()->name()->string_view(), "pi2"); |
| 926 | EXPECT_EQ(log_header[5].message().node()->name()->string_view(), "pi2"); |
| 927 | EXPECT_EQ(log_header[6].message().node()->name()->string_view(), "pi1"); |
| 928 | EXPECT_EQ(log_header[7].message().node()->name()->string_view(), "pi1"); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 929 | EXPECT_EQ(log_header[8].message().node()->name()->string_view(), "pi2"); |
| 930 | EXPECT_EQ(log_header[9].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 931 | EXPECT_EQ(log_header[10].message().node()->name()->string_view(), "pi2"); |
| 932 | EXPECT_EQ(log_header[11].message().node()->name()->string_view(), "pi2"); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 933 | EXPECT_EQ(log_header[12].message().node()->name()->string_view(), "pi1"); |
| 934 | EXPECT_EQ(log_header[13].message().node()->name()->string_view(), "pi1"); |
| 935 | if (!shared()) { |
| 936 | EXPECT_EQ(log_header[14].message().node()->name()->string_view(), "pi2"); |
| 937 | EXPECT_EQ(log_header[15].message().node()->name()->string_view(), "pi2"); |
| 938 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 939 | |
| 940 | // And the parts index matches. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 941 | EXPECT_EQ(log_header[2].message().parts_index(), 0); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 942 | EXPECT_EQ(log_header[3].message().parts_index(), 0); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 943 | EXPECT_EQ(log_header[4].message().parts_index(), 1); |
| 944 | EXPECT_EQ(log_header[5].message().parts_index(), 0); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 945 | EXPECT_EQ(log_header[6].message().parts_index(), 0); |
| 946 | EXPECT_EQ(log_header[7].message().parts_index(), 1); |
| 947 | EXPECT_EQ(log_header[8].message().parts_index(), 0); |
| 948 | EXPECT_EQ(log_header[9].message().parts_index(), 1); |
| 949 | EXPECT_EQ(log_header[10].message().parts_index(), 0); |
| 950 | EXPECT_EQ(log_header[11].message().parts_index(), 1); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 951 | EXPECT_EQ(log_header[12].message().parts_index(), 0); |
| 952 | EXPECT_EQ(log_header[13].message().parts_index(), 1); |
| 953 | if (!shared()) { |
| 954 | EXPECT_EQ(log_header[14].message().parts_index(), 0); |
| 955 | EXPECT_EQ(log_header[15].message().parts_index(), 1); |
| 956 | } |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 959 | const std::vector<LogFile> sorted_log_files = SortParts(logfiles_); |
Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 960 | { |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 961 | using ::testing::UnorderedElementsAre; |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 962 | std::shared_ptr<const aos::Configuration> config = |
| 963 | sorted_log_files[0].config; |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 964 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 965 | // Timing reports, pings |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 966 | EXPECT_THAT( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 967 | CountChannelsData(config, logfiles_[2]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 968 | UnorderedElementsAre( |
| 969 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 200), |
James Kuszmaul | 4f106fb | 2021-01-05 20:53:02 -0800 | [diff] [blame] | 970 | std::make_tuple("/pi1/aos", "aos.message_bridge.ServerStatistics", |
| 971 | 21), |
| 972 | std::make_tuple("/pi1/aos", "aos.message_bridge.ClientStatistics", |
| 973 | 200), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 974 | std::make_tuple("/pi1/aos", "aos.timing.Report", 40), |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 975 | std::make_tuple("/test", "aos.examples.Ping", 2001))) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 976 | << " : " << logfiles_[2]; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 977 | // Timestamps for pong |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 978 | EXPECT_THAT( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 979 | CountChannelsTimestamp(config, logfiles_[2]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 980 | UnorderedElementsAre( |
| 981 | std::make_tuple("/test", "aos.examples.Pong", 2001), |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 982 | std::make_tuple("/pi2/aos", "aos.message_bridge.Timestamp", 200))) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 983 | << " : " << logfiles_[2]; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 984 | |
| 985 | // Pong data. |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 986 | EXPECT_THAT( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 987 | CountChannelsData(config, logfiles_[3]), |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 988 | UnorderedElementsAre(std::make_tuple("/test", "aos.examples.Pong", 91))) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 989 | << " : " << logfiles_[3]; |
| 990 | EXPECT_THAT(CountChannelsData(config, logfiles_[4]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 991 | UnorderedElementsAre( |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 992 | std::make_tuple("/test", "aos.examples.Pong", 1910))) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 993 | << " : " << logfiles_[3]; |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 994 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 995 | // No timestamps |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 996 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[3]), |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 997 | UnorderedElementsAre()) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 998 | << " : " << logfiles_[3]; |
| 999 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[4]), |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 1000 | UnorderedElementsAre()) |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1001 | << " : " << logfiles_[4]; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1002 | |
| 1003 | // Timing reports and pongs. |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1004 | EXPECT_THAT( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1005 | CountChannelsData(config, logfiles_[5]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1006 | UnorderedElementsAre( |
| 1007 | std::make_tuple("/pi2/aos", "aos.message_bridge.Timestamp", 200), |
James Kuszmaul | 4f106fb | 2021-01-05 20:53:02 -0800 | [diff] [blame] | 1008 | std::make_tuple("/pi2/aos", "aos.message_bridge.ServerStatistics", |
| 1009 | 21), |
| 1010 | std::make_tuple("/pi2/aos", "aos.message_bridge.ClientStatistics", |
| 1011 | 200), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1012 | std::make_tuple("/pi2/aos", "aos.timing.Report", 40), |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1013 | std::make_tuple("/test", "aos.examples.Pong", 2001))) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1014 | << " : " << logfiles_[5]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1015 | // And ping timestamps. |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1016 | EXPECT_THAT( |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1017 | CountChannelsTimestamp(config, logfiles_[5]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1018 | UnorderedElementsAre( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1019 | std::make_tuple("/test", "aos.examples.Ping", 2001), |
| 1020 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 200))) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1021 | << " : " << logfiles_[5]; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1022 | |
| 1023 | // And then test that the remotely logged timestamp data files only have |
| 1024 | // timestamps in them. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1025 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[6]), |
| 1026 | UnorderedElementsAre()) |
| 1027 | << " : " << logfiles_[6]; |
| 1028 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[7]), |
| 1029 | UnorderedElementsAre()) |
| 1030 | << " : " << logfiles_[7]; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 1031 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[8]), |
| 1032 | UnorderedElementsAre()) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1033 | << " : " << logfiles_[8]; |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 1034 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[9]), |
| 1035 | UnorderedElementsAre()) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1036 | << " : " << logfiles_[9]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1037 | |
| 1038 | EXPECT_THAT(CountChannelsData(config, logfiles_[6]), |
| 1039 | UnorderedElementsAre(std::make_tuple( |
| 1040 | "/pi1/aos", "aos.message_bridge.Timestamp", 9))) |
| 1041 | << " : " << logfiles_[6]; |
| 1042 | EXPECT_THAT(CountChannelsData(config, logfiles_[7]), |
| 1043 | UnorderedElementsAre(std::make_tuple( |
| 1044 | "/pi1/aos", "aos.message_bridge.Timestamp", 191))) |
| 1045 | << " : " << logfiles_[7]; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1046 | |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1047 | EXPECT_THAT(CountChannelsData(config, logfiles_[8]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1048 | UnorderedElementsAre(std::make_tuple( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1049 | "/pi2/aos", "aos.message_bridge.Timestamp", 9))) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1050 | << " : " << logfiles_[8]; |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1051 | EXPECT_THAT(CountChannelsData(config, logfiles_[9]), |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1052 | UnorderedElementsAre(std::make_tuple( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1053 | "/pi2/aos", "aos.message_bridge.Timestamp", 191))) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1054 | << " : " << logfiles_[9]; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1055 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1056 | // Timestamps from pi2 on pi1, and the other way. |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1057 | EXPECT_THAT(CountChannelsData(config, logfiles_[10]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1058 | UnorderedElementsAre()) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1059 | << " : " << logfiles_[10]; |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1060 | EXPECT_THAT(CountChannelsData(config, logfiles_[11]), |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1061 | UnorderedElementsAre()) |
Austin Schuh | 20ac95d | 2020-12-05 17:24:19 -0800 | [diff] [blame] | 1062 | << " : " << logfiles_[11]; |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1063 | EXPECT_THAT(CountChannelsData(config, logfiles_[12]), |
| 1064 | UnorderedElementsAre()) |
| 1065 | << " : " << logfiles_[12]; |
| 1066 | EXPECT_THAT(CountChannelsData(config, logfiles_[13]), |
| 1067 | UnorderedElementsAre()) |
| 1068 | << " : " << logfiles_[13]; |
| 1069 | if (!shared()) { |
| 1070 | EXPECT_THAT(CountChannelsData(config, logfiles_[14]), |
| 1071 | UnorderedElementsAre()) |
| 1072 | << " : " << logfiles_[14]; |
| 1073 | EXPECT_THAT(CountChannelsData(config, logfiles_[15]), |
| 1074 | UnorderedElementsAre()) |
| 1075 | << " : " << logfiles_[15]; |
| 1076 | } |
| 1077 | |
| 1078 | if (shared()) { |
| 1079 | EXPECT_THAT( |
| 1080 | CountChannelsTimestamp(config, logfiles_[10]), |
| 1081 | UnorderedElementsAre( |
| 1082 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 9), |
| 1083 | std::make_tuple("/test", "aos.examples.Ping", 91))) |
| 1084 | << " : " << logfiles_[10]; |
| 1085 | EXPECT_THAT( |
| 1086 | CountChannelsTimestamp(config, logfiles_[11]), |
| 1087 | UnorderedElementsAre( |
| 1088 | std::make_tuple("/pi1/aos", "aos.message_bridge.Timestamp", 191), |
| 1089 | std::make_tuple("/test", "aos.examples.Ping", 1910))) |
| 1090 | << " : " << logfiles_[11]; |
| 1091 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[12]), |
| 1092 | UnorderedElementsAre(std::make_tuple( |
| 1093 | "/pi2/aos", "aos.message_bridge.Timestamp", 9))) |
| 1094 | << " : " << logfiles_[12]; |
| 1095 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[13]), |
| 1096 | UnorderedElementsAre(std::make_tuple( |
| 1097 | "/pi2/aos", "aos.message_bridge.Timestamp", 191))) |
| 1098 | << " : " << logfiles_[13]; |
| 1099 | } else { |
| 1100 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[10]), |
| 1101 | UnorderedElementsAre(std::make_tuple( |
| 1102 | "/pi1/aos", "aos.message_bridge.Timestamp", 9))) |
| 1103 | << " : " << logfiles_[10]; |
| 1104 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[11]), |
| 1105 | UnorderedElementsAre(std::make_tuple( |
| 1106 | "/pi1/aos", "aos.message_bridge.Timestamp", 191))) |
| 1107 | << " : " << logfiles_[11]; |
| 1108 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[12]), |
| 1109 | UnorderedElementsAre(std::make_tuple( |
| 1110 | "/pi2/aos", "aos.message_bridge.Timestamp", 9))) |
| 1111 | << " : " << logfiles_[12]; |
| 1112 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[13]), |
| 1113 | UnorderedElementsAre(std::make_tuple( |
| 1114 | "/pi2/aos", "aos.message_bridge.Timestamp", 191))) |
| 1115 | << " : " << logfiles_[13]; |
| 1116 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[14]), |
| 1117 | UnorderedElementsAre( |
| 1118 | std::make_tuple("/test", "aos.examples.Ping", 91))) |
| 1119 | << " : " << logfiles_[14]; |
| 1120 | EXPECT_THAT(CountChannelsTimestamp(config, logfiles_[15]), |
| 1121 | UnorderedElementsAre( |
| 1122 | std::make_tuple("/test", "aos.examples.Ping", 1910))) |
| 1123 | << " : " << logfiles_[15]; |
| 1124 | } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1125 | } |
| 1126 | |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 1127 | LogReader reader(sorted_log_files); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1128 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1129 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
Austin Schuh | 6331ef9 | 2020-01-07 18:28:09 -0800 | [diff] [blame] | 1130 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1131 | |
| 1132 | // This sends out the fetched messages and advances time to the start of the |
| 1133 | // log file. |
Austin Schuh | 6331ef9 | 2020-01-07 18:28:09 -0800 | [diff] [blame] | 1134 | reader.Register(&log_reader_factory); |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 1135 | |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 1136 | const Node *pi1 = |
| 1137 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1138 | const Node *pi2 = |
| 1139 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 1140 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1141 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi1) << " pi1"; |
| 1142 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi2) << " pi2"; |
| 1143 | LOG(INFO) << "now pi1 " |
| 1144 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now(); |
| 1145 | LOG(INFO) << "now pi2 " |
| 1146 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now(); |
| 1147 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 1148 | EXPECT_THAT(reader.LoggedNodes(), |
| 1149 | ::testing::ElementsAre( |
| 1150 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 1151 | configuration::GetNode(reader.logged_configuration(), pi2))); |
James Kuszmaul | 84ff3e5 | 2020-01-03 19:48:53 -0800 | [diff] [blame] | 1152 | |
| 1153 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(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 | std::unique_ptr<EventLoop> pi1_event_loop = |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 1156 | log_reader_factory.MakeEventLoop("test", pi1); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1157 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1158 | log_reader_factory.MakeEventLoop("test", pi2); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1159 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1160 | int pi1_ping_count = 10; |
| 1161 | int pi2_ping_count = 10; |
| 1162 | int pi1_pong_count = 10; |
| 1163 | int pi2_pong_count = 10; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1164 | |
| 1165 | // Confirm that the ping value matches. |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1166 | pi1_event_loop->MakeWatcher( |
| 1167 | "/test", [&pi1_ping_count, &pi1_event_loop](const examples::Ping &ping) { |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1168 | VLOG(1) << "Pi1 ping " << FlatbufferToJson(&ping) << " at " |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1169 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1170 | << pi1_event_loop->context().monotonic_event_time; |
| 1171 | EXPECT_EQ(ping.value(), pi1_ping_count + 1); |
| 1172 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time, |
| 1173 | pi1_ping_count * chrono::milliseconds(10) + |
| 1174 | monotonic_clock::epoch()); |
| 1175 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time, |
| 1176 | pi1_ping_count * chrono::milliseconds(10) + |
| 1177 | realtime_clock::epoch()); |
| 1178 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time, |
| 1179 | pi1_event_loop->context().monotonic_event_time); |
| 1180 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time, |
| 1181 | pi1_event_loop->context().realtime_event_time); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1182 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1183 | ++pi1_ping_count; |
| 1184 | }); |
| 1185 | pi2_event_loop->MakeWatcher( |
| 1186 | "/test", [&pi2_ping_count, &pi2_event_loop](const examples::Ping &ping) { |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1187 | VLOG(1) << "Pi2 ping " << FlatbufferToJson(&ping) << " at " |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1188 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1189 | << pi2_event_loop->context().monotonic_event_time; |
| 1190 | EXPECT_EQ(ping.value(), pi2_ping_count + 1); |
| 1191 | |
| 1192 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time, |
| 1193 | pi2_ping_count * chrono::milliseconds(10) + |
| 1194 | monotonic_clock::epoch()); |
| 1195 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time, |
| 1196 | pi2_ping_count * chrono::milliseconds(10) + |
| 1197 | realtime_clock::epoch()); |
| 1198 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time + |
| 1199 | chrono::microseconds(150), |
| 1200 | pi2_event_loop->context().monotonic_event_time); |
| 1201 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time + |
| 1202 | chrono::microseconds(150), |
| 1203 | pi2_event_loop->context().realtime_event_time); |
| 1204 | ++pi2_ping_count; |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1205 | }); |
| 1206 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1207 | constexpr ssize_t kQueueIndexOffset = -9; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1208 | // Confirm that the ping and pong counts both match, and the value also |
| 1209 | // matches. |
| 1210 | pi1_event_loop->MakeWatcher( |
| 1211 | "/test", [&pi1_event_loop, &pi1_ping_count, |
| 1212 | &pi1_pong_count](const examples::Pong &pong) { |
| 1213 | VLOG(1) << "Pi1 pong " << FlatbufferToJson(&pong) << " at " |
| 1214 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1215 | << pi1_event_loop->context().monotonic_event_time; |
| 1216 | |
| 1217 | EXPECT_EQ(pi1_event_loop->context().remote_queue_index, |
| 1218 | pi1_pong_count + kQueueIndexOffset); |
| 1219 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time, |
| 1220 | chrono::microseconds(200) + |
| 1221 | pi1_pong_count * chrono::milliseconds(10) + |
| 1222 | monotonic_clock::epoch()); |
| 1223 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time, |
| 1224 | chrono::microseconds(200) + |
| 1225 | pi1_pong_count * chrono::milliseconds(10) + |
| 1226 | realtime_clock::epoch()); |
| 1227 | |
| 1228 | EXPECT_EQ(pi1_event_loop->context().monotonic_remote_time + |
| 1229 | chrono::microseconds(150), |
| 1230 | pi1_event_loop->context().monotonic_event_time); |
| 1231 | EXPECT_EQ(pi1_event_loop->context().realtime_remote_time + |
| 1232 | chrono::microseconds(150), |
| 1233 | pi1_event_loop->context().realtime_event_time); |
| 1234 | |
| 1235 | EXPECT_EQ(pong.value(), pi1_pong_count + 1); |
| 1236 | ++pi1_pong_count; |
| 1237 | EXPECT_EQ(pi1_ping_count, pi1_pong_count); |
| 1238 | }); |
| 1239 | pi2_event_loop->MakeWatcher( |
| 1240 | "/test", [&pi2_event_loop, &pi2_ping_count, |
| 1241 | &pi2_pong_count](const examples::Pong &pong) { |
| 1242 | VLOG(1) << "Pi2 pong " << FlatbufferToJson(&pong) << " at " |
| 1243 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1244 | << pi2_event_loop->context().monotonic_event_time; |
| 1245 | |
| 1246 | EXPECT_EQ(pi2_event_loop->context().remote_queue_index, |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1247 | pi2_pong_count + kQueueIndexOffset); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1248 | |
| 1249 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time, |
| 1250 | chrono::microseconds(200) + |
| 1251 | pi2_pong_count * chrono::milliseconds(10) + |
| 1252 | monotonic_clock::epoch()); |
| 1253 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time, |
| 1254 | chrono::microseconds(200) + |
| 1255 | pi2_pong_count * chrono::milliseconds(10) + |
| 1256 | realtime_clock::epoch()); |
| 1257 | |
| 1258 | EXPECT_EQ(pi2_event_loop->context().monotonic_remote_time, |
| 1259 | pi2_event_loop->context().monotonic_event_time); |
| 1260 | EXPECT_EQ(pi2_event_loop->context().realtime_remote_time, |
| 1261 | pi2_event_loop->context().realtime_event_time); |
| 1262 | |
| 1263 | EXPECT_EQ(pong.value(), pi2_pong_count + 1); |
| 1264 | ++pi2_pong_count; |
| 1265 | EXPECT_EQ(pi2_ping_count, pi2_pong_count); |
| 1266 | }); |
| 1267 | |
| 1268 | log_reader_factory.Run(); |
| 1269 | EXPECT_EQ(pi1_ping_count, 2010); |
| 1270 | EXPECT_EQ(pi2_ping_count, 2010); |
| 1271 | EXPECT_EQ(pi1_pong_count, 2010); |
| 1272 | EXPECT_EQ(pi2_pong_count, 2010); |
Austin Schuh | 6331ef9 | 2020-01-07 18:28:09 -0800 | [diff] [blame] | 1273 | |
| 1274 | reader.Deregister(); |
Austin Schuh | 15649d6 | 2019-12-28 16:36:38 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1277 | typedef MultinodeLoggerTest MultinodeLoggerDeathTest; |
| 1278 | |
| 1279 | // Test that if we feed the replay with a mismatched node list that we die on |
| 1280 | // the LogReader constructor. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1281 | TEST_P(MultinodeLoggerDeathTest, MultiNodeBadReplayConfig) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1282 | time_converter_.StartEqual(); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1283 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1284 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1285 | LoggerState pi2_logger = MakeLogger(pi2_); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1286 | |
| 1287 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1288 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1289 | StartLogger(&pi1_logger); |
| 1290 | StartLogger(&pi2_logger); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1291 | |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1292 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 1293 | } |
| 1294 | |
| 1295 | // Test that, if we add an additional node to the replay config that the |
| 1296 | // logger complains about the mismatch in number of nodes. |
| 1297 | FlatbufferDetachedBuffer<Configuration> extra_nodes_config = |
| 1298 | configuration::MergeWithConfig(&config_.message(), R"({ |
| 1299 | "nodes": [ |
| 1300 | { |
| 1301 | "name": "extra-node" |
| 1302 | } |
| 1303 | ] |
| 1304 | } |
| 1305 | )"); |
| 1306 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 1307 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
| 1308 | EXPECT_DEATH(LogReader(sorted_parts, &extra_nodes_config.message()), |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1309 | "Log file and replay config need to have matching nodes lists."); |
James Kuszmaul | 46d8258 | 2020-05-09 19:50:09 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1312 | // Tests that we can read log files where they don't start at the same monotonic |
| 1313 | // time. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1314 | TEST_P(MultinodeLoggerTest, StaggeredStart) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1315 | time_converter_.StartEqual(); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1316 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1317 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1318 | LoggerState pi2_logger = MakeLogger(pi2_); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1319 | |
| 1320 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1321 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1322 | StartLogger(&pi1_logger); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1323 | |
| 1324 | event_loop_factory_.RunFor(chrono::milliseconds(200)); |
| 1325 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1326 | StartLogger(&pi2_logger); |
| 1327 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1328 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 1329 | } |
| 1330 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 1331 | LogReader reader(SortParts(logfiles_)); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1332 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1333 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1334 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 1335 | |
| 1336 | // This sends out the fetched messages and advances time to the start of the |
| 1337 | // log file. |
| 1338 | reader.Register(&log_reader_factory); |
| 1339 | |
| 1340 | const Node *pi1 = |
| 1341 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 1342 | const Node *pi2 = |
| 1343 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 1344 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 1345 | EXPECT_THAT(reader.LoggedNodes(), |
| 1346 | ::testing::ElementsAre( |
| 1347 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 1348 | configuration::GetNode(reader.logged_configuration(), pi2))); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1349 | |
| 1350 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
| 1351 | |
| 1352 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 1353 | log_reader_factory.MakeEventLoop("test", pi1); |
| 1354 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1355 | log_reader_factory.MakeEventLoop("test", pi2); |
| 1356 | |
| 1357 | int pi1_ping_count = 30; |
| 1358 | int pi2_ping_count = 30; |
| 1359 | int pi1_pong_count = 30; |
| 1360 | int pi2_pong_count = 30; |
| 1361 | |
| 1362 | // Confirm that the ping value matches. |
| 1363 | pi1_event_loop->MakeWatcher( |
| 1364 | "/test", [&pi1_ping_count, &pi1_event_loop](const examples::Ping &ping) { |
| 1365 | VLOG(1) << "Pi1 ping " << FlatbufferToJson(&ping) |
| 1366 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1367 | << pi1_event_loop->context().monotonic_event_time; |
| 1368 | EXPECT_EQ(ping.value(), pi1_ping_count + 1); |
| 1369 | |
| 1370 | ++pi1_ping_count; |
| 1371 | }); |
| 1372 | pi2_event_loop->MakeWatcher( |
| 1373 | "/test", [&pi2_ping_count, &pi2_event_loop](const examples::Ping &ping) { |
| 1374 | VLOG(1) << "Pi2 ping " << FlatbufferToJson(&ping) |
| 1375 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1376 | << pi2_event_loop->context().monotonic_event_time; |
| 1377 | EXPECT_EQ(ping.value(), pi2_ping_count + 1); |
| 1378 | |
| 1379 | ++pi2_ping_count; |
| 1380 | }); |
| 1381 | |
| 1382 | // Confirm that the ping and pong counts both match, and the value also |
| 1383 | // matches. |
| 1384 | pi1_event_loop->MakeWatcher( |
| 1385 | "/test", [&pi1_event_loop, &pi1_ping_count, |
| 1386 | &pi1_pong_count](const examples::Pong &pong) { |
| 1387 | VLOG(1) << "Pi1 pong " << FlatbufferToJson(&pong) << " at " |
| 1388 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1389 | << pi1_event_loop->context().monotonic_event_time; |
| 1390 | |
| 1391 | EXPECT_EQ(pong.value(), pi1_pong_count + 1); |
| 1392 | ++pi1_pong_count; |
| 1393 | EXPECT_EQ(pi1_ping_count, pi1_pong_count); |
| 1394 | }); |
| 1395 | pi2_event_loop->MakeWatcher( |
| 1396 | "/test", [&pi2_event_loop, &pi2_ping_count, |
| 1397 | &pi2_pong_count](const examples::Pong &pong) { |
| 1398 | VLOG(1) << "Pi2 pong " << FlatbufferToJson(&pong) << " at " |
| 1399 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1400 | << pi2_event_loop->context().monotonic_event_time; |
| 1401 | |
| 1402 | EXPECT_EQ(pong.value(), pi2_pong_count + 1); |
| 1403 | ++pi2_pong_count; |
| 1404 | EXPECT_EQ(pi2_ping_count, pi2_pong_count); |
| 1405 | }); |
| 1406 | |
| 1407 | log_reader_factory.Run(); |
| 1408 | EXPECT_EQ(pi1_ping_count, 2030); |
| 1409 | EXPECT_EQ(pi2_ping_count, 2030); |
| 1410 | EXPECT_EQ(pi1_pong_count, 2030); |
| 1411 | EXPECT_EQ(pi2_pong_count, 2030); |
| 1412 | |
| 1413 | reader.Deregister(); |
| 1414 | } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 1415 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1416 | // Tests that we can read log files where the monotonic clocks drift and don't |
| 1417 | // match correctly. While we are here, also test that different ending times |
| 1418 | // also is readable. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1419 | TEST_P(MultinodeLoggerTest, MismatchedClocks) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1420 | // TODO(austin): Negate... |
| 1421 | const chrono::nanoseconds initial_pi2_offset = chrono::seconds(1000); |
| 1422 | |
| 1423 | time_converter_.AddMonotonic({monotonic_clock::epoch(), |
| 1424 | monotonic_clock::epoch() + initial_pi2_offset}); |
| 1425 | // Wait for 95 ms, (~0.1 seconds - 1/2 of the ping/pong period), and set the |
| 1426 | // skew to be 200 uS/s |
| 1427 | const chrono::nanoseconds startup_sleep1 = time_converter_.AddMonotonic( |
| 1428 | {chrono::milliseconds(95), |
| 1429 | chrono::milliseconds(95) - chrono::nanoseconds(200) * 95}); |
| 1430 | // Run another 200 ms to have one logger start first. |
| 1431 | const chrono::nanoseconds startup_sleep2 = time_converter_.AddMonotonic( |
| 1432 | {chrono::milliseconds(200), chrono::milliseconds(200)}); |
| 1433 | // Slew one way then the other at the same 200 uS/S slew rate. Make sure we |
| 1434 | // go far enough to cause problems if this isn't accounted for. |
| 1435 | const chrono::nanoseconds logger_run1 = time_converter_.AddMonotonic( |
| 1436 | {chrono::milliseconds(20000), |
| 1437 | chrono::milliseconds(20000) - chrono::nanoseconds(200) * 20000}); |
| 1438 | const chrono::nanoseconds logger_run2 = time_converter_.AddMonotonic( |
| 1439 | {chrono::milliseconds(40000), |
| 1440 | chrono::milliseconds(40000) + chrono::nanoseconds(200) * 40000}); |
| 1441 | const chrono::nanoseconds logger_run3 = time_converter_.AddMonotonic( |
| 1442 | {chrono::milliseconds(400), chrono::milliseconds(400)}); |
| 1443 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1444 | { |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1445 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 1446 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1447 | NodeEventLoopFactory *pi1 = |
| 1448 | event_loop_factory_.GetNodeEventLoopFactory(pi1_); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1449 | NodeEventLoopFactory *pi2 = |
| 1450 | event_loop_factory_.GetNodeEventLoopFactory(pi2_); |
| 1451 | LOG(INFO) << "pi2 times: " << pi2->monotonic_now() << " " |
| 1452 | << pi2->realtime_now() << " distributed " |
| 1453 | << pi2->ToDistributedClock(pi2->monotonic_now()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1454 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1455 | LOG(INFO) << "pi2 times: " << pi2->monotonic_now() << " " |
| 1456 | << pi2->realtime_now() << " distributed " |
| 1457 | << pi2->ToDistributedClock(pi2->monotonic_now()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1458 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1459 | event_loop_factory_.RunFor(startup_sleep1); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1460 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1461 | StartLogger(&pi2_logger); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1462 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1463 | event_loop_factory_.RunFor(startup_sleep2); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1464 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1465 | { |
| 1466 | // Run pi1's logger for only part of the time. |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1467 | LoggerState pi1_logger = MakeLogger(pi1_); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1468 | |
James Kuszmaul | bb28ef2 | 2020-05-09 22:30:38 -0700 | [diff] [blame] | 1469 | StartLogger(&pi1_logger); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1470 | event_loop_factory_.RunFor(logger_run1); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1471 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1472 | // Make sure we slewed time far enough so that the difference is greater |
| 1473 | // than the network delay. This confirms that if we sort incorrectly, it |
| 1474 | // would show in the results. |
| 1475 | EXPECT_LT( |
| 1476 | (pi2->monotonic_now() - pi1->monotonic_now()) - initial_pi2_offset, |
| 1477 | -event_loop_factory_.send_delay() - |
| 1478 | event_loop_factory_.network_delay()); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1479 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1480 | event_loop_factory_.RunFor(logger_run2); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1481 | |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1482 | // And now check that we went far enough the other way to make sure we |
| 1483 | // cover both problems. |
| 1484 | EXPECT_GT( |
| 1485 | (pi2->monotonic_now() - pi1->monotonic_now()) - initial_pi2_offset, |
| 1486 | event_loop_factory_.send_delay() + |
| 1487 | event_loop_factory_.network_delay()); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | // And log a bit more on pi2. |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1491 | event_loop_factory_.RunFor(logger_run3); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1492 | } |
| 1493 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 1494 | LogReader reader(SortParts(logfiles_)); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1495 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1496 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1497 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 1498 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1499 | const Node *pi1 = |
| 1500 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 1501 | const Node *pi2 = |
| 1502 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 1503 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 1504 | // This sends out the fetched messages and advances time to the start of the |
| 1505 | // log file. |
| 1506 | reader.Register(&log_reader_factory); |
| 1507 | |
| 1508 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi1) << " pi1"; |
| 1509 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi2) << " pi2"; |
| 1510 | LOG(INFO) << "now pi1 " |
| 1511 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now(); |
| 1512 | LOG(INFO) << "now pi2 " |
| 1513 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now(); |
| 1514 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1515 | LOG(INFO) << "Done registering (pi1) " |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1516 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now() |
| 1517 | << " " |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1518 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->realtime_now(); |
| 1519 | LOG(INFO) << "Done registering (pi2) " |
Austin Schuh | 391e317 | 2020-09-01 22:48:18 -0700 | [diff] [blame] | 1520 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now() |
| 1521 | << " " |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1522 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->realtime_now(); |
| 1523 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 1524 | EXPECT_THAT(reader.LoggedNodes(), |
| 1525 | ::testing::ElementsAre( |
| 1526 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 1527 | configuration::GetNode(reader.logged_configuration(), pi2))); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1528 | |
| 1529 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
| 1530 | |
| 1531 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 1532 | log_reader_factory.MakeEventLoop("test", pi1); |
| 1533 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1534 | log_reader_factory.MakeEventLoop("test", pi2); |
| 1535 | |
| 1536 | int pi1_ping_count = 30; |
| 1537 | int pi2_ping_count = 30; |
| 1538 | int pi1_pong_count = 30; |
| 1539 | int pi2_pong_count = 30; |
| 1540 | |
| 1541 | // Confirm that the ping value matches. |
| 1542 | pi1_event_loop->MakeWatcher( |
| 1543 | "/test", [&pi1_ping_count, &pi1_event_loop](const examples::Ping &ping) { |
| 1544 | VLOG(1) << "Pi1 ping " << FlatbufferToJson(&ping) |
| 1545 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1546 | << pi1_event_loop->context().monotonic_event_time; |
| 1547 | EXPECT_EQ(ping.value(), pi1_ping_count + 1); |
| 1548 | |
| 1549 | ++pi1_ping_count; |
| 1550 | }); |
| 1551 | pi2_event_loop->MakeWatcher( |
| 1552 | "/test", [&pi2_ping_count, &pi2_event_loop](const examples::Ping &ping) { |
| 1553 | VLOG(1) << "Pi2 ping " << FlatbufferToJson(&ping) |
| 1554 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1555 | << pi2_event_loop->context().monotonic_event_time; |
| 1556 | EXPECT_EQ(ping.value(), pi2_ping_count + 1); |
| 1557 | |
| 1558 | ++pi2_ping_count; |
| 1559 | }); |
| 1560 | |
| 1561 | // Confirm that the ping and pong counts both match, and the value also |
| 1562 | // matches. |
| 1563 | pi1_event_loop->MakeWatcher( |
| 1564 | "/test", [&pi1_event_loop, &pi1_ping_count, |
| 1565 | &pi1_pong_count](const examples::Pong &pong) { |
| 1566 | VLOG(1) << "Pi1 pong " << FlatbufferToJson(&pong) << " at " |
| 1567 | << pi1_event_loop->context().monotonic_remote_time << " -> " |
| 1568 | << pi1_event_loop->context().monotonic_event_time; |
| 1569 | |
| 1570 | EXPECT_EQ(pong.value(), pi1_pong_count + 1); |
| 1571 | ++pi1_pong_count; |
| 1572 | EXPECT_EQ(pi1_ping_count, pi1_pong_count); |
| 1573 | }); |
| 1574 | pi2_event_loop->MakeWatcher( |
| 1575 | "/test", [&pi2_event_loop, &pi2_ping_count, |
| 1576 | &pi2_pong_count](const examples::Pong &pong) { |
| 1577 | VLOG(1) << "Pi2 pong " << FlatbufferToJson(&pong) << " at " |
| 1578 | << pi2_event_loop->context().monotonic_remote_time << " -> " |
| 1579 | << pi2_event_loop->context().monotonic_event_time; |
| 1580 | |
| 1581 | EXPECT_EQ(pong.value(), pi2_pong_count + 1); |
| 1582 | ++pi2_pong_count; |
| 1583 | EXPECT_EQ(pi2_ping_count, pi2_pong_count); |
| 1584 | }); |
| 1585 | |
| 1586 | log_reader_factory.Run(); |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 1587 | EXPECT_EQ(pi1_ping_count, 6030); |
| 1588 | EXPECT_EQ(pi2_ping_count, 6030); |
| 1589 | EXPECT_EQ(pi1_pong_count, 6030); |
| 1590 | EXPECT_EQ(pi2_pong_count, 6030); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 1591 | |
| 1592 | reader.Deregister(); |
| 1593 | } |
| 1594 | |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 1595 | // 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] | 1596 | TEST_P(MultinodeLoggerTest, SortParts) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1597 | time_converter_.StartEqual(); |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 1598 | // Make a bunch of parts. |
| 1599 | { |
| 1600 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1601 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 1602 | |
| 1603 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1604 | |
| 1605 | StartLogger(&pi1_logger); |
| 1606 | StartLogger(&pi2_logger); |
| 1607 | |
| 1608 | event_loop_factory_.RunFor(chrono::milliseconds(2000)); |
| 1609 | } |
| 1610 | |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 1611 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1612 | VerifyParts(sorted_parts); |
| 1613 | } |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 1614 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1615 | // Tests that we can sort a bunch of parts with an empty part. We should ignore |
| 1616 | // it and remove it from the sorted list. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1617 | TEST_P(MultinodeLoggerTest, SortEmptyParts) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1618 | time_converter_.StartEqual(); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1619 | // Make a bunch of parts. |
| 1620 | { |
| 1621 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1622 | LoggerState pi2_logger = MakeLogger(pi2_); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 1623 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1624 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 1625 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1626 | StartLogger(&pi1_logger); |
| 1627 | StartLogger(&pi2_logger); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 1628 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1629 | event_loop_factory_.RunFor(chrono::milliseconds(2000)); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1632 | // TODO(austin): Should we flip out if the file can't open? |
| 1633 | const std::string kEmptyFile("foobarinvalidfiledoesnotexist.bfbs"); |
Austin Schuh | 11d4373 | 2020-09-21 17:28:30 -0700 | [diff] [blame] | 1634 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1635 | aos::util::WriteStringToFileOrDie(kEmptyFile, ""); |
| 1636 | logfiles_.emplace_back(kEmptyFile); |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 1637 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1638 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
| 1639 | VerifyParts(sorted_parts, {kEmptyFile}); |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1642 | #ifdef LZMA |
| 1643 | // Tests that we can sort a bunch of parts with an empty .xz file in there. The |
| 1644 | // empty file should be ignored. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1645 | TEST_P(MultinodeLoggerTest, SortEmptyCompressedParts) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1646 | time_converter_.StartEqual(); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1647 | // Make a bunch of parts. |
| 1648 | { |
| 1649 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1650 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 1651 | |
| 1652 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1653 | |
| 1654 | StartLogger(&pi1_logger, "", true); |
| 1655 | StartLogger(&pi2_logger, "", true); |
| 1656 | |
| 1657 | event_loop_factory_.RunFor(chrono::milliseconds(2000)); |
| 1658 | } |
| 1659 | |
| 1660 | // TODO(austin): Should we flip out if the file can't open? |
| 1661 | const std::string kEmptyFile("foobarinvalidfiledoesnotexist.bfbs.xz"); |
| 1662 | |
| 1663 | AddExtension(".xz"); |
| 1664 | |
| 1665 | aos::util::WriteStringToFileOrDie(kEmptyFile, ""); |
| 1666 | logfiles_.emplace_back(kEmptyFile); |
| 1667 | |
| 1668 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
| 1669 | VerifyParts(sorted_parts, {kEmptyFile}); |
| 1670 | } |
| 1671 | |
| 1672 | // Tests that we can sort a bunch of parts with the end missing off a compressed |
| 1673 | // file. We should use the part we can read. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1674 | TEST_P(MultinodeLoggerTest, SortTruncatedCompressedParts) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1675 | time_converter_.StartEqual(); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1676 | // Make a bunch of parts. |
| 1677 | { |
| 1678 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1679 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 1680 | |
| 1681 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1682 | |
| 1683 | StartLogger(&pi1_logger, "", true); |
| 1684 | StartLogger(&pi2_logger, "", true); |
| 1685 | |
| 1686 | event_loop_factory_.RunFor(chrono::milliseconds(2000)); |
| 1687 | } |
| 1688 | |
| 1689 | // Append everything with .xz. |
| 1690 | AddExtension(".xz"); |
| 1691 | |
| 1692 | // Strip off the end of one of the files. Pick one with a lot of data. |
| 1693 | ::std::string compressed_contents = |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1694 | aos::util::ReadFileToStringOrDie(logfiles_[2]); |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1695 | |
| 1696 | aos::util::WriteStringToFileOrDie( |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1697 | logfiles_[2], |
Austin Schuh | 3bd4c40 | 2020-11-06 18:19:06 -0800 | [diff] [blame] | 1698 | compressed_contents.substr(0, compressed_contents.size() - 100)); |
| 1699 | |
| 1700 | const std::vector<LogFile> sorted_parts = SortParts(logfiles_); |
| 1701 | VerifyParts(sorted_parts); |
| 1702 | } |
| 1703 | #endif |
| 1704 | |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 1705 | // Tests that if we remap a remapped channel, it shows up correctly. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1706 | TEST_P(MultinodeLoggerTest, RemapLoggedChannel) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1707 | time_converter_.StartEqual(); |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 1708 | { |
| 1709 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1710 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 1711 | |
| 1712 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1713 | |
| 1714 | StartLogger(&pi1_logger); |
| 1715 | StartLogger(&pi2_logger); |
| 1716 | |
| 1717 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 1718 | } |
| 1719 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 1720 | LogReader reader(SortParts(logfiles_)); |
Austin Schuh | 01b4c35 | 2020-09-21 23:09:39 -0700 | [diff] [blame] | 1721 | |
| 1722 | // Remap just on pi1. |
| 1723 | reader.RemapLoggedChannel<aos::timing::Report>( |
| 1724 | "/aos", configuration::GetNode(reader.configuration(), "pi1")); |
| 1725 | |
| 1726 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 1727 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 1728 | |
| 1729 | reader.Register(&log_reader_factory); |
| 1730 | |
| 1731 | const Node *pi1 = |
| 1732 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 1733 | const Node *pi2 = |
| 1734 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 1735 | |
| 1736 | // Confirm we can read the data on the remapped channel, just for pi1. Nothing |
| 1737 | // else should have moved. |
| 1738 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 1739 | log_reader_factory.MakeEventLoop("test", pi1); |
| 1740 | pi1_event_loop->SkipTimingReport(); |
| 1741 | std::unique_ptr<EventLoop> full_pi1_event_loop = |
| 1742 | log_reader_factory.MakeEventLoop("test", pi1); |
| 1743 | full_pi1_event_loop->SkipTimingReport(); |
| 1744 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1745 | log_reader_factory.MakeEventLoop("test", pi2); |
| 1746 | pi2_event_loop->SkipTimingReport(); |
| 1747 | |
| 1748 | MessageCounter<aos::timing::Report> pi1_timing_report(pi1_event_loop.get(), |
| 1749 | "/aos"); |
| 1750 | MessageCounter<aos::timing::Report> full_pi1_timing_report( |
| 1751 | full_pi1_event_loop.get(), "/pi1/aos"); |
| 1752 | MessageCounter<aos::timing::Report> pi1_original_timing_report( |
| 1753 | pi1_event_loop.get(), "/original/aos"); |
| 1754 | MessageCounter<aos::timing::Report> full_pi1_original_timing_report( |
| 1755 | full_pi1_event_loop.get(), "/original/pi1/aos"); |
| 1756 | MessageCounter<aos::timing::Report> pi2_timing_report(pi2_event_loop.get(), |
| 1757 | "/aos"); |
| 1758 | |
| 1759 | log_reader_factory.Run(); |
| 1760 | |
| 1761 | EXPECT_EQ(pi1_timing_report.count(), 0u); |
| 1762 | EXPECT_EQ(full_pi1_timing_report.count(), 0u); |
| 1763 | EXPECT_NE(pi1_original_timing_report.count(), 0u); |
| 1764 | EXPECT_NE(full_pi1_original_timing_report.count(), 0u); |
| 1765 | EXPECT_NE(pi2_timing_report.count(), 0u); |
| 1766 | |
| 1767 | reader.Deregister(); |
| 1768 | } |
| 1769 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1770 | // Tests that we properly recreate forwarded timestamps when replaying a log. |
| 1771 | // This should be enough that we can then re-run the logger and get a valid log |
| 1772 | // back. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1773 | TEST_P(MultinodeLoggerTest, MessageHeader) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 1774 | time_converter_.StartEqual(); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1775 | { |
| 1776 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 1777 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 1778 | |
| 1779 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 1780 | |
| 1781 | StartLogger(&pi1_logger); |
| 1782 | StartLogger(&pi2_logger); |
| 1783 | |
| 1784 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 1785 | } |
| 1786 | |
Austin Schuh | 287d43d | 2020-12-04 20:19:33 -0800 | [diff] [blame] | 1787 | LogReader reader(SortParts(logfiles_)); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1788 | |
| 1789 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 1790 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 1791 | |
| 1792 | // This sends out the fetched messages and advances time to the start of the |
| 1793 | // log file. |
| 1794 | reader.Register(&log_reader_factory); |
| 1795 | |
| 1796 | const Node *pi1 = |
| 1797 | configuration::GetNode(log_reader_factory.configuration(), "pi1"); |
| 1798 | const Node *pi2 = |
| 1799 | configuration::GetNode(log_reader_factory.configuration(), "pi2"); |
| 1800 | |
| 1801 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi1) << " pi1"; |
| 1802 | LOG(INFO) << "Start time " << reader.monotonic_start_time(pi2) << " pi2"; |
| 1803 | LOG(INFO) << "now pi1 " |
| 1804 | << log_reader_factory.GetNodeEventLoopFactory(pi1)->monotonic_now(); |
| 1805 | LOG(INFO) << "now pi2 " |
| 1806 | << log_reader_factory.GetNodeEventLoopFactory(pi2)->monotonic_now(); |
| 1807 | |
Austin Schuh | 0767662 | 2021-01-21 18:59:17 -0800 | [diff] [blame] | 1808 | EXPECT_THAT(reader.LoggedNodes(), |
| 1809 | ::testing::ElementsAre( |
| 1810 | configuration::GetNode(reader.logged_configuration(), pi1), |
| 1811 | configuration::GetNode(reader.logged_configuration(), pi2))); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1812 | |
| 1813 | reader.event_loop_factory()->set_send_delay(chrono::microseconds(0)); |
| 1814 | |
| 1815 | std::unique_ptr<EventLoop> pi1_event_loop = |
| 1816 | log_reader_factory.MakeEventLoop("test", pi1); |
| 1817 | std::unique_ptr<EventLoop> pi2_event_loop = |
| 1818 | log_reader_factory.MakeEventLoop("test", pi2); |
| 1819 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1820 | aos::Fetcher<message_bridge::Timestamp> pi1_timestamp_on_pi1_fetcher = |
| 1821 | pi1_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi1/aos"); |
| 1822 | aos::Fetcher<message_bridge::Timestamp> pi1_timestamp_on_pi2_fetcher = |
| 1823 | pi2_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi1/aos"); |
| 1824 | |
| 1825 | aos::Fetcher<examples::Ping> ping_on_pi1_fetcher = |
| 1826 | pi1_event_loop->MakeFetcher<examples::Ping>("/test"); |
| 1827 | aos::Fetcher<examples::Ping> ping_on_pi2_fetcher = |
| 1828 | pi2_event_loop->MakeFetcher<examples::Ping>("/test"); |
| 1829 | |
| 1830 | aos::Fetcher<message_bridge::Timestamp> pi2_timestamp_on_pi2_fetcher = |
| 1831 | pi2_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi2/aos"); |
| 1832 | aos::Fetcher<message_bridge::Timestamp> pi2_timestamp_on_pi1_fetcher = |
| 1833 | pi1_event_loop->MakeFetcher<message_bridge::Timestamp>("/pi2/aos"); |
| 1834 | |
| 1835 | aos::Fetcher<examples::Pong> pong_on_pi2_fetcher = |
| 1836 | pi2_event_loop->MakeFetcher<examples::Pong>("/test"); |
| 1837 | aos::Fetcher<examples::Pong> pong_on_pi1_fetcher = |
| 1838 | pi1_event_loop->MakeFetcher<examples::Pong>("/test"); |
| 1839 | |
| 1840 | const size_t pi1_timestamp_channel = configuration::ChannelIndex( |
| 1841 | pi1_event_loop->configuration(), pi1_timestamp_on_pi1_fetcher.channel()); |
| 1842 | const size_t ping_timestamp_channel = configuration::ChannelIndex( |
| 1843 | pi2_event_loop->configuration(), ping_on_pi2_fetcher.channel()); |
| 1844 | |
| 1845 | const size_t pi2_timestamp_channel = configuration::ChannelIndex( |
| 1846 | pi2_event_loop->configuration(), pi2_timestamp_on_pi2_fetcher.channel()); |
| 1847 | const size_t pong_timestamp_channel = configuration::ChannelIndex( |
| 1848 | pi1_event_loop->configuration(), pong_on_pi1_fetcher.channel()); |
| 1849 | |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 1850 | const chrono::nanoseconds network_delay = event_loop_factory_.network_delay(); |
Austin Schuh | 816e5d6 | 2021-01-05 23:42:20 -0800 | [diff] [blame] | 1851 | const chrono::nanoseconds send_delay = event_loop_factory_.send_delay(); |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 1852 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1853 | for (std::pair<int, std::string> channel : |
| 1854 | shared() |
| 1855 | ? std::vector< |
| 1856 | std::pair<int, std::string>>{{-1, |
| 1857 | "/aos/remote_timestamps/pi2"}} |
| 1858 | : std::vector<std::pair<int, std::string>>{ |
| 1859 | {pi1_timestamp_channel, |
| 1860 | "/aos/remote_timestamps/pi2/pi1/aos/" |
| 1861 | "aos-message_bridge-Timestamp"}, |
| 1862 | {ping_timestamp_channel, |
| 1863 | "/aos/remote_timestamps/pi2/test/aos-examples-Ping"}}) { |
| 1864 | pi1_event_loop->MakeWatcher( |
| 1865 | channel.second, |
| 1866 | [&pi1_event_loop, &pi2_event_loop, pi1_timestamp_channel, |
| 1867 | ping_timestamp_channel, &pi1_timestamp_on_pi1_fetcher, |
| 1868 | &pi1_timestamp_on_pi2_fetcher, &ping_on_pi1_fetcher, |
| 1869 | &ping_on_pi2_fetcher, network_delay, send_delay, |
| 1870 | channel_index = channel.first](const RemoteMessage &header) { |
| 1871 | const aos::monotonic_clock::time_point header_monotonic_sent_time( |
| 1872 | chrono::nanoseconds(header.monotonic_sent_time())); |
| 1873 | const aos::realtime_clock::time_point header_realtime_sent_time( |
| 1874 | chrono::nanoseconds(header.realtime_sent_time())); |
| 1875 | const aos::monotonic_clock::time_point header_monotonic_remote_time( |
| 1876 | chrono::nanoseconds(header.monotonic_remote_time())); |
| 1877 | const aos::realtime_clock::time_point header_realtime_remote_time( |
| 1878 | chrono::nanoseconds(header.realtime_remote_time())); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1879 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1880 | if (channel_index != -1) { |
| 1881 | ASSERT_EQ(channel_index, header.channel_index()); |
| 1882 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1883 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1884 | const Context *pi1_context = nullptr; |
| 1885 | const Context *pi2_context = nullptr; |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1886 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1887 | if (header.channel_index() == pi1_timestamp_channel) { |
| 1888 | ASSERT_TRUE(pi1_timestamp_on_pi1_fetcher.FetchNext()); |
| 1889 | ASSERT_TRUE(pi1_timestamp_on_pi2_fetcher.FetchNext()); |
| 1890 | pi1_context = &pi1_timestamp_on_pi1_fetcher.context(); |
| 1891 | pi2_context = &pi1_timestamp_on_pi2_fetcher.context(); |
| 1892 | } else if (header.channel_index() == ping_timestamp_channel) { |
| 1893 | ASSERT_TRUE(ping_on_pi1_fetcher.FetchNext()); |
| 1894 | ASSERT_TRUE(ping_on_pi2_fetcher.FetchNext()); |
| 1895 | pi1_context = &ping_on_pi1_fetcher.context(); |
| 1896 | pi2_context = &ping_on_pi2_fetcher.context(); |
| 1897 | } else { |
| 1898 | LOG(FATAL) << "Unknown channel " << FlatbufferToJson(&header) << " " |
| 1899 | << configuration::CleanedChannelToString( |
| 1900 | pi1_event_loop->configuration()->channels()->Get( |
| 1901 | header.channel_index())); |
| 1902 | } |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 1903 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1904 | ASSERT_TRUE(header.has_boot_uuid()); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 1905 | EXPECT_EQ(UUID::FromVector(header.boot_uuid()), |
| 1906 | pi2_event_loop->boot_uuid()); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1907 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1908 | EXPECT_EQ(pi1_context->queue_index, header.remote_queue_index()); |
| 1909 | EXPECT_EQ(pi2_context->remote_queue_index, |
| 1910 | header.remote_queue_index()); |
| 1911 | EXPECT_EQ(pi2_context->queue_index, header.queue_index()); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1912 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1913 | EXPECT_EQ(pi2_context->monotonic_event_time, |
| 1914 | header_monotonic_sent_time); |
| 1915 | EXPECT_EQ(pi2_context->realtime_event_time, |
| 1916 | header_realtime_sent_time); |
| 1917 | EXPECT_EQ(pi2_context->realtime_remote_time, |
| 1918 | header_realtime_remote_time); |
| 1919 | EXPECT_EQ(pi2_context->monotonic_remote_time, |
| 1920 | header_monotonic_remote_time); |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 1921 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1922 | EXPECT_EQ(pi1_context->realtime_event_time, |
| 1923 | header_realtime_remote_time); |
| 1924 | EXPECT_EQ(pi1_context->monotonic_event_time, |
| 1925 | header_monotonic_remote_time); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1926 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1927 | // Time estimation isn't perfect, but we know the clocks were |
| 1928 | // identical when logged, so we know when this should have come back. |
| 1929 | // Confirm we got it when we expected. |
| 1930 | EXPECT_EQ(pi1_event_loop->context().monotonic_event_time, |
| 1931 | pi1_context->monotonic_event_time + 2 * network_delay + |
| 1932 | send_delay); |
| 1933 | }); |
| 1934 | } |
| 1935 | for (std::pair<int, std::string> channel : |
| 1936 | shared() |
| 1937 | ? std::vector< |
| 1938 | std::pair<int, std::string>>{{-1, |
| 1939 | "/aos/remote_timestamps/pi1"}} |
| 1940 | : std::vector<std::pair<int, std::string>>{ |
| 1941 | {pi2_timestamp_channel, |
| 1942 | "/aos/remote_timestamps/pi1/pi2/aos/" |
| 1943 | "aos-message_bridge-Timestamp"}}) { |
| 1944 | pi2_event_loop->MakeWatcher( |
| 1945 | channel.second, |
| 1946 | [&pi2_event_loop, &pi1_event_loop, pi2_timestamp_channel, |
| 1947 | pong_timestamp_channel, &pi2_timestamp_on_pi2_fetcher, |
| 1948 | &pi2_timestamp_on_pi1_fetcher, &pong_on_pi2_fetcher, |
| 1949 | &pong_on_pi1_fetcher, network_delay, send_delay, |
| 1950 | channel_index = channel.first](const RemoteMessage &header) { |
| 1951 | const aos::monotonic_clock::time_point header_monotonic_sent_time( |
| 1952 | chrono::nanoseconds(header.monotonic_sent_time())); |
| 1953 | const aos::realtime_clock::time_point header_realtime_sent_time( |
| 1954 | chrono::nanoseconds(header.realtime_sent_time())); |
| 1955 | const aos::monotonic_clock::time_point header_monotonic_remote_time( |
| 1956 | chrono::nanoseconds(header.monotonic_remote_time())); |
| 1957 | const aos::realtime_clock::time_point header_realtime_remote_time( |
| 1958 | chrono::nanoseconds(header.realtime_remote_time())); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1959 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1960 | if (channel_index != -1) { |
| 1961 | ASSERT_EQ(channel_index, header.channel_index()); |
| 1962 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1963 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1964 | const Context *pi2_context = nullptr; |
| 1965 | const Context *pi1_context = nullptr; |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 1966 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1967 | if (header.channel_index() == pi2_timestamp_channel) { |
| 1968 | ASSERT_TRUE(pi2_timestamp_on_pi2_fetcher.FetchNext()); |
| 1969 | ASSERT_TRUE(pi2_timestamp_on_pi1_fetcher.FetchNext()); |
| 1970 | pi2_context = &pi2_timestamp_on_pi2_fetcher.context(); |
| 1971 | pi1_context = &pi2_timestamp_on_pi1_fetcher.context(); |
| 1972 | } else if (header.channel_index() == pong_timestamp_channel) { |
| 1973 | ASSERT_TRUE(pong_on_pi2_fetcher.FetchNext()); |
| 1974 | ASSERT_TRUE(pong_on_pi1_fetcher.FetchNext()); |
| 1975 | pi2_context = &pong_on_pi2_fetcher.context(); |
| 1976 | pi1_context = &pong_on_pi1_fetcher.context(); |
| 1977 | } else { |
| 1978 | LOG(FATAL) << "Unknown channel " << FlatbufferToJson(&header) << " " |
| 1979 | << configuration::CleanedChannelToString( |
| 1980 | pi2_event_loop->configuration()->channels()->Get( |
| 1981 | header.channel_index())); |
| 1982 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1983 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1984 | ASSERT_TRUE(header.has_boot_uuid()); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 1985 | EXPECT_EQ(UUID::FromVector(header.boot_uuid()), |
| 1986 | pi1_event_loop->boot_uuid()); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 1987 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1988 | EXPECT_EQ(pi2_context->queue_index, header.remote_queue_index()); |
| 1989 | EXPECT_EQ(pi1_context->remote_queue_index, |
| 1990 | header.remote_queue_index()); |
| 1991 | EXPECT_EQ(pi1_context->queue_index, header.queue_index()); |
Austin Schuh | 969cd60 | 2021-01-03 00:09:45 -0800 | [diff] [blame] | 1992 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 1993 | EXPECT_EQ(pi1_context->monotonic_event_time, |
| 1994 | header_monotonic_sent_time); |
| 1995 | EXPECT_EQ(pi1_context->realtime_event_time, |
| 1996 | header_realtime_sent_time); |
| 1997 | EXPECT_EQ(pi1_context->realtime_remote_time, |
| 1998 | header_realtime_remote_time); |
| 1999 | EXPECT_EQ(pi1_context->monotonic_remote_time, |
| 2000 | header_monotonic_remote_time); |
| 2001 | |
| 2002 | EXPECT_EQ(pi2_context->realtime_event_time, |
| 2003 | header_realtime_remote_time); |
| 2004 | EXPECT_EQ(pi2_context->monotonic_event_time, |
| 2005 | header_monotonic_remote_time); |
| 2006 | |
| 2007 | // Time estimation isn't perfect, but we know the clocks were |
| 2008 | // identical when logged, so we know when this should have come back. |
| 2009 | // Confirm we got it when we expected. |
| 2010 | EXPECT_EQ(pi2_event_loop->context().monotonic_event_time, |
| 2011 | pi2_context->monotonic_event_time + 2 * network_delay + |
| 2012 | send_delay); |
| 2013 | }); |
| 2014 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2015 | |
| 2016 | // And confirm we can re-create a log again, while checking the contents. |
| 2017 | { |
| 2018 | LoggerState pi1_logger = MakeLogger( |
| 2019 | configuration::GetNode(log_reader_factory.configuration(), pi1_), |
| 2020 | &log_reader_factory); |
| 2021 | LoggerState pi2_logger = MakeLogger( |
| 2022 | configuration::GetNode(log_reader_factory.configuration(), pi2_), |
| 2023 | &log_reader_factory); |
| 2024 | |
Austin Schuh | 25b4671 | 2021-01-03 00:04:38 -0800 | [diff] [blame] | 2025 | StartLogger(&pi1_logger, tmp_dir_ + "/relogged1"); |
| 2026 | StartLogger(&pi2_logger, tmp_dir_ + "/relogged2"); |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2027 | |
| 2028 | log_reader_factory.Run(); |
| 2029 | } |
| 2030 | |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2031 | reader.Deregister(); |
James Kuszmaul | 4f106fb | 2021-01-05 20:53:02 -0800 | [diff] [blame] | 2032 | |
| 2033 | // And verify that we can run the LogReader over the relogged files without |
| 2034 | // hitting any fatal errors. |
| 2035 | { |
| 2036 | LogReader relogged_reader(SortParts( |
| 2037 | MakeLogFiles(tmp_dir_ + "/relogged1", tmp_dir_ + "/relogged2"))); |
| 2038 | relogged_reader.Register(); |
| 2039 | |
| 2040 | relogged_reader.event_loop_factory()->Run(); |
| 2041 | } |
Austin Schuh | 8d7e0bb | 2020-10-02 17:57:00 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2044 | // Tests that we properly populate and extract the logger_start time by setting |
| 2045 | // 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] | 2046 | TEST_P(MultinodeLoggerTest, LoggerStartTime) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2047 | time_converter_.AddMonotonic( |
| 2048 | {monotonic_clock::epoch(), |
| 2049 | monotonic_clock::epoch() + chrono::seconds(1000)}); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2050 | { |
| 2051 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2052 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2053 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2054 | StartLogger(&pi1_logger); |
| 2055 | StartLogger(&pi2_logger); |
| 2056 | |
| 2057 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2058 | } |
| 2059 | |
| 2060 | for (const LogFile &log_file : SortParts(logfiles_)) { |
| 2061 | for (const LogParts &log_part : log_file.parts) { |
| 2062 | if (log_part.node == log_file.logger_node) { |
| 2063 | EXPECT_EQ(log_part.logger_monotonic_start_time, |
| 2064 | aos::monotonic_clock::min_time); |
| 2065 | EXPECT_EQ(log_part.logger_realtime_start_time, |
| 2066 | aos::realtime_clock::min_time); |
| 2067 | } else { |
| 2068 | const chrono::seconds offset = log_file.logger_node == "pi1" |
| 2069 | ? -chrono::seconds(1000) |
| 2070 | : chrono::seconds(1000); |
| 2071 | EXPECT_EQ(log_part.logger_monotonic_start_time, |
| 2072 | log_part.monotonic_start_time + offset); |
| 2073 | EXPECT_EQ(log_part.logger_realtime_start_time, |
| 2074 | log_file.realtime_start_time + |
| 2075 | (log_part.logger_monotonic_start_time - |
| 2076 | log_file.monotonic_start_time)); |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | } |
| 2081 | |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame^] | 2082 | // Test that renaming the base, renames the folder. |
| 2083 | TEST_F(MultinodeLoggerTest, LoggerRenameFolder) { |
| 2084 | time_converter_.AddMonotonic( |
| 2085 | {monotonic_clock::epoch(), |
| 2086 | monotonic_clock::epoch() + chrono::seconds(1000)}); |
| 2087 | logfile_base1_ = tmp_dir_ + "/renamefolder/multi_logfile1"; |
| 2088 | logfile_base2_ = tmp_dir_ + "/renamefolder/multi_logfile2"; |
| 2089 | logfiles_ = MakeLogFiles(logfile_base1_, logfile_base2_); |
| 2090 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2091 | LoggerState pi2_logger = MakeLogger(pi2_); |
| 2092 | |
| 2093 | StartLogger(&pi1_logger); |
| 2094 | StartLogger(&pi2_logger); |
| 2095 | |
| 2096 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2097 | logfile_base1_ = tmp_dir_ + "/new-good/multi_logfile1"; |
| 2098 | logfile_base2_ = tmp_dir_ + "/new-good/multi_logfile2"; |
| 2099 | logfiles_ = MakeLogFiles(logfile_base1_, logfile_base2_); |
| 2100 | ASSERT_TRUE(pi1_logger.logger->RenameLogBase(logfile_base1_)); |
| 2101 | ASSERT_TRUE(pi2_logger.logger->RenameLogBase(logfile_base2_)); |
| 2102 | for (auto &file : logfiles_) { |
| 2103 | struct stat s; |
| 2104 | EXPECT_EQ(0, stat(file.c_str(), &s)); |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | // Test that renaming the file base dies. |
| 2109 | TEST_P(MultinodeLoggerDeathTest, LoggerRenameFile) { |
| 2110 | time_converter_.AddMonotonic( |
| 2111 | {monotonic_clock::epoch(), |
| 2112 | monotonic_clock::epoch() + chrono::seconds(1000)}); |
| 2113 | logfile_base1_ = tmp_dir_ + "/renamefile/multi_logfile1"; |
| 2114 | logfile_base2_ = tmp_dir_ + "/renamefile/multi_logfile2"; |
| 2115 | logfiles_ = MakeLogFiles(logfile_base1_, logfile_base2_); |
| 2116 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2117 | StartLogger(&pi1_logger); |
| 2118 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2119 | logfile_base1_ = tmp_dir_ + "/new-renamefile/new_multi_logfile1"; |
| 2120 | EXPECT_DEATH({ pi1_logger.logger->RenameLogBase(logfile_base1_); }, |
| 2121 | "Rename of file base from"); |
| 2122 | } |
| 2123 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 2124 | // TODO(austin): We can write a test which recreates a logfile and confirms that |
| 2125 | // we get it back. That is the ultimate test. |
| 2126 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2127 | // Tests that we properly recreate forwarded timestamps when replaying a log. |
| 2128 | // This should be enough that we can then re-run the logger and get a valid log |
| 2129 | // back. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2130 | TEST_P(MultinodeLoggerDeathTest, RemoteReboot) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2131 | time_converter_.StartEqual(); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2132 | std::string pi2_boot1; |
| 2133 | std::string pi2_boot2; |
| 2134 | { |
| 2135 | pi2_boot1 = event_loop_factory_.GetNodeEventLoopFactory(pi2_) |
| 2136 | ->boot_uuid() |
Austin Schuh | 5e2bfb8 | 2021-03-13 22:46:55 -0800 | [diff] [blame] | 2137 | .ToString(); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2138 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2139 | |
| 2140 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2141 | |
| 2142 | StartLogger(&pi1_logger); |
| 2143 | |
| 2144 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2145 | |
| 2146 | event_loop_factory_.GetNodeEventLoopFactory(pi2_)->Reboot(); |
| 2147 | |
| 2148 | pi2_boot2 = event_loop_factory_.GetNodeEventLoopFactory(pi2_) |
| 2149 | ->boot_uuid() |
Austin Schuh | 5e2bfb8 | 2021-03-13 22:46:55 -0800 | [diff] [blame] | 2150 | .ToString(); |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 2151 | |
| 2152 | event_loop_factory_.RunFor(chrono::milliseconds(20000)); |
| 2153 | } |
| 2154 | |
| 2155 | // Confirm that we refuse to replay logs with missing boot uuids. |
| 2156 | EXPECT_DEATH( |
| 2157 | { |
| 2158 | LogReader reader(SortParts(pi1_reboot_logfiles_)); |
| 2159 | |
| 2160 | SimulatedEventLoopFactory log_reader_factory(reader.configuration()); |
| 2161 | log_reader_factory.set_send_delay(chrono::microseconds(0)); |
| 2162 | |
| 2163 | // This sends out the fetched messages and advances time to the start of |
| 2164 | // the log file. |
| 2165 | reader.Register(&log_reader_factory); |
| 2166 | }, |
| 2167 | absl::StrFormat("(%s|%s).*(%s|%s).*Found parts from different boots", |
| 2168 | pi2_boot1, pi2_boot2, pi2_boot2, pi2_boot1)); |
| 2169 | } |
| 2170 | |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 2171 | // Tests that we properly handle one direction of message_bridge being |
| 2172 | // unavailable. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2173 | TEST_P(MultinodeLoggerTest, OneDirectionWithNegativeSlope) { |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 2174 | event_loop_factory_.GetNodeEventLoopFactory(pi1_)->Disconnect(pi2_); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2175 | time_converter_.AddMonotonic( |
| 2176 | {monotonic_clock::epoch(), |
| 2177 | monotonic_clock::epoch() + chrono::seconds(1000)}); |
| 2178 | |
| 2179 | time_converter_.AddMonotonic( |
| 2180 | {chrono::milliseconds(10000), |
| 2181 | chrono::milliseconds(10000) - chrono::milliseconds(1)}); |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 2182 | { |
| 2183 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2184 | |
| 2185 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2186 | |
| 2187 | StartLogger(&pi1_logger); |
| 2188 | |
| 2189 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2190 | } |
| 2191 | |
| 2192 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 2193 | // to confirm the right thing happened. |
| 2194 | ConfirmReadable(pi1_single_direction_logfiles_); |
| 2195 | } |
| 2196 | |
| 2197 | // Tests that we properly handle one direction of message_bridge being |
| 2198 | // unavailable. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2199 | TEST_P(MultinodeLoggerTest, OneDirectionWithPositiveSlope) { |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 2200 | event_loop_factory_.GetNodeEventLoopFactory(pi1_)->Disconnect(pi2_); |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2201 | time_converter_.AddMonotonic( |
| 2202 | {monotonic_clock::epoch(), |
| 2203 | monotonic_clock::epoch() + chrono::seconds(500)}); |
| 2204 | |
| 2205 | time_converter_.AddMonotonic( |
| 2206 | {chrono::milliseconds(10000), |
| 2207 | chrono::milliseconds(10000) + chrono::milliseconds(1)}); |
| 2208 | { |
| 2209 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2210 | |
| 2211 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2212 | |
| 2213 | StartLogger(&pi1_logger); |
| 2214 | |
| 2215 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2216 | } |
| 2217 | |
| 2218 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 2219 | // to confirm the right thing happened. |
| 2220 | ConfirmReadable(pi1_single_direction_logfiles_); |
| 2221 | } |
| 2222 | |
| 2223 | // Tests that we properly handle a dead node. Do this by just disconnecting it |
| 2224 | // and only using one nodes of logs. |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2225 | TEST_P(MultinodeLoggerTest, DeadNode) { |
Austin Schuh | 87dd383 | 2021-01-01 23:07:31 -0800 | [diff] [blame] | 2226 | event_loop_factory_.GetNodeEventLoopFactory(pi1_)->Disconnect(pi2_); |
| 2227 | event_loop_factory_.GetNodeEventLoopFactory(pi2_)->Disconnect(pi1_); |
| 2228 | time_converter_.AddMonotonic( |
| 2229 | {monotonic_clock::epoch(), |
| 2230 | monotonic_clock::epoch() + chrono::seconds(1000)}); |
Austin Schuh | c904973 | 2020-12-21 22:27:15 -0800 | [diff] [blame] | 2231 | { |
| 2232 | LoggerState pi1_logger = MakeLogger(pi1_); |
| 2233 | |
| 2234 | event_loop_factory_.RunFor(chrono::milliseconds(95)); |
| 2235 | |
| 2236 | StartLogger(&pi1_logger); |
| 2237 | |
| 2238 | event_loop_factory_.RunFor(chrono::milliseconds(10000)); |
| 2239 | } |
| 2240 | |
| 2241 | // Confirm that we can parse the result. LogReader has enough internal CHECKs |
| 2242 | // to confirm the right thing happened. |
| 2243 | ConfirmReadable(pi1_single_direction_logfiles_); |
| 2244 | } |
| 2245 | |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 2246 | constexpr std::string_view kCombinedConfigSha1( |
Austin Schuh | e61d438 | 2021-03-31 21:33:02 -0700 | [diff] [blame] | 2247 | "0184681f8b83b5b9902a88ab12504c06b780907f6d156353bd958ebcf9389ef9"); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 2248 | constexpr std::string_view kSplitConfigSha1( |
Austin Schuh | e61d438 | 2021-03-31 21:33:02 -0700 | [diff] [blame] | 2249 | "1020274679a8f8c15ea20a48e4a35dd59a435203e5f31a57e15355e5a6ee31f7"); |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 2250 | |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2251 | INSTANTIATE_TEST_CASE_P( |
| 2252 | All, MultinodeLoggerTest, |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 2253 | ::testing::Values(Param{"multinode_pingpong_combined_config.json", true, |
| 2254 | kCombinedConfigSha1}, |
| 2255 | Param{"multinode_pingpong_split_config.json", false, |
| 2256 | kSplitConfigSha1})); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2257 | |
| 2258 | INSTANTIATE_TEST_CASE_P( |
| 2259 | All, MultinodeLoggerDeathTest, |
Austin Schuh | cdd9027 | 2021-03-15 12:46:16 -0700 | [diff] [blame] | 2260 | ::testing::Values(Param{"multinode_pingpong_combined_config.json", true, |
| 2261 | kCombinedConfigSha1}, |
| 2262 | Param{"multinode_pingpong_split_config.json", false, |
| 2263 | kSplitConfigSha1})); |
Austin Schuh | 61e973f | 2021-02-21 21:43:56 -0800 | [diff] [blame] | 2264 | |
Austin Schuh | a04efed | 2021-01-24 18:04:20 -0800 | [diff] [blame] | 2265 | // TODO(austin): Make a log file where the remote node has no start time. |
| 2266 | |
Austin Schuh | e309d2a | 2019-11-29 13:25:21 -0800 | [diff] [blame] | 2267 | } // namespace testing |
| 2268 | } // namespace logger |
| 2269 | } // namespace aos |