• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 "power_hidl_hal_test"
18 #include <android-base/logging.h>
19 #include <android/hardware/power/1.2/IPower.h>
20 
21 #include <VtsHalHidlTargetTestBase.h>
22 #include <VtsHalHidlTargetTestEnvBase.h>
23 
24 using ::android::sp;
25 using ::android::hardware::hidl_vec;
26 using ::android::hardware::Return;
27 using ::android::hardware::power::V1_2::IPower;
28 using ::android::hardware::power::V1_2::PowerHint;
29 
30 // Test environment for Power HIDL HAL.
31 class PowerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
32    public:
33     // get the test environment singleton
Instance()34     static PowerHidlEnvironment* Instance() {
35         static PowerHidlEnvironment* instance = new PowerHidlEnvironment;
36         return instance;
37     }
38 
registerTestServices()39     virtual void registerTestServices() override { registerTestService<IPower>(); }
40 };
41 
42 class PowerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
43    public:
SetUp()44     virtual void SetUp() override {
45         power = ::testing::VtsHalHidlTargetTestBase::getService<IPower>(
46             PowerHidlEnvironment::Instance()->getServiceName<IPower>());
47         ASSERT_NE(power, nullptr);
48     }
49 
50     sp<IPower> power;
51 };
52 
53 // Sanity check Power::PowerHintAsync_1_2 on good and bad inputs.
TEST_F(PowerHidlTest,PowerHintAsync_1_2)54 TEST_F(PowerHidlTest, PowerHintAsync_1_2) {
55     std::vector<PowerHint> hints;
56     for (uint32_t i = static_cast<uint32_t>(PowerHint::VSYNC);
57          i <= static_cast<uint32_t>(PowerHint::CAMERA_SHOT); ++i) {
58         hints.emplace_back(static_cast<PowerHint>(i));
59     }
60     PowerHint badHint = static_cast<PowerHint>(0xFF);
61     hints.emplace_back(badHint);
62 
63     Return<void> ret;
64     for (auto& hint : hints) {
65         ret = power->powerHintAsync_1_2(hint, 30000);
66         ASSERT_TRUE(ret.isOk());
67 
68         ret = power->powerHintAsync_1_2(hint, 0);
69         ASSERT_TRUE(ret.isOk());
70     }
71 
72     // Turning these hints on in different orders triggers different code paths,
73     // so iterate over possible orderings.
74     std::vector<PowerHint> hints2 = {PowerHint::AUDIO_STREAMING, PowerHint::CAMERA_LAUNCH,
75                                      PowerHint::CAMERA_STREAMING, PowerHint::CAMERA_SHOT};
76     auto compareHints = [](PowerHint l, PowerHint r) {
77         return static_cast<uint32_t>(l) < static_cast<uint32_t>(r);
78     };
79     std::sort(hints2.begin(), hints2.end(), compareHints);
80     do {
81         for (auto iter = hints2.begin(); iter != hints2.end(); iter++) {
82             ret = power->powerHintAsync_1_2(*iter, 0);
83             ASSERT_TRUE(ret.isOk());
84         }
85         for (auto iter = hints2.begin(); iter != hints2.end(); iter++) {
86             ret = power->powerHintAsync_1_2(*iter, 30000);
87             ASSERT_TRUE(ret.isOk());
88         }
89     } while (std::next_permutation(hints2.begin(), hints2.end(), compareHints));
90 }
91 
main(int argc,char ** argv)92 int main(int argc, char** argv) {
93     ::testing::AddGlobalTestEnvironment(PowerHidlEnvironment::Instance());
94     ::testing::InitGoogleTest(&argc, argv);
95     PowerHidlEnvironment::Instance()->init(&argc, argv);
96     int status = RUN_ALL_TESTS();
97     LOG(INFO) << "Test result = " << status;
98     return status;
99 }
100