From 13b5b0ce06d0e9f2f05f71abc93024f6142a6329 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Sat, 15 Jun 2024 19:18:03 -0700 Subject: [PATCH] lmkd/tests: handle kill reports being confused with reap reports The starting line for kill and reap reports are the same. Add additional logic in the test to distinguish between them and retry if a kill report is found. Bug: 347296675 Bug: 358830454 Test: mock the input data where lmkd_tests failed Change-Id: Idf83831e45e6682c1dfb6cde258d4ec631a5eb32 Signed-off-by: Suren Baghdasaryan --- tests/lmkd_tests.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/lmkd_tests.cpp b/tests/lmkd_tests.cpp index 9b70d38..2d1b754 100644 --- a/tests/lmkd_tests.cpp +++ b/tests/lmkd_tests.cpp @@ -42,6 +42,7 @@ using namespace android::base; #define LMKD_REAP_FAIL_TEMPLATE "process_mrelease %d failed" #define LMKD_KILL_LINE_START LMKD_LOGCAT_MARKER ": Kill" +#define LMKD_KILLED_LINE_START LMKD_LOGCAT_MARKER ": Process got killed" #define LMKD_REAP_LINE_START LMKD_LOGCAT_MARKER ": Process" #define LMKD_REAP_TIME_TEMPLATE LMKD_LOGCAT_MARKER ": Process %d was reaped in %ldms" #define LMKD_REAP_MRELESE_ERR_MARKER ": process_mrelease" @@ -223,8 +224,10 @@ TEST_F(LmkdTest, TargetReaping) { long rss, swap; ASSERT_TRUE(ParseProcSize(line, rss, swap)) << "Kill report format is invalid"; + line_start = 0; +retry: // find reap duration report - line_start = logcat_out.find(LMKD_REAP_LINE_START); + line_start = logcat_out.find(LMKD_REAP_LINE_START, line_start); if (line_start == std::string::npos) { // Target might have exited before reaping started line_start = logcat_out.find(LMKD_REAP_MRELESE_ERR_MARKER); @@ -240,6 +243,11 @@ TEST_F(LmkdTest, TargetReaping) { line_end = logcat_out.find('\n', line_start); line = logcat_out.substr( line_start, line_end == std::string::npos ? std::string::npos : line_end - line_start); + if (line.find(LMKD_KILLED_LINE_START) != std::string::npos) { + // we found process kill report, keep looking for reaping report + line_start = line_end; + goto retry; + } long reap_time; ASSERT_TRUE(ParseReapTime(line, pid, reap_time) && reap_time >= 0) << "Reaping time report format is invalid";