Add test for ChannelsInLog() function

Change-Id: I857a76039a30f693bc5d82bd7e91c3bd593cb995
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/BUILD b/aos/events/logging/BUILD
index 9b179ba..1edc142 100644
--- a/aos/events/logging/BUILD
+++ b/aos/events/logging/BUILD
@@ -642,6 +642,19 @@
 )
 
 cc_test(
+    name = "log_reader_utils_test",
+    srcs = ["log_reader_utils_test.cc"],
+    data = [
+        ":multinode_pingpong_combined_config",
+    ],
+    target_compatible_with = ["@platforms//os:linux"],
+    deps = [
+        ":log_reader_utils",
+        ":multinode_logger_test_lib",
+    ],
+)
+
+cc_test(
     name = "multinode_logger_test",
     srcs = ["multinode_logger_test.cc"],
     copts = select({
diff --git a/aos/events/logging/log_reader_utils_test.cc b/aos/events/logging/log_reader_utils_test.cc
new file mode 100644
index 0000000..680b472
--- /dev/null
+++ b/aos/events/logging/log_reader_utils_test.cc
@@ -0,0 +1,79 @@
+#include "aos/events/logging/log_reader_utils.h"
+
+#include "aos/events/logging/multinode_logger_test_lib.h"
+
+namespace aos::logger::testing {
+
+namespace chrono = std::chrono;
+// Created this test fixture because the test case checks for channel names
+// which are different in different configs
+using MultinodeLoggerOneConfigTest = MultinodeLoggerTest;
+
+INSTANTIATE_TEST_SUITE_P(
+    All, MultinodeLoggerOneConfigTest,
+    ::testing::Combine(::testing::Values(ConfigParams{
+                           "multinode_pingpong_combined_config.json", true,
+                           kCombinedConfigSha1(), kCombinedConfigSha1()}),
+                       ::testing::ValuesIn(SupportedCompressionAlgorithms())));
+
+// This test is to check if we are able to get the right channels from a log
+// given nodes and applications using the function ChannelsInLog
+TEST_P(MultinodeLoggerOneConfigTest, ChannelsInLogTest) {
+  // Run the logger
+  time_converter_.StartEqual();
+  {
+    LoggerState pi1_logger = MakeLogger(pi1_);
+    LoggerState pi2_logger = MakeLogger(pi2_);
+
+    event_loop_factory_.RunFor(chrono::milliseconds(95));
+
+    StartLogger(&pi1_logger);
+    StartLogger(&pi2_logger);
+
+    event_loop_factory_.RunFor(chrono::milliseconds(20000));
+  }
+
+  auto sorted_parts = SortParts(logfiles_);
+  // Read all the sorted log files
+  LogReader reader(sorted_parts);
+
+  std::vector<const Node *> active_nodes;
+  std::vector<std::string> applications;
+  // Get the active node
+  active_nodes.emplace_back(
+      configuration::GetNode(reader.configuration(), "pi1"));
+
+  // Get the application for which you want to check channels
+  applications.push_back("ping");
+  aos::logger::ChannelsInLogResult channels =
+      aos::logger::ChannelsInLog(sorted_parts, active_nodes, applications);
+
+  // Check for the right sender channels
+  std::vector<std::string> expected_senders;
+  expected_senders.push_back("/pi1/aos aos.logging.LogMessageFbs");
+  expected_senders.push_back("/pi1/aos aos.timing.Report");
+  expected_senders.push_back("/test aos.examples.Ping");
+
+  std::vector<std::string> check_senders;
+  for (const auto &sender : channels.senders.value()) {
+    check_senders.push_back(sender.name + " " + sender.type);
+  }
+  ASSERT_THAT(check_senders,
+              ::testing::UnorderedElementsAreArray(expected_senders));
+  ASSERT_EQ(channels.senders.value().size(), 3);
+
+  // Check for the right watcher channels
+  std::vector<std::string> expected_watchers;
+  expected_watchers.push_back("/test aos.examples.Pong");
+  std::vector<std::string> check_watchers;
+  for (const auto &watcher : channels.watchers.value()) {
+    check_watchers.push_back(watcher.name + " " + watcher.type);
+  }
+  ASSERT_THAT(check_watchers,
+              ::testing::UnorderedElementsAreArray(expected_watchers));
+  ASSERT_EQ(channels.watchers.value().size(), 1);
+
+  // There no fetcher channels, check for none
+  ASSERT_EQ(channels.fetchers.value().size(), 0);
+}
+}  // namespace aos::logger::testing
diff --git a/aos/events/logging/multinode_logger_test.cc b/aos/events/logging/multinode_logger_test.cc
index bc1f5b8..f1784bf 100644
--- a/aos/events/logging/multinode_logger_test.cc
+++ b/aos/events/logging/multinode_logger_test.cc
@@ -18,21 +18,14 @@
 using aos::testing::ArtifactPath;
 using aos::testing::MessageCounter;
 
-constexpr std::string_view kCombinedConfigSha1(
-    "5d73fe35bacaa59d24f8f0c1a806fe10b783b0fcc80809ee30a9db824e82538b");
-constexpr std::string_view kSplitConfigSha1(
-    "f25e8f6f90d61f41c41517e652300566228b077e44cd86f1af2af4a9bed31ad4");
-constexpr std::string_view kReloggedSplitConfigSha1(
-    "f1fabd629bdf8735c3d81bc791d7a454e8e636951c26cba6426545cbc97f911f");
-
 INSTANTIATE_TEST_SUITE_P(
     All, MultinodeLoggerTest,
     ::testing::Combine(
         ::testing::Values(
             ConfigParams{"multinode_pingpong_combined_config.json", true,
-                         kCombinedConfigSha1, kCombinedConfigSha1},
+                         kCombinedConfigSha1(), kCombinedConfigSha1()},
             ConfigParams{"multinode_pingpong_split_config.json", false,
-                         kSplitConfigSha1, kReloggedSplitConfigSha1}),
+                         kSplitConfigSha1(), kReloggedSplitConfigSha1()}),
         ::testing::ValuesIn(SupportedCompressionAlgorithms())));
 
 INSTANTIATE_TEST_SUITE_P(
@@ -40,9 +33,9 @@
     ::testing::Combine(
         ::testing::Values(
             ConfigParams{"multinode_pingpong_combined_config.json", true,
-                         kCombinedConfigSha1, kCombinedConfigSha1},
+                         kCombinedConfigSha1(), kCombinedConfigSha1()},
             ConfigParams{"multinode_pingpong_split_config.json", false,
-                         kSplitConfigSha1, kReloggedSplitConfigSha1}),
+                         kSplitConfigSha1(), kReloggedSplitConfigSha1()}),
         ::testing::ValuesIn(SupportedCompressionAlgorithms())));
 
 // Tests that we can write and read simple multi-node log files.
diff --git a/aos/events/logging/multinode_logger_test_lib.h b/aos/events/logging/multinode_logger_test_lib.h
index d3754e4..f3f322e 100644
--- a/aos/events/logging/multinode_logger_test_lib.h
+++ b/aos/events/logging/multinode_logger_test_lib.h
@@ -55,6 +55,16 @@
   ~LoggerState();
 };
 
+constexpr std::string_view kCombinedConfigSha1() {
+  return "5d73fe35bacaa59d24f8f0c1a806fe10b783b0fcc80809ee30a9db824e82538b";
+}
+constexpr std::string_view kSplitConfigSha1() {
+  return "f25e8f6f90d61f41c41517e652300566228b077e44cd86f1af2af4a9bed31ad4";
+}
+constexpr std::string_view kReloggedSplitConfigSha1() {
+  return "f1fabd629bdf8735c3d81bc791d7a454e8e636951c26cba6426545cbc97f911f";
+}
+
 LoggerState MakeLoggerState(NodeEventLoopFactory *node,
                             SimulatedEventLoopFactory *factory,
                             CompressionParams params,