blob: 92d7d1cff068a0c8a3cb4e563682c4832ad7f801 [file] [log] [blame]
Eric Laurent566fcda2016-11-23 10:36:36 -08001/*
2 * Copyright (C) 2016 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#define LOG_TAG "BroadcastRadioHidlHalTest"
Yuexi Maed2bb4e2017-03-10 00:44:45 -080018#include <VtsHalHidlTargetTestBase.h>
Eric Laurent566fcda2016-11-23 10:36:36 -080019#include <android-base/logging.h>
20#include <cutils/native_handle.h>
21#include <cutils/properties.h>
Martijn Coenen02822372016-12-29 14:03:41 +010022#include <hidl/HidlTransportSupport.h>
Eric Laurent566fcda2016-11-23 10:36:36 -080023#include <utils/threads.h>
Eric Laurent566fcda2016-11-23 10:36:36 -080024
25#include <android/hardware/broadcastradio/1.0/IBroadcastRadioFactory.h>
26#include <android/hardware/broadcastradio/1.0/IBroadcastRadio.h>
27#include <android/hardware/broadcastradio/1.0/ITuner.h>
28#include <android/hardware/broadcastradio/1.0/ITunerCallback.h>
29#include <android/hardware/broadcastradio/1.0/types.h>
30
31
32using ::android::sp;
33using ::android::Mutex;
34using ::android::Condition;
Eric Laurent566fcda2016-11-23 10:36:36 -080035using ::android::hardware::Return;
Eric Laurent566fcda2016-11-23 10:36:36 -080036using ::android::hardware::Void;
37using ::android::hardware::broadcastradio::V1_0::IBroadcastRadioFactory;
38using ::android::hardware::broadcastradio::V1_0::IBroadcastRadio;
39using ::android::hardware::broadcastradio::V1_0::ITuner;
40using ::android::hardware::broadcastradio::V1_0::ITunerCallback;
41using ::android::hardware::broadcastradio::V1_0::Result;
42using ::android::hardware::broadcastradio::V1_0::Class;
43using ::android::hardware::broadcastradio::V1_0::Properties;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080044using ::android::hardware::broadcastradio::V1_0::Band;
Eric Laurent566fcda2016-11-23 10:36:36 -080045using ::android::hardware::broadcastradio::V1_0::BandConfig;
46using ::android::hardware::broadcastradio::V1_0::Direction;
47using ::android::hardware::broadcastradio::V1_0::ProgramInfo;
48using ::android::hardware::broadcastradio::V1_0::MetaData;
49
50
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080051// The main test class for Broadcast Radio HIDL HAL.
Eric Laurent566fcda2016-11-23 10:36:36 -080052
Yuexi Maed2bb4e2017-03-10 00:44:45 -080053class BroadcastRadioHidlTest : public ::testing::VtsHalHidlTargetTestBase {
Eric Laurent566fcda2016-11-23 10:36:36 -080054 protected:
55 virtual void SetUp() override {
Eric Laurent566fcda2016-11-23 10:36:36 -080056 sp<IBroadcastRadioFactory> factory =
Yuexi Maed2bb4e2017-03-10 00:44:45 -080057 ::testing::VtsHalHidlTargetTestBase::getService<IBroadcastRadioFactory>();
Eric Laurent566fcda2016-11-23 10:36:36 -080058 if (factory != 0) {
59 factory->connectModule(Class::AM_FM,
60 [&](Result retval, const ::android::sp<IBroadcastRadio>& result) {
61 if (retval == Result::OK) {
62 mRadio = result;
63 }
64 });
65 }
66 mTunerCallback = new MyCallback(this);
67 ASSERT_NE(nullptr, mRadio.get());
Eric Laurent566fcda2016-11-23 10:36:36 -080068 ASSERT_NE(nullptr, mTunerCallback.get());
69 }
70
71 virtual void TearDown() override {
72 mTuner.clear();
73 mRadio.clear();
74 }
75
76 class MyCallback : public ITunerCallback {
77 public:
78
79 // ITunerCallback methods (see doc in ITunerCallback.hal)
80 virtual Return<void> hardwareFailure() {
81 ALOGI("%s", __FUNCTION__);
82 mParentTest->onHwFailureCallback();
83 return Void();
84 }
85
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080086 virtual Return<void> configChange(Result result, const BandConfig& config) {
Eric Laurent566fcda2016-11-23 10:36:36 -080087 ALOGI("%s result %d", __FUNCTION__, result);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080088 mParentTest->onConfigChangeCallback(result, config);
Eric Laurent566fcda2016-11-23 10:36:36 -080089 return Void();
90 }
91
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080092 virtual Return<void> tuneComplete(Result result, const ProgramInfo& info) {
Eric Laurent566fcda2016-11-23 10:36:36 -080093 ALOGI("%s result %d", __FUNCTION__, result);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080094 mParentTest->onTuneCompleteCallback(result, info);
Eric Laurent566fcda2016-11-23 10:36:36 -080095 return Void();
96 }
97
98 virtual Return<void> afSwitch(const ProgramInfo& info __unused) {
99 return Void();
100 }
101
102 virtual Return<void> antennaStateChange(bool connected) {
103 ALOGI("%s connected %d", __FUNCTION__, connected);
104 return Void();
105 }
106
107 virtual Return<void> trafficAnnouncement(bool active) {
108 ALOGI("%s active %d", __FUNCTION__, active);
109 return Void();
110 }
111
112 virtual Return<void> emergencyAnnouncement(bool active) {
113 ALOGI("%s active %d", __FUNCTION__, active);
114 return Void();
115 }
116
117 virtual Return<void> newMetadata(uint32_t channel __unused, uint32_t subChannel __unused,
118 const ::android::hardware::hidl_vec<MetaData>& metadata __unused) {
119 ALOGI("%s", __FUNCTION__);
120 return Void();
121 }
122
123 MyCallback(BroadcastRadioHidlTest *parentTest) : mParentTest(parentTest) {}
124
125 private:
126 // BroadcastRadioHidlTest instance to which callbacks will be notified.
127 BroadcastRadioHidlTest *mParentTest;
128 };
129
130
131 /**
132 * Method called by MyCallback when a callback with no status or boolean value is received
133 */
134 void onCallback() {
135 Mutex::Autolock _l(mLock);
136 onCallback_l();
137 }
138
139 /**
140 * Method called by MyCallback when hardwareFailure() callback is received
141 */
142 void onHwFailureCallback() {
143 Mutex::Autolock _l(mLock);
144 mHwFailure = true;
145 onCallback_l();
146 }
147
148 /**
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800149 * Method called by MyCallback when configChange() callback is received.
Eric Laurent566fcda2016-11-23 10:36:36 -0800150 */
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800151 void onConfigChangeCallback(Result result, const BandConfig& config) {
Eric Laurent566fcda2016-11-23 10:36:36 -0800152 Mutex::Autolock _l(mLock);
153 mResultCallbackData = result;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800154 mBandConfigCallbackData = config;
155 onCallback_l();
156 }
157
158 /**
159 * Method called by MyCallback when tuneComplete() callback is received.
160 */
161 void onTuneCompleteCallback(Result result, const ProgramInfo& info) {
162 Mutex::Autolock _l(mLock);
163 mResultCallbackData = result;
164 mProgramInfoCallbackData = info;
Eric Laurent566fcda2016-11-23 10:36:36 -0800165 onCallback_l();
166 }
167
168 /**
169 * Method called by MyCallback when a boolean indication is received
170 */
171 void onBoolCallback(bool result) {
172 Mutex::Autolock _l(mLock);
173 mBoolCallbackData = result;
174 onCallback_l();
175 }
176
177
178 BroadcastRadioHidlTest() :
179 mCallbackCalled(false), mBoolCallbackData(false),
180 mResultCallbackData(Result::OK), mHwFailure(false) {}
181
182 void onCallback_l() {
183 if (!mCallbackCalled) {
184 mCallbackCalled = true;
185 mCallbackCond.broadcast();
186 }
187 }
188
189
190 bool waitForCallback(nsecs_t reltime = 0) {
191 Mutex::Autolock _l(mLock);
192 nsecs_t endTime = systemTime() + reltime;
193 while (!mCallbackCalled) {
194 if (reltime == 0) {
195 mCallbackCond.wait(mLock);
196 } else {
197 nsecs_t now = systemTime();
198 if (now > endTime) {
199 return false;
200 }
201 mCallbackCond.waitRelative(mLock, endTime - now);
202 }
203 }
204 return true;
205 }
206
207 bool getProperties();
208 bool openTuner();
209 bool checkAntenna();
210
211 static const nsecs_t kConfigCallbacktimeoutNs = seconds_to_nanoseconds(10);
212 static const nsecs_t kTuneCallbacktimeoutNs = seconds_to_nanoseconds(30);
213
214 sp<IBroadcastRadio> mRadio;
215 Properties mHalProperties;
216 sp<ITuner> mTuner;
217 sp<MyCallback> mTunerCallback;
218 Mutex mLock;
219 Condition mCallbackCond;
220 bool mCallbackCalled;
221 bool mBoolCallbackData;
222 Result mResultCallbackData;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800223 ProgramInfo mProgramInfoCallbackData;
224 BandConfig mBandConfigCallbackData;
Eric Laurent566fcda2016-11-23 10:36:36 -0800225 bool mHwFailure;
226};
227
228// A class for test environment setup (kept since this file is a template).
229class BroadcastRadioHidlEnvironment : public ::testing::Environment {
230 public:
231 virtual void SetUp() {}
232 virtual void TearDown() {}
233};
234
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800235namespace android {
236namespace hardware {
237namespace broadcastradio {
238namespace V1_0 {
239
240/**
241 * Compares two BandConfig objects for testing purposes.
242 */
243static bool operator==(const BandConfig& l, const BandConfig& r) {
244 if (l.type != r.type) return false;
245 if (l.antennaConnected != r.antennaConnected) return false;
246 if (l.lowerLimit != r.lowerLimit) return false;
247 if (l.upperLimit != r.upperLimit) return false;
248 if (l.spacings != r.spacings) return false;
249 if (l.type == Band::AM || l.type == Band::AM_HD) {
250 return l.ext.am == r.ext.am;
251 } else if (l.type == Band::FM || l.type == Band::FM_HD) {
252 return l.ext.fm == r.ext.fm;
253 } else {
254 // unsupported type
255 return false;
256 }
257}
258
259} // V1_0
260} // broadcastradio
261} // hardware
262} // android
263
Eric Laurent566fcda2016-11-23 10:36:36 -0800264bool BroadcastRadioHidlTest::getProperties()
265{
266 if (mHalProperties.bands.size() == 0) {
267 Result halResult = Result::NOT_INITIALIZED;
268 Return<void> hidlReturn =
269 mRadio->getProperties([&](Result result, const Properties& properties) {
270 halResult = result;
271 if (result == Result::OK) {
272 mHalProperties = properties;
273 }
274 });
275
Steven Morelandb6438422017-01-03 17:06:57 -0800276 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800277 EXPECT_EQ(Result::OK, halResult);
278 EXPECT_EQ(Class::AM_FM, mHalProperties.classId);
279 EXPECT_GT(mHalProperties.numTuners, 0u);
280 EXPECT_GT(mHalProperties.bands.size(), 0u);
281 }
282 return mHalProperties.bands.size() > 0;
283}
284
285bool BroadcastRadioHidlTest::openTuner()
286{
287 if (!getProperties()) {
288 return false;
289 }
290 if (mTuner.get() == nullptr) {
291 Result halResult = Result::NOT_INITIALIZED;
292 Return<void> hidlReturn =
293 mRadio->openTuner(mHalProperties.bands[0], true, mTunerCallback,
294 [&](Result result, const sp<ITuner>& tuner) {
295 halResult = result;
296 if (result == Result::OK) {
297 mTuner = tuner;
298 }
299 });
Steven Morelandb6438422017-01-03 17:06:57 -0800300 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800301 EXPECT_EQ(Result::OK, halResult);
302 EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
303 }
304 EXPECT_NE(nullptr, mTuner.get());
305 return nullptr != mTuner.get();
306}
307
308bool BroadcastRadioHidlTest::checkAntenna()
309{
310 BandConfig halConfig;
311 Result halResult = Result::NOT_INITIALIZED;
312 Return<void> hidlReturn =
313 mTuner->getConfiguration([&](Result result, const BandConfig& config) {
314 halResult = result;
315 if (result == Result::OK) {
316 halConfig = config;
317 }
318 });
319
320 return ((halResult == Result::OK) && (halConfig.antennaConnected == true));
321}
322
323
324/**
325 * Test IBroadcastRadio::getProperties() method
326 *
327 * Verifies that:
328 * - the HAL implements the method
329 * - the method returns 0 (no error)
330 * - the implementation class is AM_FM
331 * - the implementation supports at least one tuner
332 * - the implementation supports at one band
333 */
334TEST_F(BroadcastRadioHidlTest, GetProperties) {
335 EXPECT_EQ(true, getProperties());
336}
337
338/**
339 * Test IBroadcastRadio::openTuner() method
340 *
341 * Verifies that:
342 * - the HAL implements the method
343 * - the method returns 0 (no error) and a valid ITuner interface
344 */
345TEST_F(BroadcastRadioHidlTest, OpenTuner) {
346 EXPECT_EQ(true, openTuner());
347}
348
349/**
Tomasz Wasilczykbe71e9c2016-12-22 11:49:17 -0800350 * Test IBroadcastRadio::openTuner() after ITuner disposal.
351 *
352 * Verifies that:
353 * - ITuner destruction gets propagated through HAL
354 * - the openTuner method works well when called for the second time
355 */
356TEST_F(BroadcastRadioHidlTest, ReopenTuner) {
357 EXPECT_TRUE(openTuner());
358 mTuner.clear();
359 EXPECT_TRUE(openTuner());
360}
361
362/**
363 * Test IBroadcastRadio::openTuner() method called twice.
364 *
365 * Verifies that:
366 * - the openTuner method fails when called for the second time without deleting previous
367 * ITuner instance
368 */
369TEST_F(BroadcastRadioHidlTest, OpenTunerTwice) {
370 EXPECT_TRUE(openTuner());
371
372 Result halResult = Result::NOT_INITIALIZED;
373 Return<void> hidlReturn =
374 mRadio->openTuner(mHalProperties.bands[0], true, mTunerCallback,
375 [&](Result result, const sp<ITuner>&) {
376 halResult = result;
377 });
378 EXPECT_TRUE(hidlReturn.isOk());
379 EXPECT_EQ(Result::INVALID_STATE, halResult);
380 EXPECT_TRUE(waitForCallback(kConfigCallbacktimeoutNs));
381}
382
383/**
Eric Laurent566fcda2016-11-23 10:36:36 -0800384 * Test ITuner::setConfiguration() and getConfiguration methods
385 *
386 * Verifies that:
387 * - the HAL implements both methods
388 * - the methods return 0 (no error)
389 * - the configuration callback is received within kConfigCallbacktimeoutNs ns
390 * - the configuration read back from HAl has the same class Id
391 */
392TEST_F(BroadcastRadioHidlTest, SetAndGetConfiguration) {
393 ASSERT_EQ(true, openTuner());
394 // test setConfiguration
395 mCallbackCalled = false;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800396 Return<Result> hidlResult = mTuner->setConfiguration(mHalProperties.bands[1]);
Steven Morelandb6438422017-01-03 17:06:57 -0800397 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800398 EXPECT_EQ(Result::OK, hidlResult);
399 EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
400 EXPECT_EQ(Result::OK, mResultCallbackData);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800401 EXPECT_EQ(mHalProperties.bands[1], mBandConfigCallbackData);
Eric Laurent566fcda2016-11-23 10:36:36 -0800402
403 // test getConfiguration
404 BandConfig halConfig;
405 Result halResult;
406 Return<void> hidlReturn =
407 mTuner->getConfiguration([&](Result result, const BandConfig& config) {
408 halResult = result;
409 if (result == Result::OK) {
410 halConfig = config;
411 }
412 });
Steven Morelandb6438422017-01-03 17:06:57 -0800413 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800414 EXPECT_EQ(Result::OK, halResult);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800415 EXPECT_EQ(mHalProperties.bands[1], halConfig);
Eric Laurent566fcda2016-11-23 10:36:36 -0800416}
417
418/**
Tomasz Wasilczyk10877cd2017-03-07 17:04:26 -0800419 * Test ITuner::setConfiguration() with invalid arguments.
420 *
421 * Verifies that:
422 * - the methods returns INVALID_ARGUMENTS on invalid arguments
423 * - the method recovers and succeeds after passing correct arguments
424 */
425TEST_F(BroadcastRadioHidlTest, SetConfigurationFails) {
426 ASSERT_EQ(true, openTuner());
427
428 // Let's define a config that's bad for sure.
429 BandConfig badConfig = {};
430 badConfig.type = Band::FM;
431 badConfig.lowerLimit = 0xFFFFFFFF;
432 badConfig.upperLimit = 0;
433 badConfig.spacings = (std::vector<uint32_t>){ 0 };
434
435 // Test setConfiguration failing on bad data.
436 mCallbackCalled = false;
437 auto setResult = mTuner->setConfiguration(badConfig);
438 EXPECT_TRUE(setResult.isOk());
439 EXPECT_EQ(Result::INVALID_ARGUMENTS, setResult);
440
441 // Test setConfiguration recovering after passing good data.
442 mCallbackCalled = false;
443 setResult = mTuner->setConfiguration(mHalProperties.bands[0]);
444 EXPECT_TRUE(setResult.isOk());
445 EXPECT_EQ(Result::OK, setResult);
446 EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
447 EXPECT_EQ(Result::OK, mResultCallbackData);
448}
449
450/**
Eric Laurent566fcda2016-11-23 10:36:36 -0800451 * Test ITuner::scan
452 *
453 * Verifies that:
454 * - the HAL implements the method
455 * - the method returns 0 (no error)
456 * - the tuned callback is received within kTuneCallbacktimeoutNs ns
457 */
458TEST_F(BroadcastRadioHidlTest, Scan) {
459 ASSERT_EQ(true, openTuner());
460 ASSERT_TRUE(checkAntenna());
461 // test scan UP
462 mCallbackCalled = false;
463 Return<Result> hidlResult = mTuner->scan(Direction::UP, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800464 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800465 EXPECT_EQ(Result::OK, hidlResult);
466 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
467
468 // test scan DOWN
469 mCallbackCalled = false;
470 hidlResult = mTuner->scan(Direction::DOWN, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800471 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800472 EXPECT_EQ(Result::OK, hidlResult);
473 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
474}
475
476/**
477 * Test ITuner::step
478 *
479 * Verifies that:
480 * - the HAL implements the method
481 * - the method returns 0 (no error)
482 * - the tuned callback is received within kTuneCallbacktimeoutNs ns
483 */
484TEST_F(BroadcastRadioHidlTest, Step) {
485 ASSERT_EQ(true, openTuner());
486 ASSERT_TRUE(checkAntenna());
487 // test step UP
488 mCallbackCalled = false;
489 Return<Result> hidlResult = mTuner->step(Direction::UP, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800490 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800491 EXPECT_EQ(Result::OK, hidlResult);
492 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
493
494 // test step DOWN
495 mCallbackCalled = false;
496 hidlResult = mTuner->step(Direction::DOWN, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800497 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800498 EXPECT_EQ(Result::OK, hidlResult);
499 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
500}
501
502/**
503 * Test ITuner::tune, getProgramInformation and cancel methods
504 *
505 * Verifies that:
506 * - the HAL implements the methods
507 * - the methods return 0 (no error)
508 * - the tuned callback is received within kTuneCallbacktimeoutNs ns after tune()
509 */
510TEST_F(BroadcastRadioHidlTest, TuneAndGetProgramInformationAndCancel) {
511 ASSERT_EQ(true, openTuner());
512 ASSERT_TRUE(checkAntenna());
513
514 // test tune
515 ASSERT_GT(mHalProperties.bands[0].spacings.size(), 0u);
516 ASSERT_GT(mHalProperties.bands[0].upperLimit, mHalProperties.bands[0].lowerLimit);
517
518 // test scan UP
519 uint32_t lowerLimit = mHalProperties.bands[0].lowerLimit;
520 uint32_t upperLimit = mHalProperties.bands[0].upperLimit;
521 uint32_t spacing = mHalProperties.bands[0].spacings[0];
522
523 uint32_t channel =
524 lowerLimit + (((upperLimit - lowerLimit) / 2 + spacing - 1) / spacing) * spacing;
525 mCallbackCalled = false;
526 mResultCallbackData = Result::NOT_INITIALIZED;
527 Return<Result> hidlResult = mTuner->tune(channel, 0);
Steven Morelandb6438422017-01-03 17:06:57 -0800528 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800529 EXPECT_EQ(Result::OK, hidlResult);
530 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800531 EXPECT_EQ(channel, mProgramInfoCallbackData.channel);
Eric Laurent566fcda2016-11-23 10:36:36 -0800532
533 // test getProgramInformation
534 ProgramInfo halInfo;
535 Result halResult = Result::NOT_INITIALIZED;
536 Return<void> hidlReturn = mTuner->getProgramInformation(
Tomasz Wasilczyk5cc9d862017-01-06 14:19:11 -0800537 [&](Result result, const ProgramInfo& info) {
538 halResult = result;
539 if (result == Result::OK) {
540 halInfo = info;
541 }
Eric Laurent566fcda2016-11-23 10:36:36 -0800542 });
Steven Morelandb6438422017-01-03 17:06:57 -0800543 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800544 EXPECT_EQ(Result::OK, halResult);
545 if (mResultCallbackData == Result::OK) {
546 EXPECT_EQ(true, halInfo.tuned);
547 EXPECT_LE(halInfo.channel, upperLimit);
548 EXPECT_GE(halInfo.channel, lowerLimit);
549 } else {
550 EXPECT_EQ(false, halInfo.tuned);
551 }
552
553 // test cancel
554 mTuner->tune(lowerLimit, 0);
555 hidlResult = mTuner->cancel();
Steven Morelandb6438422017-01-03 17:06:57 -0800556 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800557 EXPECT_EQ(Result::OK, hidlResult);
558}
559
Tomasz Wasilczyk59d985d2017-03-03 13:02:15 -0800560/**
561 * Test ITuner::tune failing when channel out of the range is provided.
562 *
563 * Verifies that:
564 * - the method returns INVALID_ARGUMENTS when applicable
565 * - the method recovers and succeeds after passing correct arguments
566 */
567TEST_F(BroadcastRadioHidlTest, TuneFailsOutOfBounds) {
568 ASSERT_TRUE(openTuner());
569 ASSERT_TRUE(checkAntenna());
570
571 // get current channel bounds
572 BandConfig halConfig;
573 Result halResult;
574 auto configResult = mTuner->getConfiguration([&](Result result, const BandConfig& config) {
575 halResult = result;
576 halConfig = config;
577 });
578 ASSERT_TRUE(configResult.isOk());
579 ASSERT_EQ(Result::OK, halResult);
580
581 // try to tune slightly above the limit and expect to fail
582 auto badChannel = halConfig.upperLimit + halConfig.spacings[0];
583 auto tuneResult = mTuner->tune(badChannel, 0);
584 EXPECT_TRUE(tuneResult.isOk());
585 EXPECT_EQ(Result::INVALID_ARGUMENTS, tuneResult);
586 EXPECT_TRUE(waitForCallback(kTuneCallbacktimeoutNs));
587
588 // tuning exactly at the limit should succeed
589 auto goodChannel = halConfig.upperLimit;
590 tuneResult = mTuner->tune(goodChannel, 0);
591 EXPECT_TRUE(tuneResult.isOk());
592 EXPECT_EQ(Result::OK, tuneResult);
593 EXPECT_TRUE(waitForCallback(kTuneCallbacktimeoutNs));
594}
595
Eric Laurent566fcda2016-11-23 10:36:36 -0800596
597int main(int argc, char** argv) {
Eric Laurent566fcda2016-11-23 10:36:36 -0800598 ::testing::AddGlobalTestEnvironment(new BroadcastRadioHidlEnvironment);
599 ::testing::InitGoogleTest(&argc, argv);
600 int status = RUN_ALL_TESTS();
601 ALOGI("Test result = %d", status);
602 return status;
603}