blob: 513b2ef8eabf6a4a666e5b057495242868f8bd38 [file] [log] [blame]
Lais Andrade4d51f6c2020-03-25 10:58:31 +00001/*
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
17#define LOG_TAG "PowerHalWrapperAidlTest"
18
Xiang Wang99f6f3c2023-05-22 13:12:16 -070019#include <aidl/android/hardware/power/Boost.h>
20#include <aidl/android/hardware/power/IPowerHintSession.h>
21#include <aidl/android/hardware/power/Mode.h>
Lais Andrade4d51f6c2020-03-25 10:58:31 +000022#include <binder/IServiceManager.h>
Lais Andrade4d51f6c2020-03-25 10:58:31 +000023#include <gmock/gmock.h>
24#include <gtest/gtest.h>
Lais Andrade4d51f6c2020-03-25 10:58:31 +000025#include <powermanager/PowerHalWrapper.h>
Lais Andradeb59a9b52020-05-07 17:23:42 +010026#include <utils/Log.h>
Lais Andrade4d51f6c2020-03-25 10:58:31 +000027
Jimmy Shiu0b264bb2021-03-03 00:30:50 +080028#include <unistd.h>
Lais Andrade4d51f6c2020-03-25 10:58:31 +000029#include <thread>
Lais Andrade4d51f6c2020-03-25 10:58:31 +000030
Matt Buckley290d4262024-11-21 01:47:05 +000031
Lais Andrade4d51f6c2020-03-25 10:58:31 +000032using android::binder::Status;
Lais Andrade4d51f6c2020-03-25 10:58:31 +000033
Matt Buckley290d4262024-11-21 01:47:05 +000034using namespace aidl::android::hardware::power;
Lais Andrade4d51f6c2020-03-25 10:58:31 +000035using namespace android;
Lais Andradeb59a9b52020-05-07 17:23:42 +010036using namespace android::power;
Lais Andrade4d51f6c2020-03-25 10:58:31 +000037using namespace std::chrono_literals;
38using namespace testing;
39
40// -------------------------------------------------------------------------------------------------
41
42class MockIPower : public IPower {
43public:
Xiang Wang99f6f3c2023-05-22 13:12:16 -070044 MockIPower() = default;
45
46 MOCK_METHOD(ndk::ScopedAStatus, isBoostSupported, (Boost boost, bool* ret), (override));
47 MOCK_METHOD(ndk::ScopedAStatus, setBoost, (Boost boost, int32_t durationMs), (override));
48 MOCK_METHOD(ndk::ScopedAStatus, isModeSupported, (Mode mode, bool* ret), (override));
49 MOCK_METHOD(ndk::ScopedAStatus, setMode, (Mode mode, bool enabled), (override));
50 MOCK_METHOD(ndk::ScopedAStatus, createHintSession,
Jimmy Shiu0b264bb2021-03-03 00:30:50 +080051 (int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
Xiang Wang99f6f3c2023-05-22 13:12:16 -070052 int64_t durationNanos, std::shared_ptr<IPowerHintSession>* session),
Jimmy Shiu0b264bb2021-03-03 00:30:50 +080053 (override));
Matt Buckley104f53a2023-12-14 00:19:20 +000054 MOCK_METHOD(ndk::ScopedAStatus, createHintSessionWithConfig,
55 (int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
56 int64_t durationNanos, SessionTag tag, SessionConfig* config,
57 std::shared_ptr<IPowerHintSession>* _aidl_return),
58 (override));
59 MOCK_METHOD(ndk::ScopedAStatus, getSessionChannel,
60 (int32_t tgid, int32_t uid, ChannelConfig* _aidl_return), (override));
61 MOCK_METHOD(ndk::ScopedAStatus, closeSessionChannel, (int32_t tgid, int32_t uid), (override));
Xiang Wang99f6f3c2023-05-22 13:12:16 -070062 MOCK_METHOD(ndk::ScopedAStatus, getHintSessionPreferredRate, (int64_t * rate), (override));
Matt Buckley666659a2024-10-28 18:41:40 +000063 MOCK_METHOD(ndk::ScopedAStatus, getSupportInfo, (SupportInfo * _aidl_return), (override));
Xiang Wang99f6f3c2023-05-22 13:12:16 -070064 MOCK_METHOD(ndk::ScopedAStatus, getInterfaceVersion, (int32_t * version), (override));
65 MOCK_METHOD(ndk::ScopedAStatus, getInterfaceHash, (std::string * hash), (override));
66 MOCK_METHOD(ndk::SpAIBinder, asBinder, (), (override));
67 MOCK_METHOD(bool, isRemote, (), (override));
Xiang Wangc7bf1642024-10-22 17:37:25 -070068 MOCK_METHOD(ndk::ScopedAStatus, getCpuHeadroom,
69 (const CpuHeadroomParams& params, std::vector<float>* headroom), (override));
70 MOCK_METHOD(ndk::ScopedAStatus, getGpuHeadroom,
71 (const GpuHeadroomParams& params, float* headroom), (override));
72 MOCK_METHOD(ndk::ScopedAStatus, getCpuHeadroomMinIntervalMillis, (int64_t* interval),
73 (override));
74 MOCK_METHOD(ndk::ScopedAStatus, getGpuHeadroomMinIntervalMillis, (int64_t* interval),
75 (override));
Matt Buckley290d4262024-11-21 01:47:05 +000076 MOCK_METHOD(ndk::ScopedAStatus, sendCompositionData,
77 (const std::vector<CompositionData>& in_data), (override));
78 MOCK_METHOD(ndk::ScopedAStatus, sendCompositionUpdate,
79 (const CompositionUpdate& in_update), (override));
Lais Andrade4d51f6c2020-03-25 10:58:31 +000080};
81
82// -------------------------------------------------------------------------------------------------
83
84class PowerHalWrapperAidlTest : public Test {
85public:
86 void SetUp() override;
87
88protected:
Lais Andradeb59a9b52020-05-07 17:23:42 +010089 std::unique_ptr<HalWrapper> mWrapper = nullptr;
Xiang Wang99f6f3c2023-05-22 13:12:16 -070090 std::shared_ptr<StrictMock<MockIPower>> mMockHal = nullptr;
Lais Andrade4d51f6c2020-03-25 10:58:31 +000091};
92
93// -------------------------------------------------------------------------------------------------
94
95void PowerHalWrapperAidlTest::SetUp() {
Xiang Wang99f6f3c2023-05-22 13:12:16 -070096 mMockHal = ndk::SharedRefBase::make<StrictMock<MockIPower>>();
Matt Buckley6c18e6d2024-02-07 23:39:50 +000097 EXPECT_CALL(*mMockHal, getInterfaceVersion(_)).WillRepeatedly(([](int32_t* ret) {
98 *ret = 5;
99 return ndk::ScopedAStatus::ok();
100 }));
Lais Andradeb59a9b52020-05-07 17:23:42 +0100101 mWrapper = std::make_unique<AidlHalWrapper>(mMockHal);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800102 ASSERT_NE(nullptr, mWrapper);
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000103}
104
105// -------------------------------------------------------------------------------------------------
106
107TEST_F(PowerHalWrapperAidlTest, TestSetBoostSuccessful) {
108 {
109 InSequence seq;
110 EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::DISPLAY_UPDATE_IMMINENT), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100111 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700112 .WillOnce(DoAll(SetArgPointee<1>(true),
113 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000114 EXPECT_CALL(*mMockHal.get(), setBoost(Eq(Boost::DISPLAY_UPDATE_IMMINENT), Eq(100)))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700115 .Times(Exactly(1))
116 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000117 }
118
119 auto result = mWrapper->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 100);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800120 ASSERT_TRUE(result.isOk());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000121}
122
123TEST_F(PowerHalWrapperAidlTest, TestSetBoostFailed) {
124 {
125 InSequence seq;
126 EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::INTERACTION), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100127 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700128 .WillOnce(DoAll(SetArgPointee<1>(true),
129 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000130 EXPECT_CALL(*mMockHal.get(), setBoost(Eq(Boost::INTERACTION), Eq(100)))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100131 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700132 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::fromExceptionCode(-1))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000133 EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::DISPLAY_UPDATE_IMMINENT), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100134 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700135 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::fromExceptionCode(-1))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000136 }
137
138 auto result = mWrapper->setBoost(Boost::INTERACTION, 100);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800139 ASSERT_TRUE(result.isFailed());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000140 result = mWrapper->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 1000);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800141 ASSERT_TRUE(result.isFailed());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000142}
143
144TEST_F(PowerHalWrapperAidlTest, TestSetBoostUnsupported) {
Matt Buckley6c18e6d2024-02-07 23:39:50 +0000145 EXPECT_CALL(*mMockHal.get(), isBoostSupported(_, _))
146 .Times(Exactly(2))
147 .WillRepeatedly([](Boost, bool* ret) {
148 *ret = false;
149 return ndk::ScopedAStatus::ok();
150 });
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000151
152 auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800153 ASSERT_TRUE(result.isUnsupported());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000154 result = mWrapper->setBoost(Boost::CAMERA_SHOT, 10);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800155 ASSERT_TRUE(result.isUnsupported());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000156}
157
158TEST_F(PowerHalWrapperAidlTest, TestSetBoostMultiThreadCheckSupportedOnlyOnce) {
159 {
160 InSequence seq;
161 EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::INTERACTION), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100162 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700163 .WillOnce(DoAll(SetArgPointee<1>(true),
164 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
165 auto& exp = EXPECT_CALL(*mMockHal.get(), setBoost(Eq(Boost::INTERACTION), Eq(100)))
166 .Times(Exactly(10));
167 for (int i = 0; i < 10; i++) {
168 exp.WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
169 }
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000170 }
171
172 std::vector<std::thread> threads;
173 for (int i = 0; i < 10; i++) {
174 threads.push_back(std::thread([&]() {
175 auto result = mWrapper->setBoost(Boost::INTERACTION, 100);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800176 ASSERT_TRUE(result.isOk());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000177 }));
178 }
179 std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
180}
181
182TEST_F(PowerHalWrapperAidlTest, TestSetModeSuccessful) {
183 {
184 InSequence seq;
185 EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::DISPLAY_INACTIVE), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100186 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700187 .WillOnce(DoAll(SetArgPointee<1>(true),
188 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000189 EXPECT_CALL(*mMockHal.get(), setMode(Eq(Mode::DISPLAY_INACTIVE), Eq(false)))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700190 .Times(Exactly(1))
191 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000192 }
193
194 auto result = mWrapper->setMode(Mode::DISPLAY_INACTIVE, false);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800195 ASSERT_TRUE(result.isOk());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000196}
197
198TEST_F(PowerHalWrapperAidlTest, TestSetModeFailed) {
199 {
200 InSequence seq;
201 EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::LAUNCH), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100202 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700203 .WillOnce(DoAll(SetArgPointee<1>(true),
204 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000205 EXPECT_CALL(*mMockHal.get(), setMode(Eq(Mode::LAUNCH), Eq(true)))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100206 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700207 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::fromExceptionCode(-1))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000208 EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::DISPLAY_INACTIVE), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100209 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700210 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::fromExceptionCode(-1))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000211 }
212
213 auto result = mWrapper->setMode(Mode::LAUNCH, true);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800214 ASSERT_TRUE(result.isFailed());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000215 result = mWrapper->setMode(Mode::DISPLAY_INACTIVE, false);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800216 ASSERT_TRUE(result.isFailed());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000217}
218
219TEST_F(PowerHalWrapperAidlTest, TestSetModeUnsupported) {
220 EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::LAUNCH), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100221 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700222 .WillOnce(DoAll(SetArgPointee<1>(false),
223 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000224
225 auto result = mWrapper->setMode(Mode::LAUNCH, true);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800226 ASSERT_TRUE(result.isUnsupported());
Jim Blackler559361b2021-11-29 00:07:39 +0000227
228 EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::CAMERA_STREAMING_HIGH), _))
229 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700230 .WillOnce(DoAll(SetArgPointee<1>(false),
231 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000232 result = mWrapper->setMode(Mode::CAMERA_STREAMING_HIGH, true);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800233 ASSERT_TRUE(result.isUnsupported());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000234}
235
236TEST_F(PowerHalWrapperAidlTest, TestSetModeMultiThreadCheckSupportedOnlyOnce) {
237 {
238 InSequence seq;
239 EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::LAUNCH), _))
Lais Andradeb59a9b52020-05-07 17:23:42 +0100240 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700241 .WillOnce(DoAll(SetArgPointee<1>(true),
242 Return(testing::ByMove(ndk::ScopedAStatus::ok()))));
243 auto& exp = EXPECT_CALL(*mMockHal.get(), setMode(Eq(Mode::LAUNCH), Eq(false)))
244 .Times(Exactly(10));
245 for (int i = 0; i < 10; i++) {
246 exp.WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
247 }
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000248 }
249
250 std::vector<std::thread> threads;
251 for (int i = 0; i < 10; i++) {
252 threads.push_back(std::thread([&]() {
253 auto result = mWrapper->setMode(Mode::LAUNCH, false);
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800254 ASSERT_TRUE(result.isOk());
Lais Andrade4d51f6c2020-03-25 10:58:31 +0000255 }));
256 }
257 std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
258}
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800259
260TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionSuccessful) {
261 std::vector<int> threadIds{gettid()};
262 int32_t tgid = 999;
263 int32_t uid = 1001;
264 int64_t durationNanos = 16666666L;
265 EXPECT_CALL(*mMockHal.get(),
266 createHintSession(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos), _))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700267 .Times(Exactly(1))
268 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800269 auto result = mWrapper->createHintSession(tgid, uid, threadIds, durationNanos);
270 ASSERT_TRUE(result.isOk());
271}
272
Matt Buckleydb4192a2023-12-21 20:00:32 +0000273TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionWithConfigSuccessful) {
274 std::vector<int> threadIds{gettid()};
275 int32_t tgid = 999;
276 int32_t uid = 1001;
277 int64_t durationNanos = 16666666L;
278 SessionTag tag = SessionTag::OTHER;
279 SessionConfig out;
280 EXPECT_CALL(*mMockHal.get(),
281 createHintSessionWithConfig(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos),
282 Eq(tag), _, _))
283 .Times(Exactly(1))
284 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
285 auto result =
286 mWrapper->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos, tag, &out);
287 ASSERT_TRUE(result.isOk());
288}
289
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800290TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionFailed) {
291 int32_t tgid = 999;
292 int32_t uid = 1001;
293 std::vector<int> threadIds{};
294 int64_t durationNanos = 16666666L;
295 EXPECT_CALL(*mMockHal.get(),
296 createHintSession(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos), _))
297 .Times(Exactly(1))
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700298 .WillOnce(Return(testing::ByMove(
299 ndk::ScopedAStatus::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT))));
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800300 auto result = mWrapper->createHintSession(tgid, uid, threadIds, durationNanos);
301 ASSERT_TRUE(result.isFailed());
302}
303
304TEST_F(PowerHalWrapperAidlTest, TestGetHintSessionPreferredRate) {
Xiang Wang99f6f3c2023-05-22 13:12:16 -0700305 EXPECT_CALL(*mMockHal.get(), getHintSessionPreferredRate(_))
306 .Times(Exactly(1))
307 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
Jimmy Shiu0b264bb2021-03-03 00:30:50 +0800308 auto result = mWrapper->getHintSessionPreferredRate();
309 ASSERT_TRUE(result.isOk());
310 int64_t rate = result.value();
311 ASSERT_GE(0, rate);
312}
Matt Buckleydb4192a2023-12-21 20:00:32 +0000313
314TEST_F(PowerHalWrapperAidlTest, TestSessionChannel) {
315 int32_t tgid = 999;
316 int32_t uid = 1001;
317 EXPECT_CALL(*mMockHal.get(), getSessionChannel(Eq(tgid), Eq(uid), _))
318 .Times(Exactly(1))
319 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
320 EXPECT_CALL(*mMockHal.get(), closeSessionChannel(Eq(tgid), Eq(uid)))
321 .Times(Exactly(1))
322 .WillOnce(Return(testing::ByMove(ndk::ScopedAStatus::ok())));
323 auto createResult = mWrapper->getSessionChannel(tgid, uid);
324 ASSERT_TRUE(createResult.isOk());
325 auto closeResult = mWrapper->closeSessionChannel(tgid, uid);
326 ASSERT_TRUE(closeResult.isOk());
327}
Matt Buckley6c18e6d2024-02-07 23:39:50 +0000328
329TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionWithConfigUnsupported) {
330 std::vector<int> threadIds{gettid()};
331 int32_t tgid = 999;
332 int32_t uid = 1001;
333 int64_t durationNanos = 16666666L;
334 SessionTag tag = SessionTag::OTHER;
335 SessionConfig out;
336 EXPECT_CALL(*mMockHal.get(),
337 createHintSessionWithConfig(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos),
338 Eq(tag), _, _))
339 .Times(1)
340 .WillOnce(Return(testing::ByMove(
341 ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION))));
342 auto result =
343 mWrapper->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos, tag, &out);
344 ASSERT_TRUE(result.isUnsupported());
345 Mock::VerifyAndClearExpectations(mMockHal.get());
346 EXPECT_CALL(*mMockHal.get(),
347 createHintSessionWithConfig(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos),
348 Eq(tag), _, _))
349 .WillOnce(Return(
350 testing::ByMove(ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_TRANSACTION))));
351 result = mWrapper->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos, tag, &out);
352 ASSERT_TRUE(result.isUnsupported());
353}