xref: /aosp_15_r20/hardware/interfaces/tv/tuner/aidl/vts/functional/VtsHalTvTunerTargetTest.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright 2021 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 #pragma once
18 
19 #include <android/binder_manager.h>
20 #include <cutils/properties.h>
21 
22 #include "DemuxTests.h"
23 #include "DescramblerTests.h"
24 #include "DvrTests.h"
25 #include "FrontendTests.h"
26 #include "LnbTests.h"
27 
28 using android::sp;
29 
30 namespace {
31 
initConfiguration()32 bool initConfiguration() {
33     std::array<char, PROPERTY_VALUE_MAX> variant;
34     property_get("ro.vendor.vts_tuner_configuration_variant", variant.data(), "");
35     string variantString = variant.data();
36     string configFilePath = "/vendor/etc/tuner_vts_config_aidl_V1";
37     if (variantString.length() != 0) {
38         configFilePath = configFilePath + "." + variantString;
39     }
40     configFilePath = configFilePath + ".xml";
41     TunerTestingConfigAidlReader1_0::setConfigFilePath(configFilePath);
42     if (!TunerTestingConfigAidlReader1_0::checkConfigFileExists()) {
43         return false;
44     }
45     initFrontendConfig();
46     initFilterConfig();
47     initDvrConfig();
48     initTimeFilterConfig();
49     initDescramblerConfig();
50     initLnbConfig();
51     initDiseqcMsgsConfig();
52     connectHardwaresToTestCases();
53     if (!validateConnections()) {
54         ALOGW("[vts] failed to validate connections.");
55         return false;
56     }
57     determineDataFlows();
58 
59     return true;
60 }
61 
success()62 static AssertionResult success() {
63     return ::testing::AssertionSuccess();
64 }
65 
filterDataOutputTestBase(FilterTests & tests)66 AssertionResult filterDataOutputTestBase(FilterTests& tests) {
67     // Data Verify Module
68     std::map<int64_t, std::shared_ptr<FilterCallback>>::iterator it;
69     std::map<int64_t, std::shared_ptr<FilterCallback>> filterCallbacks = tests.getFilterCallbacks();
70     for (it = filterCallbacks.begin(); it != filterCallbacks.end(); it++) {
71         it->second->testFilterDataOutput();
72     }
73     return success();
74 }
75 
clearIds()76 void clearIds() {
77     lnbIds.clear();
78     diseqcMsgs.clear();
79     frontendIds.clear();
80     ipFilterIds.clear();
81     pcrFilterIds.clear();
82     recordDvrIds.clear();
83     timeFilterIds.clear();
84     descramblerIds.clear();
85     audioFilterIds.clear();
86     videoFilterIds.clear();
87     playbackDvrIds.clear();
88     recordFilterIds.clear();
89     sectionFilterIds.clear();
90 }
91 
92 enum class Dataflow_Context { LNBRECORD, RECORD, DESCRAMBLING, LNBDESCRAMBLING };
93 
94 class TunerLnbAidlTest : public testing::TestWithParam<std::string> {
95   public:
SetUp()96     virtual void SetUp() override {
97         if (AServiceManager_isDeclared(GetParam().c_str())) {
98             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
99             mService = ITuner::fromBinder(binder);
100         } else {
101             mService = nullptr;
102         }
103         ASSERT_NE(mService, nullptr);
104         ASSERT_TRUE(initConfiguration());
105 
106         mLnbTests.setService(mService);
107     }
108 
TearDown()109     virtual void TearDown() override {
110         clearIds();
111         mService = nullptr;
112     }
113 
114   protected:
description(const std::string & description)115     static void description(const std::string& description) {
116         RecordProperty("description", description);
117     }
118 
119     std::shared_ptr<ITuner> mService;
120     LnbTests mLnbTests;
121 };
122 
123 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerLnbAidlTest);
124 
125 class TunerDemuxAidlTest : public testing::TestWithParam<std::string> {
126   public:
SetUp()127     virtual void SetUp() override {
128         if (AServiceManager_isDeclared(GetParam().c_str())) {
129             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
130             mService = ITuner::fromBinder(binder);
131         } else {
132             mService = nullptr;
133         }
134         ASSERT_NE(mService, nullptr);
135         ASSERT_TRUE(initConfiguration());
136 
137         mFrontendTests.setService(mService);
138         mDemuxTests.setService(mService);
139         mFilterTests.setService(mService);
140     }
141 
TearDown()142     virtual void TearDown() override {
143         clearIds();
144         mService = nullptr;
145     }
146 
147   protected:
description(const std::string & description)148     static void description(const std::string& description) {
149         RecordProperty("description", description);
150     }
151 
152     std::shared_ptr<ITuner> mService;
153     FrontendTests mFrontendTests;
154     DemuxTests mDemuxTests;
155     FilterTests mFilterTests;
156 };
157 
158 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerDemuxAidlTest);
159 
160 class TunerFilterAidlTest : public testing::TestWithParam<std::string> {
161   public:
SetUp()162     virtual void SetUp() override {
163         if (AServiceManager_isDeclared(GetParam().c_str())) {
164             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
165             mService = ITuner::fromBinder(binder);
166         } else {
167             mService = nullptr;
168         }
169         ASSERT_NE(mService, nullptr);
170         ASSERT_TRUE(initConfiguration());
171 
172         mFrontendTests.setService(mService);
173         mDemuxTests.setService(mService);
174         mFilterTests.setService(mService);
175     }
176 
TearDown()177     virtual void TearDown() override {
178         clearIds();
179         mService = nullptr;
180     }
181 
182   protected:
description(const std::string & description)183     static void description(const std::string& description) {
184         RecordProperty("description", description);
185     }
186 
187     void configSingleFilterInDemuxTest(FilterConfig filterConf, FrontendConfig frontendConf);
188     void reconfigSingleFilterInDemuxTest(FilterConfig filterConf, FilterConfig filterReconf,
189                                          FrontendConfig frontendConf);
190     void testTimeFilter(TimeFilterConfig filterConf);
191     void testDelayHint(const FilterConfig& filterConf);
192 
getLinkageFilterType(int bit)193     DemuxFilterType getLinkageFilterType(int bit) {
194         DemuxFilterType type;
195         type.mainType = static_cast<DemuxFilterMainType>(1 << bit);
196         switch (type.mainType) {
197             case DemuxFilterMainType::TS:
198                 type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
199                         DemuxTsFilterType::UNDEFINED);
200                 break;
201             case DemuxFilterMainType::MMTP:
202                 type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
203                         DemuxMmtpFilterType::UNDEFINED);
204                 break;
205             case DemuxFilterMainType::IP:
206                 type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
207                         DemuxIpFilterType::UNDEFINED);
208                 break;
209             case DemuxFilterMainType::TLV:
210                 type.subType.set<DemuxFilterSubType::Tag::tlvFilterType>(
211                         DemuxTlvFilterType::UNDEFINED);
212                 break;
213             case DemuxFilterMainType::ALP:
214                 type.subType.set<DemuxFilterSubType::Tag::alpFilterType>(
215                         DemuxAlpFilterType::UNDEFINED);
216                 break;
217             default:
218                 break;
219         }
220         return type;
221     }
222     std::shared_ptr<ITuner> mService;
223     FrontendTests mFrontendTests;
224     DemuxTests mDemuxTests;
225     FilterTests mFilterTests;
226 };
227 
228 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerFilterAidlTest);
229 
230 class TunerPlaybackAidlTest : public testing::TestWithParam<std::string> {
231   public:
SetUp()232     virtual void SetUp() override {
233         if (AServiceManager_isDeclared(GetParam().c_str())) {
234             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
235             mService = ITuner::fromBinder(binder);
236         } else {
237             mService = nullptr;
238         }
239         ASSERT_NE(mService, nullptr);
240         ASSERT_TRUE(initConfiguration());
241 
242         mFrontendTests.setService(mService);
243         mDemuxTests.setService(mService);
244         mFilterTests.setService(mService);
245         mDvrTests.setService(mService);
246     }
247 
TearDown()248     virtual void TearDown() override {
249         clearIds();
250         mService = nullptr;
251     }
252 
253   protected:
description(const std::string & description)254     static void description(const std::string& description) {
255         RecordProperty("description", description);
256     }
257 
258     std::shared_ptr<ITuner> mService;
259     FrontendTests mFrontendTests;
260     DemuxTests mDemuxTests;
261     FilterTests mFilterTests;
262     DvrTests mDvrTests;
263 
264     AssertionResult filterDataOutputTest();
265 
266     void playbackSingleFilterTest(FilterConfig filterConf, DvrConfig dvrConf);
267 
268     void setStatusCheckIntervalHintTest(int64_t milliseconds, DvrConfig dvrConf);
269 };
270 
271 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerPlaybackAidlTest);
272 
273 class TunerRecordAidlTest : public testing::TestWithParam<std::string> {
274   public:
SetUp()275     virtual void SetUp() override {
276         if (AServiceManager_isDeclared(GetParam().c_str())) {
277             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
278             mService = ITuner::fromBinder(binder);
279         } else {
280             mService = nullptr;
281         }
282         ASSERT_NE(mService, nullptr);
283         ASSERT_TRUE(initConfiguration());
284 
285         mFrontendTests.setService(mService);
286         mDemuxTests.setService(mService);
287         mFilterTests.setService(mService);
288         mDvrTests.setService(mService);
289         mLnbTests.setService(mService);
290     }
291 
TearDown()292     virtual void TearDown() override {
293         clearIds();
294         mService = nullptr;
295     }
296 
297   protected:
description(const std::string & description)298     static void description(const std::string& description) {
299         RecordProperty("description", description);
300     }
301 
302     void attachSingleFilterToRecordDvrTest(FilterConfig filterConf, FrontendConfig frontendConf,
303                                            DvrConfig dvrConf);
304     void recordSingleFilterTestWithLnb(FilterConfig filterConf, FrontendConfig frontendConf,
305                                        DvrConfig dvrConf, LnbConfig lnbConf);
306     void recordSingleFilterTest(FilterConfig filterConf, FrontendConfig frontendConf,
307                                 DvrConfig dvrConf, Dataflow_Context context);
308     void setStatusCheckIntervalHintTest(int64_t milliseconds, FrontendConfig frontendConf,
309                                         DvrConfig dvrConf);
310 
311     std::shared_ptr<ITuner> mService;
312     FrontendTests mFrontendTests;
313     DemuxTests mDemuxTests;
314     FilterTests mFilterTests;
315     DvrTests mDvrTests;
316     LnbTests mLnbTests;
317 
318   private:
319     int32_t mLnbId = INVALID_LNB_ID;
320 };
321 
322 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerRecordAidlTest);
323 
324 class TunerFrontendAidlTest : public testing::TestWithParam<std::string> {
325   public:
SetUp()326     virtual void SetUp() override {
327         if (AServiceManager_isDeclared(GetParam().c_str())) {
328             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
329             mService = ITuner::fromBinder(binder);
330         } else {
331             mService = nullptr;
332         }
333         ASSERT_NE(mService, nullptr);
334         ASSERT_TRUE(initConfiguration());
335 
336         mFrontendTests.setService(mService);
337     }
338 
TearDown()339     virtual void TearDown() override {
340         clearIds();
341         mService = nullptr;
342     }
343 
344   protected:
description(const std::string & description)345     static void description(const std::string& description) {
346         RecordProperty("description", description);
347     }
348 
349     std::shared_ptr<ITuner> mService;
350     FrontendTests mFrontendTests;
351 };
352 
353 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerFrontendAidlTest);
354 
355 class TunerBroadcastAidlTest : public testing::TestWithParam<std::string> {
356   public:
SetUp()357     virtual void SetUp() override {
358         if (AServiceManager_isDeclared(GetParam().c_str())) {
359             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
360             mService = ITuner::fromBinder(binder);
361         } else {
362             mService = nullptr;
363         }
364         ASSERT_NE(mService, nullptr);
365         ASSERT_TRUE(initConfiguration());
366 
367         mFrontendTests.setService(mService);
368         mDemuxTests.setService(mService);
369         mFilterTests.setService(mService);
370         mLnbTests.setService(mService);
371         mDvrTests.setService(mService);
372     }
373 
TearDown()374     virtual void TearDown() override {
375         clearIds();
376         mService = nullptr;
377     }
378 
379   protected:
description(const std::string & description)380     static void description(const std::string& description) {
381         RecordProperty("description", description);
382     }
383 
384     std::shared_ptr<ITuner> mService;
385     FrontendTests mFrontendTests;
386     DemuxTests mDemuxTests;
387     FilterTests mFilterTests;
388     LnbTests mLnbTests;
389     DvrTests mDvrTests;
390 
391     AssertionResult filterDataOutputTest();
392 
393     void broadcastSingleFilterTest(FilterConfig filterConf, FrontendConfig frontendConf);
394     void broadcastSingleFilterTestWithLnb(FilterConfig filterConf, FrontendConfig frontendConf,
395                                           LnbConfig lnbConf);
396     void mediaFilterUsingSharedMemoryTest(FilterConfig filterConf, FrontendConfig frontendConf);
397 
398   private:
399     int32_t mLnbId = INVALID_LNB_ID;
400 };
401 
402 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerBroadcastAidlTest);
403 
404 class TunerDescramblerAidlTest : public testing::TestWithParam<std::string> {
405   public:
SetUp()406     virtual void SetUp() override {
407         if (AServiceManager_isDeclared(GetParam().c_str())) {
408             ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
409             mService = ITuner::fromBinder(binder);
410         } else {
411             mService = nullptr;
412         }
413         ASSERT_NE(mService, nullptr);
414 
415         // Get IMediaCasService. Try getting AIDL service first, if AIDL does not exist, try HIDL.
416         if (AServiceManager_isDeclared(MEDIA_CAS_AIDL_SERVICE_NAME.c_str())) {
417             ::ndk::SpAIBinder binder(
418                     AServiceManager_waitForService(MEDIA_CAS_AIDL_SERVICE_NAME.c_str()));
419             mCasServiceAidl = IMediaCasServiceAidl::fromBinder(binder);
420         } else {
421             mCasServiceAidl = nullptr;
422         }
423         if (mCasServiceAidl == nullptr) {
424             mCasServiceHidl = IMediaCasServiceHidl::getService();
425         }
426         ASSERT_TRUE(mCasServiceAidl != nullptr || mCasServiceHidl != nullptr);
427         ASSERT_TRUE(initConfiguration());
428 
429         mFrontendTests.setService(mService);
430         mDemuxTests.setService(mService);
431         mDvrTests.setService(mService);
432         mDescramblerTests.setService(mService);
433         if (mCasServiceAidl != nullptr) {
434             mDescramblerTests.setCasServiceAidl(mCasServiceAidl);
435         } else {
436             mDescramblerTests.setCasServiceHidl(mCasServiceHidl);
437         }
438         mLnbTests.setService(mService);
439     }
440 
TearDown()441     virtual void TearDown() override {
442         clearIds();
443         mService = nullptr;
444     }
445 
446   protected:
description(const std::string & description)447     static void description(const std::string& description) {
448         RecordProperty("description", description);
449     }
450 
451     void scrambledBroadcastTest(set<struct FilterConfig> mediaFilterConfs,
452                                 FrontendConfig frontendConf, DescramblerConfig descConfig,
453                                 Dataflow_Context context);
454     void scrambledBroadcastTestWithLnb(set<struct FilterConfig>& mediaFilterConfs,
455                                        FrontendConfig& frontendConf, DescramblerConfig& descConfig,
456                                        LnbConfig& lnbConfig);
457     AssertionResult filterDataOutputTest();
458 
459     std::shared_ptr<ITuner> mService;
460     sp<IMediaCasServiceHidl> mCasServiceHidl;
461     std::shared_ptr<IMediaCasServiceAidl> mCasServiceAidl;
462     FrontendTests mFrontendTests;
463     DemuxTests mDemuxTests;
464     FilterTests mFilterTests;
465     DescramblerTests mDescramblerTests;
466     DvrTests mDvrTests;
467     LnbTests mLnbTests;
468 
469   private:
470     int32_t mLnbId = INVALID_LNB_ID;
471 };
472 
473 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TunerDescramblerAidlTest);
474 
475 }  // namespace
476