1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "PowerHalWrapperHidlV1_1Test"
#include <aidl/android/hardware/power/Boost.h>
#include <aidl/android/hardware/power/IPower.h>
#include <aidl/android/hardware/power/Mode.h>
#include <android/hardware/power/1.1/IPower.h>
#include <binder/IServiceManager.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <powermanager/PowerHalWrapper.h>
#include <utils/Log.h>
using aidl::android::hardware::power::Boost;
using aidl::android::hardware::power::Mode;
using android::hardware::power::V1_0::Feature;
using android::hardware::power::V1_0::PowerHint;
using IPowerV1_1 = android::hardware::power::V1_1::IPower;
using namespace android;
using namespace android::power;
using namespace std::chrono_literals;
using namespace testing;
// -------------------------------------------------------------------------------------------------
class MockIPowerV1_1 : public IPowerV1_1 {
public:
MOCK_METHOD(hardware::Return<void>, setInteractive, (bool interactive), (override));
MOCK_METHOD(hardware::Return<void>, powerHint, (PowerHint hint, int32_t data), (override));
MOCK_METHOD(hardware::Return<void>, setFeature, (Feature feature, bool activate), (override));
MOCK_METHOD(hardware::Return<void>, getPlatformLowPowerStats,
(getPlatformLowPowerStats_cb _hidl_cb), (override));
MOCK_METHOD(hardware::Return<void>, powerHintAsync, (PowerHint hint, int32_t data), (override));
MOCK_METHOD(hardware::Return<void>, getSubsystemLowPowerStats,
(getSubsystemLowPowerStats_cb _hidl_cb), (override));
};
// -------------------------------------------------------------------------------------------------
class PowerHalWrapperHidlV1_1Test : public Test {
public:
void SetUp() override;
protected:
std::unique_ptr<HalWrapper> mWrapper = nullptr;
sp<StrictMock<MockIPowerV1_1>> mMockHal = nullptr;
};
// -------------------------------------------------------------------------------------------------
void PowerHalWrapperHidlV1_1Test::SetUp() {
mMockHal = new StrictMock<MockIPowerV1_1>();
mWrapper = std::make_unique<HidlHalWrapperV1_1>(mMockHal);
ASSERT_NE(mWrapper, nullptr);
EXPECT_CALL(*mMockHal.get(), powerHint(_, _)).Times(0);
}
// -------------------------------------------------------------------------------------------------
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetBoostSuccessful) {
EXPECT_CALL(*mMockHal.get(), powerHintAsync(Eq(PowerHint::INTERACTION), Eq(1000)))
.Times(Exactly(1));
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetBoostFailed) {
EXPECT_CALL(*mMockHal.get(), powerHintAsync(Eq(PowerHint::INTERACTION), Eq(1000)))
.Times(Exactly(1))
.WillRepeatedly([](PowerHint, int32_t) {
return hardware::Return<void>(hardware::Status::fromExceptionCode(-1));
});
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetBoostUnsupported) {
EXPECT_CALL(*mMockHal.get(), powerHintAsync(_, _)).Times(0);
EXPECT_CALL(*mMockHal.get(), setInteractive(_)).Times(0);
EXPECT_CALL(*mMockHal.get(), setFeature(_, _)).Times(0);
auto result = mWrapper->setBoost(Boost::CAMERA_LAUNCH, 10);
ASSERT_TRUE(result.isUnsupported());
result = mWrapper->setBoost(Boost::ML_ACC, 10);
ASSERT_TRUE(result.isUnsupported());
result = mWrapper->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 10);
ASSERT_TRUE(result.isUnsupported());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetMode) {
{
InSequence seq;
EXPECT_CALL(*mMockHal.get(), powerHintAsync(Eq(PowerHint::LAUNCH), Eq(true)))
.Times(Exactly(1));
EXPECT_CALL(*mMockHal.get(), powerHintAsync(Eq(PowerHint::LOW_POWER), Eq(false)))
.Times(Exactly(1));
EXPECT_CALL(*mMockHal.get(), powerHintAsync(Eq(PowerHint::SUSTAINED_PERFORMANCE), Eq(true)))
.Times(Exactly(1));
EXPECT_CALL(*mMockHal.get(), powerHintAsync(Eq(PowerHint::VR_MODE), Eq(false)))
.Times(Exactly(1));
EXPECT_CALL(*mMockHal.get(), setInteractive(Eq(true))).Times(Exactly(1));
EXPECT_CALL(*mMockHal.get(),
setFeature(Eq(Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE), Eq(false)))
.Times(Exactly(1));
}
auto result = mWrapper->setMode(Mode::LAUNCH, true);
ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::LOW_POWER, false);
ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::SUSTAINED_PERFORMANCE, true);
ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::VR, false);
ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::INTERACTIVE, true);
ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::DOUBLE_TAP_TO_WAKE, false);
ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetModeFailed) {
EXPECT_CALL(*mMockHal.get(), powerHintAsync(Eq(PowerHint::LAUNCH), Eq(true)))
.Times(Exactly(1))
.WillRepeatedly([](PowerHint, int32_t) {
return hardware::Return<void>(hardware::Status::fromExceptionCode(-1));
});
auto result = mWrapper->setMode(Mode::LAUNCH, 1);
ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetModeIgnored) {
EXPECT_CALL(*mMockHal.get(), powerHintAsync(_, _)).Times(0);
EXPECT_CALL(*mMockHal.get(), setInteractive(_)).Times(0);
EXPECT_CALL(*mMockHal.get(), setFeature(_, _)).Times(0);
auto result = mWrapper->setMode(Mode::CAMERA_STREAMING_HIGH, true);
ASSERT_TRUE(result.isUnsupported());
result = mWrapper->setMode(Mode::EXPENSIVE_RENDERING, false);
ASSERT_TRUE(result.isUnsupported());
result = mWrapper->setMode(Mode::FIXED_PERFORMANCE, true);
ASSERT_TRUE(result.isUnsupported());
result = mWrapper->setMode(Mode::GAME_LOADING, false);
ASSERT_TRUE(result.isUnsupported());
}
|