lmkd_test: align proc_name with lmkd
This change is to align how we get proc_name between lmkd and lmkd_unit_test or it will always fail when we run command such as ./lmkd_unit_test under the device shell. Bug: 146415484 Test: Verified using lmkd_unit_test Change-Id: I3a6ebf0747a1054c5758b91fbacf3179b66b56c3
This commit is contained in:
parent
43f3d2b190
commit
f2ead0ca1a
|
|
@ -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) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue