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 <android-base/logging.h>
21#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
22#include <android/hardware/configstore/1.0/types.h>
23#include <unistd.h>
24
25using ::android::hardware::configstore::V1_0::ISurfaceFlingerConfigs;
26using ::android::hardware::configstore::V1_0::OptionalBool;
27using ::android::hardware::configstore::V1_0::OptionalInt64;
28using ::android::hardware::configstore::V1_0::OptionalUInt64;
29using ::android::hardware::hidl_vec;
30using ::android::hardware::Return;
31using ::android::hardware::Void;
32using ::android::sp;
33
34#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
35#define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
36
37class ConfigstoreHidlTest : public ::testing::VtsHalHidlTargetTestBase {
38   public:
39    sp<ISurfaceFlingerConfigs> sfConfigs;
40
41    virtual void SetUp() override {
42        sfConfigs = ::testing::VtsHalHidlTargetTestBase::getService<
43            ISurfaceFlingerConfigs>();
44    }
45
46    virtual void TearDown() override {}
47};
48
49/**
50 * Ensure all ISurfaceFlingerConfigs.hal function calls are successful.
51 */
52TEST_F(ConfigstoreHidlTest, TestFunctionCalls) {
53    bool tmp;
54
55    Return<void> status = sfConfigs->vsyncEventPhaseOffsetNs(
56        [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
57    EXPECT_OK(status);
58
59    status = sfConfigs->vsyncSfEventPhaseOffsetNs(
60        [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
61    EXPECT_OK(status);
62
63    status = sfConfigs->useContextPriority(
64        [&tmp](OptionalBool arg) { tmp = arg.specified; });
65    EXPECT_OK(status);
66
67    status = sfConfigs->hasWideColorDisplay(
68        [&tmp](OptionalBool arg) { tmp = arg.specified; });
69    EXPECT_OK(status);
70
71    status = sfConfigs->hasHDRDisplay(
72        [&tmp](OptionalBool arg) { tmp = arg.specified; });
73    EXPECT_OK(status);
74
75    status = sfConfigs->presentTimeOffsetFromVSyncNs(
76        [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
77    EXPECT_OK(status);
78
79    status = sfConfigs->useHwcForRGBtoYUV(
80        [&tmp](OptionalBool arg) { tmp = arg.specified; });
81    EXPECT_OK(status);
82
83    status = sfConfigs->maxVirtualDisplaySize(
84        [&tmp](OptionalUInt64 arg) { tmp = arg.specified; });
85    EXPECT_OK(status);
86
87    status = sfConfigs->hasSyncFramework(
88        [&tmp](OptionalBool arg) { tmp = arg.specified; });
89    EXPECT_OK(status);
90
91    status = sfConfigs->useVrFlinger(
92        [&tmp](OptionalBool arg) { tmp = arg.specified; });
93    EXPECT_OK(status);
94
95    status = sfConfigs->maxFrameBufferAcquiredBuffers(
96        [&tmp](OptionalInt64 arg) { tmp = arg.specified; });
97    EXPECT_OK(status);
98
99    status = sfConfigs->startGraphicsAllocatorService(
100        [&tmp](OptionalBool arg) { tmp = arg.specified; });
101    EXPECT_OK(status);
102}
103
104/**
105 * Ensure repeated call to the same function returns the same result.
106 */
107TEST_F(ConfigstoreHidlTest, TestSameReturnValue) {
108    int64_t original_ret;
109    Return<void> status = sfConfigs->vsyncEventPhaseOffsetNs(
110        [&original_ret](OptionalInt64 arg) { original_ret = arg.value; });
111
112    int64_t next_ret;
113    for (int cnt = 0; cnt < 10; cnt++) {
114        status = sfConfigs->vsyncEventPhaseOffsetNs(
115            [&next_ret](OptionalInt64 arg) { next_ret = arg.value; });
116        EXPECT_EQ(original_ret, next_ret);
117    }
118}
119
120int main(int argc, char** argv) {
121    ::testing::InitGoogleTest(&argc, argv);
122    int status = RUN_ALL_TESTS();
123    LOG(INFO) << "Test result = " << status;
124    return status;
125}
126