Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Yifan Hong | f86271d | 2017-11-06 12:52:20 -0800 | [diff] [blame] | 17 | #define LOG_TAG "health_hidl_hal_test" |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 18 | |
| 19 | #include <mutex> |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 20 | #include <set> |
| 21 | #include <string> |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 22 | |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 23 | #include <android-base/logging.h> |
| 24 | #include <android/hardware/health/2.0/IHealth.h> |
| 25 | #include <android/hardware/health/2.0/types.h> |
Yifan Hong | e6807dd | 2019-03-07 13:04:33 -0800 | [diff] [blame] | 26 | #include <gflags/gflags.h> |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 27 | #include <gtest/gtest.h> |
| 28 | #include <hidl/GtestPrinter.h> |
| 29 | #include <hidl/ServiceManagement.h> |
| 30 | #include <log/log.h> |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 31 | |
| 32 | using ::testing::AssertionFailure; |
| 33 | using ::testing::AssertionResult; |
| 34 | using ::testing::AssertionSuccess; |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 35 | |
Yifan Hong | e6807dd | 2019-03-07 13:04:33 -0800 | [diff] [blame] | 36 | DEFINE_bool(force, false, "Force test healthd even when the default instance is present."); |
| 37 | |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 38 | // If GTEST_SKIP is not implemented, use our own skipping mechanism |
| 39 | #ifndef GTEST_SKIP |
| 40 | static std::mutex gSkippedTestsMutex; |
| 41 | static std::set<std::string> gSkippedTests; |
| 42 | static std::string GetCurrentTestName() { |
| 43 | const auto& info = ::testing::UnitTest::GetInstance()->current_test_info(); |
| 44 | #ifdef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ |
| 45 | std::string test_suite = info->test_suite_name(); |
| 46 | #else |
| 47 | std::string test_suite = info->test_case_name(); |
| 48 | #endif |
| 49 | return test_suite + "." + info->name(); |
| 50 | } |
| 51 | |
| 52 | #define GTEST_SKIP() \ |
| 53 | do { \ |
| 54 | std::unique_lock<std::mutex> lock(gSkippedTestsMutex); \ |
| 55 | gSkippedTests.insert(GetCurrentTestName()); \ |
| 56 | return; \ |
| 57 | } while (0) |
| 58 | |
| 59 | #define SKIP_IF_SKIPPED() \ |
| 60 | do { \ |
| 61 | std::unique_lock<std::mutex> lock(gSkippedTestsMutex); \ |
| 62 | if (gSkippedTests.find(GetCurrentTestName()) != gSkippedTests.end()) { \ |
| 63 | std::cerr << "[ SKIPPED ] " << GetCurrentTestName() << std::endl; \ |
| 64 | return; \ |
| 65 | } \ |
| 66 | } while (0) |
| 67 | #else |
| 68 | #define SKIP_IF_SKIPPED() |
| 69 | #endif |
| 70 | |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 71 | namespace android { |
| 72 | namespace hardware { |
| 73 | namespace health { |
| 74 | namespace V2_0 { |
| 75 | |
| 76 | using V1_0::BatteryStatus; |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 77 | |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 78 | class HealthHidlTest : public ::testing::TestWithParam<std::string> { |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 79 | public: |
| 80 | virtual void SetUp() override { |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 81 | std::string serviceName = GetParam(); |
Yifan Hong | e6807dd | 2019-03-07 13:04:33 -0800 | [diff] [blame] | 82 | |
| 83 | if (serviceName == "backup" && !FLAGS_force && |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 84 | IHealth::getService() != nullptr) { |
Yifan Hong | e6807dd | 2019-03-07 13:04:33 -0800 | [diff] [blame] | 85 | LOG(INFO) << "Skipping tests on healthd because the default instance is present. " |
| 86 | << "Use --force if you really want to test healthd."; |
| 87 | GTEST_SKIP(); |
| 88 | } |
| 89 | |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 90 | LOG(INFO) << "get service with name:" << serviceName; |
| 91 | ASSERT_FALSE(serviceName.empty()); |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 92 | mHealth = IHealth::getService(serviceName); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 93 | ASSERT_NE(mHealth, nullptr); |
| 94 | } |
| 95 | |
| 96 | sp<IHealth> mHealth; |
| 97 | }; |
| 98 | |
| 99 | class Callback : public IHealthInfoCallback { |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 100 | public: |
Hridya Valsaraju | d31932a | 2018-01-17 23:09:24 -0800 | [diff] [blame] | 101 | Return<void> healthInfoChanged(const HealthInfo&) override { |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 102 | std::lock_guard<std::mutex> lock(mMutex); |
| 103 | mInvoked = true; |
| 104 | mInvokedNotify.notify_all(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 105 | return Void(); |
| 106 | } |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 107 | template <typename R, typename P> |
| 108 | bool waitInvoke(std::chrono::duration<R, P> duration) { |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 109 | std::unique_lock<std::mutex> lock(mMutex); |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 110 | bool r = mInvokedNotify.wait_for(lock, duration, [this] { return this->mInvoked; }); |
| 111 | mInvoked = false; |
| 112 | return r; |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 113 | } |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 114 | private: |
| 115 | std::mutex mMutex; |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 116 | std::condition_variable mInvokedNotify; |
| 117 | bool mInvoked = false; |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | #define ASSERT_OK(r) ASSERT_TRUE(isOk(r)) |
| 121 | #define EXPECT_OK(r) EXPECT_TRUE(isOk(r)) |
| 122 | template <typename T> |
| 123 | AssertionResult isOk(const Return<T>& r) { |
| 124 | return r.isOk() ? AssertionSuccess() : (AssertionFailure() << r.description()); |
| 125 | } |
| 126 | |
| 127 | #define ASSERT_ALL_OK(r) ASSERT_TRUE(isAllOk(r)) |
| 128 | // Both isOk() and Result::SUCCESS |
| 129 | AssertionResult isAllOk(const Return<Result>& r) { |
| 130 | if (!r.isOk()) { |
| 131 | return AssertionFailure() << r.description(); |
| 132 | } |
| 133 | if (static_cast<Result>(r) != Result::SUCCESS) { |
| 134 | return AssertionFailure() << toString(static_cast<Result>(r)); |
| 135 | } |
| 136 | return AssertionSuccess(); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Test whether callbacks work. Tested functions are IHealth::registerCallback, |
| 141 | * unregisterCallback, and update. |
| 142 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 143 | TEST_P(HealthHidlTest, Callbacks) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 144 | SKIP_IF_SKIPPED(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 145 | using namespace std::chrono_literals; |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 146 | sp<Callback> firstCallback = new Callback(); |
| 147 | sp<Callback> secondCallback = new Callback(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 148 | |
| 149 | ASSERT_ALL_OK(mHealth->registerCallback(firstCallback)); |
| 150 | ASSERT_ALL_OK(mHealth->registerCallback(secondCallback)); |
| 151 | |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 152 | // registerCallback may or may not invoke the callback immediately, so the test needs |
| 153 | // to wait for the invocation. If the implementation chooses not to invoke the callback |
| 154 | // immediately, just wait for some time. |
| 155 | firstCallback->waitInvoke(200ms); |
| 156 | secondCallback->waitInvoke(200ms); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 157 | |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 158 | // assert that the first callback is invoked when update is called. |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 159 | ASSERT_ALL_OK(mHealth->update()); |
| 160 | |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 161 | ASSERT_TRUE(firstCallback->waitInvoke(1s)); |
| 162 | ASSERT_TRUE(secondCallback->waitInvoke(1s)); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 163 | |
| 164 | ASSERT_ALL_OK(mHealth->unregisterCallback(firstCallback)); |
| 165 | |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 166 | // clear any potentially pending callbacks result from wakealarm / kernel events |
| 167 | // If there is none, just wait for some time. |
| 168 | firstCallback->waitInvoke(200ms); |
| 169 | secondCallback->waitInvoke(200ms); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 170 | |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 171 | // assert that the second callback is still invoked even though the first is unregistered. |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 172 | ASSERT_ALL_OK(mHealth->update()); |
| 173 | |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 174 | ASSERT_FALSE(firstCallback->waitInvoke(200ms)); |
| 175 | ASSERT_TRUE(secondCallback->waitInvoke(1s)); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 176 | |
| 177 | ASSERT_ALL_OK(mHealth->unregisterCallback(secondCallback)); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 178 | } |
| 179 | |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 180 | TEST_P(HealthHidlTest, UnregisterNonExistentCallback) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 181 | SKIP_IF_SKIPPED(); |
Yifan Hong | d6ea57e | 2017-11-20 14:41:09 -0800 | [diff] [blame] | 182 | sp<Callback> callback = new Callback(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 183 | auto ret = mHealth->unregisterCallback(callback); |
| 184 | ASSERT_OK(ret); |
| 185 | ASSERT_EQ(Result::NOT_FOUND, static_cast<Result>(ret)) << "Actual: " << toString(ret); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Pass the test if: |
| 190 | * - Property is not supported (res == NOT_SUPPORTED) |
| 191 | * - Result is success, and predicate is true |
| 192 | * @param res the Result value. |
| 193 | * @param valueStr the string representation for actual value (for error message) |
| 194 | * @param pred a predicate that test whether the value is valid |
| 195 | */ |
| 196 | #define EXPECT_VALID_OR_UNSUPPORTED_PROP(res, valueStr, pred) \ |
| 197 | EXPECT_TRUE(isPropertyOk(res, valueStr, pred, #pred)) |
| 198 | |
| 199 | AssertionResult isPropertyOk(Result res, const std::string& valueStr, bool pred, |
| 200 | const std::string& predStr) { |
| 201 | if (res == Result::SUCCESS) { |
| 202 | if (pred) { |
| 203 | return AssertionSuccess(); |
| 204 | } |
| 205 | return AssertionFailure() << "value doesn't match.\nActual: " << valueStr |
| 206 | << "\nExpected: " << predStr; |
| 207 | } |
| 208 | if (res == Result::NOT_SUPPORTED) { |
| 209 | return AssertionSuccess(); |
| 210 | } |
| 211 | return AssertionFailure() << "Result is not SUCCESS or NOT_SUPPORTED: " << toString(res); |
| 212 | } |
| 213 | |
Hridya Valsaraju | 2120ecc | 2017-12-20 13:27:52 -0800 | [diff] [blame] | 214 | bool verifyStorageInfo(const hidl_vec<struct StorageInfo>& info) { |
| 215 | for (size_t i = 0; i < info.size(); i++) { |
| 216 | if (!(0 <= info[i].eol && info[i].eol <= 3 && 0 <= info[i].lifetimeA && |
| 217 | info[i].lifetimeA <= 0x0B && 0 <= info[i].lifetimeB && info[i].lifetimeB <= 0x0B)) { |
| 218 | return false; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | return true; |
| 223 | } |
| 224 | |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 225 | template <typename T> |
| 226 | bool verifyEnum(T value) { |
Steven Moreland | c90461c | 2018-05-01 16:54:09 -0700 | [diff] [blame] | 227 | for (auto it : hidl_enum_range<T>()) { |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 228 | if (it == value) { |
| 229 | return true; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | bool verifyHealthInfo(const HealthInfo& health_info) { |
Hridya Valsaraju | 075c182 | 2018-04-03 11:19:08 -0700 | [diff] [blame] | 237 | if (!verifyStorageInfo(health_info.storageInfos)) { |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 238 | return false; |
| 239 | } |
| 240 | |
| 241 | using V1_0::BatteryStatus; |
| 242 | using V1_0::BatteryHealth; |
| 243 | |
Robin Lee | ac5a0d3 | 2019-10-09 15:48:17 +0200 | [diff] [blame] | 244 | if (!((health_info.legacy.batteryCurrent != INT32_MIN) && |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 245 | (0 <= health_info.legacy.batteryLevel && health_info.legacy.batteryLevel <= 100) && |
| 246 | verifyEnum<BatteryHealth>(health_info.legacy.batteryHealth) && |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 247 | verifyEnum<BatteryStatus>(health_info.legacy.batteryStatus))) { |
| 248 | return false; |
| 249 | } |
| 250 | |
Robin Lee | ac5a0d3 | 2019-10-09 15:48:17 +0200 | [diff] [blame] | 251 | if (health_info.legacy.batteryPresent) { |
| 252 | // If a battery is present, the battery status must be known. |
| 253 | if (!((health_info.legacy.batteryChargeCounter > 0) && |
| 254 | (health_info.legacy.batteryStatus != BatteryStatus::UNKNOWN))) { |
| 255 | return false; |
| 256 | } |
| 257 | } |
| 258 | |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 259 | return true; |
| 260 | } |
| 261 | |
| 262 | /* |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 263 | * Tests the values returned by getChargeCounter() from interface IHealth. |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 264 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 265 | TEST_P(HealthHidlTest, getChargeCounter) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 266 | SKIP_IF_SKIPPED(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 267 | EXPECT_OK(mHealth->getChargeCounter([](auto result, auto value) { |
| 268 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value > 0); |
| 269 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Tests the values returned by getCurrentNow() from interface IHealth. |
| 274 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 275 | TEST_P(HealthHidlTest, getCurrentNow) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 276 | SKIP_IF_SKIPPED(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 277 | EXPECT_OK(mHealth->getCurrentNow([](auto result, auto value) { |
| 278 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value != INT32_MIN); |
| 279 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /* |
| 283 | * Tests the values returned by getCurrentAverage() from interface IHealth. |
| 284 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 285 | TEST_P(HealthHidlTest, getCurrentAverage) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 286 | SKIP_IF_SKIPPED(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 287 | EXPECT_OK(mHealth->getCurrentAverage([](auto result, auto value) { |
| 288 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value != INT32_MIN); |
| 289 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Tests the values returned by getCapacity() from interface IHealth. |
| 294 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 295 | TEST_P(HealthHidlTest, getCapacity) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 296 | SKIP_IF_SKIPPED(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 297 | EXPECT_OK(mHealth->getCapacity([](auto result, auto value) { |
| 298 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), 0 <= value && value <= 100); |
| 299 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* |
| 303 | * Tests the values returned by getEnergyCounter() from interface IHealth. |
| 304 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 305 | TEST_P(HealthHidlTest, getEnergyCounter) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 306 | SKIP_IF_SKIPPED(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 307 | EXPECT_OK(mHealth->getEnergyCounter([](auto result, auto value) { |
| 308 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value != INT64_MIN); |
| 309 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /* |
| 313 | * Tests the values returned by getChargeStatus() from interface IHealth. |
| 314 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 315 | TEST_P(HealthHidlTest, getChargeStatus) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 316 | SKIP_IF_SKIPPED(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 317 | EXPECT_OK(mHealth->getChargeStatus([](auto result, auto value) { |
| 318 | EXPECT_VALID_OR_UNSUPPORTED_PROP( |
| 319 | result, toString(value), |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 320 | value != BatteryStatus::UNKNOWN && verifyEnum<BatteryStatus>(value)); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 321 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Tests the values returned by getStorageInfo() from interface IHealth. |
| 326 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 327 | TEST_P(HealthHidlTest, getStorageInfo) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 328 | SKIP_IF_SKIPPED(); |
Hridya Valsaraju | 2120ecc | 2017-12-20 13:27:52 -0800 | [diff] [blame] | 329 | EXPECT_OK(mHealth->getStorageInfo([](auto result, auto& value) { |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 330 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, toString(value), verifyStorageInfo(value)); |
Hridya Valsaraju | 2120ecc | 2017-12-20 13:27:52 -0800 | [diff] [blame] | 331 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* |
| 335 | * Tests the values returned by getDiskStats() from interface IHealth. |
| 336 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 337 | TEST_P(HealthHidlTest, getDiskStats) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 338 | SKIP_IF_SKIPPED(); |
Hridya Valsaraju | 2120ecc | 2017-12-20 13:27:52 -0800 | [diff] [blame] | 339 | EXPECT_OK(mHealth->getDiskStats([](auto result, auto& value) { |
Hridya Valsaraju | 075c182 | 2018-04-03 11:19:08 -0700 | [diff] [blame] | 340 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, toString(value), true); |
Hridya Valsaraju | 2120ecc | 2017-12-20 13:27:52 -0800 | [diff] [blame] | 341 | })); |
Yifan Hong | 26c1200 | 2018-10-02 14:52:02 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Tests the values returned by getHealthInfo() from interface IHealth. |
| 346 | */ |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 347 | TEST_P(HealthHidlTest, getHealthInfo) { |
Yifan Hong | 03b2a34 | 2019-03-08 11:37:33 -0800 | [diff] [blame] | 348 | SKIP_IF_SKIPPED(); |
Hridya Valsaraju | 87e2960 | 2018-01-12 17:46:22 -0800 | [diff] [blame] | 349 | EXPECT_OK(mHealth->getHealthInfo([](auto result, auto& value) { |
| 350 | EXPECT_VALID_OR_UNSUPPORTED_PROP(result, toString(value), verifyHealthInfo(value)); |
| 351 | })); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 352 | } |
| 353 | |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 354 | INSTANTIATE_TEST_SUITE_P( |
| 355 | PerInstance, HealthHidlTest, |
| 356 | testing::ValuesIn(android::hardware::getAllHalInstanceNames(IHealth::descriptor)), |
| 357 | android::hardware::PrintInstanceNameToString); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 358 | } // namespace V2_0 |
| 359 | } // namespace health |
| 360 | } // namespace hardware |
| 361 | } // namespace android |
| 362 | |
| 363 | int main(int argc, char** argv) { |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 364 | ::testing::InitGoogleTest(&argc, argv); |
Yifan Hong | e6807dd | 2019-03-07 13:04:33 -0800 | [diff] [blame] | 365 | gflags::ParseCommandLineFlags(&argc, &argv, true /* remove flags */); |
nelsonli | 4da3ca5 | 2019-12-10 17:17:09 +0800 | [diff] [blame] | 366 | return RUN_ALL_TESTS(); |
Yifan Hong | 69c2254 | 2017-10-03 17:40:24 -0700 | [diff] [blame] | 367 | } |