blob: 9684c38fcc446aaef936f3b84fb4f27517b65336 [file] [log] [blame]
Wei Wang61c2a332020-01-08 16:51:47 -08001/*
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 Wang05003412021-04-01 10:44:29 -070019#include <aidl/android/hardware/power/BnPower.h>
20#include <aidl/android/hardware/power/BnPowerHintSession.h>
Dan Stozacca80272020-01-13 13:06:13 -080021#include <android-base/properties.h>
Wei Wang05003412021-04-01 10:44:29 -070022#include <android/binder_ibinder.h>
23#include <android/binder_manager.h>
24#include <android/binder_process.h>
Wei Wang9df909d2021-06-12 18:26:38 -070025#include <android/binder_status.h>
Wei Wang61c2a332020-01-08 16:51:47 -080026
Matt Buckleycaac1472023-12-12 03:55:50 +000027#include <fmq/AidlMessageQueue.h>
28#include <fmq/EventFlag.h>
29
Wei Wang05003412021-04-01 10:44:29 -070030#include <unistd.h>
Matt Buckleycaac1472023-12-12 03:55:50 +000031#include <cstdint>
32#include "aidl/android/hardware/common/fmq/SynchronizedReadWrite.h"
Wei Wang61c2a332020-01-08 16:51:47 -080033
Wei Wang05003412021-04-01 10:44:29 -070034namespace aidl::android::hardware::power {
35namespace {
36
Matt Buckleycaac1472023-12-12 03:55:50 +000037using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
38using ::android::AidlMessageQueue;
Matt Buckleyf7c36d42024-02-27 01:31:43 +000039using ::android::hardware::EventFlag;
Wei Wang61c2a332020-01-08 16:51:47 -080040using android::hardware::power::Boost;
Matt Buckleycaac1472023-12-12 03:55:50 +000041using android::hardware::power::ChannelConfig;
42using android::hardware::power::ChannelMessage;
Wei Wang61c2a332020-01-08 16:51:47 -080043using android::hardware::power::IPower;
Wei Wang05003412021-04-01 10:44:29 -070044using android::hardware::power::IPowerHintSession;
Wei Wang61c2a332020-01-08 16:51:47 -080045using android::hardware::power::Mode;
Matt Buckley13843882022-09-15 22:32:56 +000046using android::hardware::power::SessionHint;
Matt Buckley1fde90c2023-06-28 19:55:26 +000047using android::hardware::power::SessionMode;
Matt Buckley607720e2024-10-28 19:21:37 +000048using android::hardware::power::SupportInfo;
Wei Wang05003412021-04-01 10:44:29 -070049using android::hardware::power::WorkDuration;
Matt Buckleyf7c36d42024-02-27 01:31:43 +000050using ChannelMessageContents = ChannelMessage::ChannelMessageContents;
51using ModeSetter = ChannelMessage::ChannelMessageContents::SessionModeSetter;
52using MessageTag = ChannelMessage::ChannelMessageContents::Tag;
Wei Wang61c2a332020-01-08 16:51:47 -080053
Matt Buckleycaac1472023-12-12 03:55:50 +000054using SessionMessageQueue = AidlMessageQueue<ChannelMessage, SynchronizedReadWrite>;
Matt Buckleyf7c36d42024-02-27 01:31:43 +000055using FlagMessageQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
Matt Buckleycaac1472023-12-12 03:55:50 +000056
Wei Wang05003412021-04-01 10:44:29 -070057const std::vector<Boost> kBoosts{ndk::enum_range<Boost>().begin(), ndk::enum_range<Boost>().end()};
Wei Wang61c2a332020-01-08 16:51:47 -080058
Wei Wang05003412021-04-01 10:44:29 -070059const std::vector<Mode> kModes{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().end()};
Wei Wang61c2a332020-01-08 16:51:47 -080060
Matt Buckley13843882022-09-15 22:32:56 +000061const std::vector<SessionHint> kSessionHints{ndk::enum_range<SessionHint>().begin(),
62 ndk::enum_range<SessionHint>().end()};
63
Matt Buckley1fde90c2023-06-28 19:55:26 +000064const std::vector<SessionMode> kSessionModes{ndk::enum_range<SessionMode>().begin(),
65 ndk::enum_range<SessionMode>().end()};
66
Wei Wang61c2a332020-01-08 16:51:47 -080067const std::vector<Boost> kInvalidBoosts = {
68 static_cast<Boost>(static_cast<int32_t>(kBoosts.front()) - 1),
69 static_cast<Boost>(static_cast<int32_t>(kBoosts.back()) + 1),
70};
71
72const std::vector<Mode> kInvalidModes = {
73 static_cast<Mode>(static_cast<int32_t>(kModes.front()) - 1),
74 static_cast<Mode>(static_cast<int32_t>(kModes.back()) + 1),
75};
76
Matt Buckley13843882022-09-15 22:32:56 +000077const std::vector<SessionHint> kInvalidSessionHints = {
78 static_cast<SessionHint>(static_cast<int32_t>(kSessionHints.front()) - 1),
79 static_cast<SessionHint>(static_cast<int32_t>(kSessionHints.back()) + 1),
80};
81
Matt Buckley1fde90c2023-06-28 19:55:26 +000082const std::vector<SessionMode> kInvalidSessionModes = {
83 static_cast<SessionMode>(static_cast<int32_t>(kSessionModes.front()) - 1),
84 static_cast<SessionMode>(static_cast<int32_t>(kSessionModes.back()) + 1),
85};
86
Matt Buckley607720e2024-10-28 19:21:37 +000087template <class T>
88constexpr size_t enum_size() {
89 return static_cast<size_t>(*(ndk::enum_range<T>().end() - 1)) + 1;
90}
91
92template <class E>
93bool supportFromBitset(int64_t& supportInt, E type) {
94 return (supportInt >> static_cast<int>(type)) % 2;
95}
96
Wei Wang05003412021-04-01 10:44:29 -070097class DurationWrapper : public WorkDuration {
98 public:
99 DurationWrapper(int64_t dur, int64_t time) {
100 durationNanos = dur;
101 timeStampNanos = time;
102 }
103};
104
105const std::vector<int32_t> kSelfTids = {
106 gettid(),
107};
108
109const std::vector<int32_t> kEmptyTids = {};
110
Wei Wang05003412021-04-01 10:44:29 -0700111const std::vector<WorkDuration> kDurationsWithZero = {
112 DurationWrapper(1000L, 1L),
113 DurationWrapper(0L, 2L),
114};
115
116const std::vector<WorkDuration> kDurationsWithNegative = {
117 DurationWrapper(1000L, 1L),
118 DurationWrapper(-1000L, 2L),
119};
120
121const std::vector<WorkDuration> kDurations = {
122 DurationWrapper(1L, 1L),
123 DurationWrapper(1000L, 2L),
124 DurationWrapper(1000000L, 3L),
125 DurationWrapper(1000000000L, 4L),
126};
127
Wei Wang61c2a332020-01-08 16:51:47 -0800128class PowerAidl : public testing::TestWithParam<std::string> {
129 public:
130 virtual void SetUp() override {
Wei Wang05003412021-04-01 10:44:29 -0700131 AIBinder* binder = AServiceManager_waitForService(GetParam().c_str());
132 ASSERT_NE(binder, nullptr);
133 power = IPower::fromBinder(ndk::SpAIBinder(binder));
Matt Buckley42027e02023-08-07 23:50:04 +0000134 auto status = power->getInterfaceVersion(&mServiceVersion);
135 ASSERT_TRUE(status.isOk());
jimmyshiu81915752024-03-15 16:37:19 +0000136 if (mServiceVersion >= 2) {
137 status = power->createHintSession(getpid(), getuid(), kSelfTids, 16666666L, &mSession);
138 mSessionSupport = status.isOk();
139 }
Wei Wang61c2a332020-01-08 16:51:47 -0800140 }
141
Wei Wang05003412021-04-01 10:44:29 -0700142 std::shared_ptr<IPower> power;
Matt Buckley42027e02023-08-07 23:50:04 +0000143 int32_t mServiceVersion;
jimmyshiu81915752024-03-15 16:37:19 +0000144 std::shared_ptr<IPowerHintSession> mSession;
145 bool mSessionSupport = false;
Matt Buckley42027e02023-08-07 23:50:04 +0000146};
147
148class HintSessionAidl : public PowerAidl {
149 public:
150 virtual void SetUp() override {
151 PowerAidl::SetUp();
152 if (mServiceVersion < 2) {
153 GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond.";
154 }
jimmyshiu81915752024-03-15 16:37:19 +0000155 if (!mSessionSupport) {
156 GTEST_SKIP() << "DEVICE not support Hint Session.";
157 }
Matt Buckley42027e02023-08-07 23:50:04 +0000158 ASSERT_NE(nullptr, mSession);
159 }
Wei Wang61c2a332020-01-08 16:51:47 -0800160};
161
Matt Buckleyf7c36d42024-02-27 01:31:43 +0000162class FMQAidl : public PowerAidl {
163 public:
164 virtual void SetUp() override {
165 PowerAidl::SetUp();
166 if (mServiceVersion < 5) {
167 GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
168 }
169
170 auto status =
171 power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L,
172 SessionTag::OTHER, &mSessionConfig, &mSession);
Jimmy Shiua18a54d2024-03-20 08:21:22 +0000173 mSessionSupport = status.isOk();
174 if (!mSessionSupport) {
175 GTEST_SKIP() << "DEVICE not support Hint Session.";
176 }
Matt Buckleyf7c36d42024-02-27 01:31:43 +0000177 ASSERT_NE(nullptr, mSession);
178
179 status = power->getSessionChannel(getpid(), getuid(), &mChannelConfig);
180 ASSERT_TRUE(status.isOk());
181 mChannel = std::make_shared<SessionMessageQueue>(mChannelConfig.channelDescriptor, true);
182 ASSERT_TRUE(mChannel->isValid());
183
184 if (mChannelConfig.eventFlagDescriptor.has_value()) {
185 mFlagChannel =
186 std::make_shared<FlagMessageQueue>(*mChannelConfig.eventFlagDescriptor, true);
187 ASSERT_EQ(EventFlag::createEventFlag(mFlagChannel->getEventFlagWord(), &mEventFlag),
188 ::android::OK);
189 } else {
190 ASSERT_EQ(EventFlag::createEventFlag(mChannel->getEventFlagWord(), &mEventFlag),
191 ::android::OK);
192 }
193
194 ASSERT_NE(mEventFlag, nullptr);
195 }
196 virtual void TearDown() {
jimmyshiud3753ec2024-03-19 08:56:42 +0000197 if (mSession) {
198 mSession->close();
199 if (mChannel->isValid()) {
200 ASSERT_TRUE(power->closeSessionChannel(getpid(), getuid()).isOk());
201 }
202 }
Matt Buckleyf7c36d42024-02-27 01:31:43 +0000203 }
204
205 protected:
206 std::shared_ptr<IPowerHintSession> mSession;
207 std::shared_ptr<SessionMessageQueue> mChannel;
208 std::shared_ptr<FlagMessageQueue> mFlagChannel;
209 SessionConfig mSessionConfig;
210 ChannelConfig mChannelConfig;
211 ::android::hardware::EventFlag* mEventFlag;
212};
213
Wei Wang61c2a332020-01-08 16:51:47 -0800214TEST_P(PowerAidl, setMode) {
215 for (const auto& mode : kModes) {
216 ASSERT_TRUE(power->setMode(mode, true).isOk());
217 ASSERT_TRUE(power->setMode(mode, false).isOk());
218 }
219 for (const auto& mode : kInvalidModes) {
220 ASSERT_TRUE(power->setMode(mode, true).isOk());
221 ASSERT_TRUE(power->setMode(mode, false).isOk());
222 }
223}
224
225TEST_P(PowerAidl, isModeSupported) {
226 for (const auto& mode : kModes) {
227 bool supported;
228 ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk());
229 }
230 for (const auto& mode : kInvalidModes) {
231 bool supported;
232 ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk());
Dan Stozacca80272020-01-13 13:06:13 -0800233 // Should return false for values outside enum
Wei Wang61c2a332020-01-08 16:51:47 -0800234 ASSERT_FALSE(supported);
235 }
236}
237
238TEST_P(PowerAidl, setBoost) {
239 for (const auto& boost : kBoosts) {
240 ASSERT_TRUE(power->setBoost(boost, 0).isOk());
241 ASSERT_TRUE(power->setBoost(boost, 1000).isOk());
242 ASSERT_TRUE(power->setBoost(boost, -1).isOk());
243 }
244 for (const auto& boost : kInvalidBoosts) {
245 ASSERT_TRUE(power->setBoost(boost, 0).isOk());
246 ASSERT_TRUE(power->setBoost(boost, 1000).isOk());
247 ASSERT_TRUE(power->setBoost(boost, -1).isOk());
248 }
249}
250
251TEST_P(PowerAidl, isBoostSupported) {
252 for (const auto& boost : kBoosts) {
253 bool supported;
254 ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk());
255 }
256 for (const auto& boost : kInvalidBoosts) {
257 bool supported;
258 ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk());
Dan Stozacca80272020-01-13 13:06:13 -0800259 // Should return false for values outside enum
Wei Wang61c2a332020-01-08 16:51:47 -0800260 ASSERT_FALSE(supported);
261 }
262}
263
Wei Wang05003412021-04-01 10:44:29 -0700264TEST_P(PowerAidl, getHintSessionPreferredRate) {
jimmyshiu81915752024-03-15 16:37:19 +0000265 if (!mSessionSupport) {
266 GTEST_SKIP() << "DEVICE not support Hint Session.";
267 }
Matt Buckley42027e02023-08-07 23:50:04 +0000268 if (mServiceVersion < 2) {
269 GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond.";
Wei Wang05003412021-04-01 10:44:29 -0700270 }
Matt Buckley42027e02023-08-07 23:50:04 +0000271
272 int64_t rate = -1;
273 ASSERT_TRUE(power->getHintSessionPreferredRate(&rate).isOk());
Wei Wang05003412021-04-01 10:44:29 -0700274 // At least 1ms rate limit from HAL
275 ASSERT_GE(rate, 1000000);
276}
277
Matt Buckleycaac1472023-12-12 03:55:50 +0000278TEST_P(PowerAidl, createHintSessionWithConfig) {
jimmyshiu81915752024-03-15 16:37:19 +0000279 if (!mSessionSupport) {
280 GTEST_SKIP() << "DEVICE not support Hint Session.";
281 }
Matt Buckleycaac1472023-12-12 03:55:50 +0000282 if (mServiceVersion < 5) {
283 GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
284 }
285 std::shared_ptr<IPowerHintSession> session;
286 SessionConfig config;
287
288 auto status = power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L,
289 SessionTag::OTHER, &config, &session);
290 ASSERT_TRUE(status.isOk());
291 ASSERT_NE(nullptr, session);
292}
293
Matt Buckleyf7c36d42024-02-27 01:31:43 +0000294// FIXED_PERFORMANCE mode is required for all devices which ship on Android 11
295// or later
296TEST_P(PowerAidl, hasFixedPerformance) {
297 bool supported;
298 ASSERT_TRUE(power->isModeSupported(Mode::FIXED_PERFORMANCE, &supported).isOk());
299 ASSERT_TRUE(supported);
Matt Buckleycaac1472023-12-12 03:55:50 +0000300}
301
Matt Buckley607720e2024-10-28 19:21:37 +0000302TEST_P(PowerAidl, hasSupportInfo) {
303 SupportInfo config;
304 ASSERT_TRUE(power->getSupportInfo(&config).isOk());
305 for (Mode mode : kModes) {
306 bool supported;
307 power->isModeSupported(mode, &supported);
308 ASSERT_EQ(supported, supportFromBitset(config.modes, mode));
309 }
310 for (Boost boost : kBoosts) {
311 bool supported;
312 power->isBoostSupported(boost, &supported);
313 ASSERT_EQ(supported, supportFromBitset(config.boosts, boost));
314 }
315}
316
Matt Buckley42027e02023-08-07 23:50:04 +0000317TEST_P(HintSessionAidl, createAndCloseHintSession) {
jimmyshiu81915752024-03-15 16:37:19 +0000318 if (!mSessionSupport) {
319 GTEST_SKIP() << "DEVICE not support Hint Session.";
320 }
Matt Buckley42027e02023-08-07 23:50:04 +0000321 ASSERT_TRUE(mSession->pause().isOk());
322 ASSERT_TRUE(mSession->resume().isOk());
Wei Wang05003412021-04-01 10:44:29 -0700323 // Test normal destroy operation
Matt Buckley42027e02023-08-07 23:50:04 +0000324 ASSERT_TRUE(mSession->close().isOk());
325 mSession.reset();
Wei Wang05003412021-04-01 10:44:29 -0700326}
Matt Buckley13843882022-09-15 22:32:56 +0000327
Matt Buckley42027e02023-08-07 23:50:04 +0000328TEST_P(HintSessionAidl, createHintSessionFailed) {
jimmyshiu81915752024-03-15 16:37:19 +0000329 if (!mSessionSupport) {
330 GTEST_SKIP() << "DEVICE not support Hint Session.";
331 }
Wei Wang05003412021-04-01 10:44:29 -0700332 std::shared_ptr<IPowerHintSession> session;
333 auto status = power->createHintSession(getpid(), getuid(), kEmptyTids, 16666666L, &session);
Peiyong Lin3e0eb722022-10-17 19:55:20 +0000334
335 // Regardless of whether V2 and beyond is supported, the status is always not STATUS_OK.
Wei Wang05003412021-04-01 10:44:29 -0700336 ASSERT_FALSE(status.isOk());
Wei Wang05003412021-04-01 10:44:29 -0700337 ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode());
338}
339
Matt Buckley42027e02023-08-07 23:50:04 +0000340TEST_P(HintSessionAidl, updateAndReportDurations) {
jimmyshiu81915752024-03-15 16:37:19 +0000341 if (!mSessionSupport) {
342 GTEST_SKIP() << "DEVICE not support Hint Session.";
343 }
Matt Buckley42027e02023-08-07 23:50:04 +0000344 ASSERT_TRUE(mSession->updateTargetWorkDuration(16666667LL).isOk());
345 ASSERT_TRUE(mSession->reportActualWorkDuration(kDurations).isOk());
Wei Wang05003412021-04-01 10:44:29 -0700346}
347
Matt Buckley42027e02023-08-07 23:50:04 +0000348TEST_P(HintSessionAidl, sendSessionHint) {
jimmyshiu81915752024-03-15 16:37:19 +0000349 if (!mSessionSupport) {
350 GTEST_SKIP() << "DEVICE not support Hint Session.";
351 }
Matt Buckley42027e02023-08-07 23:50:04 +0000352 if (mServiceVersion < 4) {
353 GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond.";
Matt Buckley13843882022-09-15 22:32:56 +0000354 }
Matt Buckley42027e02023-08-07 23:50:04 +0000355
Matt Buckley13843882022-09-15 22:32:56 +0000356 for (const auto& sessionHint : kSessionHints) {
Matt Buckley42027e02023-08-07 23:50:04 +0000357 ASSERT_TRUE(mSession->sendHint(sessionHint).isOk());
Matt Buckley13843882022-09-15 22:32:56 +0000358 }
359 for (const auto& sessionHint : kInvalidSessionHints) {
Matt Buckley42027e02023-08-07 23:50:04 +0000360 ASSERT_TRUE(mSession->sendHint(sessionHint).isOk());
Matt Buckley13843882022-09-15 22:32:56 +0000361 }
362}
363
Matt Buckley42027e02023-08-07 23:50:04 +0000364TEST_P(HintSessionAidl, setThreads) {
jimmyshiu81915752024-03-15 16:37:19 +0000365 if (!mSessionSupport) {
366 GTEST_SKIP() << "DEVICE not support Hint Session.";
367 }
Matt Buckley42027e02023-08-07 23:50:04 +0000368 if (mServiceVersion < 4) {
369 GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond.";
Peiyong Linc7854592022-10-13 00:10:31 +0000370 }
Peiyong Linc7854592022-10-13 00:10:31 +0000371
Matt Buckley42027e02023-08-07 23:50:04 +0000372 auto status = mSession->setThreads(kEmptyTids);
Peiyong Linc7854592022-10-13 00:10:31 +0000373 ASSERT_FALSE(status.isOk());
374 ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode());
375
Matt Buckley42027e02023-08-07 23:50:04 +0000376 ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk());
Peiyong Linc7854592022-10-13 00:10:31 +0000377}
378
Matt Buckley1fde90c2023-06-28 19:55:26 +0000379TEST_P(HintSessionAidl, setSessionMode) {
jimmyshiu81915752024-03-15 16:37:19 +0000380 if (!mSessionSupport) {
381 GTEST_SKIP() << "DEVICE not support Hint Session.";
382 }
Matt Buckley1fde90c2023-06-28 19:55:26 +0000383 if (mServiceVersion < 5) {
384 GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
385 }
386
387 for (const auto& sessionMode : kSessionModes) {
388 ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk());
389 ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk());
390 }
391 for (const auto& sessionMode : kInvalidSessionModes) {
392 ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk());
393 ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk());
394 }
395}
396
Matt Buckleycaac1472023-12-12 03:55:50 +0000397TEST_P(HintSessionAidl, getSessionConfig) {
jimmyshiu81915752024-03-15 16:37:19 +0000398 if (!mSessionSupport) {
399 GTEST_SKIP() << "DEVICE not support Hint Session.";
400 }
Matt Buckleycaac1472023-12-12 03:55:50 +0000401 if (mServiceVersion < 5) {
402 GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
403 }
404 SessionConfig config;
405 ASSERT_TRUE(mSession->getSessionConfig(&config).isOk());
406}
407
Matt Buckleyf7c36d42024-02-27 01:31:43 +0000408TEST_P(FMQAidl, getAndCloseSessionChannel) {}
409
410TEST_P(FMQAidl, writeItems) {
411 std::vector<ChannelMessage> messages{
412 {.sessionID = static_cast<int32_t>(mSessionConfig.id),
413 .timeStampNanos = 1000,
414 .data = ChannelMessageContents::make<MessageTag::workDuration, WorkDurationFixedV1>(
415 {.durationNanos = 1000,
416 .workPeriodStartTimestampNanos = 10,
417 .cpuDurationNanos = 900,
418 .gpuDurationNanos = 100})},
419 {.sessionID = static_cast<int32_t>(mSessionConfig.id),
420 .timeStampNanos = 1000,
421 .data = ChannelMessageContents::make<MessageTag::mode, ModeSetter>(
422 {.modeInt = SessionMode::POWER_EFFICIENCY, .enabled = true})},
423 {.sessionID = static_cast<int32_t>(mSessionConfig.id),
424 .timeStampNanos = 1000,
425 .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>(
426 SessionHint::CPU_LOAD_UP)},
427 {.sessionID = static_cast<int32_t>(mSessionConfig.id),
428 .timeStampNanos = 1000,
429 .data = ChannelMessageContents::make<MessageTag::targetDuration, int64_t>(
430 10000000 /* 10ms */)},
431 };
432 for (auto& message : messages) {
433 ASSERT_TRUE(mChannel->writeBlocking(&message, 1, mChannelConfig.readFlagBitmask,
434 mChannelConfig.writeFlagBitmask, 100000000,
435 mEventFlag));
436 }
437 // Make sure this still works after everything else is done to check crash
438 ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk());
439}
440
441TEST_P(FMQAidl, writeExcess) {
442 std::vector<ChannelMessage> messages;
443 size_t channelSize = mChannel->getQuantumCount();
444 for (size_t i = 0; i < channelSize; ++i) {
445 messages.push_back({.sessionID = static_cast<int32_t>(mSessionConfig.id),
446 .timeStampNanos = 1000,
447 .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>(
448 SessionHint::CPU_LOAD_UP)});
449 }
450 ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(),
451 mChannelConfig.readFlagBitmask,
452 mChannelConfig.writeFlagBitmask, 100000000, mEventFlag));
453 ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(),
454 mChannelConfig.readFlagBitmask,
455 mChannelConfig.writeFlagBitmask, 1000000000, mEventFlag));
456 // Make sure this still works after everything else is done to check crash
457 ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk());
Dan Stozacca80272020-01-13 13:06:13 -0800458}
459
Dan Shiba4d5322020-07-28 13:09:30 -0700460GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PowerAidl);
Matt Buckley42027e02023-08-07 23:50:04 +0000461GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HintSessionAidl);
Matt Buckleyf7c36d42024-02-27 01:31:43 +0000462GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FMQAidl);
Matt Buckley42027e02023-08-07 23:50:04 +0000463
Wei Wang61c2a332020-01-08 16:51:47 -0800464INSTANTIATE_TEST_SUITE_P(Power, PowerAidl,
Wei Wang05003412021-04-01 10:44:29 -0700465 testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)),
466 ::android::PrintInstanceNameToString);
Matt Buckley42027e02023-08-07 23:50:04 +0000467INSTANTIATE_TEST_SUITE_P(Power, HintSessionAidl,
468 testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)),
469 ::android::PrintInstanceNameToString);
Matt Buckleyf7c36d42024-02-27 01:31:43 +0000470INSTANTIATE_TEST_SUITE_P(Power, FMQAidl,
471 testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)),
472 ::android::PrintInstanceNameToString);
Wei Wang05003412021-04-01 10:44:29 -0700473
474} // namespace
Xiang Wangdd0edc62023-02-08 16:47:06 -0800475} // namespace aidl::android::hardware::power
Wei Wang61c2a332020-01-08 16:51:47 -0800476
477int main(int argc, char** argv) {
478 ::testing::InitGoogleTest(&argc, argv);
Wei Wang05003412021-04-01 10:44:29 -0700479 ABinderProcess_setThreadPoolMaxThreadCount(1);
480 ABinderProcess_startThreadPool();
Wei Wang61c2a332020-01-08 16:51:47 -0800481 return RUN_ALL_TESTS();
482}