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/aos/events/shm_event_loop_test.cc b/aos/events/shm_event_loop_test.cc
index 2aeefb4..8e7ad93 100644
--- a/aos/events/shm_event_loop_test.cc
+++ b/aos/events/shm_event_loop_test.cc
@@ -3,6 +3,7 @@
#include <string_view>
#include "aos/events/event_loop_param_test.h"
+#include "aos/realtime.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
@@ -95,8 +96,22 @@
int scheduler;
PCHECK((scheduler = sched_getscheduler(0)) != -1);
- LOG(INFO) << "scheduler is " << scheduler;
- return scheduler == SCHED_FIFO || scheduler == SCHED_RR;
+ {
+ // If we are RT, logging the scheduler will crash us. Mark that we just
+ // don't care.
+ aos::ScopedNotRealtime nrt;
+ LOG(INFO) << "scheduler is " << scheduler;
+ }
+
+ const bool result = scheduler == SCHED_FIFO || scheduler == SCHED_RR;
+ // Confirm that the scheduler matches AOS' interpretation of if we are
+ // realtime or not.
+ if (result) {
+ aos::CheckRealtime();
+ } else {
+ aos::CheckNotRealtime();
+ }
+ return result;
}
class ShmEventLoopTest : public ::testing::TestWithParam<ReadMethod> {