Merge "power: fix TryDifferentGovernors test" into rvc-dev am: d78626d962

Change-Id: I2f20a99d0b9bd7fc3d075b0c19158fb57f624fbe
This commit is contained in:
Connor O'Brien 2020-04-24 02:12:09 +00:00 committed by Automerger Merge Worker
commit f58a9662b5

View file

@ -19,6 +19,8 @@
#include <cutils/properties.h>
#include <android-base/file.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <android/hardware/power/1.0/IPower.h>
#include <gtest/gtest.h>
@ -73,26 +75,16 @@ TEST_P(PowerHidlTest, SetInteractive) {
TEST_P(PowerHidlTest, TryDifferentGovernors) {
Return<void> ret;
unique_fd fd1(open(CPU_GOVERNOR_PATH, O_RDWR));
unique_fd fd2(open(AVAILABLE_GOVERNORS_PATH, O_RDONLY));
if (fd1 < 0 || fd2 < 0) {
std::string old_governor, governors;
if (!android::base::ReadFileToString(CPU_GOVERNOR_PATH, &old_governor) ||
!android::base::ReadFileToString(AVAILABLE_GOVERNORS_PATH, &governors)) {
// Files don't exist, so skip the rest of the test case
SUCCEED();
return;
}
char old_governor[80];
ASSERT_LE(0, read(fd1, old_governor, 80));
char governors[1024];
unsigned len = read(fd2, governors, 1024);
ASSERT_LE(0u, len);
governors[len] = '\0';
char *saveptr;
char *name = strtok_r(governors, " \n", &saveptr);
while (name) {
ASSERT_LE(0, write(fd1, name, strlen(name)));
auto all_governors = android::base::Split(governors, " \n");
for (const auto &governor : all_governors) {
ASSERT_TRUE(android::base::WriteStringToFile(governor, CPU_GOVERNOR_PATH));
ret = power->setInteractive(true);
ASSERT_TRUE(ret.isOk());
@ -104,11 +96,9 @@ TEST_P(PowerHidlTest, TryDifferentGovernors) {
power->powerHint(PowerHint::LAUNCH, 1);
power->powerHint(PowerHint::LAUNCH, 0);
name = strtok_r(NULL, " \n", &saveptr);
}
ASSERT_LE(0, write(fd1, old_governor, strlen(old_governor)));
ASSERT_TRUE(android::base::WriteStringToFile(old_governor, CPU_GOVERNOR_PATH));
}
// Sanity check Power::powerHint on good and bad inputs.