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