Adding a basic config validator

Signed-off-by: Milo Lin <100027790@mvla.net>
Change-Id: I1226cf2a9483fecad37a197a8acabdf095c4d395
diff --git a/aos/util/BUILD b/aos/util/BUILD
index bc62f87..0808062 100644
--- a/aos/util/BUILD
+++ b/aos/util/BUILD
@@ -1,7 +1,13 @@
 load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
+load("config_validator_macro.bzl", "config_validator_rule")
 
 package(default_visibility = ["//visibility:public"])
 
+config_validator_rule(
+    name = "config_validator_test",
+    config = "//aos/events:pingpong_config",
+)
+
 cc_library(
     name = "bitpacking",
     hdrs = [
@@ -406,3 +412,21 @@
         "//aos/testing:googletest",
     ],
 )
+
+cc_binary(
+    name = "config_validator",
+    testonly = True,
+    srcs = ["config_validator.cc"],
+    target_compatible_with = ["@platforms//os:linux"],
+    deps = [
+        "//aos:init",
+        "//aos:json_to_flatbuffer",
+        "//aos/events:simulated_event_loop",
+        "//aos/events/logging:log_reader",
+        "//aos/events/logging:log_writer",
+        "//aos/testing:googletest",
+        "@com_github_gflags_gflags//:gflags",
+        "@com_github_google_glog//:glog",
+        "@com_google_googletest//:gtest",
+    ],
+)
diff --git a/aos/util/config_validator.cc b/aos/util/config_validator.cc
new file mode 100644
index 0000000..78bd0b1
--- /dev/null
+++ b/aos/util/config_validator.cc
@@ -0,0 +1,32 @@
+#include <chrono>
+#include "aos/configuration.h"
+#include "aos/events/logging/log_reader.h"
+#include "aos/events/logging/log_writer.h"
+#include "aos/events/simulated_event_loop.h"
+#include "aos/init.h"
+#include "aos/json_to_flatbuffer.h"
+#include "aos/network/team_number.h"
+#include "gflags/gflags.h"
+#include "gtest/gtest.h"
+
+DEFINE_string(config, "",
+              "Name of the config file to replay using.");
+/* This binary is used to validate that all of the
+   needed remote timestamps channels are in the config
+   to log the timestamps.
+   Future versions of the validator will provide the option
+   to confirm that the timestamps in the config are able to
+   replay all of the data in the log
+   This can be done by getting a list of all of the nodes and
+   iterating through it with a for loop creating a logger for 
+   each one 
+   Reference superstructure_lib_test.cc*/
+TEST(ConfigValidatorTest, ReadConfig) {
+  ASSERT_TRUE(!FLAGS_config.empty());
+  const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+      aos::configuration::ReadConfig(FLAGS_config);
+
+  aos::SimulatedEventLoopFactory factory(&config.message());
+
+  factory.RunFor(std::chrono::seconds(1));
+}
diff --git a/aos/util/config_validator_macro.bzl b/aos/util/config_validator_macro.bzl
new file mode 100644
index 0000000..47ab240
--- /dev/null
+++ b/aos/util/config_validator_macro.bzl
@@ -0,0 +1,20 @@
+def config_validator_rule(name, config, visibility = None):
+    '''
+    Macro to take a config and pass it to the config validator to validate that it will work on a real system.
+
+    Currently just checks that the system can startup, but will check that timestamp channels are properly logged in the future.
+
+    Args:
+        name: name that the config validator uses, e.g. "test_config",
+        config: config rule that needs to be validated, e.g. "//aos/events:pingpong_config",
+    '''
+    config_bfbs = config + ".bfbs"
+    native.genrule(
+        name = name,
+        outs = [name + ".txt"],
+        cmd = "$(location //aos/util:config_validator) --config $(location %s) > $@" % config_bfbs,
+        srcs = [config_bfbs],
+        tools = ["//aos/util:config_validator"],
+        testonly = True,
+        visibility = visibility,
+    )