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