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 "ConfigstoreHidlHalTest"
18
19 #include <VtsHalHidlTargetTestBase.h>
20 #include <VtsHalHidlTargetTestEnvBase.h>
21 #include <android-base/logging.h>
22 #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
23 #include <android/hardware/configstore/1.0/types.h>
24 #include <unistd.h>
25
26 using ::android::hardware::configstore::V1_0::ISurfaceFlingerConfigs;
27 using ::android::hardware::configstore::V1_0::OptionalBool;
28 using ::android::hardware::configstore::V1_0::OptionalInt64;
29 using ::android::hardware::configstore::V1_0::OptionalUInt64;
30 using ::android::hardware::hidl_vec;
31 using ::android::hardware::Return;
32 using ::android::hardware::Void;
33 using ::android::sp;
34
35 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
36 #define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
37
38 // Test environment for Configstore HIDL HAL.
39 class ConfigstoreHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
40 public:
41 // get the test environment singleton
Instance()42 static ConfigstoreHidlEnvironment* Instance() {
43 static ConfigstoreHidlEnvironment* instance = new ConfigstoreHidlEnvironment;
44 return instance;
45 }
46
registerTestServices()47 virtual void registerTestServices() override { registerTestService<ISurfaceFlingerConfigs>(); }
48 };
49
50 class ConfigstoreHidlTest : public ::testing::VtsHalHidlTargetTestBase {
51 public:
52 sp<ISurfaceFlingerConfigs> sfConfigs;
53
SetUp()54 virtual void SetUp() override {
55 sfConfigs = ::testing::VtsHalHidlTargetTestBase::getService<ISurfaceFlingerConfigs>(
56 ConfigstoreHidlEnvironment::Instance()->getServiceName<ISurfaceFlingerConfigs>());
57 ASSERT_NE(sfConfigs, nullptr);
58 }
59
TearDown()60 virtual void TearDown() override {}
61 };
62
63 /**
64 * Ensure all ISurfaceFlingerConfigs.hal function calls are successful.
65 */
TEST_F(ConfigstoreHidlTest,TestFunctionCalls)66 TEST_F(ConfigstoreHidlTest, TestFunctionCalls) {
67 bool tmp;
68
69 Return<void> status = sfConfigs->vsyncEventPhaseOffsetNs(
70 [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
71 EXPECT_OK(status);
72
73 status = sfConfigs->vsyncSfEventPhaseOffsetNs(
74 [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
75 EXPECT_OK(status);
76
77 status = sfConfigs->useContextPriority(
78 [&tmp](OptionalBool arg) { tmp = arg.specified; });
79 EXPECT_OK(status);
80
81 status = sfConfigs->hasWideColorDisplay(
82 [&tmp](OptionalBool arg) { tmp = arg.specified; });
83 EXPECT_OK(status);
84
85 status = sfConfigs->hasHDRDisplay(
86 [&tmp](OptionalBool arg) { tmp = arg.specified; });
87 EXPECT_OK(status);
88
89 status = sfConfigs->presentTimeOffsetFromVSyncNs(
90 [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
91 EXPECT_OK(status);
92
93 status = sfConfigs->useHwcForRGBtoYUV(
94 [&tmp](OptionalBool arg) { tmp = arg.specified; });
95 EXPECT_OK(status);
96
97 status = sfConfigs->maxVirtualDisplaySize(
98 [&tmp](OptionalUInt64 arg) { tmp = arg.specified; });
99 EXPECT_OK(status);
100
101 status = sfConfigs->hasSyncFramework(
102 [&tmp](OptionalBool arg) { tmp = arg.specified; });
103 EXPECT_OK(status);
104
105 status = sfConfigs->useVrFlinger(
106 [&tmp](OptionalBool arg) { tmp = arg.specified; });
107 EXPECT_OK(status);
108
109 status = sfConfigs->maxFrameBufferAcquiredBuffers(
110 [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
111 EXPECT_OK(status);
112
113 status = sfConfigs->startGraphicsAllocatorService(
114 [&tmp](OptionalBool arg) { tmp = arg.specified; });
115 EXPECT_OK(status);
116 }
117
118 /**
119 * Ensure repeated call to the same function returns the same result.
120 */
TEST_F(ConfigstoreHidlTest,TestSameReturnValue)121 TEST_F(ConfigstoreHidlTest, TestSameReturnValue) {
122 int64_t original_ret;
123 Return<void> status = sfConfigs->vsyncEventPhaseOffsetNs(
124 [&original_ret](OptionalInt64 arg) { original_ret = arg.value; });
125
126 int64_t next_ret;
127 for (int cnt = 0; cnt < 10; cnt++) {
128 status = sfConfigs->vsyncEventPhaseOffsetNs(
129 [&next_ret](OptionalInt64 arg) { next_ret = arg.value; });
130 EXPECT_EQ(original_ret, next_ret);
131 }
132 }
133
134 /**
135 * Make sure the constrains of hasWideColorDisplay, hasHDRDisplay
136 * are enforced.
137 */
TEST_F(ConfigstoreHidlTest,TestColorConstrainsBasic)138 TEST_F(ConfigstoreHidlTest, TestColorConstrainsBasic) {
139 bool hasWideColorDisplay;
140 bool hasHDRDisplay;
141
142 Return<void> status = sfConfigs->hasWideColorDisplay(
143 [&](OptionalBool arg) { hasWideColorDisplay = arg.specified; });
144 EXPECT_OK(status);
145
146 status = sfConfigs->hasHDRDisplay([&](OptionalBool arg) { hasHDRDisplay = arg.specified; });
147 EXPECT_OK(status);
148
149 // When hasHDRDisplay returns true, hasWideColorDisplay must also return true.
150 if (hasHDRDisplay) {
151 ASSERT_TRUE(hasWideColorDisplay);
152 }
153 }
154
main(int argc,char ** argv)155 int main(int argc, char** argv) {
156 ::testing::AddGlobalTestEnvironment(ConfigstoreHidlEnvironment::Instance());
157 ::testing::InitGoogleTest(&argc, argv);
158 ConfigstoreHidlEnvironment::Instance()->init(&argc, argv);
159 int status = RUN_ALL_TESTS();
160 LOG(INFO) << "Test result = " << status;
161 return status;
162 }
163