1 /*
2  * Copyright 2024 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 #pragma once
18 
19 #include <aidl/AdpfTypes.h>
20 #include <aidl/AppDescriptorTrace.h>
21 #include <aidl/AppHintDesc.h>
22 #include <aidl/PhysicalQuantityTypes.h>
23 #include <aidl/SessionMetrics.h>
24 #include <gmock/gmock.h>
25 
26 namespace aidl::google::hardware::power::mock::pixel {
27 
28 class MockPowerSessionManager {
29   public:
30     MockPowerSessionManager() = default;
31     ~MockPowerSessionManager() = default;
32 
33     MOCK_METHOD(void, updateHintMode, (const std::string &mode, bool enabled), ());
34     MOCK_METHOD(void, updateHintBoost, (const std::string &boost, int32_t durationMs), ());
35     MOCK_METHOD(int, getDisplayRefreshRate, (), ());
36     MOCK_METHOD(void, addPowerSession,
37                 (const std::string &idString,
38                  const std::shared_ptr<impl::pixel::AppHintDesc> &sessionDescriptor,
39                  const std::shared_ptr<impl::pixel::AppDescriptorTrace> &sessionTrace,
40                  const std::vector<int32_t> &threadIds, const impl::pixel::ProcessTag procTag),
41                 ());
42     MOCK_METHOD(void, removePowerSession,
43                 (int64_t sessionId, const impl::pixel::ProcessTag procTag), ());
44     MOCK_METHOD(void, setThreadsFromPowerSession,
45                 (int64_t sessionId, const std::vector<int32_t> &threadIds,
46                  const impl::pixel::ProcessTag procTag),
47                 ());
48     MOCK_METHOD(void, pause, (int64_t sessionId), ());
49     MOCK_METHOD(void, resume, (int64_t sessionId), ());
50     MOCK_METHOD(void, updateUniversalBoostMode, (), ());
51     MOCK_METHOD(void, dumpToFd, (int fd), ());
52     MOCK_METHOD(void, updateTargetWorkDuration,
53                 (int64_t sessionId, impl::pixel::AdpfVoteType voteId,
54                  std::chrono::nanoseconds durationNs),
55                 ());
56     MOCK_METHOD(void, voteSet,
57                 (int64_t sessionId, impl::pixel::AdpfVoteType voteId, int uclampMin, int uclampMax,
58                  std::chrono::steady_clock::time_point startTime,
59                  std::chrono::nanoseconds durationNs),
60                 ());
61     MOCK_METHOD(void, voteSet,
62                 (int64_t sessionId, impl::pixel::AdpfVoteType voteId, impl::pixel::Cycles capacity,
63                  std::chrono::steady_clock::time_point startTime,
64                  std::chrono::nanoseconds durationNs),
65                 ());
66 
67     MOCK_METHOD(void, disableBoosts, (int64_t sessionId), ());
68     MOCK_METHOD(void, setPreferPowerEfficiency, (int64_t sessionId, bool enabled), ());
69     MOCK_METHOD(std::optional<impl::pixel::Frequency>, gpuFrequency, (), (const));
70 
71     MOCK_METHOD(void, registerSession, (std::shared_ptr<void> session, int64_t sessionId), ());
72     MOCK_METHOD(void, unregisterSession, (int64_t sessionId), ());
73     MOCK_METHOD(void, clear, (), ());
74     MOCK_METHOD(std::shared_ptr<void>, getSession, (int64_t sessionId), ());
75     MOCK_METHOD(void, updateHboostStatistics,
76                 (int64_t sessionId, impl::pixel::SessionJankyLevel jankyLevel, int32_t numOfFrames),
77                 ());
78     MOCK_METHOD(bool, getGameModeEnableState, (), ());
79     MOCK_METHOD(void, updateFrameBuckets,
80                 (int64_t sessionId, const impl::pixel::FrameBuckets &lastReportedFrames), ());
81 
getInstance()82     static testing::NiceMock<MockPowerSessionManager> *getInstance() {
83         static testing::NiceMock<MockPowerSessionManager> instance{};
84         return &instance;
85     }
86 };
87 
88 }  // namespace aidl::google::hardware::power::mock::pixel
89