Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -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 | #include <aidl/Gtest.h> |
| 17 | #include <aidl/Vintf.h> |
| 18 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 19 | #include <aidl/android/hardware/power/BnPower.h> |
| 20 | #include <aidl/android/hardware/power/BnPowerHintSession.h> |
Dan Stoza | cca8027 | 2020-01-13 13:06:13 -0800 | [diff] [blame] | 21 | #include <android-base/properties.h> |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 22 | #include <android/binder_ibinder.h> |
| 23 | #include <android/binder_manager.h> |
| 24 | #include <android/binder_process.h> |
Wei Wang | 9df909d | 2021-06-12 18:26:38 -0700 | [diff] [blame] | 25 | #include <android/binder_status.h> |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 26 | |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 27 | #include <fmq/AidlMessageQueue.h> |
| 28 | #include <fmq/EventFlag.h> |
| 29 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 30 | #include <unistd.h> |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 31 | #include <cstdint> |
| 32 | #include "aidl/android/hardware/common/fmq/SynchronizedReadWrite.h" |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 33 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 34 | namespace aidl::android::hardware::power { |
| 35 | namespace { |
| 36 | |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 37 | using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; |
| 38 | using ::android::AidlMessageQueue; |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 39 | using ::android::hardware::EventFlag; |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 40 | using android::hardware::power::Boost; |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 41 | using android::hardware::power::ChannelConfig; |
| 42 | using android::hardware::power::ChannelMessage; |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 43 | using android::hardware::power::IPower; |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 44 | using android::hardware::power::IPowerHintSession; |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 45 | using android::hardware::power::Mode; |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 46 | using android::hardware::power::SessionHint; |
Matt Buckley | 1fde90c | 2023-06-28 19:55:26 +0000 | [diff] [blame] | 47 | using android::hardware::power::SessionMode; |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 48 | using android::hardware::power::WorkDuration; |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 49 | using ChannelMessageContents = ChannelMessage::ChannelMessageContents; |
| 50 | using ModeSetter = ChannelMessage::ChannelMessageContents::SessionModeSetter; |
| 51 | using MessageTag = ChannelMessage::ChannelMessageContents::Tag; |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 52 | |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 53 | using SessionMessageQueue = AidlMessageQueue<ChannelMessage, SynchronizedReadWrite>; |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 54 | using FlagMessageQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>; |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 55 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 56 | const std::vector<Boost> kBoosts{ndk::enum_range<Boost>().begin(), ndk::enum_range<Boost>().end()}; |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 57 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 58 | const std::vector<Mode> kModes{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().end()}; |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 59 | |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 60 | const std::vector<SessionHint> kSessionHints{ndk::enum_range<SessionHint>().begin(), |
| 61 | ndk::enum_range<SessionHint>().end()}; |
| 62 | |
Matt Buckley | 1fde90c | 2023-06-28 19:55:26 +0000 | [diff] [blame] | 63 | const std::vector<SessionMode> kSessionModes{ndk::enum_range<SessionMode>().begin(), |
| 64 | ndk::enum_range<SessionMode>().end()}; |
| 65 | |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 66 | const std::vector<Boost> kInvalidBoosts = { |
| 67 | static_cast<Boost>(static_cast<int32_t>(kBoosts.front()) - 1), |
| 68 | static_cast<Boost>(static_cast<int32_t>(kBoosts.back()) + 1), |
| 69 | }; |
| 70 | |
| 71 | const std::vector<Mode> kInvalidModes = { |
| 72 | static_cast<Mode>(static_cast<int32_t>(kModes.front()) - 1), |
| 73 | static_cast<Mode>(static_cast<int32_t>(kModes.back()) + 1), |
| 74 | }; |
| 75 | |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 76 | const std::vector<SessionHint> kInvalidSessionHints = { |
| 77 | static_cast<SessionHint>(static_cast<int32_t>(kSessionHints.front()) - 1), |
| 78 | static_cast<SessionHint>(static_cast<int32_t>(kSessionHints.back()) + 1), |
| 79 | }; |
| 80 | |
Matt Buckley | 1fde90c | 2023-06-28 19:55:26 +0000 | [diff] [blame] | 81 | const std::vector<SessionMode> kInvalidSessionModes = { |
| 82 | static_cast<SessionMode>(static_cast<int32_t>(kSessionModes.front()) - 1), |
| 83 | static_cast<SessionMode>(static_cast<int32_t>(kSessionModes.back()) + 1), |
| 84 | }; |
| 85 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 86 | class DurationWrapper : public WorkDuration { |
| 87 | public: |
| 88 | DurationWrapper(int64_t dur, int64_t time) { |
| 89 | durationNanos = dur; |
| 90 | timeStampNanos = time; |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | const std::vector<int32_t> kSelfTids = { |
| 95 | gettid(), |
| 96 | }; |
| 97 | |
| 98 | const std::vector<int32_t> kEmptyTids = {}; |
| 99 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 100 | const std::vector<WorkDuration> kDurationsWithZero = { |
| 101 | DurationWrapper(1000L, 1L), |
| 102 | DurationWrapper(0L, 2L), |
| 103 | }; |
| 104 | |
| 105 | const std::vector<WorkDuration> kDurationsWithNegative = { |
| 106 | DurationWrapper(1000L, 1L), |
| 107 | DurationWrapper(-1000L, 2L), |
| 108 | }; |
| 109 | |
| 110 | const std::vector<WorkDuration> kDurations = { |
| 111 | DurationWrapper(1L, 1L), |
| 112 | DurationWrapper(1000L, 2L), |
| 113 | DurationWrapper(1000000L, 3L), |
| 114 | DurationWrapper(1000000000L, 4L), |
| 115 | }; |
| 116 | |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 117 | class PowerAidl : public testing::TestWithParam<std::string> { |
| 118 | public: |
| 119 | virtual void SetUp() override { |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 120 | AIBinder* binder = AServiceManager_waitForService(GetParam().c_str()); |
| 121 | ASSERT_NE(binder, nullptr); |
| 122 | power = IPower::fromBinder(ndk::SpAIBinder(binder)); |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 123 | auto status = power->getInterfaceVersion(&mServiceVersion); |
| 124 | ASSERT_TRUE(status.isOk()); |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 127 | std::shared_ptr<IPower> power; |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 128 | int32_t mServiceVersion; |
| 129 | }; |
| 130 | |
| 131 | class HintSessionAidl : public PowerAidl { |
| 132 | public: |
| 133 | virtual void SetUp() override { |
| 134 | PowerAidl::SetUp(); |
| 135 | if (mServiceVersion < 2) { |
| 136 | GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond."; |
| 137 | } |
| 138 | |
| 139 | auto status = power->createHintSession(getpid(), getuid(), kSelfTids, 16666666L, &mSession); |
| 140 | ASSERT_TRUE(status.isOk()); |
| 141 | ASSERT_NE(nullptr, mSession); |
| 142 | } |
| 143 | std::shared_ptr<IPowerHintSession> mSession; |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 146 | class FMQAidl : public PowerAidl { |
| 147 | public: |
| 148 | virtual void SetUp() override { |
| 149 | PowerAidl::SetUp(); |
| 150 | if (mServiceVersion < 5) { |
| 151 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 152 | } |
| 153 | |
| 154 | auto status = |
| 155 | power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L, |
| 156 | SessionTag::OTHER, &mSessionConfig, &mSession); |
| 157 | ASSERT_TRUE(status.isOk()); |
| 158 | ASSERT_NE(nullptr, mSession); |
| 159 | |
| 160 | status = power->getSessionChannel(getpid(), getuid(), &mChannelConfig); |
| 161 | ASSERT_TRUE(status.isOk()); |
| 162 | mChannel = std::make_shared<SessionMessageQueue>(mChannelConfig.channelDescriptor, true); |
| 163 | ASSERT_TRUE(mChannel->isValid()); |
| 164 | |
| 165 | if (mChannelConfig.eventFlagDescriptor.has_value()) { |
| 166 | mFlagChannel = |
| 167 | std::make_shared<FlagMessageQueue>(*mChannelConfig.eventFlagDescriptor, true); |
| 168 | ASSERT_EQ(EventFlag::createEventFlag(mFlagChannel->getEventFlagWord(), &mEventFlag), |
| 169 | ::android::OK); |
| 170 | } else { |
| 171 | ASSERT_EQ(EventFlag::createEventFlag(mChannel->getEventFlagWord(), &mEventFlag), |
| 172 | ::android::OK); |
| 173 | } |
| 174 | |
| 175 | ASSERT_NE(mEventFlag, nullptr); |
| 176 | } |
| 177 | virtual void TearDown() { |
| 178 | mSession->close(); |
| 179 | ASSERT_TRUE(power->closeSessionChannel(getpid(), getuid()).isOk()); |
| 180 | } |
| 181 | |
| 182 | protected: |
| 183 | std::shared_ptr<IPowerHintSession> mSession; |
| 184 | std::shared_ptr<SessionMessageQueue> mChannel; |
| 185 | std::shared_ptr<FlagMessageQueue> mFlagChannel; |
| 186 | SessionConfig mSessionConfig; |
| 187 | ChannelConfig mChannelConfig; |
| 188 | ::android::hardware::EventFlag* mEventFlag; |
| 189 | }; |
| 190 | |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 191 | TEST_P(PowerAidl, setMode) { |
| 192 | for (const auto& mode : kModes) { |
| 193 | ASSERT_TRUE(power->setMode(mode, true).isOk()); |
| 194 | ASSERT_TRUE(power->setMode(mode, false).isOk()); |
| 195 | } |
| 196 | for (const auto& mode : kInvalidModes) { |
| 197 | ASSERT_TRUE(power->setMode(mode, true).isOk()); |
| 198 | ASSERT_TRUE(power->setMode(mode, false).isOk()); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | TEST_P(PowerAidl, isModeSupported) { |
| 203 | for (const auto& mode : kModes) { |
| 204 | bool supported; |
| 205 | ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk()); |
| 206 | } |
| 207 | for (const auto& mode : kInvalidModes) { |
| 208 | bool supported; |
| 209 | ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk()); |
Dan Stoza | cca8027 | 2020-01-13 13:06:13 -0800 | [diff] [blame] | 210 | // Should return false for values outside enum |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 211 | ASSERT_FALSE(supported); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | TEST_P(PowerAidl, setBoost) { |
| 216 | for (const auto& boost : kBoosts) { |
| 217 | ASSERT_TRUE(power->setBoost(boost, 0).isOk()); |
| 218 | ASSERT_TRUE(power->setBoost(boost, 1000).isOk()); |
| 219 | ASSERT_TRUE(power->setBoost(boost, -1).isOk()); |
| 220 | } |
| 221 | for (const auto& boost : kInvalidBoosts) { |
| 222 | ASSERT_TRUE(power->setBoost(boost, 0).isOk()); |
| 223 | ASSERT_TRUE(power->setBoost(boost, 1000).isOk()); |
| 224 | ASSERT_TRUE(power->setBoost(boost, -1).isOk()); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | TEST_P(PowerAidl, isBoostSupported) { |
| 229 | for (const auto& boost : kBoosts) { |
| 230 | bool supported; |
| 231 | ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk()); |
| 232 | } |
| 233 | for (const auto& boost : kInvalidBoosts) { |
| 234 | bool supported; |
| 235 | ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk()); |
Dan Stoza | cca8027 | 2020-01-13 13:06:13 -0800 | [diff] [blame] | 236 | // Should return false for values outside enum |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 237 | ASSERT_FALSE(supported); |
| 238 | } |
| 239 | } |
| 240 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 241 | TEST_P(PowerAidl, getHintSessionPreferredRate) { |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 242 | if (mServiceVersion < 2) { |
| 243 | GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond."; |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 244 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 245 | |
| 246 | int64_t rate = -1; |
| 247 | ASSERT_TRUE(power->getHintSessionPreferredRate(&rate).isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 248 | // At least 1ms rate limit from HAL |
| 249 | ASSERT_GE(rate, 1000000); |
| 250 | } |
| 251 | |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 252 | TEST_P(PowerAidl, createHintSessionWithConfig) { |
| 253 | if (mServiceVersion < 5) { |
| 254 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 255 | } |
| 256 | std::shared_ptr<IPowerHintSession> session; |
| 257 | SessionConfig config; |
| 258 | |
| 259 | auto status = power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L, |
| 260 | SessionTag::OTHER, &config, &session); |
| 261 | ASSERT_TRUE(status.isOk()); |
| 262 | ASSERT_NE(nullptr, session); |
| 263 | } |
| 264 | |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 265 | // FIXED_PERFORMANCE mode is required for all devices which ship on Android 11 |
| 266 | // or later |
| 267 | TEST_P(PowerAidl, hasFixedPerformance) { |
| 268 | bool supported; |
| 269 | ASSERT_TRUE(power->isModeSupported(Mode::FIXED_PERFORMANCE, &supported).isOk()); |
| 270 | ASSERT_TRUE(supported); |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 273 | TEST_P(HintSessionAidl, createAndCloseHintSession) { |
| 274 | ASSERT_TRUE(mSession->pause().isOk()); |
| 275 | ASSERT_TRUE(mSession->resume().isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 276 | // Test normal destroy operation |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 277 | ASSERT_TRUE(mSession->close().isOk()); |
| 278 | mSession.reset(); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 279 | } |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 280 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 281 | TEST_P(HintSessionAidl, createHintSessionFailed) { |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 282 | std::shared_ptr<IPowerHintSession> session; |
| 283 | auto status = power->createHintSession(getpid(), getuid(), kEmptyTids, 16666666L, &session); |
Peiyong Lin | 3e0eb72 | 2022-10-17 19:55:20 +0000 | [diff] [blame] | 284 | |
| 285 | // Regardless of whether V2 and beyond is supported, the status is always not STATUS_OK. |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 286 | ASSERT_FALSE(status.isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 287 | ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode()); |
| 288 | } |
| 289 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 290 | TEST_P(HintSessionAidl, updateAndReportDurations) { |
| 291 | ASSERT_TRUE(mSession->updateTargetWorkDuration(16666667LL).isOk()); |
| 292 | ASSERT_TRUE(mSession->reportActualWorkDuration(kDurations).isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 295 | TEST_P(HintSessionAidl, sendSessionHint) { |
| 296 | if (mServiceVersion < 4) { |
| 297 | GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond."; |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 298 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 299 | |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 300 | for (const auto& sessionHint : kSessionHints) { |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 301 | ASSERT_TRUE(mSession->sendHint(sessionHint).isOk()); |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 302 | } |
| 303 | for (const auto& sessionHint : kInvalidSessionHints) { |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 304 | ASSERT_TRUE(mSession->sendHint(sessionHint).isOk()); |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 308 | TEST_P(HintSessionAidl, setThreads) { |
| 309 | if (mServiceVersion < 4) { |
| 310 | GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond."; |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 311 | } |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 312 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 313 | auto status = mSession->setThreads(kEmptyTids); |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 314 | ASSERT_FALSE(status.isOk()); |
| 315 | ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode()); |
| 316 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 317 | ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk()); |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Matt Buckley | 1fde90c | 2023-06-28 19:55:26 +0000 | [diff] [blame] | 320 | TEST_P(HintSessionAidl, setSessionMode) { |
| 321 | if (mServiceVersion < 5) { |
| 322 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 323 | } |
| 324 | |
| 325 | for (const auto& sessionMode : kSessionModes) { |
| 326 | ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk()); |
| 327 | ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk()); |
| 328 | } |
| 329 | for (const auto& sessionMode : kInvalidSessionModes) { |
| 330 | ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk()); |
| 331 | ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk()); |
| 332 | } |
| 333 | } |
| 334 | |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 335 | TEST_P(HintSessionAidl, getSessionConfig) { |
| 336 | if (mServiceVersion < 5) { |
| 337 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 338 | } |
| 339 | SessionConfig config; |
| 340 | ASSERT_TRUE(mSession->getSessionConfig(&config).isOk()); |
| 341 | } |
| 342 | |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 343 | TEST_P(FMQAidl, getAndCloseSessionChannel) {} |
| 344 | |
| 345 | TEST_P(FMQAidl, writeItems) { |
| 346 | std::vector<ChannelMessage> messages{ |
| 347 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 348 | .timeStampNanos = 1000, |
| 349 | .data = ChannelMessageContents::make<MessageTag::workDuration, WorkDurationFixedV1>( |
| 350 | {.durationNanos = 1000, |
| 351 | .workPeriodStartTimestampNanos = 10, |
| 352 | .cpuDurationNanos = 900, |
| 353 | .gpuDurationNanos = 100})}, |
| 354 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 355 | .timeStampNanos = 1000, |
| 356 | .data = ChannelMessageContents::make<MessageTag::mode, ModeSetter>( |
| 357 | {.modeInt = SessionMode::POWER_EFFICIENCY, .enabled = true})}, |
| 358 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 359 | .timeStampNanos = 1000, |
| 360 | .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>( |
| 361 | SessionHint::CPU_LOAD_UP)}, |
| 362 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 363 | .timeStampNanos = 1000, |
| 364 | .data = ChannelMessageContents::make<MessageTag::targetDuration, int64_t>( |
| 365 | 10000000 /* 10ms */)}, |
| 366 | }; |
| 367 | for (auto& message : messages) { |
| 368 | ASSERT_TRUE(mChannel->writeBlocking(&message, 1, mChannelConfig.readFlagBitmask, |
| 369 | mChannelConfig.writeFlagBitmask, 100000000, |
| 370 | mEventFlag)); |
| 371 | } |
| 372 | // Make sure this still works after everything else is done to check crash |
| 373 | ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk()); |
| 374 | } |
| 375 | |
| 376 | TEST_P(FMQAidl, writeExcess) { |
| 377 | std::vector<ChannelMessage> messages; |
| 378 | size_t channelSize = mChannel->getQuantumCount(); |
| 379 | for (size_t i = 0; i < channelSize; ++i) { |
| 380 | messages.push_back({.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 381 | .timeStampNanos = 1000, |
| 382 | .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>( |
| 383 | SessionHint::CPU_LOAD_UP)}); |
| 384 | } |
| 385 | ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(), |
| 386 | mChannelConfig.readFlagBitmask, |
| 387 | mChannelConfig.writeFlagBitmask, 100000000, mEventFlag)); |
| 388 | ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(), |
| 389 | mChannelConfig.readFlagBitmask, |
| 390 | mChannelConfig.writeFlagBitmask, 1000000000, mEventFlag)); |
| 391 | // Make sure this still works after everything else is done to check crash |
| 392 | ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk()); |
Dan Stoza | cca8027 | 2020-01-13 13:06:13 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Dan Shi | ba4d532 | 2020-07-28 13:09:30 -0700 | [diff] [blame] | 395 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PowerAidl); |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 396 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HintSessionAidl); |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 397 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FMQAidl); |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 398 | |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 399 | INSTANTIATE_TEST_SUITE_P(Power, PowerAidl, |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 400 | testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)), |
| 401 | ::android::PrintInstanceNameToString); |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 402 | INSTANTIATE_TEST_SUITE_P(Power, HintSessionAidl, |
| 403 | testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)), |
| 404 | ::android::PrintInstanceNameToString); |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 405 | INSTANTIATE_TEST_SUITE_P(Power, FMQAidl, |
| 406 | testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)), |
| 407 | ::android::PrintInstanceNameToString); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 408 | |
| 409 | } // namespace |
Xiang Wang | dd0edc6 | 2023-02-08 16:47:06 -0800 | [diff] [blame] | 410 | } // namespace aidl::android::hardware::power |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 411 | |
| 412 | int main(int argc, char** argv) { |
| 413 | ::testing::InitGoogleTest(&argc, argv); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 414 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 415 | ABinderProcess_startThreadPool(); |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 416 | return RUN_ALL_TESTS(); |
| 417 | } |