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