Add (default off) support for dying on malloc in RT code

Our malloc is not realtime.  We shouldn't be using it in RT code.  To
enforce this, add a hook into tcmalloc to LOG_RAW(FATAL) whenever an
application tries to allocate memory inside code running at the RT
priority level.

We have code in our drivetrain code which is allocating memory still
when realtime.  That prevents us from enabling it yet.

Change-Id: I7679bb11fc9ef0cc676c77f5ef7b041427e1f32a
diff --git a/frc971/wpilib/loop_output_handler_test.cc b/frc971/wpilib/loop_output_handler_test.cc
index a74b762..fcbcbb5 100644
--- a/frc971/wpilib/loop_output_handler_test.cc
+++ b/frc971/wpilib/loop_output_handler_test.cc
@@ -5,7 +5,7 @@
 #include "gtest/gtest.h"
 
 #include "aos/events/simulated_event_loop.h"
-#include "aos/logging/logging.h"
+#include "aos/realtime.h"
 #include "aos/testing/test_logging.h"
 #include "aos/time/time.h"
 #include "frc971/wpilib/loop_output_handler_test_generated.h"
@@ -43,8 +43,6 @@
   TestLoopOutputHandler(::aos::EventLoop *event_loop, const ::std::string &name)
       : LoopOutputHandler(event_loop, name) {}
 
-  ~TestLoopOutputHandler() { Stop(); }
-
   int count() const { return count_; }
 
   ::aos::monotonic_clock::time_point last_time() const { return last_time_; }
@@ -52,12 +50,18 @@
 
  protected:
   void Write(const LoopOutputHandlerTestOutput &output) override {
+    aos::CheckRealtime();
+    // We don't care if this is RT if we are testing.
+    aos::ScopedNotRealtime nrt;
     LOG(INFO) << "output " << aos::FlatbufferToJson(&output);
     ++count_;
     last_time_ = event_loop()->monotonic_now();
   }
 
   void Stop() override {
+    aos::CheckRealtime();
+    // We don't care if this is RT if we are testing.
+    aos::ScopedNotRealtime nrt;
     stop_time_ = event_loop()->monotonic_now();
     LOG(INFO) << "Stopping";
   }