blob: 5bc3705fcd2ee94ae3ba8cd58d1c76bc4ab2fafe [file] [log] [blame]
Amy Zhangb3fb40b2020-04-02 13:48:43 -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
19Return<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 }
33}
34
35Return<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();
47 return Void();
48}
49
50void FrontendCallback::tuneTestOnEventReceive(sp<IFrontend>& frontend, FrontendSettings settings) {
51 Result result = frontend->tune(settings);
52 EXPECT_TRUE(result == Result::SUCCESS);
53
54 android::Mutex::Autolock autoLock(mMsgLock);
55 while (!mEventReceived) {
56 if (-ETIMEDOUT == mMsgCondition.waitRelative(mMsgLock, WAIT_TIMEOUT)) {
57 EXPECT_TRUE(false) << "Event not received within timeout";
58 mLockMsgReceived = false;
59 return;
60 }
61 }
62 mEventReceived = false;
63}
64
65void FrontendCallback::tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings) {
66 Result result = frontend->tune(settings);
67 EXPECT_TRUE(result == Result::SUCCESS);
68
69 android::Mutex::Autolock autoLock(mMsgLock);
70 while (!mLockMsgReceived) {
71 if (-ETIMEDOUT == mLockMsgCondition.waitRelative(mMsgLock, WAIT_TIMEOUT)) {
72 EXPECT_TRUE(false) << "Event LOCKED not received within timeout";
73 mLockMsgReceived = false;
74 return;
75 }
76 }
77 mLockMsgReceived = false;
78}
79
80void FrontendCallback::scanTest(sp<IFrontend>& frontend, FrontendConfig config,
81 FrontendScanType type) {
82 uint32_t targetFrequency = getTargetFrequency(config.settings, config.type);
83 if (type == FrontendScanType::SCAN_BLIND) {
84 // reset the frequency in the scan configuration to test blind scan. The settings param of
85 // passed in means the real input config on the transponder connected to the DUT.
86 // We want the blind the test to start from lower frequency than this to check the blind
87 // scan implementation.
88 resetBlindScanStartingFrequency(config, targetFrequency - 100);
89 }
90
91 Result result = frontend->scan(config.settings, type);
92 EXPECT_TRUE(result == Result::SUCCESS);
93
94 bool scanMsgLockedReceived = false;
95 bool targetFrequencyReceived = false;
96
97 android::Mutex::Autolock autoLock(mMsgLock);
98wait:
99 while (!mScanMessageReceived) {
100 if (-ETIMEDOUT == mMsgCondition.waitRelative(mMsgLock, WAIT_TIMEOUT)) {
101 EXPECT_TRUE(false) << "Scan message not received within timeout";
102 mScanMessageReceived = false;
103 mScanMsgProcessed = true;
104 return;
105 }
106 }
107
108 if (mScanMessageType != FrontendScanMessageType::END) {
109 if (mScanMessageType == FrontendScanMessageType::LOCKED) {
110 scanMsgLockedReceived = true;
111 Result result = frontend->scan(config.settings, type);
112 EXPECT_TRUE(result == Result::SUCCESS);
113 }
114
115 if (mScanMessageType == FrontendScanMessageType::FREQUENCY) {
116 targetFrequencyReceived = mScanMessage.frequencies().size() > 0 &&
117 mScanMessage.frequencies()[0] == targetFrequency;
118 }
119
120 if (mScanMessageType == FrontendScanMessageType::PROGRESS_PERCENT) {
121 ALOGD("[vts] Scan in progress...[%d%%]", mScanMessage.progressPercent());
122 }
123
124 mScanMessageReceived = false;
125 mScanMsgProcessed = true;
126 mMsgCondition.signal();
127 goto wait;
128 }
129
130 EXPECT_TRUE(scanMsgLockedReceived) << "Scan message LOCKED not received before END";
131 EXPECT_TRUE(targetFrequencyReceived) << "frequency not received before LOCKED on blindScan";
132 mScanMessageReceived = false;
133 mScanMsgProcessed = true;
134}
135
136uint32_t FrontendCallback::getTargetFrequency(FrontendSettings settings, FrontendType type) {
137 switch (type) {
138 case FrontendType::ANALOG:
139 return settings.analog().frequency;
140 case FrontendType::ATSC:
141 return settings.atsc().frequency;
142 case FrontendType::ATSC3:
143 return settings.atsc3().frequency;
144 case FrontendType::DVBC:
145 return settings.dvbc().frequency;
146 case FrontendType::DVBS:
147 return settings.dvbs().frequency;
148 case FrontendType::DVBT:
149 return settings.dvbt().frequency;
150 case FrontendType::ISDBS:
151 return settings.isdbs().frequency;
152 case FrontendType::ISDBS3:
153 return settings.isdbs3().frequency;
154 case FrontendType::ISDBT:
155 return settings.isdbt().frequency;
156 default:
157 return 0;
158 }
159}
160
161void FrontendCallback::resetBlindScanStartingFrequency(FrontendConfig& config,
162 uint32_t resetingFreq) {
163 switch (config.type) {
164 case FrontendType::ANALOG:
165 config.settings.analog().frequency = resetingFreq;
166 break;
167 case FrontendType::ATSC:
168 config.settings.atsc().frequency = resetingFreq;
169 break;
170 case FrontendType::ATSC3:
171 config.settings.atsc3().frequency = resetingFreq;
172 break;
173 case FrontendType::DVBC:
174 config.settings.dvbc().frequency = resetingFreq;
175 break;
176 case FrontendType::DVBS:
177 config.settings.dvbs().frequency = resetingFreq;
178 break;
179 case FrontendType::DVBT:
180 config.settings.dvbt().frequency = resetingFreq;
181 break;
182 case FrontendType::ISDBS:
183 config.settings.isdbs().frequency = resetingFreq;
184 break;
185 case FrontendType::ISDBS3:
186 config.settings.isdbs3().frequency = resetingFreq;
187 break;
188 case FrontendType::ISDBT:
189 config.settings.isdbt().frequency = resetingFreq;
190 break;
191 default:
192 // do nothing
193 return;
194 }
195}
196
197AssertionResult FrontendTests::getFrontendIds() {
198 Result status;
199 mService->getFrontendIds([&](Result result, const hidl_vec<FrontendId>& frontendIds) {
200 status = result;
201 mFeIds = frontendIds;
202 });
203 return AssertionResult(status == Result::SUCCESS);
204}
205
206AssertionResult FrontendTests::getFrontendInfo(uint32_t frontendId) {
207 Result status;
208 mService->getFrontendInfo(frontendId, [&](Result result, const FrontendInfo& frontendInfo) {
209 mFrontendInfo = frontendInfo;
210 status = result;
211 });
212 return AssertionResult(status == Result::SUCCESS);
213}
214
215AssertionResult FrontendTests::openFrontendById(uint32_t frontendId) {
216 Result status;
217 mService->openFrontendById(frontendId, [&](Result result, const sp<IFrontend>& frontend) {
218 mFrontend = frontend;
219 status = result;
220 });
221 return AssertionResult(status == Result::SUCCESS);
222}
223
224AssertionResult FrontendTests::setFrontendCallback() {
225 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
226 mFrontendCallback = new FrontendCallback();
227 auto callbackStatus = mFrontend->setCallback(mFrontendCallback);
228 return AssertionResult(callbackStatus.isOk());
229}
230
231AssertionResult FrontendTests::scanFrontend(FrontendConfig config, FrontendScanType type) {
232 EXPECT_TRUE(mFrontendCallback)
233 << "test with openFrontendById/setFrontendCallback/getFrontendInfo first.";
234
235 EXPECT_TRUE(mFrontendInfo.type == config.type)
236 << "FrontendConfig does not match the frontend info of the given id.";
237
238 mFrontendCallback->scanTest(mFrontend, config, type);
239 return AssertionResult(true);
240}
241
242AssertionResult FrontendTests::stopScanFrontend() {
243 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
244 Result status;
245 status = mFrontend->stopScan();
246 return AssertionResult(status == Result::SUCCESS);
247}
248
249AssertionResult FrontendTests::tuneFrontend(FrontendConfig config) {
250 EXPECT_TRUE(mFrontendCallback)
251 << "test with openFrontendById/setFrontendCallback/getFrontendInfo first.";
252
253 EXPECT_TRUE(mFrontendInfo.type == config.type)
254 << "FrontendConfig does not match the frontend info of the given id.";
255
256 mFrontendCallback->tuneTestOnLock(mFrontend, config.settings);
257 return AssertionResult(true);
258}
259
260AssertionResult FrontendTests::stopTuneFrontend() {
261 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
262 Result status;
263 status = mFrontend->stopTune();
264 return AssertionResult(status == Result::SUCCESS);
265}
266
267AssertionResult FrontendTests::closeFrontend() {
268 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
269 Result status;
270 status = mFrontend->close();
271 mFrontend = nullptr;
272 mFrontendCallback = nullptr;
273 return AssertionResult(status == Result::SUCCESS);
274}
275
276void FrontendTests::getFrontendIdByType(FrontendType feType, uint32_t& feId) {
277 ASSERT_TRUE(getFrontendIds());
278 ASSERT_TRUE(mFeIds.size() > 0);
279 for (size_t i = 0; i < mFeIds.size(); i++) {
280 ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
281 if (mFrontendInfo.type != feType) {
282 continue;
283 }
284 feId = mFeIds[i];
285 return;
286 }
287 feId = INVALID_ID;
288}
289
290void FrontendTests::tuneTest(FrontendConfig frontendConf) {
291 uint32_t feId;
292 getFrontendIdByType(frontendConf.type, feId);
293 ASSERT_TRUE(feId != INVALID_ID);
294 ASSERT_TRUE(openFrontendById(feId));
295 ASSERT_TRUE(setFrontendCallback());
296 ASSERT_TRUE(tuneFrontend(frontendConf));
297 ASSERT_TRUE(stopTuneFrontend());
298 ASSERT_TRUE(closeFrontend());
299}
300
301void FrontendTests::scanTest(FrontendConfig frontendConf, FrontendScanType scanType) {
302 uint32_t feId;
303 getFrontendIdByType(frontendConf.type, feId);
304 ASSERT_TRUE(feId != INVALID_ID);
305 ASSERT_TRUE(openFrontendById(feId));
306 ASSERT_TRUE(setFrontendCallback());
307 ASSERT_TRUE(scanFrontend(frontendConf, scanType));
308 ASSERT_TRUE(stopScanFrontend());
309 ASSERT_TRUE(closeFrontend());
310}