diff options
author | Connor O'Brien <connoro@google.com> | 2017-02-24 12:49:44 -0800 |
---|---|---|
committer | Connor O'Brien <connoro@google.com> | 2017-02-27 11:22:06 -0800 |
commit | 990ec56cdb8ce00489c7994c16e839e8060e1e0e (patch) | |
tree | a48ee0ae0d791d76471962af3517ca69f0b93aab /power/1.0/vts | |
parent | 33df4dbeb37a37c6d3c0320083cece0631fbe140 (diff) | |
download | platform_hardware_interfaces-990ec56cdb8ce00489c7994c16e839e8060e1e0e.tar.gz platform_hardware_interfaces-990ec56cdb8ce00489c7994c16e839e8060e1e0e.tar.bz2 platform_hardware_interfaces-990ec56cdb8ce00489c7994c16e839e8060e1e0e.zip |
Fix bugs in power HAL VTS test
Ensure CPU governor list is null-terminated; stop treating newline
char as a governor name; stop leaking file descriptors on failure.
Bug: 35753237
Test: Test runs and passes on marlin and bullhead
Change-Id: I8a6409a50e5daac36770dc577d0628fec8148847
Signed-off-by: Connor O'Brien <connoro@google.com>
Diffstat (limited to 'power/1.0/vts')
-rw-r--r-- | power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp b/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp index 6783961ff2..7a34f00dfc 100644 --- a/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp +++ b/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp @@ -19,6 +19,7 @@ #include <cutils/properties.h> +#include <android-base/unique_fd.h> #include <android/hardware/power/1.0/IPower.h> #include <gtest/gtest.h> @@ -33,6 +34,7 @@ using ::android::hardware::power::V1_0::Status; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::sp; +using ::android::base::unique_fd; using std::vector; @@ -69,23 +71,24 @@ TEST_F(PowerHidlTest, SetInteractive) { TEST_F(PowerHidlTest, TryDifferentGovernors) { Return<void> ret; - int fd1 = open(CPU_GOVERNOR_PATH, O_RDWR); - int fd2 = open(AVAILABLE_GOVERNORS_PATH, O_RDONLY); + unique_fd fd1(open(CPU_GOVERNOR_PATH, O_RDWR)); + unique_fd fd2(open(AVAILABLE_GOVERNORS_PATH, O_RDONLY)); if (fd1 < 0 || fd2 < 0) { - // Files don't exist, so skip the rest of the test case - SUCCEED(); + // Files don't exist, so skip the rest of the test case + SUCCEED(); } char old_governor[80]; ASSERT_LE(0, read(fd1, old_governor, 80)); char governors[1024]; - ASSERT_LE(0, read(fd2, governors, 1024)); - close(fd2); + unsigned len = read(fd2, governors, 1024); + ASSERT_LE(0, len); + governors[len] = '\0'; char *saveptr; - char *name = strtok_r(governors, " ", &saveptr); - while (name && strlen(name) > 1) { + char *name = strtok_r(governors, " \n", &saveptr); + while (name) { ASSERT_LE(0, write(fd1, name, strlen(name))); ret = power->setInteractive(true); ASSERT_TRUE(ret.isOk()); @@ -99,11 +102,10 @@ TEST_F(PowerHidlTest, TryDifferentGovernors) { power->powerHint(PowerHint::LAUNCH, 1); power->powerHint(PowerHint::LAUNCH, 0); - name = strtok_r(NULL, " ", &saveptr); + name = strtok_r(NULL, " \n", &saveptr); } ASSERT_LE(0, write(fd1, old_governor, strlen(old_governor))); - close(fd1); } // Sanity check Power::powerHint on good and bad inputs. |