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