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()); |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 125 | if (mServiceVersion >= 2) { |
| 126 | status = power->createHintSession(getpid(), getuid(), kSelfTids, 16666666L, &mSession); |
| 127 | mSessionSupport = status.isOk(); |
| 128 | } |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 131 | std::shared_ptr<IPower> power; |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 132 | int32_t mServiceVersion; |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 133 | std::shared_ptr<IPowerHintSession> mSession; |
| 134 | bool mSessionSupport = false; |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | class HintSessionAidl : public PowerAidl { |
| 138 | public: |
| 139 | virtual void SetUp() override { |
| 140 | PowerAidl::SetUp(); |
| 141 | if (mServiceVersion < 2) { |
| 142 | GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond."; |
| 143 | } |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 144 | if (!mSessionSupport) { |
| 145 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 146 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 147 | ASSERT_NE(nullptr, mSession); |
| 148 | } |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 149 | }; |
| 150 | |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 151 | class FMQAidl : public PowerAidl { |
| 152 | public: |
| 153 | virtual void SetUp() override { |
| 154 | PowerAidl::SetUp(); |
| 155 | if (mServiceVersion < 5) { |
| 156 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 157 | } |
| 158 | |
| 159 | auto status = |
| 160 | power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L, |
| 161 | SessionTag::OTHER, &mSessionConfig, &mSession); |
| 162 | ASSERT_TRUE(status.isOk()); |
| 163 | ASSERT_NE(nullptr, mSession); |
| 164 | |
| 165 | status = power->getSessionChannel(getpid(), getuid(), &mChannelConfig); |
| 166 | ASSERT_TRUE(status.isOk()); |
| 167 | mChannel = std::make_shared<SessionMessageQueue>(mChannelConfig.channelDescriptor, true); |
| 168 | ASSERT_TRUE(mChannel->isValid()); |
| 169 | |
| 170 | if (mChannelConfig.eventFlagDescriptor.has_value()) { |
| 171 | mFlagChannel = |
| 172 | std::make_shared<FlagMessageQueue>(*mChannelConfig.eventFlagDescriptor, true); |
| 173 | ASSERT_EQ(EventFlag::createEventFlag(mFlagChannel->getEventFlagWord(), &mEventFlag), |
| 174 | ::android::OK); |
| 175 | } else { |
| 176 | ASSERT_EQ(EventFlag::createEventFlag(mChannel->getEventFlagWord(), &mEventFlag), |
| 177 | ::android::OK); |
| 178 | } |
| 179 | |
| 180 | ASSERT_NE(mEventFlag, nullptr); |
| 181 | } |
| 182 | virtual void TearDown() { |
| 183 | mSession->close(); |
| 184 | ASSERT_TRUE(power->closeSessionChannel(getpid(), getuid()).isOk()); |
| 185 | } |
| 186 | |
| 187 | protected: |
| 188 | std::shared_ptr<IPowerHintSession> mSession; |
| 189 | std::shared_ptr<SessionMessageQueue> mChannel; |
| 190 | std::shared_ptr<FlagMessageQueue> mFlagChannel; |
| 191 | SessionConfig mSessionConfig; |
| 192 | ChannelConfig mChannelConfig; |
| 193 | ::android::hardware::EventFlag* mEventFlag; |
| 194 | }; |
| 195 | |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 196 | TEST_P(PowerAidl, setMode) { |
| 197 | for (const auto& mode : kModes) { |
| 198 | ASSERT_TRUE(power->setMode(mode, true).isOk()); |
| 199 | ASSERT_TRUE(power->setMode(mode, false).isOk()); |
| 200 | } |
| 201 | for (const auto& mode : kInvalidModes) { |
| 202 | ASSERT_TRUE(power->setMode(mode, true).isOk()); |
| 203 | ASSERT_TRUE(power->setMode(mode, false).isOk()); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | TEST_P(PowerAidl, isModeSupported) { |
| 208 | for (const auto& mode : kModes) { |
| 209 | bool supported; |
| 210 | ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk()); |
| 211 | } |
| 212 | for (const auto& mode : kInvalidModes) { |
| 213 | bool supported; |
| 214 | ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk()); |
Dan Stoza | cca8027 | 2020-01-13 13:06:13 -0800 | [diff] [blame] | 215 | // Should return false for values outside enum |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 216 | ASSERT_FALSE(supported); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | TEST_P(PowerAidl, setBoost) { |
| 221 | for (const auto& boost : kBoosts) { |
| 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 | for (const auto& boost : kInvalidBoosts) { |
| 227 | ASSERT_TRUE(power->setBoost(boost, 0).isOk()); |
| 228 | ASSERT_TRUE(power->setBoost(boost, 1000).isOk()); |
| 229 | ASSERT_TRUE(power->setBoost(boost, -1).isOk()); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | TEST_P(PowerAidl, isBoostSupported) { |
| 234 | for (const auto& boost : kBoosts) { |
| 235 | bool supported; |
| 236 | ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk()); |
| 237 | } |
| 238 | for (const auto& boost : kInvalidBoosts) { |
| 239 | bool supported; |
| 240 | ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk()); |
Dan Stoza | cca8027 | 2020-01-13 13:06:13 -0800 | [diff] [blame] | 241 | // Should return false for values outside enum |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 242 | ASSERT_FALSE(supported); |
| 243 | } |
| 244 | } |
| 245 | |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 246 | TEST_P(PowerAidl, getHintSessionPreferredRate) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 247 | if (!mSessionSupport) { |
| 248 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 249 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 250 | if (mServiceVersion < 2) { |
| 251 | GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond."; |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 252 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 253 | |
| 254 | int64_t rate = -1; |
| 255 | ASSERT_TRUE(power->getHintSessionPreferredRate(&rate).isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 256 | // At least 1ms rate limit from HAL |
| 257 | ASSERT_GE(rate, 1000000); |
| 258 | } |
| 259 | |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 260 | TEST_P(PowerAidl, createHintSessionWithConfig) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 261 | if (!mSessionSupport) { |
| 262 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 263 | } |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 264 | if (mServiceVersion < 5) { |
| 265 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 266 | } |
| 267 | std::shared_ptr<IPowerHintSession> session; |
| 268 | SessionConfig config; |
| 269 | |
| 270 | auto status = power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L, |
| 271 | SessionTag::OTHER, &config, &session); |
| 272 | ASSERT_TRUE(status.isOk()); |
| 273 | ASSERT_NE(nullptr, session); |
| 274 | } |
| 275 | |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 276 | // FIXED_PERFORMANCE mode is required for all devices which ship on Android 11 |
| 277 | // or later |
| 278 | TEST_P(PowerAidl, hasFixedPerformance) { |
| 279 | bool supported; |
| 280 | ASSERT_TRUE(power->isModeSupported(Mode::FIXED_PERFORMANCE, &supported).isOk()); |
| 281 | ASSERT_TRUE(supported); |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 284 | TEST_P(HintSessionAidl, createAndCloseHintSession) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 285 | if (!mSessionSupport) { |
| 286 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 287 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 288 | ASSERT_TRUE(mSession->pause().isOk()); |
| 289 | ASSERT_TRUE(mSession->resume().isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 290 | // Test normal destroy operation |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 291 | ASSERT_TRUE(mSession->close().isOk()); |
| 292 | mSession.reset(); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 293 | } |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 294 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 295 | TEST_P(HintSessionAidl, createHintSessionFailed) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 296 | if (!mSessionSupport) { |
| 297 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 298 | } |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 299 | std::shared_ptr<IPowerHintSession> session; |
| 300 | auto status = power->createHintSession(getpid(), getuid(), kEmptyTids, 16666666L, &session); |
Peiyong Lin | 3e0eb72 | 2022-10-17 19:55:20 +0000 | [diff] [blame] | 301 | |
| 302 | // 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] | 303 | ASSERT_FALSE(status.isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 304 | ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode()); |
| 305 | } |
| 306 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 307 | TEST_P(HintSessionAidl, updateAndReportDurations) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 308 | if (!mSessionSupport) { |
| 309 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 310 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 311 | ASSERT_TRUE(mSession->updateTargetWorkDuration(16666667LL).isOk()); |
| 312 | ASSERT_TRUE(mSession->reportActualWorkDuration(kDurations).isOk()); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 315 | TEST_P(HintSessionAidl, sendSessionHint) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 316 | if (!mSessionSupport) { |
| 317 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 318 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 319 | if (mServiceVersion < 4) { |
| 320 | GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond."; |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 321 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 322 | |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 323 | for (const auto& sessionHint : kSessionHints) { |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 324 | ASSERT_TRUE(mSession->sendHint(sessionHint).isOk()); |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 325 | } |
| 326 | for (const auto& sessionHint : kInvalidSessionHints) { |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 327 | ASSERT_TRUE(mSession->sendHint(sessionHint).isOk()); |
Matt Buckley | 1384388 | 2022-09-15 22:32:56 +0000 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 331 | TEST_P(HintSessionAidl, setThreads) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 332 | if (!mSessionSupport) { |
| 333 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 334 | } |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 335 | if (mServiceVersion < 4) { |
| 336 | GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond."; |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 337 | } |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 338 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 339 | auto status = mSession->setThreads(kEmptyTids); |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 340 | ASSERT_FALSE(status.isOk()); |
| 341 | ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode()); |
| 342 | |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 343 | ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk()); |
Peiyong Lin | c785459 | 2022-10-13 00:10:31 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Matt Buckley | 1fde90c | 2023-06-28 19:55:26 +0000 | [diff] [blame] | 346 | TEST_P(HintSessionAidl, setSessionMode) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 347 | if (!mSessionSupport) { |
| 348 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 349 | } |
Matt Buckley | 1fde90c | 2023-06-28 19:55:26 +0000 | [diff] [blame] | 350 | if (mServiceVersion < 5) { |
| 351 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 352 | } |
| 353 | |
| 354 | for (const auto& sessionMode : kSessionModes) { |
| 355 | ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk()); |
| 356 | ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk()); |
| 357 | } |
| 358 | for (const auto& sessionMode : kInvalidSessionModes) { |
| 359 | ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk()); |
| 360 | ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk()); |
| 361 | } |
| 362 | } |
| 363 | |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 364 | TEST_P(HintSessionAidl, getSessionConfig) { |
jimmyshiu | 8191575 | 2024-03-15 16:37:19 +0000 | [diff] [blame] | 365 | if (!mSessionSupport) { |
| 366 | GTEST_SKIP() << "DEVICE not support Hint Session."; |
| 367 | } |
Matt Buckley | caac147 | 2023-12-12 03:55:50 +0000 | [diff] [blame] | 368 | if (mServiceVersion < 5) { |
| 369 | GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond."; |
| 370 | } |
| 371 | SessionConfig config; |
| 372 | ASSERT_TRUE(mSession->getSessionConfig(&config).isOk()); |
| 373 | } |
| 374 | |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 375 | TEST_P(FMQAidl, getAndCloseSessionChannel) {} |
| 376 | |
| 377 | TEST_P(FMQAidl, writeItems) { |
| 378 | std::vector<ChannelMessage> messages{ |
| 379 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 380 | .timeStampNanos = 1000, |
| 381 | .data = ChannelMessageContents::make<MessageTag::workDuration, WorkDurationFixedV1>( |
| 382 | {.durationNanos = 1000, |
| 383 | .workPeriodStartTimestampNanos = 10, |
| 384 | .cpuDurationNanos = 900, |
| 385 | .gpuDurationNanos = 100})}, |
| 386 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 387 | .timeStampNanos = 1000, |
| 388 | .data = ChannelMessageContents::make<MessageTag::mode, ModeSetter>( |
| 389 | {.modeInt = SessionMode::POWER_EFFICIENCY, .enabled = true})}, |
| 390 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 391 | .timeStampNanos = 1000, |
| 392 | .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>( |
| 393 | SessionHint::CPU_LOAD_UP)}, |
| 394 | {.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 395 | .timeStampNanos = 1000, |
| 396 | .data = ChannelMessageContents::make<MessageTag::targetDuration, int64_t>( |
| 397 | 10000000 /* 10ms */)}, |
| 398 | }; |
| 399 | for (auto& message : messages) { |
| 400 | ASSERT_TRUE(mChannel->writeBlocking(&message, 1, mChannelConfig.readFlagBitmask, |
| 401 | mChannelConfig.writeFlagBitmask, 100000000, |
| 402 | mEventFlag)); |
| 403 | } |
| 404 | // Make sure this still works after everything else is done to check crash |
| 405 | ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk()); |
| 406 | } |
| 407 | |
| 408 | TEST_P(FMQAidl, writeExcess) { |
| 409 | std::vector<ChannelMessage> messages; |
| 410 | size_t channelSize = mChannel->getQuantumCount(); |
| 411 | for (size_t i = 0; i < channelSize; ++i) { |
| 412 | messages.push_back({.sessionID = static_cast<int32_t>(mSessionConfig.id), |
| 413 | .timeStampNanos = 1000, |
| 414 | .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>( |
| 415 | SessionHint::CPU_LOAD_UP)}); |
| 416 | } |
| 417 | ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(), |
| 418 | mChannelConfig.readFlagBitmask, |
| 419 | mChannelConfig.writeFlagBitmask, 100000000, mEventFlag)); |
| 420 | ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(), |
| 421 | mChannelConfig.readFlagBitmask, |
| 422 | mChannelConfig.writeFlagBitmask, 1000000000, mEventFlag)); |
| 423 | // Make sure this still works after everything else is done to check crash |
| 424 | ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk()); |
Dan Stoza | cca8027 | 2020-01-13 13:06:13 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Dan Shi | ba4d532 | 2020-07-28 13:09:30 -0700 | [diff] [blame] | 427 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PowerAidl); |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 428 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HintSessionAidl); |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 429 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FMQAidl); |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 430 | |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 431 | INSTANTIATE_TEST_SUITE_P(Power, PowerAidl, |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 432 | testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)), |
| 433 | ::android::PrintInstanceNameToString); |
Matt Buckley | 42027e0 | 2023-08-07 23:50:04 +0000 | [diff] [blame] | 434 | INSTANTIATE_TEST_SUITE_P(Power, HintSessionAidl, |
| 435 | testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)), |
| 436 | ::android::PrintInstanceNameToString); |
Matt Buckley | f7c36d4 | 2024-02-27 01:31:43 +0000 | [diff] [blame] | 437 | INSTANTIATE_TEST_SUITE_P(Power, FMQAidl, |
| 438 | testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)), |
| 439 | ::android::PrintInstanceNameToString); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 440 | |
| 441 | } // namespace |
Xiang Wang | dd0edc6 | 2023-02-08 16:47:06 -0800 | [diff] [blame] | 442 | } // namespace aidl::android::hardware::power |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 443 | |
| 444 | int main(int argc, char** argv) { |
| 445 | ::testing::InitGoogleTest(&argc, argv); |
Wei Wang | 0500341 | 2021-04-01 10:44:29 -0700 | [diff] [blame] | 446 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 447 | ABinderProcess_startThreadPool(); |
Wei Wang | 61c2a33 | 2020-01-08 16:51:47 -0800 | [diff] [blame] | 448 | return RUN_ALL_TESTS(); |
| 449 | } |