1 /*
2  * Copyright 2020 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 #include "DemuxTests.h"
18 #include "FrontendTests.h"
19 
20 namespace {
21 
initConfiguration()22 bool initConfiguration() {
23     TunerTestingConfigReader1_0::setConfigFilePath(configFilePath);
24     if (!TunerTestingConfigReader1_0::checkConfigFileExists()) {
25         return false;
26     }
27     initFrontendConfig();
28     initFilterConfig();
29     initDvrConfig();
30     connectHardwaresToTestCases();
31     if (!validateConnections()) {
32         ALOGW("[vts] failed to validate connections.");
33         return false;
34     }
35     return true;
36 }
37 
success()38 static AssertionResult success() {
39     return ::testing::AssertionSuccess();
40 }
41 
filterDataOutputTestBase(FilterTests & tests)42 AssertionResult filterDataOutputTestBase(FilterTests& tests) {
43     // Data Verify Module
44     std::map<uint64_t, sp<FilterCallback>>::iterator it;
45     std::map<uint64_t, sp<FilterCallback>> filterCallbacks = tests.getFilterCallbacks();
46     for (it = filterCallbacks.begin(); it != filterCallbacks.end(); it++) {
47         it->second->testFilterDataOutput();
48     }
49     return success();
50 }
51 
52 class TunerFilterHidlTest : public testing::TestWithParam<std::string> {
53   public:
SetUp()54     virtual void SetUp() override {
55         mService = ITuner::getService(GetParam());
56         ASSERT_NE(mService, nullptr);
57         initConfiguration();
58 
59         mFrontendTests.setService(mService);
60         mDemuxTests.setService(mService);
61         mFilterTests.setService(mService);
62     }
63 
64   protected:
description(const std::string & description)65     static void description(const std::string& description) {
66         RecordProperty("description", description);
67     }
68 
69     void configSingleFilterInDemuxTest(FilterConfig1_1 filterConf, FrontendConfig1_1 frontendConf);
70     void reconfigSingleFilterInDemuxTest(FilterConfig1_1 filterConf, FilterConfig1_1 filterReconf,
71                                          FrontendConfig1_1 frontendConf);
72     sp<ITuner> mService;
73     FrontendTests mFrontendTests;
74     DemuxTests mDemuxTests;
75     FilterTests mFilterTests;
76 };
77 
78 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerFilterHidlTest);
79 
80 class TunerRecordHidlTest : public testing::TestWithParam<std::string> {
81   public:
SetUp()82     virtual void SetUp() override {
83         mService = ITuner::getService(GetParam());
84         ASSERT_NE(mService, nullptr);
85         initConfiguration();
86 
87         mFrontendTests.setService(mService);
88         mDemuxTests.setService(mService);
89         mFilterTests.setService(mService);
90         mDvrTests.setService(mService);
91     }
92 
93   protected:
description(const std::string & description)94     static void description(const std::string& description) {
95         RecordProperty("description", description);
96     }
97 
98     void recordSingleFilterTest(FilterConfig1_1 filterConf, FrontendConfig1_1 frontendConf,
99                                 DvrConfig dvrConf);
100 
101     sp<ITuner> mService;
102     FrontendTests mFrontendTests;
103     DemuxTests mDemuxTests;
104     FilterTests mFilterTests;
105     DvrTests mDvrTests;
106 };
107 
108 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerRecordHidlTest);
109 
110 class TunerFrontendHidlTest : public testing::TestWithParam<std::string> {
111   public:
SetUp()112     virtual void SetUp() override {
113         mService = ITuner::getService(GetParam());
114         ASSERT_NE(mService, nullptr);
115         initConfiguration();
116 
117         mFrontendTests.setService(mService);
118     }
119 
120   protected:
description(const std::string & description)121     static void description(const std::string& description) {
122         RecordProperty("description", description);
123     }
124 
125     sp<ITuner> mService;
126     FrontendTests mFrontendTests;
127 };
128 
129 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerFrontendHidlTest);
130 
131 class TunerBroadcastHidlTest : public testing::TestWithParam<std::string> {
132   public:
SetUp()133     virtual void SetUp() override {
134         mService = ITuner::getService(GetParam());
135         ASSERT_NE(mService, nullptr);
136         initConfiguration();
137 
138         mFrontendTests.setService(mService);
139         mDemuxTests.setService(mService);
140         mFilterTests.setService(mService);
141     }
142 
143   protected:
description(const std::string & description)144     static void description(const std::string& description) {
145         RecordProperty("description", description);
146     }
147 
148     sp<ITuner> mService;
149     FrontendTests mFrontendTests;
150     DemuxTests mDemuxTests;
151     FilterTests mFilterTests;
152 
153     AssertionResult filterDataOutputTest();
154 
155     void mediaFilterUsingSharedMemoryTest(FilterConfig1_1 filterConf,
156                                           FrontendConfig1_1 frontendConf);
157 };
158 
159 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerBroadcastHidlTest);
160 }  // namespace
161