Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "dumpstate_1_1_hidl_hal_test" |
| 18 | |
| 19 | #include <fcntl.h> |
| 20 | #include <unistd.h> |
Hunter Knepshield | 7b20bd7 | 2020-01-22 18:25:14 -0800 | [diff] [blame] | 21 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 22 | #include <functional> |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
| 25 | #include <android/hardware/dumpstate/1.1/IDumpstateDevice.h> |
| 26 | #include <android/hardware/dumpstate/1.1/types.h> |
| 27 | #include <cutils/native_handle.h> |
| 28 | #include <gtest/gtest.h> |
| 29 | #include <hidl/GtestPrinter.h> |
| 30 | #include <hidl/ServiceManagement.h> |
| 31 | #include <log/log.h> |
| 32 | |
Hunter Knepshield | 7b20bd7 | 2020-01-22 18:25:14 -0800 | [diff] [blame] | 33 | namespace { |
| 34 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 35 | using ::android::sp; |
| 36 | using ::android::hardware::Return; |
| 37 | using ::android::hardware::dumpstate::V1_1::DumpstateMode; |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 38 | using ::android::hardware::dumpstate::V1_1::DumpstateStatus; |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 39 | using ::android::hardware::dumpstate::V1_1::IDumpstateDevice; |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 40 | using ::android::hardware::dumpstate::V1_1::toString; |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 41 | |
| 42 | class DumpstateHidl1_1Test : public ::testing::TestWithParam<std::string> { |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 43 | protected: |
| 44 | virtual void SetUp() override { GetService(); } |
| 45 | |
| 46 | void GetService() { |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 47 | dumpstate = IDumpstateDevice::getService(GetParam()); |
| 48 | ASSERT_NE(dumpstate, nullptr) << "Could not get HIDL instance"; |
| 49 | } |
| 50 | |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 51 | void ToggleVerboseLogging(bool enable) { |
| 52 | Return<void> status = dumpstate->setVerboseLoggingEnabled(enable); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 53 | ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); |
| 54 | |
| 55 | if (!dumpstate->ping().isOk()) { |
| 56 | ALOGW("IDumpstateDevice service appears to have exited lazily, attempting to get " |
| 57 | "again"); |
| 58 | GetService(); |
| 59 | } |
| 60 | |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 61 | Return<bool> logging_enabled = dumpstate->getVerboseLoggingEnabled(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 62 | ASSERT_TRUE(logging_enabled.isOk()) |
| 63 | << "Status should be ok: " << logging_enabled.description(); |
| 64 | ASSERT_EQ(logging_enabled, enable) |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 65 | << "Verbose logging should now be " << (enable ? "enabled" : "disabled"); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 66 | |
| 67 | if (!dumpstate->ping().isOk()) { |
| 68 | ALOGW("IDumpstateDevice service appears to have exited lazily, attempting to get " |
| 69 | "again"); |
| 70 | GetService(); |
| 71 | } |
| 72 | } |
| 73 | |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 74 | void EnableVerboseLogging() { ToggleVerboseLogging(true); } |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 75 | |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 76 | void DisableVerboseLogging() { ToggleVerboseLogging(false); } |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 77 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 78 | sp<IDumpstateDevice> dumpstate; |
| 79 | }; |
| 80 | |
| 81 | #define TEST_FOR_DUMPSTATE_MODE(name, body, mode) \ |
| 82 | TEST_P(DumpstateHidl1_1Test, name##_##mode) { body(DumpstateMode::mode); } |
| 83 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 84 | // We use a macro to define individual test cases instead of hidl_enum_range<> because some HAL |
| 85 | // implementations are lazy and may call exit() at the end of dumpstateBoard(), which would cause |
| 86 | // DEAD_OBJECT errors after the first iteration. Separate cases re-get the service each time as part |
| 87 | // of SetUp(), and also provide better separation of concerns when specific modes are problematic. |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 88 | #define TEST_FOR_ALL_DUMPSTATE_MODES(name, body) \ |
| 89 | TEST_FOR_DUMPSTATE_MODE(name, body, FULL); \ |
| 90 | TEST_FOR_DUMPSTATE_MODE(name, body, INTERACTIVE); \ |
| 91 | TEST_FOR_DUMPSTATE_MODE(name, body, REMOTE); \ |
| 92 | TEST_FOR_DUMPSTATE_MODE(name, body, WEAR); \ |
| 93 | TEST_FOR_DUMPSTATE_MODE(name, body, CONNECTIVITY); \ |
| 94 | TEST_FOR_DUMPSTATE_MODE(name, body, WIFI); \ |
Mike Ma | 6165e2d | 2020-02-13 13:11:00 -0800 | [diff] [blame] | 95 | TEST_FOR_DUMPSTATE_MODE(name, body, DEFAULT); \ |
| 96 | TEST_FOR_DUMPSTATE_MODE(name, body, PROTO); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 97 | |
Hunter Knepshield | 7b20bd7 | 2020-01-22 18:25:14 -0800 | [diff] [blame] | 98 | constexpr uint64_t kDefaultTimeoutMillis = 30 * 1000; // 30 seconds |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 99 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 100 | // Will only execute additional_assertions when status == expected. |
| 101 | void AssertStatusForMode(const DumpstateMode mode, const Return<DumpstateStatus>& status, |
| 102 | const DumpstateStatus expected, |
| 103 | std::function<void()> additional_assertions = nullptr) { |
| 104 | ASSERT_TRUE(status.isOk()) << "Status should be ok and return a more specific DumpstateStatus: " |
| 105 | << status.description(); |
| 106 | if (mode == DumpstateMode::DEFAULT) { |
| 107 | ASSERT_EQ(expected, status) << "Required mode (DumpstateMode::" << toString(mode) |
| 108 | << "): status should be DumpstateStatus::" << toString(expected) |
| 109 | << ", but got DumpstateStatus::" << toString(status); |
| 110 | } else { |
| 111 | // The rest of the modes are optional to support, but they MUST return either the expected |
| 112 | // value or UNSUPPORTED_MODE. |
| 113 | ASSERT_TRUE(status == expected || status == DumpstateStatus::UNSUPPORTED_MODE) |
| 114 | << "Optional mode (DumpstateMode::" << toString(mode) |
| 115 | << "): status should be DumpstateStatus::" << toString(expected) |
| 116 | << " or DumpstateStatus::UNSUPPORTED_MODE, but got DumpstateStatus::" |
| 117 | << toString(status); |
| 118 | } |
| 119 | if (status == expected && additional_assertions != nullptr) { |
| 120 | additional_assertions(); |
| 121 | } |
| 122 | } |
| 123 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 124 | // Negative test: make sure dumpstateBoard() doesn't crash when passed a null pointer. |
| 125 | TEST_FOR_ALL_DUMPSTATE_MODES(TestNullHandle, [this](DumpstateMode mode) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 126 | EnableVerboseLogging(); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 127 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 128 | Return<DumpstateStatus> status = |
| 129 | dumpstate->dumpstateBoard_1_1(nullptr, mode, kDefaultTimeoutMillis); |
| 130 | |
| 131 | AssertStatusForMode(mode, status, DumpstateStatus::ILLEGAL_ARGUMENT); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 132 | }); |
| 133 | |
| 134 | // Negative test: make sure dumpstateBoard() ignores a handle with no FD. |
| 135 | TEST_FOR_ALL_DUMPSTATE_MODES(TestHandleWithNoFd, [this](DumpstateMode mode) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 136 | EnableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 137 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 138 | native_handle_t* handle = native_handle_create(0, 0); |
| 139 | ASSERT_NE(handle, nullptr) << "Could not create native_handle"; |
| 140 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 141 | Return<DumpstateStatus> status = |
| 142 | dumpstate->dumpstateBoard_1_1(handle, mode, kDefaultTimeoutMillis); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 143 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 144 | AssertStatusForMode(mode, status, DumpstateStatus::ILLEGAL_ARGUMENT); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 145 | |
| 146 | native_handle_close(handle); |
| 147 | native_handle_delete(handle); |
| 148 | }); |
| 149 | |
| 150 | // Positive test: make sure dumpstateBoard() writes something to the FD. |
| 151 | TEST_FOR_ALL_DUMPSTATE_MODES(TestOk, [this](DumpstateMode mode) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 152 | EnableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 153 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 154 | // Index 0 corresponds to the read end of the pipe; 1 to the write end. |
| 155 | int fds[2]; |
| 156 | ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; |
| 157 | |
| 158 | native_handle_t* handle = native_handle_create(1, 0); |
| 159 | ASSERT_NE(handle, nullptr) << "Could not create native_handle"; |
| 160 | handle->data[0] = fds[1]; |
| 161 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 162 | Return<DumpstateStatus> status = |
| 163 | dumpstate->dumpstateBoard_1_1(handle, mode, kDefaultTimeoutMillis); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 164 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 165 | AssertStatusForMode(mode, status, DumpstateStatus::OK, [&fds]() { |
| 166 | // Check that at least one byte was written. |
| 167 | char buff; |
| 168 | ASSERT_EQ(1, read(fds[0], &buff, 1)) << "Dumped nothing"; |
| 169 | }); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 170 | |
| 171 | native_handle_close(handle); |
| 172 | native_handle_delete(handle); |
| 173 | }); |
| 174 | |
| 175 | // Positive test: make sure dumpstateBoard() doesn't crash with two FDs. |
| 176 | TEST_FOR_ALL_DUMPSTATE_MODES(TestHandleWithTwoFds, [this](DumpstateMode mode) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 177 | EnableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 178 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 179 | int fds1[2]; |
| 180 | int fds2[2]; |
| 181 | ASSERT_EQ(0, pipe2(fds1, O_NONBLOCK)) << errno; |
| 182 | ASSERT_EQ(0, pipe2(fds2, O_NONBLOCK)) << errno; |
| 183 | |
| 184 | native_handle_t* handle = native_handle_create(2, 0); |
| 185 | ASSERT_NE(handle, nullptr) << "Could not create native_handle"; |
| 186 | handle->data[0] = fds1[1]; |
| 187 | handle->data[1] = fds2[1]; |
| 188 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 189 | Return<DumpstateStatus> status = |
| 190 | dumpstate->dumpstateBoard_1_1(handle, mode, kDefaultTimeoutMillis); |
| 191 | |
| 192 | AssertStatusForMode(mode, status, DumpstateStatus::OK, [&fds1, &fds2]() { |
| 193 | // Check that at least one byte was written to one of the FDs. |
| 194 | char buff; |
| 195 | size_t read1 = read(fds1[0], &buff, 1); |
| 196 | size_t read2 = read(fds2[0], &buff, 1); |
| 197 | // Sometimes read returns -1, so we can't just add them together and expect >= 1. |
| 198 | ASSERT_TRUE(read1 == 1 || read2 == 1) << "Dumped nothing"; |
| 199 | }); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 200 | |
| 201 | native_handle_close(handle); |
| 202 | native_handle_delete(handle); |
| 203 | }); |
| 204 | |
| 205 | // Make sure dumpstateBoard_1_1 actually validates its arguments. |
| 206 | TEST_P(DumpstateHidl1_1Test, TestInvalidModeArgument_Negative) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 207 | EnableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 208 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 209 | int fds[2]; |
| 210 | ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; |
| 211 | |
| 212 | native_handle_t* handle = native_handle_create(1, 0); |
| 213 | ASSERT_NE(handle, nullptr) << "Could not create native_handle"; |
| 214 | handle->data[0] = fds[1]; |
| 215 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 216 | Return<DumpstateStatus> status = dumpstate->dumpstateBoard_1_1( |
| 217 | handle, static_cast<DumpstateMode>(-100), kDefaultTimeoutMillis); |
| 218 | |
| 219 | ASSERT_TRUE(status.isOk()) << "Status should be ok and return a more specific DumpstateStatus: " |
| 220 | << status.description(); |
| 221 | ASSERT_EQ(status, DumpstateStatus::ILLEGAL_ARGUMENT) |
| 222 | << "Should return DumpstateStatus::ILLEGAL_ARGUMENT for invalid mode param"; |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 223 | |
| 224 | native_handle_close(handle); |
| 225 | native_handle_delete(handle); |
| 226 | } |
| 227 | |
| 228 | TEST_P(DumpstateHidl1_1Test, TestInvalidModeArgument_Undefined) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 229 | EnableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 230 | |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 231 | int fds[2]; |
| 232 | ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; |
| 233 | |
| 234 | native_handle_t* handle = native_handle_create(1, 0); |
| 235 | ASSERT_NE(handle, nullptr) << "Could not create native_handle"; |
| 236 | handle->data[0] = fds[1]; |
| 237 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 238 | Return<DumpstateStatus> status = dumpstate->dumpstateBoard_1_1( |
| 239 | handle, static_cast<DumpstateMode>(9001), kDefaultTimeoutMillis); |
| 240 | |
| 241 | ASSERT_TRUE(status.isOk()) << "Status should be ok and return a more specific DumpstateStatus: " |
| 242 | << status.description(); |
| 243 | ASSERT_EQ(status, DumpstateStatus::ILLEGAL_ARGUMENT) |
| 244 | << "Should return DumpstateStatus::ILLEGAL_ARGUMENT for invalid mode param"; |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 245 | |
| 246 | native_handle_close(handle); |
| 247 | native_handle_delete(handle); |
| 248 | } |
| 249 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 250 | // Positive test: make sure dumpstateBoard() from 1.0 doesn't fail. |
| 251 | TEST_P(DumpstateHidl1_1Test, Test1_0MethodOk) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 252 | EnableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 253 | |
| 254 | int fds[2]; |
| 255 | ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; |
| 256 | |
| 257 | native_handle_t* handle = native_handle_create(1, 0); |
| 258 | ASSERT_NE(handle, nullptr) << "Could not create native_handle"; |
| 259 | handle->data[0] = fds[1]; |
| 260 | |
| 261 | Return<void> status = dumpstate->dumpstateBoard(handle); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 262 | |
| 263 | ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 264 | |
| 265 | // Check that at least one byte was written. |
| 266 | char buff; |
| 267 | ASSERT_EQ(1, read(fds[0], &buff, 1)) << "Dumped nothing"; |
| 268 | |
| 269 | native_handle_close(handle); |
| 270 | native_handle_delete(handle); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 273 | // Make sure disabling verbose logging behaves correctly. Some info is still allowed to be emitted, |
| 274 | // but it can't have privacy/storage/battery impacts. |
| 275 | TEST_FOR_ALL_DUMPSTATE_MODES(TestVerboseLoggingDisabled, [this](DumpstateMode mode) { |
| 276 | DisableVerboseLogging(); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 277 | |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 278 | // Index 0 corresponds to the read end of the pipe; 1 to the write end. |
| 279 | int fds[2]; |
| 280 | ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; |
| 281 | |
| 282 | native_handle_t* handle = native_handle_create(1, 0); |
| 283 | ASSERT_NE(handle, nullptr) << "Could not create native_handle"; |
| 284 | handle->data[0] = fds[1]; |
| 285 | |
| 286 | Return<DumpstateStatus> status = |
| 287 | dumpstate->dumpstateBoard_1_1(handle, mode, kDefaultTimeoutMillis); |
| 288 | |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 289 | // We don't include additional assertions here about the file passed in. If verbose logging is |
| 290 | // disabled, the OEM may choose to include nothing at all, but it is allowed to include some |
| 291 | // essential information based on the mode as long as it isn't private user information. |
| 292 | AssertStatusForMode(mode, status, DumpstateStatus::OK); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 293 | |
| 294 | native_handle_close(handle); |
| 295 | native_handle_delete(handle); |
| 296 | }); |
| 297 | |
| 298 | // Double-enable is perfectly valid, but the second call shouldn't do anything. |
| 299 | TEST_P(DumpstateHidl1_1Test, TestRepeatedEnable) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 300 | EnableVerboseLogging(); |
| 301 | EnableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // Double-disable is perfectly valid, but the second call shouldn't do anything. |
| 305 | TEST_P(DumpstateHidl1_1Test, TestRepeatedDisable) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 306 | DisableVerboseLogging(); |
| 307 | DisableVerboseLogging(); |
Hunter Knepshield | 256f77a | 2020-02-03 16:25:57 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | // Toggling in short order is perfectly valid. |
| 311 | TEST_P(DumpstateHidl1_1Test, TestRepeatedToggle) { |
Hunter Knepshield | 84dbf58 | 2020-02-12 18:55:28 -0800 | [diff] [blame^] | 312 | EnableVerboseLogging(); |
| 313 | DisableVerboseLogging(); |
| 314 | EnableVerboseLogging(); |
| 315 | DisableVerboseLogging(); |
Hunter Knepshield | 1b92d26 | 2020-01-15 17:48:01 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | INSTANTIATE_TEST_SUITE_P( |
| 319 | PerInstance, DumpstateHidl1_1Test, |
| 320 | testing::ValuesIn(android::hardware::getAllHalInstanceNames(IDumpstateDevice::descriptor)), |
| 321 | android::hardware::PrintInstanceNameToString); |
Hunter Knepshield | 7b20bd7 | 2020-01-22 18:25:14 -0800 | [diff] [blame] | 322 | |
| 323 | } // namespace |