lmkd_test: align proc_name with lmkd am: f2ead0ca1a am: 3cfaed6e43

Change-Id: I78837e4a72b0086498a5b6824d2a7c4ad5b86e86
This commit is contained in:
Automerger Merge Worker 2019-12-21 04:22:51 +00:00
commit 6b9bcd6944
1 changed files with 11 additions and 10 deletions

View File

@ -109,14 +109,15 @@ std::string getTextAround(const std::string& text, size_t pos,
std::string::npos : pos - start_pos); std::string::npos : pos - start_pos);
} }
bool getExecPath(std::string &path) { bool getTaskName(std::string &name) {
char buf[PATH_MAX + 1]; std::string cmdline;
int ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
if (ret < 0) { if (!ReadFileToString("/proc/self/cmdline", &cmdline)) {
GTEST_LOG_(INFO) << "Failed to read /proc/self/cmdline";
return false; return false;
} }
buf[ret] = '\0'; //filter out paramters as cmdline use null bytes to separate
path = buf; name = cmdline.c_str();
return true; return true;
} }
@ -308,15 +309,15 @@ TEST(lmkd, check_for_oom) {
ASSERT_TRUE(writeKmsg(marker)); ASSERT_TRUE(writeKmsg(marker));
// get executable complete path // get executable complete path
std::string test_path; std::string task_name;
ASSERT_TRUE(getExecPath(test_path)); ASSERT_TRUE(getTaskName(task_name));
std::string test_output; std::string test_output;
if (getuid() != static_cast<unsigned>(AID_ROOT)) { if (getuid() != static_cast<unsigned>(AID_ROOT)) {
// if not root respawn itself as root and capture output // if not root respawn itself as root and capture output
std::string command = StringPrintf( std::string command = StringPrintf(
"%s=true su root %s 2>&1", LMKDTEST_RESPAWN_FLAG, "%s=true su root %s 2>&1", LMKDTEST_RESPAWN_FLAG,
test_path.c_str()); task_name.c_str());
std::string test_output = readCommand(command); std::string test_output = readCommand(command);
GTEST_LOG_(INFO) << test_output; GTEST_LOG_(INFO) << test_output;
} else { } else {
@ -332,7 +333,7 @@ TEST(lmkd, check_for_oom) {
std::stringstream kill_logs; std::stringstream kill_logs;
int hit_count = 0; int hit_count = 0;
size_t pos = 0; size_t pos = 0;
marker = StringPrintf(LMKD_KILL_MARKER_TEMPLATE, test_path.c_str()); marker = StringPrintf(LMKD_KILL_MARKER_TEMPLATE, task_name.c_str());
while (true) { while (true) {
if ((pos = logcat_out.find(marker, pos)) != std::string::npos) { if ((pos = logcat_out.find(marker, pos)) != std::string::npos) {