summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConnor O'Brien2017-04-05 16:41:34 -0500
committerConnor O'Brien2017-04-05 17:50:14 -0500
commitbb88422d9328023aa02f557d5fc4058c841550e4 (patch)
treeb7bc40a7f7d9e0af279d8ddd58721ac043618d96 /boot/1.0/vts
parentae880e49225d29f27a507814db5805f1a0357f45 (diff)
downloadplatform-hardware-interfaces-bb88422d9328023aa02f557d5fc4058c841550e4.tar.gz
platform-hardware-interfaces-bb88422d9328023aa02f557d5fc4058c841550e4.tar.xz
platform-hardware-interfaces-bb88422d9328023aa02f557d5fc4058c841550e4.zip
Fix hidl_string copy in boot VTS test
hidl_strings returned through a callback need to be copied; the current approach just saves a pointer to the underlying buffer, which is incorrect and sometimes causes the test to fail. Test: the GetSuffix test now passes reliably Change-Id: I4bb143be98b00b20f9da4aebef3b5ab4980b7690 Signed-off-by: Connor O'Brien <connoro@google.com>
Diffstat (limited to 'boot/1.0/vts')
-rw-r--r--boot/1.0/vts/functional/VtsHalBootV1_0TargetTest.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/boot/1.0/vts/functional/VtsHalBootV1_0TargetTest.cpp b/boot/1.0/vts/functional/VtsHalBootV1_0TargetTest.cpp
index 9789ee6b..f48a95d8 100644
--- a/boot/1.0/vts/functional/VtsHalBootV1_0TargetTest.cpp
+++ b/boot/1.0/vts/functional/VtsHalBootV1_0TargetTest.cpp
@@ -30,6 +30,8 @@ using ::android::hardware::boot::V1_0::Slot;
30using ::android::hardware::hidl_string; 30using ::android::hardware::hidl_string;
31using ::android::hardware::Return; 31using ::android::hardware::Return;
32using ::android::sp; 32using ::android::sp;
33using std::string;
34using std::vector;
33 35
34// The main test class for the Boot HIDL HAL. 36// The main test class for the Boot HIDL HAL.
35class BootHidlTest : public ::testing::VtsHalHidlTargetTestBase { 37class BootHidlTest : public ::testing::VtsHalHidlTargetTestBase {
@@ -83,7 +85,7 @@ TEST_F(BootHidlTest, SetActiveBootSlot) {
83 { 85 {
84 // Restore original flags to avoid problems on reboot 86 // Restore original flags to avoid problems on reboot
85 CommandResult cr; 87 CommandResult cr;
86 Return <void> result = boot->markBootSuccessful(generate_callback(&cr)); 88 Return<void> result = boot->markBootSuccessful(generate_callback(&cr));
87 EXPECT_TRUE(result.isOk()); 89 EXPECT_TRUE(result.isOk());
88 EXPECT_TRUE(cr.success); 90 EXPECT_TRUE(cr.success);
89 } 91 }
@@ -151,22 +153,21 @@ TEST_F(BootHidlTest, IsSlotMarkedSuccessful) {
151 153
152// Sanity check Boot::getSuffix() on good and bad inputs. 154// Sanity check Boot::getSuffix() on good and bad inputs.
153TEST_F(BootHidlTest, GetSuffix) { 155TEST_F(BootHidlTest, GetSuffix) {
154 const char *suffixPtr; 156 string suffixStr;
155 auto cb = [&](hidl_string suffix) { suffixPtr = suffix.c_str(); }; 157 vector<string> correctSuffixes = {"_a", "_b"};
156 for (Slot i = 0; i < 2; i++) { 158 auto cb = [&](hidl_string suffix) { suffixStr = suffix.c_str(); };
157 CommandResult cr; 159 for (Slot i = 0; i < 2; i++) {
158 Return<void> result = boot->getSuffix(i, cb); 160 CommandResult cr;
159 EXPECT_TRUE(result.isOk()); 161 Return<void> result = boot->getSuffix(i, cb);
160 char correctSuffix[3]; 162 EXPECT_TRUE(result.isOk());
161 snprintf(correctSuffix, sizeof(correctSuffix), "_%c", 'a' + i); 163 ASSERT_EQ(0, suffixStr.compare(correctSuffixes[i]));
162 ASSERT_EQ(0, strcmp(suffixPtr, correctSuffix)); 164 }
163 } 165 {
164 { 166 string emptySuffix = "";
165 char emptySuffix[] = ""; 167 Return<void> result = boot->getSuffix(boot->getNumberSlots(), cb);
166 Return<void> result = boot->getSuffix(boot->getNumberSlots(), cb); 168 EXPECT_TRUE(result.isOk());
167 EXPECT_TRUE(result.isOk()); 169 ASSERT_EQ(0, suffixStr.compare(emptySuffix));
168 ASSERT_EQ(0, strcmp(emptySuffix, suffixPtr)); 170 }
169 }
170} 171}
171 172
172int main(int argc, char **argv) { 173int main(int argc, char **argv) {