Validate flatbuffers before printing in aos_dump, log_cat, and simulated_event_loop

We had a corrupted flatbuffer being logged, and the error was very poor
when it was being printed.  Let's try to catch this a lot earlier.

Fix 1: log_cat should validate before printing.  That'll prevent us
from wasting time debugging why it is crashing and point the finger a
lot better.

Fix 2: aos_dump should do the same.  That'll save us from nasty crashes
there too and focus attention a lot better.

Fix 3: SimulatedEventLoop sender Send should also validate in debug
mode.  This will avoid too big a performance hit in the fast path, but
will catch corrupted flatbuffers in any simulations we do, or any log
replay that gets done with debug turned on.

This caught a couple of places where we were missing schemas, so add
those in too.

Change-Id: I1873ddd592d33fe4e64210a2e08aa9b937d61ab8
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/event_loop_param_test.h b/aos/events/event_loop_param_test.h
index 0cbb5fe..3138c51 100644
--- a/aos/events/event_loop_param_test.h
+++ b/aos/events/event_loop_param_test.h
@@ -7,8 +7,14 @@
 
 #include "aos/events/event_loop.h"
 #include "aos/events/test_message_generated.h"
+#include "aos/events/test_message_schema.h"
+#include "aos/events/timing_report_schema.h"
 #include "aos/flatbuffers.h"
 #include "aos/json_to_flatbuffer.h"
+#include "aos/logging/log_message_schema.h"
+#include "aos/network/message_bridge_client_schema.h"
+#include "aos/network/message_bridge_server_schema.h"
+#include "aos/network/timestamp_schema.h"
 #include "gtest/gtest.h"
 
 namespace aos {
@@ -17,7 +23,8 @@
 class EventLoopTestFactory {
  public:
   EventLoopTestFactory()
-      : flatbuffer_(JsonToFlatbuffer<Configuration>(R"config({
+      : flatbuffer_(configuration::AddSchema(
+            R"config({
   "channels": [
     {
       "name": "/aos",
@@ -40,7 +47,11 @@
       "type": "aos.TestMessage"
     }
   ]
-})config")) {}
+})config",
+            {aos::FlatbufferSpan<reflection::Schema>(
+                 logging::LogMessageFbsSchema()),
+             aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()),
+             aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema())})) {}
 
   virtual ~EventLoopTestFactory() {}
 
@@ -61,7 +72,8 @@
 
   // Sets the config to a config with a max size with an invalid alignment.
   void InvalidChannelAlignment() {
-    flatbuffer_ = JsonToFlatbuffer<Configuration>(R"config({
+    flatbuffer_ = configuration::AddSchema(
+        R"config({
   "channels": [
     {
       "name": "/aos",
@@ -85,7 +97,11 @@
       "type": "aos.TestMessage"
     }
   ]
-})config");
+})config",
+        {aos::FlatbufferSpan<reflection::Schema>(
+             logging::LogMessageFbsSchema()),
+         aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()),
+         aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema())});
   }
 
   void PinReads() {
@@ -124,8 +140,11 @@
   ]
 })config";
 
-    flatbuffer_ = FlatbufferDetachedBuffer<Configuration>(
-        JsonToFlatbuffer(kJson, Configuration::MiniReflectTypeTable()));
+    flatbuffer_ = configuration::AddSchema(
+        kJson, {aos::FlatbufferSpan<reflection::Schema>(
+                    logging::LogMessageFbsSchema()),
+                aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()),
+                aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema())});
   }
 
   void EnableNodes(std::string_view my_node) {
@@ -239,8 +258,19 @@
 })config";
 
     flatbuffer_ = configuration::MergeConfiguration(
-        FlatbufferDetachedBuffer<Configuration>(
-            JsonToFlatbuffer(kJson, Configuration::MiniReflectTypeTable())));
+        configuration::MergeConfiguration(
+            aos::FlatbufferDetachedBuffer<Configuration>(
+                JsonToFlatbuffer<Configuration>(kJson))),
+        {aos::FlatbufferSpan<reflection::Schema>(
+             logging::LogMessageFbsSchema()),
+         aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()),
+         aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema()),
+         aos::FlatbufferSpan<reflection::Schema>(
+             message_bridge::ClientStatisticsSchema()),
+         aos::FlatbufferSpan<reflection::Schema>(
+             message_bridge::ServerStatisticsSchema()),
+         aos::FlatbufferSpan<reflection::Schema>(
+             message_bridge::TimestampSchema())});
 
     my_node_ = configuration::GetNode(&flatbuffer_.message(), my_node);
   }