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 <surenb@google.com>
This commit is contained in:
Suren Baghdasaryan 2024-06-15 19:18:03 -07:00
parent b1d5c43490
commit 13b5b0ce06
1 changed files with 9 additions and 1 deletions

View File

@ -42,6 +42,7 @@ using namespace android::base;
#define LMKD_REAP_FAIL_TEMPLATE "process_mrelease %d failed" #define LMKD_REAP_FAIL_TEMPLATE "process_mrelease %d failed"
#define LMKD_KILL_LINE_START LMKD_LOGCAT_MARKER ": Kill" #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_LINE_START LMKD_LOGCAT_MARKER ": Process"
#define LMKD_REAP_TIME_TEMPLATE LMKD_LOGCAT_MARKER ": Process %d was reaped in %ldms" #define LMKD_REAP_TIME_TEMPLATE LMKD_LOGCAT_MARKER ": Process %d was reaped in %ldms"
#define LMKD_REAP_MRELESE_ERR_MARKER ": process_mrelease" #define LMKD_REAP_MRELESE_ERR_MARKER ": process_mrelease"
@ -223,8 +224,10 @@ TEST_F(LmkdTest, TargetReaping) {
long rss, swap; long rss, swap;
ASSERT_TRUE(ParseProcSize(line, rss, swap)) << "Kill report format is invalid"; ASSERT_TRUE(ParseProcSize(line, rss, swap)) << "Kill report format is invalid";
line_start = 0;
retry:
// find reap duration report // 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) { if (line_start == std::string::npos) {
// Target might have exited before reaping started // Target might have exited before reaping started
line_start = logcat_out.find(LMKD_REAP_MRELESE_ERR_MARKER); 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_end = logcat_out.find('\n', line_start);
line = logcat_out.substr( line = logcat_out.substr(
line_start, line_end == std::string::npos ? std::string::npos : line_end - line_start); 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; long reap_time;
ASSERT_TRUE(ParseReapTime(line, pid, reap_time) && reap_time >= 0) ASSERT_TRUE(ParseReapTime(line, pid, reap_time) && reap_time >= 0)
<< "Reaping time report format is invalid"; << "Reaping time report format is invalid";