From 9e4b111a3399baf5d3befea056c69fcf029bf7ab Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Fri, 11 Dec 2020 17:59:38 +0000 Subject: [PATCH] Log start of the test to logcat This makes it easier to associate logs written during the test with the test case that was running. Test: atest CtsInitTestCases Change-Id: I832f1c9ba8358341c934fdd91a65f5739bc98e37 --- init/init_test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/init/init_test.cpp b/init/init_test.cpp index fa6574026..8550ec8f3 100644 --- a/init/init_test.cpp +++ b/init/init_test.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -268,6 +269,17 @@ service A something ASSERT_EQ(1u, parser.parse_error_count()); } +class TestCaseLogger : public ::testing::EmptyTestEventListener { + void OnTestStart(const ::testing::TestInfo& test_info) override { +#ifdef __ANDROID__ + LOG(INFO) << "===== " << test_info.test_suite_name() << "::" << test_info.name() << " (" + << test_info.file() << ":" << test_info.line() << ")"; +#else + UNUSED(test_info); +#endif + } +}; + } // namespace init } // namespace android @@ -284,5 +296,6 @@ int main(int argc, char** argv) { } testing::InitGoogleTest(&argc, argv); + testing::UnitTest::GetInstance()->listeners().Append(new android::init::TestCaseLogger()); return RUN_ALL_TESTS(); }