blob: 0fd5be066412d1f8f4136870b3edd46bcabb847d [file] [log] [blame]
Amy Zhang45cc57a2020-07-09 22:56:25 -07001/*
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 "FrontendTests.h"
18
Amy Zhang68afca62020-07-20 18:28:58 -070019Return<void> FrontendCallback::onEvent(FrontendEventType frontendEventType) {
20 android::Mutex::Autolock autoLock(mMsgLock);
21 ALOGD("[vts] frontend event received. Type: %d", frontendEventType);
22 mEventReceived = true;
23 mMsgCondition.signal();
24 switch (frontendEventType) {
25 case FrontendEventType::LOCKED:
26 mLockMsgReceived = true;
27 mLockMsgCondition.signal();
28 return Void();
29 default:
30 // do nothing
31 return Void();
32 }
Amy Zhang45cc57a2020-07-09 22:56:25 -070033}
34
Amy Zhang3ea25a62020-08-04 10:23:52 -070035Return<void> FrontendCallback::onScanMessage(FrontendScanMessageType type,
36 const FrontendScanMessage& message) {
37 android::Mutex::Autolock autoLock(mMsgLock);
38 while (!mScanMsgProcessed) {
39 mMsgCondition.wait(mMsgLock);
40 }
41 ALOGD("[vts] frontend scan message. Type: %d", type);
42 mScanMessageReceived = true;
43 mScanMsgProcessed = false;
44 mScanMessageType = type;
45 mScanMessage = message;
46 mMsgCondition.signal();
Amy Zhang45cc57a2020-07-09 22:56:25 -070047 return Void();
48}
49
Amy Zhang19ed17b2020-08-04 10:23:52 -070050Return<void> FrontendCallback::onScanMessageExt1_1(FrontendScanMessageTypeExt1_1 type,
51 const FrontendScanMessageExt1_1& message) {
52 android::Mutex::Autolock autoLock(mMsgLock);
53 ALOGD("[vts] frontend ext1_1 scan message. Type: %d", type);
Amy Zhang7ec2b702020-10-05 18:07:20 -070054 switch (message.getDiscriminator()) {
55 case FrontendScanMessageExt1_1::hidl_discriminator::modulation:
56 readFrontendScanMessageExt1_1Modulation(message.modulation());
57 break;
58 case FrontendScanMessageExt1_1::hidl_discriminator::isHighPriority:
59 ALOGD("[vts] frontend ext1_1 scan message high priority: %d", message.isHighPriority());
Amy Zhang19ed17b2020-08-04 10:23:52 -070060 break;
Amy Zhang7e669ce2020-10-20 16:41:30 -070061 case FrontendScanMessageExt1_1::hidl_discriminator::annex:
62 ALOGD("[vts] frontend ext1_1 scan message dvbc annex: %hhu", message.annex());
63 break;
Amy Zhang19ed17b2020-08-04 10:23:52 -070064 default:
65 break;
66 }
67 return Void();
68}
69
70void FrontendCallback::readFrontendScanMessageExt1_1Modulation(FrontendModulation modulation) {
71 switch (modulation.getDiscriminator()) {
72 case FrontendModulation::hidl_discriminator::dvbc:
73 ALOGD("[vts] frontend ext1_1 scan message modulation dvbc: %d", modulation.dvbc());
74 break;
75 case FrontendModulation::hidl_discriminator::dvbs:
76 ALOGD("[vts] frontend ext1_1 scan message modulation dvbs: %d", modulation.dvbs());
77 break;
78 case FrontendModulation::hidl_discriminator::isdbs:
79 ALOGD("[vts] frontend ext1_1 scan message modulation isdbs: %d", modulation.isdbs());
80 break;
81 case FrontendModulation::hidl_discriminator::isdbs3:
82 ALOGD("[vts] frontend ext1_1 scan message modulation isdbs3: %d", modulation.isdbs3());
83 break;
84 case FrontendModulation::hidl_discriminator::isdbt:
85 ALOGD("[vts] frontend ext1_1 scan message modulation isdbt: %d", modulation.isdbt());
86 break;
87 case FrontendModulation::hidl_discriminator::atsc:
88 ALOGD("[vts] frontend ext1_1 scan message modulation atsc: %d", modulation.atsc());
89 break;
90 case FrontendModulation::hidl_discriminator::atsc3:
91 ALOGD("[vts] frontend ext1_1 scan message modulation atsc3: %d", modulation.atsc3());
92 break;
93 case FrontendModulation::hidl_discriminator::dvbt:
94 ALOGD("[vts] frontend ext1_1 scan message modulation dvbt: %d", modulation.dvbt());
95 break;
96 default:
97 break;
98 }
99}
100
Amy Zhang3ea25a62020-08-04 10:23:52 -0700101void FrontendCallback::tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings,
Amy Zhangbc15b592020-09-25 15:35:55 -0700102 FrontendSettingsExt1_1 settingsExt1_1) {
Amy Zhang3ea25a62020-08-04 10:23:52 -0700103 sp<android::hardware::tv::tuner::V1_1::IFrontend> frontend_1_1;
104 frontend_1_1 = android::hardware::tv::tuner::V1_1::IFrontend::castFrom(frontend);
105 if (frontend_1_1 == nullptr) {
106 EXPECT_TRUE(false) << "Couldn't get 1.1 IFrontend from the Hal implementation.";
107 return;
108 }
109
Amy Zhangbc15b592020-09-25 15:35:55 -0700110 Result result = frontend_1_1->tune_1_1(settings, settingsExt1_1);
Amy Zhang68afca62020-07-20 18:28:58 -0700111 EXPECT_TRUE(result == Result::SUCCESS);
112
113 android::Mutex::Autolock autoLock(mMsgLock);
114 while (!mLockMsgReceived) {
115 if (-ETIMEDOUT == mLockMsgCondition.waitRelative(mMsgLock, WAIT_TIMEOUT)) {
116 EXPECT_TRUE(false) << "Event LOCKED not received within timeout";
117 mLockMsgReceived = false;
118 return;
119 }
120 }
121 mLockMsgReceived = false;
122}
123
Amy Zhang3ea25a62020-08-04 10:23:52 -0700124void FrontendCallback::scanTest(sp<IFrontend>& frontend, FrontendConfig config,
125 FrontendScanType type) {
126 sp<android::hardware::tv::tuner::V1_1::IFrontend> frontend_1_1;
127 frontend_1_1 = android::hardware::tv::tuner::V1_1::IFrontend::castFrom(frontend);
128 if (frontend_1_1 == nullptr) {
129 EXPECT_TRUE(false) << "Couldn't get 1.1 IFrontend from the Hal implementation.";
130 return;
131 }
132
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800133 uint32_t targetFrequency = getTargetFrequency(config.settings);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700134 if (type == FrontendScanType::SCAN_BLIND) {
135 // reset the frequency in the scan configuration to test blind scan. The settings param of
136 // passed in means the real input config on the transponder connected to the DUT.
137 // We want the blind the test to start from lower frequency than this to check the blind
138 // scan implementation.
139 resetBlindScanStartingFrequency(config, targetFrequency - 100);
140 }
141
Amy Zhangbc15b592020-09-25 15:35:55 -0700142 Result result = frontend_1_1->scan_1_1(config.settings, type, config.settingsExt1_1);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700143 EXPECT_TRUE(result == Result::SUCCESS);
144
145 bool scanMsgLockedReceived = false;
146 bool targetFrequencyReceived = false;
147
148 android::Mutex::Autolock autoLock(mMsgLock);
149wait:
150 while (!mScanMessageReceived) {
151 if (-ETIMEDOUT == mMsgCondition.waitRelative(mMsgLock, WAIT_TIMEOUT)) {
152 EXPECT_TRUE(false) << "Scan message not received within timeout";
153 mScanMessageReceived = false;
154 mScanMsgProcessed = true;
155 return;
156 }
157 }
158
159 if (mScanMessageType != FrontendScanMessageType::END) {
160 if (mScanMessageType == FrontendScanMessageType::LOCKED) {
161 scanMsgLockedReceived = true;
Amy Zhangbc15b592020-09-25 15:35:55 -0700162 Result result = frontend_1_1->scan_1_1(config.settings, type, config.settingsExt1_1);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700163 EXPECT_TRUE(result == Result::SUCCESS);
164 }
165
166 if (mScanMessageType == FrontendScanMessageType::FREQUENCY) {
167 targetFrequencyReceived = mScanMessage.frequencies().size() > 0 &&
168 mScanMessage.frequencies()[0] == targetFrequency;
169 }
170
171 if (mScanMessageType == FrontendScanMessageType::PROGRESS_PERCENT) {
172 ALOGD("[vts] Scan in progress...[%d%%]", mScanMessage.progressPercent());
173 }
174
175 mScanMessageReceived = false;
176 mScanMsgProcessed = true;
177 mMsgCondition.signal();
178 goto wait;
179 }
180
181 EXPECT_TRUE(scanMsgLockedReceived) << "Scan message LOCKED not received before END";
182 EXPECT_TRUE(targetFrequencyReceived) << "frequency not received before LOCKED on blindScan";
183 mScanMessageReceived = false;
184 mScanMsgProcessed = true;
185}
186
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800187uint32_t FrontendCallback::getTargetFrequency(FrontendSettings settings) {
188 switch (settings.getDiscriminator()) {
189 case FrontendSettings::hidl_discriminator::analog:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700190 return settings.analog().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800191 case FrontendSettings::hidl_discriminator::atsc:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700192 return settings.atsc().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800193 case FrontendSettings::hidl_discriminator::atsc3:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700194 return settings.atsc3().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800195 case FrontendSettings::hidl_discriminator::dvbc:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700196 return settings.dvbc().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800197 case FrontendSettings::hidl_discriminator::dvbs:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700198 return settings.dvbs().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800199 case FrontendSettings::hidl_discriminator::dvbt:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700200 return settings.dvbt().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800201 case FrontendSettings::hidl_discriminator::isdbs:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700202 return settings.isdbs().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800203 case FrontendSettings::hidl_discriminator::isdbs3:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700204 return settings.isdbs3().frequency;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800205 case FrontendSettings::hidl_discriminator::isdbt:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700206 return settings.isdbt().frequency;
Amy Zhang3ea25a62020-08-04 10:23:52 -0700207 }
208}
209
210void FrontendCallback::resetBlindScanStartingFrequency(FrontendConfig& config,
211 uint32_t resetingFreq) {
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800212 switch (config.settings.getDiscriminator()) {
213 case FrontendSettings::hidl_discriminator::analog:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700214 config.settings.analog().frequency = resetingFreq;
215 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800216 case FrontendSettings::hidl_discriminator::atsc:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700217 config.settings.atsc().frequency = resetingFreq;
218 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800219 case FrontendSettings::hidl_discriminator::atsc3:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700220 config.settings.atsc3().frequency = resetingFreq;
221 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800222 case FrontendSettings::hidl_discriminator::dvbc:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700223 config.settings.dvbc().frequency = resetingFreq;
224 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800225 case FrontendSettings::hidl_discriminator::dvbs:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700226 config.settings.dvbs().frequency = resetingFreq;
227 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800228 case FrontendSettings::hidl_discriminator::dvbt:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700229 config.settings.dvbt().frequency = resetingFreq;
230 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800231 case FrontendSettings::hidl_discriminator::isdbs:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700232 config.settings.isdbs().frequency = resetingFreq;
233 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800234 case FrontendSettings::hidl_discriminator::isdbs3:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700235 config.settings.isdbs3().frequency = resetingFreq;
236 break;
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800237 case FrontendSettings::hidl_discriminator::isdbt:
Amy Zhang3ea25a62020-08-04 10:23:52 -0700238 config.settings.isdbt().frequency = resetingFreq;
239 break;
Amy Zhang3ea25a62020-08-04 10:23:52 -0700240 }
241}
242
Amy Zhang45cc57a2020-07-09 22:56:25 -0700243AssertionResult FrontendTests::getFrontendIds() {
244 Result status;
245 mService->getFrontendIds([&](Result result, const hidl_vec<FrontendId>& frontendIds) {
246 status = result;
247 mFeIds = frontendIds;
248 });
249 return AssertionResult(status == Result::SUCCESS);
250}
251
252AssertionResult FrontendTests::getFrontendInfo(uint32_t frontendId) {
253 Result status;
254 mService->getFrontendInfo(frontendId, [&](Result result, const FrontendInfo& frontendInfo) {
255 mFrontendInfo = frontendInfo;
256 status = result;
257 });
258 return AssertionResult(status == Result::SUCCESS);
259}
260
261AssertionResult FrontendTests::openFrontendById(uint32_t frontendId) {
262 Result status;
263 mService->openFrontendById(frontendId, [&](Result result, const sp<IFrontend>& frontend) {
264 mFrontend = frontend;
265 status = result;
266 });
267 return AssertionResult(status == Result::SUCCESS);
268}
269
270AssertionResult FrontendTests::setFrontendCallback() {
271 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
272 mFrontendCallback = new FrontendCallback();
273 auto callbackStatus = mFrontend->setCallback(mFrontendCallback);
274 return AssertionResult(callbackStatus.isOk());
275}
276
Amy Zhang3ea25a62020-08-04 10:23:52 -0700277AssertionResult FrontendTests::scanFrontend(FrontendConfig config, FrontendScanType type) {
278 EXPECT_TRUE(mFrontendCallback)
279 << "test with openFrontendById/setFrontendCallback/getFrontendInfo first.";
280
281 EXPECT_TRUE(mFrontendInfo.type == config.type)
282 << "FrontendConfig does not match the frontend info of the given id.";
283
284 mFrontendCallback->scanTest(mFrontend, config, type);
285 return AssertionResult(true);
286}
287
288AssertionResult FrontendTests::stopScanFrontend() {
289 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
290 Result status;
291 status = mFrontend->stopScan();
Amy Zhang4c49c152020-08-25 21:08:19 -0700292
293 return AssertionResult(status == Result::SUCCESS);
294}
295
296AssertionResult FrontendTests::getFrontendDtmbCaps(uint32_t id) {
297 Result status;
298 mService->getFrontendDtmbCapabilities(
299 id, [&](Result result, const FrontendDtmbCapabilities& /*caps*/) { status = result; });
Amy Zhang3ea25a62020-08-04 10:23:52 -0700300 return AssertionResult(status == Result::SUCCESS);
301}
302
Amy Zhangda3a54d2021-02-18 21:47:00 -0800303AssertionResult FrontendTests::linkCiCam(uint32_t ciCamId) {
304 sp<android::hardware::tv::tuner::V1_1::IFrontend> frontend_1_1;
305 frontend_1_1 = android::hardware::tv::tuner::V1_1::IFrontend::castFrom(mFrontend);
306 if (frontend_1_1 == nullptr) {
307 EXPECT_TRUE(false) << "Couldn't get 1.1 IFrontend from the Hal implementation.";
308 return failure();
309 }
310
311 Result status;
312 uint32_t ltsId;
313 frontend_1_1->linkCiCam(ciCamId, [&](Result r, uint32_t id) {
314 status = r;
315 ltsId = id;
316 });
317
318 return AssertionResult(status == Result::SUCCESS);
319}
320
321AssertionResult FrontendTests::unlinkCiCam(uint32_t ciCamId) {
322 sp<android::hardware::tv::tuner::V1_1::IFrontend> frontend_1_1;
323 frontend_1_1 = android::hardware::tv::tuner::V1_1::IFrontend::castFrom(mFrontend);
324 if (frontend_1_1 == nullptr) {
325 EXPECT_TRUE(false) << "Couldn't get 1.1 IFrontend from the Hal implementation.";
326 return failure();
327 }
328
329 Result status = frontend_1_1->unlinkCiCam(ciCamId);
330 return AssertionResult(status == Result::SUCCESS);
331}
332
Amy Zhang422bb112020-08-12 15:21:44 -0700333void FrontendTests::verifyFrontendStatusExt1_1(vector<FrontendStatusTypeExt1_1> statusTypes,
334 vector<FrontendStatusExt1_1> expectStatuses) {
Amy Zhang3ea25a62020-08-04 10:23:52 -0700335 ASSERT_TRUE(mFrontend) << "Frontend is not opened yet.";
336 Result status;
Amy Zhang422bb112020-08-12 15:21:44 -0700337 vector<FrontendStatusExt1_1> realStatuses;
Amy Zhang3ea25a62020-08-04 10:23:52 -0700338
Amy Zhang422bb112020-08-12 15:21:44 -0700339 sp<android::hardware::tv::tuner::V1_1::IFrontend> frontend_1_1;
340 frontend_1_1 = android::hardware::tv::tuner::V1_1::IFrontend::castFrom(mFrontend);
341 if (frontend_1_1 == nullptr) {
342 EXPECT_TRUE(false) << "Couldn't get 1.1 IFrontend from the Hal implementation.";
343 return;
344 }
345
346 frontend_1_1->getStatusExt1_1(
347 statusTypes, [&](Result result, const hidl_vec<FrontendStatusExt1_1>& statuses) {
348 status = result;
349 realStatuses = statuses;
350 });
Amy Zhang3ea25a62020-08-04 10:23:52 -0700351
352 ASSERT_TRUE(realStatuses.size() == statusTypes.size());
353 for (int i = 0; i < statusTypes.size(); i++) {
Amy Zhang422bb112020-08-12 15:21:44 -0700354 FrontendStatusTypeExt1_1 type = statusTypes[i];
Amy Zhang3ea25a62020-08-04 10:23:52 -0700355 switch (type) {
Amy Zhang422bb112020-08-12 15:21:44 -0700356 case FrontendStatusTypeExt1_1::MODULATIONS: {
357 // TODO: verify modulations
Amy Zhang3ea25a62020-08-04 10:23:52 -0700358 break;
359 }
Amy Zhang422bb112020-08-12 15:21:44 -0700360 case FrontendStatusTypeExt1_1::BERS: {
361 ASSERT_TRUE(std::equal(realStatuses[i].bers().begin(), realStatuses[i].bers().end(),
362 expectStatuses[i].bers().begin()));
Amy Zhang3ea25a62020-08-04 10:23:52 -0700363 break;
364 }
Amy Zhang422bb112020-08-12 15:21:44 -0700365 case FrontendStatusTypeExt1_1::CODERATES: {
366 ASSERT_TRUE(std::equal(realStatuses[i].codeRates().begin(),
367 realStatuses[i].codeRates().end(),
368 expectStatuses[i].codeRates().begin()));
Amy Zhang3ea25a62020-08-04 10:23:52 -0700369 break;
370 }
Amy Zhang422bb112020-08-12 15:21:44 -0700371 case FrontendStatusTypeExt1_1::GUARD_INTERVAL: {
372 // TODO: verify interval
Amy Zhang3ea25a62020-08-04 10:23:52 -0700373 break;
374 }
Amy Zhang422bb112020-08-12 15:21:44 -0700375 case FrontendStatusTypeExt1_1::TRANSMISSION_MODE: {
376 // TODO: verify tranmission mode
Amy Zhang3ea25a62020-08-04 10:23:52 -0700377 break;
378 }
Amy Zhang422bb112020-08-12 15:21:44 -0700379 case FrontendStatusTypeExt1_1::UEC: {
380 ASSERT_TRUE(realStatuses[i].uec() == expectStatuses[i].uec());
Amy Zhang3ea25a62020-08-04 10:23:52 -0700381 break;
382 }
Amy Zhang422bb112020-08-12 15:21:44 -0700383 case FrontendStatusTypeExt1_1::T2_SYSTEM_ID: {
384 ASSERT_TRUE(realStatuses[i].systemId() == expectStatuses[i].systemId());
Amy Zhang3ea25a62020-08-04 10:23:52 -0700385 break;
386 }
Amy Zhang422bb112020-08-12 15:21:44 -0700387 case FrontendStatusTypeExt1_1::INTERLEAVINGS: {
388 ASSERT_TRUE(std::equal(realStatuses[i].interleaving().begin(),
389 realStatuses[i].interleaving().end(),
390 expectStatuses[i].interleaving().begin()));
Amy Zhang3ea25a62020-08-04 10:23:52 -0700391 break;
392 }
Amy Zhang422bb112020-08-12 15:21:44 -0700393 case FrontendStatusTypeExt1_1::ISDBT_SEGMENTS: {
394 ASSERT_TRUE(std::equal(realStatuses[i].isdbtSegment().begin(),
395 realStatuses[i].isdbtSegment().end(),
396 expectStatuses[i].isdbtSegment().begin()));
Amy Zhang3ea25a62020-08-04 10:23:52 -0700397 break;
398 }
Amy Zhang422bb112020-08-12 15:21:44 -0700399 case FrontendStatusTypeExt1_1::TS_DATA_RATES: {
400 ASSERT_TRUE(std::equal(realStatuses[i].tsDataRate().begin(),
401 realStatuses[i].tsDataRate().end(),
402 expectStatuses[i].tsDataRate().begin()));
Amy Zhang3ea25a62020-08-04 10:23:52 -0700403 break;
404 }
Amy Zhang7e669ce2020-10-20 16:41:30 -0700405 case FrontendStatusTypeExt1_1::ROLL_OFF: {
406 // TODO: verify roll off
407 break;
408 }
409 case FrontendStatusTypeExt1_1::IS_MISO: {
410 ASSERT_TRUE(realStatuses[i].isMiso() == expectStatuses[i].isMiso());
411 break;
412 }
413 case FrontendStatusTypeExt1_1::IS_LINEAR: {
414 ASSERT_TRUE(realStatuses[i].isLinear() == expectStatuses[i].isLinear());
415 break;
416 }
417 case FrontendStatusTypeExt1_1::IS_SHORT_FRAMES: {
418 ASSERT_TRUE(realStatuses[i].isShortFrames() == expectStatuses[i].isShortFrames());
419 break;
420 }
Amy Zhang422bb112020-08-12 15:21:44 -0700421 default: {
Amy Zhang3ea25a62020-08-04 10:23:52 -0700422 continue;
Amy Zhang422bb112020-08-12 15:21:44 -0700423 }
Amy Zhang3ea25a62020-08-04 10:23:52 -0700424 }
425 }
426 ASSERT_TRUE(status == Result::SUCCESS);
427}
428
Amy Zhang68afca62020-07-20 18:28:58 -0700429AssertionResult FrontendTests::tuneFrontend(FrontendConfig config, bool testWithDemux) {
430 EXPECT_TRUE(mFrontendCallback)
431 << "test with openFrontendById/setFrontendCallback/getFrontendInfo first.";
432
433 EXPECT_TRUE(mFrontendInfo.type == config.type)
434 << "FrontendConfig does not match the frontend info of the given id.";
435
436 mIsSoftwareFe = config.isSoftwareFe;
437 bool result = true;
438 if (mIsSoftwareFe && testWithDemux) {
439 result &= mDvrTests.openDvrInDemux(mDvrConfig.type, mDvrConfig.bufferSize) == success();
440 result &= mDvrTests.configDvrPlayback(mDvrConfig.settings) == success();
441 result &= mDvrTests.getDvrPlaybackMQDescriptor() == success();
442 mDvrTests.startPlaybackInputThread(mDvrConfig.playbackInputFile,
443 mDvrConfig.settings.playback());
444 if (!result) {
445 ALOGW("[vts] Software frontend dvr configure failed.");
446 return failure();
447 }
448 }
Amy Zhangbc15b592020-09-25 15:35:55 -0700449 mFrontendCallback->tuneTestOnLock(mFrontend, config.settings, config.settingsExt1_1);
Amy Zhang68afca62020-07-20 18:28:58 -0700450 return AssertionResult(true);
451}
452
453AssertionResult FrontendTests::stopTuneFrontend(bool testWithDemux) {
454 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
455 Result status;
456 status = mFrontend->stopTune();
457 if (mIsSoftwareFe && testWithDemux) {
458 mDvrTests.stopPlaybackThread();
459 mDvrTests.closeDvrPlayback();
460 }
461 return AssertionResult(status == Result::SUCCESS);
462}
463
Amy Zhang45cc57a2020-07-09 22:56:25 -0700464AssertionResult FrontendTests::closeFrontend() {
465 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
466 Result status;
467 status = mFrontend->close();
468 mFrontend = nullptr;
469 mFrontendCallback = nullptr;
470 return AssertionResult(status == Result::SUCCESS);
471}
472
473void FrontendTests::getFrontendIdByType(FrontendType feType, uint32_t& feId) {
474 ASSERT_TRUE(getFrontendIds());
475 ASSERT_TRUE(mFeIds.size() > 0);
476 for (size_t i = 0; i < mFeIds.size(); i++) {
477 ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
478 if (mFrontendInfo.type != feType) {
479 continue;
480 }
481 feId = mFeIds[i];
482 return;
483 }
484 feId = INVALID_ID;
Amy Zhang68afca62020-07-20 18:28:58 -0700485}
Amy Zhang3ea25a62020-08-04 10:23:52 -0700486
487void FrontendTests::tuneTest(FrontendConfig frontendConf) {
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800488 if (!frontendConf.enable) {
489 return;
490 }
Amy Zhang3ea25a62020-08-04 10:23:52 -0700491 uint32_t feId;
492 getFrontendIdByType(frontendConf.type, feId);
493 ASSERT_TRUE(feId != INVALID_ID);
494 ASSERT_TRUE(openFrontendById(feId));
495 ASSERT_TRUE(setFrontendCallback());
Amy Zhangda3a54d2021-02-18 21:47:00 -0800496 if (frontendConf.canConnectToCiCam) {
497 ASSERT_TRUE(linkCiCam(frontendConf.ciCamId));
498 ASSERT_TRUE(unlinkCiCam(frontendConf.ciCamId));
499 }
Amy Zhang3ea25a62020-08-04 10:23:52 -0700500 ASSERT_TRUE(tuneFrontend(frontendConf, false /*testWithDemux*/));
Amy Zhang422bb112020-08-12 15:21:44 -0700501 verifyFrontendStatusExt1_1(frontendConf.tuneStatusTypes, frontendConf.expectTuneStatuses);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700502 ASSERT_TRUE(stopTuneFrontend(false /*testWithDemux*/));
503 ASSERT_TRUE(closeFrontend());
504}
505
506void FrontendTests::scanTest(FrontendConfig frontendConf, FrontendScanType scanType) {
Amy Zhangdf57fbf2021-03-11 17:39:10 -0800507 if (!frontendConf.enable) {
508 return;
509 }
Amy Zhang3ea25a62020-08-04 10:23:52 -0700510 uint32_t feId;
511 getFrontendIdByType(frontendConf.type, feId);
512 ASSERT_TRUE(feId != INVALID_ID);
513 ASSERT_TRUE(openFrontendById(feId));
514 ASSERT_TRUE(setFrontendCallback());
515 ASSERT_TRUE(scanFrontend(frontendConf, scanType));
516 ASSERT_TRUE(stopScanFrontend());
517 ASSERT_TRUE(closeFrontend());
518}
Amy Zhang4c49c152020-08-25 21:08:19 -0700519
520void FrontendTests::getFrontendDtmbCapsTest() {
521 uint32_t feId;
522 getFrontendIdByType(
523 static_cast<FrontendType>(android::hardware::tv::tuner::V1_1::FrontendType::DTMB),
524 feId);
525 if (feId != INVALID_ID) {
526 ALOGD("[vts] Found DTMB Frontend");
527 ASSERT_TRUE(getFrontendDtmbCaps(feId));
528 }
529}