xref: /aosp_15_r20/hardware/interfaces/power/aidl/vts/VtsHalPowerTargetTest.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
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 
19 #include <aidl/android/hardware/power/BnPower.h>
20 #include <aidl/android/hardware/power/BnPowerHintSession.h>
21 #include <android-base/properties.h>
22 #include <android/binder_ibinder.h>
23 #include <android/binder_manager.h>
24 #include <android/binder_process.h>
25 #include <android/binder_status.h>
26 
27 #include <fmq/AidlMessageQueue.h>
28 #include <fmq/EventFlag.h>
29 
30 #include <unistd.h>
31 #include <cstdint>
32 #include "aidl/android/hardware/common/fmq/SynchronizedReadWrite.h"
33 #include "aidl/android/hardware/power/CpuHeadroomParams.h"
34 #include "aidl/android/hardware/power/GpuHeadroomParams.h"
35 
36 namespace aidl::android::hardware::power {
37 namespace {
38 
39 using namespace std::chrono_literals;
40 
41 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
42 using ::android::AidlMessageQueue;
43 using ::android::hardware::EventFlag;
44 using android::hardware::power::Boost;
45 using android::hardware::power::ChannelConfig;
46 using android::hardware::power::ChannelMessage;
47 using android::hardware::power::CpuHeadroomParams;
48 using android::hardware::power::CpuHeadroomResult;
49 using android::hardware::power::GpuHeadroomParams;
50 using android::hardware::power::GpuHeadroomResult;
51 using android::hardware::power::IPower;
52 using android::hardware::power::IPowerHintSession;
53 using android::hardware::power::Mode;
54 using android::hardware::power::SessionHint;
55 using android::hardware::power::SessionMode;
56 using android::hardware::power::SupportInfo;
57 using android::hardware::power::WorkDuration;
58 using ChannelMessageContents = ChannelMessage::ChannelMessageContents;
59 using ModeSetter = ChannelMessage::ChannelMessageContents::SessionModeSetter;
60 using MessageTag = ChannelMessage::ChannelMessageContents::Tag;
61 
62 using SessionMessageQueue = AidlMessageQueue<ChannelMessage, SynchronizedReadWrite>;
63 using FlagMessageQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
64 
65 const std::vector<Boost> kBoosts{ndk::enum_range<Boost>().begin(), ndk::enum_range<Boost>().end()};
66 
67 const std::vector<Mode> kModes{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().end()};
68 
69 const std::vector<SessionHint> kSessionHints{ndk::enum_range<SessionHint>().begin(),
70                                              ndk::enum_range<SessionHint>().end()};
71 
72 const std::vector<SessionMode> kSessionModes{ndk::enum_range<SessionMode>().begin(),
73                                              ndk::enum_range<SessionMode>().end()};
74 
75 const std::vector<Boost> kInvalidBoosts = {
76         static_cast<Boost>(static_cast<int32_t>(kBoosts.front()) - 1),
77         static_cast<Boost>(static_cast<int32_t>(kBoosts.back()) + 1),
78 };
79 
80 const std::vector<Mode> kInvalidModes = {
81         static_cast<Mode>(static_cast<int32_t>(kModes.front()) - 1),
82         static_cast<Mode>(static_cast<int32_t>(kModes.back()) + 1),
83 };
84 
85 const std::vector<SessionHint> kInvalidSessionHints = {
86         static_cast<SessionHint>(static_cast<int32_t>(kSessionHints.front()) - 1),
87         static_cast<SessionHint>(static_cast<int32_t>(kSessionHints.back()) + 1),
88 };
89 
90 const std::vector<SessionMode> kInvalidSessionModes = {
91         static_cast<SessionMode>(static_cast<int32_t>(kSessionModes.front()) - 1),
92         static_cast<SessionMode>(static_cast<int32_t>(kSessionModes.back()) + 1),
93 };
94 
95 template <class T>
enum_size()96 constexpr size_t enum_size() {
97     return static_cast<size_t>(*(ndk::enum_range<T>().end() - 1)) + 1;
98 }
99 
100 template <class E>
supportFromBitset(int64_t & supportInt,E type)101 bool supportFromBitset(int64_t& supportInt, E type) {
102     return (supportInt >> static_cast<int>(type)) % 2;
103 }
104 
105 class DurationWrapper : public WorkDuration {
106   public:
DurationWrapper(int64_t dur,int64_t time)107     DurationWrapper(int64_t dur, int64_t time) {
108         durationNanos = dur;
109         timeStampNanos = time;
110     }
111 };
112 
113 const std::vector<int32_t> kSelfTids = {
114         gettid(),
115 };
116 
117 const std::vector<int32_t> kEmptyTids = {};
118 
119 const std::vector<WorkDuration> kDurationsWithZero = {
120         DurationWrapper(1000L, 1L),
121         DurationWrapper(0L, 2L),
122 };
123 
124 const std::vector<WorkDuration> kDurationsWithNegative = {
125         DurationWrapper(1000L, 1L),
126         DurationWrapper(-1000L, 2L),
127 };
128 
129 const std::vector<WorkDuration> kDurations = {
130         DurationWrapper(1L, 1L),
131         DurationWrapper(1000L, 2L),
132         DurationWrapper(1000000L, 3L),
133         DurationWrapper(1000000000L, 4L),
134 };
135 
136 class PowerAidl : public testing::TestWithParam<std::string> {
137   public:
SetUp()138     virtual void SetUp() override {
139         AIBinder* binder = AServiceManager_waitForService(GetParam().c_str());
140         ASSERT_NE(binder, nullptr);
141         power = IPower::fromBinder(ndk::SpAIBinder(binder));
142         auto status = power->getInterfaceVersion(&mServiceVersion);
143         ASSERT_TRUE(status.isOk());
144         if (mServiceVersion >= 2) {
145             status = power->createHintSession(getpid(), getuid(), kSelfTids, 16666666L, &mSession);
146             mSessionSupport = status.isOk();
147         }
148         if (mServiceVersion >= 6) {
149             mSupportInfo = std::make_optional<SupportInfo>();
150             ASSERT_TRUE(power->getSupportInfo(&(*mSupportInfo)).isOk());
151         }
152     }
153 
154     std::shared_ptr<IPower> power;
155     int32_t mServiceVersion;
156     std::shared_ptr<IPowerHintSession> mSession;
157     bool mSessionSupport = false;
158     std::optional<SupportInfo> mSupportInfo = std::nullopt;
159 };
160 
161 class HintSessionAidl : public PowerAidl {
162   public:
SetUp()163     virtual void SetUp() override {
164         PowerAidl::SetUp();
165         if (mServiceVersion < 2) {
166             GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond.";
167         }
168         if (!mSessionSupport) {
169             GTEST_SKIP() << "DEVICE not support Hint Session.";
170         }
171         ASSERT_NE(nullptr, mSession);
172     }
173 };
174 
175 class FMQAidl : public PowerAidl {
176   public:
SetUp()177     virtual void SetUp() override {
178         PowerAidl::SetUp();
179         if (mServiceVersion < 5) {
180             GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
181         }
182 
183         auto status =
184                 power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L,
185                                                    SessionTag::OTHER, &mSessionConfig, &mSession);
186         mSessionSupport = status.isOk();
187         if (!mSessionSupport) {
188             GTEST_SKIP() << "DEVICE not support Hint Session.";
189         }
190         ASSERT_NE(nullptr, mSession);
191 
192         status = power->getSessionChannel(getpid(), getuid(), &mChannelConfig);
193         ASSERT_TRUE(status.isOk());
194         mChannel = std::make_shared<SessionMessageQueue>(mChannelConfig.channelDescriptor, true);
195         ASSERT_TRUE(mChannel->isValid());
196 
197         if (mChannelConfig.eventFlagDescriptor.has_value()) {
198             mFlagChannel =
199                     std::make_shared<FlagMessageQueue>(*mChannelConfig.eventFlagDescriptor, true);
200             ASSERT_EQ(EventFlag::createEventFlag(mFlagChannel->getEventFlagWord(), &mEventFlag),
201                       ::android::OK);
202         } else {
203             ASSERT_EQ(EventFlag::createEventFlag(mChannel->getEventFlagWord(), &mEventFlag),
204                       ::android::OK);
205         }
206 
207         ASSERT_NE(mEventFlag, nullptr);
208     }
TearDown()209     virtual void TearDown() {
210         if (mSession) {
211             mSession->close();
212             if (mChannel->isValid()) {
213                 ASSERT_TRUE(power->closeSessionChannel(getpid(), getuid()).isOk());
214             }
215         }
216     }
217 
218   protected:
219     std::shared_ptr<IPowerHintSession> mSession;
220     std::shared_ptr<SessionMessageQueue> mChannel;
221     std::shared_ptr<FlagMessageQueue> mFlagChannel;
222     SessionConfig mSessionConfig;
223     ChannelConfig mChannelConfig;
224     ::android::hardware::EventFlag* mEventFlag;
225 };
226 
TEST_P(PowerAidl,setMode)227 TEST_P(PowerAidl, setMode) {
228     for (const auto& mode : kModes) {
229         ASSERT_TRUE(power->setMode(mode, true).isOk());
230         ASSERT_TRUE(power->setMode(mode, false).isOk());
231     }
232     for (const auto& mode : kInvalidModes) {
233         ASSERT_TRUE(power->setMode(mode, true).isOk());
234         ASSERT_TRUE(power->setMode(mode, false).isOk());
235     }
236 }
237 
TEST_P(PowerAidl,isModeSupported)238 TEST_P(PowerAidl, isModeSupported) {
239     for (const auto& mode : kModes) {
240         bool supported;
241         ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk());
242     }
243     for (const auto& mode : kInvalidModes) {
244         bool supported;
245         ASSERT_TRUE(power->isModeSupported(mode, &supported).isOk());
246         // Should return false for values outside enum
247         ASSERT_FALSE(supported);
248     }
249 }
250 
TEST_P(PowerAidl,setBoost)251 TEST_P(PowerAidl, setBoost) {
252     for (const auto& boost : kBoosts) {
253         ASSERT_TRUE(power->setBoost(boost, 0).isOk());
254         ASSERT_TRUE(power->setBoost(boost, 1000).isOk());
255         ASSERT_TRUE(power->setBoost(boost, -1).isOk());
256     }
257     for (const auto& boost : kInvalidBoosts) {
258         ASSERT_TRUE(power->setBoost(boost, 0).isOk());
259         ASSERT_TRUE(power->setBoost(boost, 1000).isOk());
260         ASSERT_TRUE(power->setBoost(boost, -1).isOk());
261     }
262 }
263 
TEST_P(PowerAidl,isBoostSupported)264 TEST_P(PowerAidl, isBoostSupported) {
265     for (const auto& boost : kBoosts) {
266         bool supported;
267         ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk());
268     }
269     for (const auto& boost : kInvalidBoosts) {
270         bool supported;
271         ASSERT_TRUE(power->isBoostSupported(boost, &supported).isOk());
272         // Should return false for values outside enum
273         ASSERT_FALSE(supported);
274     }
275 }
276 
TEST_P(PowerAidl,getHintSessionPreferredRate)277 TEST_P(PowerAidl, getHintSessionPreferredRate) {
278     if (!mSessionSupport) {
279         GTEST_SKIP() << "DEVICE not support Hint Session.";
280     }
281     if (mServiceVersion < 2) {
282         GTEST_SKIP() << "DEVICE not launching with Power V2 and beyond.";
283     }
284 
285     int64_t rate = -1;
286     ASSERT_TRUE(power->getHintSessionPreferredRate(&rate).isOk());
287     // At least 1ms rate limit from HAL
288     ASSERT_GE(rate, 1000000);
289 }
290 
TEST_P(PowerAidl,createHintSessionWithConfig)291 TEST_P(PowerAidl, createHintSessionWithConfig) {
292     if (!mSessionSupport) {
293         GTEST_SKIP() << "DEVICE not support Hint Session.";
294     }
295     if (mServiceVersion < 5) {
296         GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
297     }
298     std::shared_ptr<IPowerHintSession> session;
299     SessionConfig config;
300 
301     auto status = power->createHintSessionWithConfig(getpid(), getuid(), kSelfTids, 16666666L,
302                                                      SessionTag::OTHER, &config, &session);
303     ASSERT_TRUE(status.isOk());
304     ASSERT_NE(nullptr, session);
305 }
306 
TEST_P(PowerAidl,getCpuHeadroom)307 TEST_P(PowerAidl, getCpuHeadroom) {
308     if (mServiceVersion < 6) {
309         GTEST_SKIP() << "DEVICE not launching with Power V6 and beyond.";
310     }
311     CpuHeadroomParams params;
312     CpuHeadroomResult headroom;
313     auto ret = power->getCpuHeadroom(params, &headroom);
314     if (!mSupportInfo->headroom.isCpuSupported) {
315         ASSERT_EQ(ret.getExceptionCode(), EX_UNSUPPORTED_OPERATION);
316         GTEST_SKIP() << "power->getCpuHeadroom is not supported";
317     }
318     ASSERT_TRUE(ret.isOk());
319     ASSERT_GE(mSupportInfo->headroom.cpuMinIntervalMillis, 0);
320     ASSERT_EQ(headroom.getTag(), CpuHeadroomResult::globalHeadroom);
321     ASSERT_GE(headroom.get<CpuHeadroomResult::globalHeadroom>(), 0.0f);
322     ASSERT_LE(headroom.get<CpuHeadroomResult::globalHeadroom>(), 100.00f);
323 }
324 
TEST_P(PowerAidl,getGpuHeadroom)325 TEST_P(PowerAidl, getGpuHeadroom) {
326     if (mServiceVersion < 6) {
327         GTEST_SKIP() << "DEVICE not launching with Power V6 and beyond.";
328     }
329     GpuHeadroomParams params;
330     GpuHeadroomResult headroom;
331     auto ret = power->getGpuHeadroom(params, &headroom);
332     if (!mSupportInfo->headroom.isGpuSupported) {
333         ASSERT_EQ(ret.getExceptionCode(), EX_UNSUPPORTED_OPERATION);
334         GTEST_SKIP() << "power->getGpuHeadroom is not supported";
335     }
336     ASSERT_TRUE(ret.isOk());
337     ASSERT_GE(mSupportInfo->headroom.gpuMinIntervalMillis, 0);
338     ASSERT_EQ(headroom.getTag(), GpuHeadroomResult::globalHeadroom);
339     ASSERT_GE(headroom.get<GpuHeadroomResult::globalHeadroom>(), 0.0f);
340     ASSERT_LE(headroom.get<GpuHeadroomResult::globalHeadroom>(), 100.00f);
341 }
342 
343 // FIXED_PERFORMANCE mode is required for all devices which ship on Android 11
344 // or later
TEST_P(PowerAidl,hasFixedPerformance)345 TEST_P(PowerAidl, hasFixedPerformance) {
346     bool supported;
347     ASSERT_TRUE(power->isModeSupported(Mode::FIXED_PERFORMANCE, &supported).isOk());
348     ASSERT_TRUE(supported);
349 }
350 
TEST_P(PowerAidl,hasSupportInfo)351 TEST_P(PowerAidl, hasSupportInfo) {
352     if (mServiceVersion < 6) {
353         GTEST_SKIP() << "DEVICE not launching with Power V6 and beyond.";
354     }
355     ASSERT_TRUE(mSupportInfo.has_value());
356     for (Mode mode : kModes) {
357         bool supported;
358         power->isModeSupported(mode, &supported);
359         ASSERT_EQ(supported, supportFromBitset(mSupportInfo->modes, mode));
360     }
361     for (Boost boost : kBoosts) {
362         bool supported;
363         power->isBoostSupported(boost, &supported);
364         ASSERT_EQ(supported, supportFromBitset(mSupportInfo->boosts, boost));
365     }
366 }
367 
TEST_P(PowerAidl,receivesCompositionData)368 TEST_P(PowerAidl, receivesCompositionData) {
369     if (mServiceVersion < 6) {
370         GTEST_SKIP() << "DEVICE not launching with Power V6 and beyond.";
371     }
372     if (mSupportInfo->compositionData.isSupported) {
373         GTEST_SKIP() << "Composition data marked as unsupported.";
374     }
375     // Sending an empty object is fine, we just want to confirm it accepts the tx
376     std::vector<CompositionData> out{};
377     out.emplace_back();
378     auto status = power->sendCompositionData(out);
379     ASSERT_TRUE(status.isOk());
380 }
381 
TEST_P(PowerAidl,receivesCompositionUpdate)382 TEST_P(PowerAidl, receivesCompositionUpdate) {
383     if (mServiceVersion < 6) {
384         GTEST_SKIP() << "DEVICE not launching with Power V6 and beyond.";
385     }
386     if (mSupportInfo->compositionData.isSupported) {
387         GTEST_SKIP() << "Composition data marked as unsupported.";
388     }
389 
390     CompositionUpdate out{};
391     auto status = power->sendCompositionUpdate(out);
392     ASSERT_TRUE(status.isOk());
393 }
394 
TEST_P(HintSessionAidl,createAndCloseHintSession)395 TEST_P(HintSessionAidl, createAndCloseHintSession) {
396     if (!mSessionSupport) {
397         GTEST_SKIP() << "DEVICE not support Hint Session.";
398     }
399     ASSERT_TRUE(mSession->pause().isOk());
400     ASSERT_TRUE(mSession->resume().isOk());
401     // Test normal destroy operation
402     ASSERT_TRUE(mSession->close().isOk());
403     mSession.reset();
404 }
405 
TEST_P(HintSessionAidl,createHintSessionFailed)406 TEST_P(HintSessionAidl, createHintSessionFailed) {
407     if (!mSessionSupport) {
408         GTEST_SKIP() << "DEVICE not support Hint Session.";
409     }
410     std::shared_ptr<IPowerHintSession> session;
411     auto status = power->createHintSession(getpid(), getuid(), kEmptyTids, 16666666L, &session);
412 
413     // Regardless of whether V2 and beyond is supported, the status is always not STATUS_OK.
414     ASSERT_FALSE(status.isOk());
415     ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode());
416 }
417 
TEST_P(HintSessionAidl,updateAndReportDurations)418 TEST_P(HintSessionAidl, updateAndReportDurations) {
419     if (!mSessionSupport) {
420         GTEST_SKIP() << "DEVICE not support Hint Session.";
421     }
422     ASSERT_TRUE(mSession->updateTargetWorkDuration(16666667LL).isOk());
423     ASSERT_TRUE(mSession->reportActualWorkDuration(kDurations).isOk());
424 }
425 
TEST_P(HintSessionAidl,sendSessionHint)426 TEST_P(HintSessionAidl, sendSessionHint) {
427     if (!mSessionSupport) {
428         GTEST_SKIP() << "DEVICE not support Hint Session.";
429     }
430     if (mServiceVersion < 4) {
431         GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond.";
432     }
433 
434     for (const auto& sessionHint : kSessionHints) {
435         ASSERT_TRUE(mSession->sendHint(sessionHint).isOk());
436     }
437     for (const auto& sessionHint : kInvalidSessionHints) {
438         ASSERT_TRUE(mSession->sendHint(sessionHint).isOk());
439     }
440 }
441 
TEST_P(HintSessionAidl,setThreads)442 TEST_P(HintSessionAidl, setThreads) {
443     if (!mSessionSupport) {
444         GTEST_SKIP() << "DEVICE not support Hint Session.";
445     }
446     if (mServiceVersion < 4) {
447         GTEST_SKIP() << "DEVICE not launching with Power V4 and beyond.";
448     }
449 
450     auto status = mSession->setThreads(kEmptyTids);
451     ASSERT_FALSE(status.isOk());
452     ASSERT_EQ(EX_ILLEGAL_ARGUMENT, status.getExceptionCode());
453 
454     ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk());
455 }
456 
TEST_P(HintSessionAidl,setSessionMode)457 TEST_P(HintSessionAidl, setSessionMode) {
458     if (!mSessionSupport) {
459         GTEST_SKIP() << "DEVICE not support Hint Session.";
460     }
461     if (mServiceVersion < 5) {
462         GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
463     }
464 
465     for (const auto& sessionMode : kSessionModes) {
466         ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk());
467         ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk());
468     }
469     for (const auto& sessionMode : kInvalidSessionModes) {
470         ASSERT_TRUE(mSession->setMode(sessionMode, true).isOk());
471         ASSERT_TRUE(mSession->setMode(sessionMode, false).isOk());
472     }
473 }
474 
TEST_P(HintSessionAidl,getSessionConfig)475 TEST_P(HintSessionAidl, getSessionConfig) {
476     if (!mSessionSupport) {
477         GTEST_SKIP() << "DEVICE not support Hint Session.";
478     }
479     if (mServiceVersion < 5) {
480         GTEST_SKIP() << "DEVICE not launching with Power V5 and beyond.";
481     }
482     SessionConfig config;
483     ASSERT_TRUE(mSession->getSessionConfig(&config).isOk());
484 }
485 
TEST_P(FMQAidl,getAndCloseSessionChannel)486 TEST_P(FMQAidl, getAndCloseSessionChannel) {}
487 
TEST_P(FMQAidl,writeItems)488 TEST_P(FMQAidl, writeItems) {
489     std::vector<ChannelMessage> messages{
490             {.sessionID = static_cast<int32_t>(mSessionConfig.id),
491              .timeStampNanos = 1000,
492              .data = ChannelMessageContents::make<MessageTag::workDuration, WorkDurationFixedV1>(
493                      {.durationNanos = 1000,
494                       .workPeriodStartTimestampNanos = 10,
495                       .cpuDurationNanos = 900,
496                       .gpuDurationNanos = 100})},
497             {.sessionID = static_cast<int32_t>(mSessionConfig.id),
498              .timeStampNanos = 1000,
499              .data = ChannelMessageContents::make<MessageTag::mode, ModeSetter>(
500                      {.modeInt = SessionMode::POWER_EFFICIENCY, .enabled = true})},
501             {.sessionID = static_cast<int32_t>(mSessionConfig.id),
502              .timeStampNanos = 1000,
503              .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>(
504                      SessionHint::CPU_LOAD_UP)},
505             {.sessionID = static_cast<int32_t>(mSessionConfig.id),
506              .timeStampNanos = 1000,
507              .data = ChannelMessageContents::make<MessageTag::targetDuration, int64_t>(
508                      10000000 /* 10ms */)},
509     };
510     for (auto& message : messages) {
511         ASSERT_TRUE(mChannel->writeBlocking(&message, 1, mChannelConfig.readFlagBitmask,
512                                             mChannelConfig.writeFlagBitmask, 100000000,
513                                             mEventFlag));
514     }
515     // Make sure this still works after everything else is done to check crash
516     ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk());
517 }
518 
TEST_P(FMQAidl,writeExcess)519 TEST_P(FMQAidl, writeExcess) {
520     std::vector<ChannelMessage> messages;
521     size_t channelSize = mChannel->getQuantumCount();
522     for (size_t i = 0; i < channelSize; ++i) {
523         messages.push_back({.sessionID = static_cast<int32_t>(mSessionConfig.id),
524                             .timeStampNanos = 1000,
525                             .data = ChannelMessageContents::make<MessageTag::hint, SessionHint>(
526                                     SessionHint::CPU_LOAD_UP)});
527     }
528     ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(),
529                                         mChannelConfig.readFlagBitmask,
530                                         mChannelConfig.writeFlagBitmask, 100000000, mEventFlag));
531     ASSERT_TRUE(mChannel->writeBlocking(messages.data(), messages.size(),
532                                         mChannelConfig.readFlagBitmask,
533                                         mChannelConfig.writeFlagBitmask, 1000000000, mEventFlag));
534     // Make sure this still works after everything else is done to check crash
535     ASSERT_TRUE(mSession->setThreads(kSelfTids).isOk());
536 }
537 
538 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PowerAidl);
539 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HintSessionAidl);
540 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FMQAidl);
541 
542 INSTANTIATE_TEST_SUITE_P(Power, PowerAidl,
543                          testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)),
544                          ::android::PrintInstanceNameToString);
545 INSTANTIATE_TEST_SUITE_P(Power, HintSessionAidl,
546                          testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)),
547                          ::android::PrintInstanceNameToString);
548 INSTANTIATE_TEST_SUITE_P(Power, FMQAidl,
549                          testing::ValuesIn(::android::getAidlHalInstanceNames(IPower::descriptor)),
550                          ::android::PrintInstanceNameToString);
551 
552 }  // namespace
553 }  // namespace aidl::android::hardware::power
554 
main(int argc,char ** argv)555 int main(int argc, char** argv) {
556     ::testing::InitGoogleTest(&argc, argv);
557     ABinderProcess_setThreadPoolMaxThreadCount(1);
558     ABinderProcess_startThreadPool();
559     return RUN_ALL_TESTS();
560 }
561