Use the event loop name instead of thread name for AOS_LOG
This kills 2 birds with 1 stone.
1) A simulated event loop should print out the name of each event
loop, not the program name.
2) prctl(PR_GET_NAME, thread_name_array) can require higher privileges
sometimes, and is un-necesary for simulations. See 1)
Change-Id: I48731b1cabe34ec66a97f27ee720ba3081da4e94
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/events/event_loop_param_test.cc b/aos/events/event_loop_param_test.cc
index d3d21ac..2749f60 100644
--- a/aos/events/event_loop_param_test.cc
+++ b/aos/events/event_loop_param_test.cc
@@ -5,6 +5,8 @@
#include <unordered_set>
#include "aos/flatbuffer_merge.h"
+#include "aos/logging/log_message_generated.h"
+#include "aos/logging/logging.h"
#include "aos/realtime.h"
#include "glog/logging.h"
#include "gmock/gmock.h"
@@ -947,6 +949,74 @@
Run();
}
+// Verify that AOS_LOG has the right name.
+TEST_P(AbstractEventLoopTest, AOSLog) {
+ auto loop2 = MakePrimary("loop1");
+ auto loop1 = Make("loop0");
+
+ auto fetcher = loop1->MakeFetcher<aos::logging::LogMessageFbs>("/aos");
+
+ EXPECT_FALSE(fetcher.Fetch());
+
+ loop2->OnRun([&]() {
+ AOS_LOG(INFO, "Testing123");
+ this->Exit();
+ });
+
+ Run();
+ EXPECT_TRUE(fetcher.Fetch());
+ EXPECT_EQ(fetcher->name()->string_view(), "loop1");
+}
+
+// Verify that AOS_LOG has the right name in a watcher.
+TEST_P(AbstractEventLoopTest, AOSLogWatcher) {
+ auto loop2 = MakePrimary("loop1");
+ auto loop1 = Make("loop0");
+
+ auto fetcher = loop1->MakeFetcher<aos::logging::LogMessageFbs>("/aos");
+
+ EXPECT_FALSE(fetcher.Fetch());
+
+ auto sender = loop1->MakeSender<TestMessage>("/test2");
+
+ loop2->MakeWatcher("/test2", [&](const TestMessage & /*message*/) {
+ AOS_LOG(INFO, "Testing123");
+ this->Exit();
+ });
+
+ loop2->OnRun([&]() {
+ aos::Sender<TestMessage>::Builder msg = sender.MakeBuilder();
+ TestMessage::Builder builder = msg.MakeBuilder<TestMessage>();
+ builder.add_value(200);
+ ASSERT_TRUE(msg.Send(builder.Finish()));
+ });
+
+ Run();
+ EXPECT_TRUE(fetcher.Fetch());
+ EXPECT_EQ(fetcher->name()->string_view(), "loop1");
+}
+
+// Verify that AOS_LOG has the right name in a timer.
+TEST_P(AbstractEventLoopTest, AOSLogTimer) {
+ auto loop2 = MakePrimary("loop1");
+ auto loop1 = Make("loop0");
+
+ auto fetcher = loop1->MakeFetcher<aos::logging::LogMessageFbs>("/aos");
+
+ EXPECT_FALSE(fetcher.Fetch());
+
+ auto test_timer = loop2->AddTimer([&]() {
+ AOS_LOG(INFO, "Testing123");
+ this->Exit();
+ });
+
+ loop2->OnRun([&]() { test_timer->Setup(loop2->monotonic_now()); });
+
+ Run();
+ EXPECT_TRUE(fetcher.Fetch());
+ EXPECT_EQ(fetcher->name()->string_view(), "loop1");
+}
+
// Verify that timer intervals and duration function properly.
TEST_P(AbstractEventLoopTest, TimerIntervalAndDuration) {
// Force a slower rate so we are guaranteed to have reports for our timer.