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 "VtsHalTvTunerV1_1TargetTest.h"
18
19 namespace {
20
filterDataOutputTest()21 AssertionResult TunerBroadcastHidlTest::filterDataOutputTest() {
22 return filterDataOutputTestBase(mFilterTests);
23 }
24
configSingleFilterInDemuxTest(FilterConfig1_1 filterConf,FrontendConfig1_1 frontendConf)25 void TunerFilterHidlTest::configSingleFilterInDemuxTest(FilterConfig1_1 filterConf,
26 FrontendConfig1_1 frontendConf) {
27 uint32_t feId;
28 uint32_t demuxId;
29 sp<IDemux> demux;
30 uint64_t filterId;
31
32 mFrontendTests.getFrontendIdByType(frontendConf.config1_0.type, feId);
33 ASSERT_TRUE(feId != INVALID_ID);
34 ASSERT_TRUE(mFrontendTests.openFrontendById(feId));
35 ASSERT_TRUE(mFrontendTests.setFrontendCallback());
36 ASSERT_TRUE(mDemuxTests.openDemux(demux, demuxId));
37 ASSERT_TRUE(mDemuxTests.setDemuxFrontendDataSource(feId));
38 mFrontendTests.setDemux(demux);
39 mFilterTests.setDemux(demux);
40 ASSERT_TRUE(mFilterTests.openFilterInDemux(filterConf.config1_0.type,
41 filterConf.config1_0.bufferSize));
42 ASSERT_TRUE(mFilterTests.getNewlyOpenedFilterId_64bit(filterId));
43 ASSERT_TRUE(mFilterTests.configFilter(filterConf.config1_0.settings, filterId));
44 if (filterConf.config1_0.type.mainType == DemuxFilterMainType::IP) {
45 ASSERT_TRUE(mFilterTests.configIpFilterCid(filterConf.ipCid, filterId));
46 }
47 if (filterConf.monitorEventTypes > 0) {
48 ASSERT_TRUE(mFilterTests.configureMonitorEvent(filterId, filterConf.monitorEventTypes));
49 }
50 ASSERT_TRUE(mFilterTests.getFilterMQDescriptor(filterId, filterConf.config1_0.getMqDesc));
51 ASSERT_TRUE(mFilterTests.startFilter(filterId));
52 ASSERT_TRUE(mFrontendTests.tuneFrontend(frontendConf, true /*testWithDemux*/));
53 if (filterConf.monitorEventTypes > 0) {
54 ASSERT_TRUE(mFilterTests.testMonitorEvent(filterId, filterConf.monitorEventTypes));
55 }
56 ASSERT_TRUE(mFrontendTests.stopTuneFrontend(true /*testWithDemux*/));
57 ASSERT_TRUE(mFilterTests.stopFilter(filterId));
58 ASSERT_TRUE(mFilterTests.closeFilter(filterId));
59 ASSERT_TRUE(mDemuxTests.closeDemux());
60 ASSERT_TRUE(mFrontendTests.closeFrontend());
61 }
62
reconfigSingleFilterInDemuxTest(FilterConfig1_1 filterConf,FilterConfig1_1 filterReconf,FrontendConfig1_1 frontendConf)63 void TunerFilterHidlTest::reconfigSingleFilterInDemuxTest(FilterConfig1_1 filterConf,
64 FilterConfig1_1 filterReconf,
65 FrontendConfig1_1 frontendConf) {
66 uint32_t feId;
67 uint32_t demuxId;
68 sp<IDemux> demux;
69 uint64_t filterId;
70
71 mFrontendTests.getFrontendIdByType(frontendConf.config1_0.type, feId);
72 ASSERT_TRUE(feId != INVALID_ID);
73 ASSERT_TRUE(mFrontendTests.openFrontendById(feId));
74 ASSERT_TRUE(mFrontendTests.setFrontendCallback());
75 if (frontendConf.config1_0.isSoftwareFe) {
76 mFrontendTests.setSoftwareFrontendDvrConfig(dvrMap[live.dvrSoftwareFeId]);
77 }
78 ASSERT_TRUE(mDemuxTests.openDemux(demux, demuxId));
79 ASSERT_TRUE(mDemuxTests.setDemuxFrontendDataSource(feId));
80 mFrontendTests.setDemux(demux);
81 mFilterTests.setDemux(demux);
82 ASSERT_TRUE(mFilterTests.openFilterInDemux(filterConf.config1_0.type,
83 filterConf.config1_0.bufferSize));
84 ASSERT_TRUE(mFilterTests.getNewlyOpenedFilterId_64bit(filterId));
85 ASSERT_TRUE(mFilterTests.configFilter(filterConf.config1_0.settings, filterId));
86 ASSERT_TRUE(mFilterTests.getFilterMQDescriptor(filterId, filterConf.config1_0.getMqDesc));
87 ASSERT_TRUE(mFilterTests.startFilter(filterId));
88 ASSERT_TRUE(mFilterTests.stopFilter(filterId));
89 ASSERT_TRUE(mFilterTests.configFilter(filterReconf.config1_0.settings, filterId));
90 ASSERT_TRUE(mFilterTests.startFilter(filterId));
91 ASSERT_TRUE(mFrontendTests.tuneFrontend(frontendConf, true /*testWithDemux*/));
92 ASSERT_TRUE(mFilterTests.startIdTest(filterId));
93 ASSERT_TRUE(mFrontendTests.stopTuneFrontend(true /*testWithDemux*/));
94 ASSERT_TRUE(mFilterTests.stopFilter(filterId));
95 ASSERT_TRUE(mFilterTests.closeFilter(filterId));
96 ASSERT_TRUE(mDemuxTests.closeDemux());
97 ASSERT_TRUE(mFrontendTests.closeFrontend());
98 }
99
mediaFilterUsingSharedMemoryTest(FilterConfig1_1 filterConf,FrontendConfig1_1 frontendConf)100 void TunerBroadcastHidlTest::mediaFilterUsingSharedMemoryTest(FilterConfig1_1 filterConf,
101 FrontendConfig1_1 frontendConf) {
102 uint32_t feId;
103 uint32_t demuxId;
104 sp<IDemux> demux;
105 uint64_t filterId;
106
107 mFrontendTests.getFrontendIdByType(frontendConf.config1_0.type, feId);
108 ASSERT_TRUE(feId != INVALID_ID);
109 ASSERT_TRUE(mFrontendTests.openFrontendById(feId));
110 ASSERT_TRUE(mFrontendTests.setFrontendCallback());
111 if (frontendConf.config1_0.isSoftwareFe) {
112 mFrontendTests.setSoftwareFrontendDvrConfig(dvrMap[live.dvrSoftwareFeId]);
113 }
114 ASSERT_TRUE(mDemuxTests.openDemux(demux, demuxId));
115 ASSERT_TRUE(mDemuxTests.setDemuxFrontendDataSource(feId));
116 mFrontendTests.setDemux(demux);
117 mFilterTests.setDemux(demux);
118 ASSERT_TRUE(mFilterTests.openFilterInDemux(filterConf.config1_0.type,
119 filterConf.config1_0.bufferSize));
120 ASSERT_TRUE(mFilterTests.getNewlyOpenedFilterId_64bit(filterId));
121 ASSERT_TRUE(mFilterTests.configFilter(filterConf.config1_0.settings, filterId));
122 ASSERT_TRUE(mFilterTests.getSharedAvMemoryHandle(filterId));
123 ASSERT_TRUE(mFilterTests.configAvFilterStreamType(filterConf.streamType, filterId));
124 ASSERT_TRUE(mFilterTests.getFilterMQDescriptor(filterId, filterConf.config1_0.getMqDesc));
125 ASSERT_TRUE(mFilterTests.startFilter(filterId));
126 // tune test
127 ASSERT_TRUE(mFrontendTests.tuneFrontend(frontendConf, true /*testWithDemux*/));
128 ASSERT_TRUE(filterDataOutputTest());
129 ASSERT_TRUE(mFrontendTests.stopTuneFrontend(true /*testWithDemux*/));
130 ASSERT_TRUE(mFilterTests.stopFilter(filterId));
131 ASSERT_TRUE(mFilterTests.releaseShareAvHandle(filterId));
132 ASSERT_TRUE(mFilterTests.closeFilter(filterId));
133 ASSERT_TRUE(mDemuxTests.closeDemux());
134 ASSERT_TRUE(mFrontendTests.closeFrontend());
135 }
136
recordSingleFilterTest(FilterConfig1_1 filterConf,FrontendConfig1_1 frontendConf,DvrConfig dvrConf)137 void TunerRecordHidlTest::recordSingleFilterTest(FilterConfig1_1 filterConf,
138 FrontendConfig1_1 frontendConf,
139 DvrConfig dvrConf) {
140 uint32_t demuxId;
141 sp<IDemux> demux;
142 ASSERT_TRUE(mDemuxTests.openDemux(demux, demuxId));
143 mDvrTests.setDemux(demux);
144
145 DvrConfig dvrSourceConfig;
146 if (record.hasFrontendConnection) {
147 uint32_t feId;
148 mFrontendTests.getFrontendIdByType(frontendConf.config1_0.type, feId);
149 ASSERT_TRUE(feId != INVALID_ID);
150 ASSERT_TRUE(mFrontendTests.openFrontendById(feId));
151 ASSERT_TRUE(mFrontendTests.setFrontendCallback());
152 if (frontendConf.config1_0.isSoftwareFe) {
153 mFrontendTests.setSoftwareFrontendDvrConfig(dvrMap[record.dvrSoftwareFeId]);
154 }
155 ASSERT_TRUE(mDemuxTests.setDemuxFrontendDataSource(feId));
156 mFrontendTests.setDvrTests(&mDvrTests);
157 } else {
158 dvrSourceConfig = dvrMap[record.dvrSourceId];
159 ASSERT_TRUE(mDvrTests.openDvrInDemux(dvrSourceConfig.type, dvrSourceConfig.bufferSize));
160 ASSERT_TRUE(mDvrTests.configDvrPlayback(dvrSourceConfig.settings));
161 ASSERT_TRUE(mDvrTests.getDvrPlaybackMQDescriptor());
162 }
163
164 uint64_t filterId;
165 sp<IFilter> filter;
166 mFilterTests.setDemux(demux);
167 ASSERT_TRUE(mDvrTests.openDvrInDemux(dvrConf.type, dvrConf.bufferSize));
168 ASSERT_TRUE(mDvrTests.configDvrRecord(dvrConf.settings));
169 ASSERT_TRUE(mDvrTests.getDvrRecordMQDescriptor());
170 ASSERT_TRUE(mFilterTests.openFilterInDemux(filterConf.config1_0.type,
171 filterConf.config1_0.bufferSize));
172 ASSERT_TRUE(mFilterTests.getNewlyOpenedFilterId_64bit(filterId));
173 ASSERT_TRUE(mFilterTests.configFilter(filterConf.config1_0.settings, filterId));
174 ASSERT_TRUE(mFilterTests.getFilterMQDescriptor(filterId, filterConf.config1_0.getMqDesc));
175 filter = mFilterTests.getFilterById(filterId);
176 ASSERT_TRUE(filter != nullptr);
177 mDvrTests.startRecordOutputThread(dvrConf.settings.record());
178 ASSERT_TRUE(mDvrTests.attachFilterToDvr(filter));
179 ASSERT_TRUE(mDvrTests.startDvrRecord());
180 ASSERT_TRUE(mFilterTests.startFilter(filterId));
181
182 if (record.hasFrontendConnection) {
183 ASSERT_TRUE(mFrontendTests.tuneFrontend(frontendConf, true /*testWithDemux*/));
184 } else {
185 // Start DVR Source
186 mDvrTests.startPlaybackInputThread(dvrSourceConfig.playbackInputFile,
187 dvrSourceConfig.settings.playback());
188 ASSERT_TRUE(mDvrTests.startDvrPlayback());
189 }
190
191 mDvrTests.testRecordOutput();
192 mDvrTests.stopRecordThread();
193
194 if (record.hasFrontendConnection) {
195 ASSERT_TRUE(mFrontendTests.stopTuneFrontend(true /*testWithDemux*/));
196 } else {
197 mDvrTests.stopPlaybackThread();
198 ASSERT_TRUE(mDvrTests.stopDvrPlayback());
199 }
200
201 ASSERT_TRUE(mFilterTests.stopFilter(filterId));
202 ASSERT_TRUE(mDvrTests.stopDvrRecord());
203 ASSERT_TRUE(mDvrTests.detachFilterToDvr(filter));
204 ASSERT_TRUE(mFilterTests.closeFilter(filterId));
205 mDvrTests.closeDvrRecord();
206
207 if (record.hasFrontendConnection) {
208 ASSERT_TRUE(mFrontendTests.closeFrontend());
209 } else {
210 mDvrTests.closeDvrPlayback();
211 }
212
213 ASSERT_TRUE(mDemuxTests.closeDemux());
214 }
215
TEST_P(TunerFilterHidlTest,StartFilterInDemux)216 TEST_P(TunerFilterHidlTest, StartFilterInDemux) {
217 description("Open and start a filter in Demux.");
218 if (!live.hasFrontendConnection) {
219 return;
220 }
221 // TODO use parameterized tests
222 configSingleFilterInDemuxTest(filterMap[live.videoFilterId], frontendMap[live.frontendId]);
223 }
224
TEST_P(TunerFilterHidlTest,ConfigIpFilterInDemuxWithCid)225 TEST_P(TunerFilterHidlTest, ConfigIpFilterInDemuxWithCid) {
226 description("Open and configure an ip filter in Demux.");
227 // TODO use parameterized tests
228 if (!live.hasFrontendConnection) {
229 return;
230 }
231 if (live.ipFilterId.compare(emptyHardwareId) == 0) {
232 return;
233 }
234 configSingleFilterInDemuxTest(filterMap[live.ipFilterId], frontendMap[live.frontendId]);
235 }
236
TEST_P(TunerFilterHidlTest,ReconfigFilterToReceiveStartId)237 TEST_P(TunerFilterHidlTest, ReconfigFilterToReceiveStartId) {
238 description("Recofigure and restart a filter to test start id.");
239 if (!live.hasFrontendConnection) {
240 return;
241 }
242 // TODO use parameterized tests
243 reconfigSingleFilterInDemuxTest(filterMap[live.videoFilterId], filterMap[live.videoFilterId],
244 frontendMap[live.frontendId]);
245 }
246
TEST_P(TunerRecordHidlTest,RecordDataFlowWithTsRecordFilterTest)247 TEST_P(TunerRecordHidlTest, RecordDataFlowWithTsRecordFilterTest) {
248 description("Feed ts data from frontend to recording and test with ts record filter");
249 if (!record.support) {
250 return;
251 }
252 recordSingleFilterTest(filterMap[record.recordFilterId], frontendMap[record.frontendId],
253 dvrMap[record.dvrRecordId]);
254 }
255
TEST_P(TunerFrontendHidlTest,TuneFrontendWithFrontendSettingsExt1_1)256 TEST_P(TunerFrontendHidlTest, TuneFrontendWithFrontendSettingsExt1_1) {
257 description("Tune one Frontend with v1_1 extended setting and check Lock event");
258 if (!live.hasFrontendConnection) {
259 return;
260 }
261 mFrontendTests.tuneTest(frontendMap[live.frontendId]);
262 }
263
TEST_P(TunerFrontendHidlTest,BlindScanFrontendWithEndFrequency)264 TEST_P(TunerFrontendHidlTest, BlindScanFrontendWithEndFrequency) {
265 description("Run an blind frontend scan with v1_1 extended setting and check lock scanMessage");
266 if (!scan.hasFrontendConnection) {
267 return;
268 }
269 mFrontendTests.scanTest(frontendMap[scan.frontendId], FrontendScanType::SCAN_BLIND);
270 }
271
TEST_P(TunerBroadcastHidlTest,MediaFilterWithSharedMemoryHandle)272 TEST_P(TunerBroadcastHidlTest, MediaFilterWithSharedMemoryHandle) {
273 description("Test the Media Filter with shared memory handle");
274 if (!live.hasFrontendConnection) {
275 return;
276 }
277 mediaFilterUsingSharedMemoryTest(filterMap[live.videoFilterId], frontendMap[live.frontendId]);
278 }
279
TEST_P(TunerFrontendHidlTest,GetFrontendDtmbCaps)280 TEST_P(TunerFrontendHidlTest, GetFrontendDtmbCaps) {
281 description("Test to query Dtmb frontend caps if exists");
282 mFrontendTests.getFrontendDtmbCapsTest();
283 }
284
TEST_P(TunerFrontendHidlTest,LinkToCiCam)285 TEST_P(TunerFrontendHidlTest, LinkToCiCam) {
286 description("Test Frontend link to CiCam");
287 if (!live.hasFrontendConnection) {
288 return;
289 }
290 if (!frontendMap[live.frontendId].canConnectToCiCam) {
291 return;
292 }
293 mFrontendTests.tuneTest(frontendMap[live.frontendId]);
294 }
295
296 INSTANTIATE_TEST_SUITE_P(
297 PerInstance, TunerBroadcastHidlTest,
298 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITuner::descriptor)),
299 android::hardware::PrintInstanceNameToString);
300
301 INSTANTIATE_TEST_SUITE_P(
302 PerInstance, TunerFrontendHidlTest,
303 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITuner::descriptor)),
304 android::hardware::PrintInstanceNameToString);
305
306 INSTANTIATE_TEST_SUITE_P(
307 PerInstance, TunerFilterHidlTest,
308 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITuner::descriptor)),
309 android::hardware::PrintInstanceNameToString);
310
311 INSTANTIATE_TEST_SUITE_P(
312 PerInstance, TunerRecordHidlTest,
313 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITuner::descriptor)),
314 android::hardware::PrintInstanceNameToString);
315 } // namespace
316