blob: 5106e5148e83118f83a95f8db12d86ca0e6c09ad [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 Ma50d7e272017-02-28 01:46:51 -080018#include <VtsHalHidlTargetBaseTest.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;
36using ::android::hardware::Status;
37using ::android::hardware::Void;
38using ::android::hardware::broadcastradio::V1_0::IBroadcastRadioFactory;
39using ::android::hardware::broadcastradio::V1_0::IBroadcastRadio;
40using ::android::hardware::broadcastradio::V1_0::ITuner;
41using ::android::hardware::broadcastradio::V1_0::ITunerCallback;
42using ::android::hardware::broadcastradio::V1_0::Result;
43using ::android::hardware::broadcastradio::V1_0::Class;
44using ::android::hardware::broadcastradio::V1_0::Properties;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080045using ::android::hardware::broadcastradio::V1_0::Band;
Eric Laurent566fcda2016-11-23 10:36:36 -080046using ::android::hardware::broadcastradio::V1_0::BandConfig;
47using ::android::hardware::broadcastradio::V1_0::Direction;
48using ::android::hardware::broadcastradio::V1_0::ProgramInfo;
49using ::android::hardware::broadcastradio::V1_0::MetaData;
50
51
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080052// The main test class for Broadcast Radio HIDL HAL.
Eric Laurent566fcda2016-11-23 10:36:36 -080053
Yuexi Ma50d7e272017-02-28 01:46:51 -080054class BroadcastRadioHidlTest : public ::testing::VtsHalHidlTargetBaseTest {
Eric Laurent566fcda2016-11-23 10:36:36 -080055 protected:
56 virtual void SetUp() override {
Eric Laurent566fcda2016-11-23 10:36:36 -080057 sp<IBroadcastRadioFactory> factory =
Yuexi Ma50d7e272017-02-28 01:46:51 -080058 ::testing::VtsHalHidlTargetBaseTest::getService<IBroadcastRadioFactory>();
Eric Laurent566fcda2016-11-23 10:36:36 -080059 if (factory != 0) {
60 factory->connectModule(Class::AM_FM,
61 [&](Result retval, const ::android::sp<IBroadcastRadio>& result) {
62 if (retval == Result::OK) {
63 mRadio = result;
64 }
65 });
66 }
67 mTunerCallback = new MyCallback(this);
68 ASSERT_NE(nullptr, mRadio.get());
Eric Laurent566fcda2016-11-23 10:36:36 -080069 ASSERT_NE(nullptr, mTunerCallback.get());
70 }
71
72 virtual void TearDown() override {
73 mTuner.clear();
74 mRadio.clear();
75 }
76
77 class MyCallback : public ITunerCallback {
78 public:
79
80 // ITunerCallback methods (see doc in ITunerCallback.hal)
81 virtual Return<void> hardwareFailure() {
82 ALOGI("%s", __FUNCTION__);
83 mParentTest->onHwFailureCallback();
84 return Void();
85 }
86
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080087 virtual Return<void> configChange(Result result, const BandConfig& config) {
Eric Laurent566fcda2016-11-23 10:36:36 -080088 ALOGI("%s result %d", __FUNCTION__, result);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080089 mParentTest->onConfigChangeCallback(result, config);
Eric Laurent566fcda2016-11-23 10:36:36 -080090 return Void();
91 }
92
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080093 virtual Return<void> tuneComplete(Result result, const ProgramInfo& info) {
Eric Laurent566fcda2016-11-23 10:36:36 -080094 ALOGI("%s result %d", __FUNCTION__, result);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -080095 mParentTest->onTuneCompleteCallback(result, info);
Eric Laurent566fcda2016-11-23 10:36:36 -080096 return Void();
97 }
98
99 virtual Return<void> afSwitch(const ProgramInfo& info __unused) {
100 return Void();
101 }
102
103 virtual Return<void> antennaStateChange(bool connected) {
104 ALOGI("%s connected %d", __FUNCTION__, connected);
105 return Void();
106 }
107
108 virtual Return<void> trafficAnnouncement(bool active) {
109 ALOGI("%s active %d", __FUNCTION__, active);
110 return Void();
111 }
112
113 virtual Return<void> emergencyAnnouncement(bool active) {
114 ALOGI("%s active %d", __FUNCTION__, active);
115 return Void();
116 }
117
118 virtual Return<void> newMetadata(uint32_t channel __unused, uint32_t subChannel __unused,
119 const ::android::hardware::hidl_vec<MetaData>& metadata __unused) {
120 ALOGI("%s", __FUNCTION__);
121 return Void();
122 }
123
124 MyCallback(BroadcastRadioHidlTest *parentTest) : mParentTest(parentTest) {}
125
126 private:
127 // BroadcastRadioHidlTest instance to which callbacks will be notified.
128 BroadcastRadioHidlTest *mParentTest;
129 };
130
131
132 /**
133 * Method called by MyCallback when a callback with no status or boolean value is received
134 */
135 void onCallback() {
136 Mutex::Autolock _l(mLock);
137 onCallback_l();
138 }
139
140 /**
141 * Method called by MyCallback when hardwareFailure() callback is received
142 */
143 void onHwFailureCallback() {
144 Mutex::Autolock _l(mLock);
145 mHwFailure = true;
146 onCallback_l();
147 }
148
149 /**
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800150 * Method called by MyCallback when configChange() callback is received.
Eric Laurent566fcda2016-11-23 10:36:36 -0800151 */
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800152 void onConfigChangeCallback(Result result, const BandConfig& config) {
Eric Laurent566fcda2016-11-23 10:36:36 -0800153 Mutex::Autolock _l(mLock);
154 mResultCallbackData = result;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800155 mBandConfigCallbackData = config;
156 onCallback_l();
157 }
158
159 /**
160 * Method called by MyCallback when tuneComplete() callback is received.
161 */
162 void onTuneCompleteCallback(Result result, const ProgramInfo& info) {
163 Mutex::Autolock _l(mLock);
164 mResultCallbackData = result;
165 mProgramInfoCallbackData = info;
Eric Laurent566fcda2016-11-23 10:36:36 -0800166 onCallback_l();
167 }
168
169 /**
170 * Method called by MyCallback when a boolean indication is received
171 */
172 void onBoolCallback(bool result) {
173 Mutex::Autolock _l(mLock);
174 mBoolCallbackData = result;
175 onCallback_l();
176 }
177
178
179 BroadcastRadioHidlTest() :
180 mCallbackCalled(false), mBoolCallbackData(false),
181 mResultCallbackData(Result::OK), mHwFailure(false) {}
182
183 void onCallback_l() {
184 if (!mCallbackCalled) {
185 mCallbackCalled = true;
186 mCallbackCond.broadcast();
187 }
188 }
189
190
191 bool waitForCallback(nsecs_t reltime = 0) {
192 Mutex::Autolock _l(mLock);
193 nsecs_t endTime = systemTime() + reltime;
194 while (!mCallbackCalled) {
195 if (reltime == 0) {
196 mCallbackCond.wait(mLock);
197 } else {
198 nsecs_t now = systemTime();
199 if (now > endTime) {
200 return false;
201 }
202 mCallbackCond.waitRelative(mLock, endTime - now);
203 }
204 }
205 return true;
206 }
207
208 bool getProperties();
209 bool openTuner();
210 bool checkAntenna();
211
212 static const nsecs_t kConfigCallbacktimeoutNs = seconds_to_nanoseconds(10);
213 static const nsecs_t kTuneCallbacktimeoutNs = seconds_to_nanoseconds(30);
214
215 sp<IBroadcastRadio> mRadio;
216 Properties mHalProperties;
217 sp<ITuner> mTuner;
218 sp<MyCallback> mTunerCallback;
219 Mutex mLock;
220 Condition mCallbackCond;
221 bool mCallbackCalled;
222 bool mBoolCallbackData;
223 Result mResultCallbackData;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800224 ProgramInfo mProgramInfoCallbackData;
225 BandConfig mBandConfigCallbackData;
Eric Laurent566fcda2016-11-23 10:36:36 -0800226 bool mHwFailure;
227};
228
229// A class for test environment setup (kept since this file is a template).
230class BroadcastRadioHidlEnvironment : public ::testing::Environment {
231 public:
232 virtual void SetUp() {}
233 virtual void TearDown() {}
234};
235
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800236namespace android {
237namespace hardware {
238namespace broadcastradio {
239namespace V1_0 {
240
241/**
242 * Compares two BandConfig objects for testing purposes.
243 */
244static bool operator==(const BandConfig& l, const BandConfig& r) {
245 if (l.type != r.type) return false;
246 if (l.antennaConnected != r.antennaConnected) return false;
247 if (l.lowerLimit != r.lowerLimit) return false;
248 if (l.upperLimit != r.upperLimit) return false;
249 if (l.spacings != r.spacings) return false;
250 if (l.type == Band::AM || l.type == Band::AM_HD) {
251 return l.ext.am == r.ext.am;
252 } else if (l.type == Band::FM || l.type == Band::FM_HD) {
253 return l.ext.fm == r.ext.fm;
254 } else {
255 // unsupported type
256 return false;
257 }
258}
259
260} // V1_0
261} // broadcastradio
262} // hardware
263} // android
264
Eric Laurent566fcda2016-11-23 10:36:36 -0800265bool BroadcastRadioHidlTest::getProperties()
266{
267 if (mHalProperties.bands.size() == 0) {
268 Result halResult = Result::NOT_INITIALIZED;
269 Return<void> hidlReturn =
270 mRadio->getProperties([&](Result result, const Properties& properties) {
271 halResult = result;
272 if (result == Result::OK) {
273 mHalProperties = properties;
274 }
275 });
276
Steven Morelandb6438422017-01-03 17:06:57 -0800277 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800278 EXPECT_EQ(Result::OK, halResult);
279 EXPECT_EQ(Class::AM_FM, mHalProperties.classId);
280 EXPECT_GT(mHalProperties.numTuners, 0u);
281 EXPECT_GT(mHalProperties.bands.size(), 0u);
282 }
283 return mHalProperties.bands.size() > 0;
284}
285
286bool BroadcastRadioHidlTest::openTuner()
287{
288 if (!getProperties()) {
289 return false;
290 }
291 if (mTuner.get() == nullptr) {
292 Result halResult = Result::NOT_INITIALIZED;
293 Return<void> hidlReturn =
294 mRadio->openTuner(mHalProperties.bands[0], true, mTunerCallback,
295 [&](Result result, const sp<ITuner>& tuner) {
296 halResult = result;
297 if (result == Result::OK) {
298 mTuner = tuner;
299 }
300 });
Steven Morelandb6438422017-01-03 17:06:57 -0800301 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800302 EXPECT_EQ(Result::OK, halResult);
303 EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
304 }
305 EXPECT_NE(nullptr, mTuner.get());
306 return nullptr != mTuner.get();
307}
308
309bool BroadcastRadioHidlTest::checkAntenna()
310{
311 BandConfig halConfig;
312 Result halResult = Result::NOT_INITIALIZED;
313 Return<void> hidlReturn =
314 mTuner->getConfiguration([&](Result result, const BandConfig& config) {
315 halResult = result;
316 if (result == Result::OK) {
317 halConfig = config;
318 }
319 });
320
321 return ((halResult == Result::OK) && (halConfig.antennaConnected == true));
322}
323
324
325/**
326 * Test IBroadcastRadio::getProperties() method
327 *
328 * Verifies that:
329 * - the HAL implements the method
330 * - the method returns 0 (no error)
331 * - the implementation class is AM_FM
332 * - the implementation supports at least one tuner
333 * - the implementation supports at one band
334 */
335TEST_F(BroadcastRadioHidlTest, GetProperties) {
336 EXPECT_EQ(true, getProperties());
337}
338
339/**
340 * Test IBroadcastRadio::openTuner() method
341 *
342 * Verifies that:
343 * - the HAL implements the method
344 * - the method returns 0 (no error) and a valid ITuner interface
345 */
346TEST_F(BroadcastRadioHidlTest, OpenTuner) {
347 EXPECT_EQ(true, openTuner());
348}
349
350/**
Tomasz Wasilczykbe71e9c2016-12-22 11:49:17 -0800351 * Test IBroadcastRadio::openTuner() after ITuner disposal.
352 *
353 * Verifies that:
354 * - ITuner destruction gets propagated through HAL
355 * - the openTuner method works well when called for the second time
356 */
357TEST_F(BroadcastRadioHidlTest, ReopenTuner) {
358 EXPECT_TRUE(openTuner());
359 mTuner.clear();
360 EXPECT_TRUE(openTuner());
361}
362
363/**
364 * Test IBroadcastRadio::openTuner() method called twice.
365 *
366 * Verifies that:
367 * - the openTuner method fails when called for the second time without deleting previous
368 * ITuner instance
369 */
370TEST_F(BroadcastRadioHidlTest, OpenTunerTwice) {
371 EXPECT_TRUE(openTuner());
372
373 Result halResult = Result::NOT_INITIALIZED;
374 Return<void> hidlReturn =
375 mRadio->openTuner(mHalProperties.bands[0], true, mTunerCallback,
376 [&](Result result, const sp<ITuner>&) {
377 halResult = result;
378 });
379 EXPECT_TRUE(hidlReturn.isOk());
380 EXPECT_EQ(Result::INVALID_STATE, halResult);
381 EXPECT_TRUE(waitForCallback(kConfigCallbacktimeoutNs));
382}
383
384/**
Eric Laurent566fcda2016-11-23 10:36:36 -0800385 * Test ITuner::setConfiguration() and getConfiguration methods
386 *
387 * Verifies that:
388 * - the HAL implements both methods
389 * - the methods return 0 (no error)
390 * - the configuration callback is received within kConfigCallbacktimeoutNs ns
391 * - the configuration read back from HAl has the same class Id
392 */
393TEST_F(BroadcastRadioHidlTest, SetAndGetConfiguration) {
394 ASSERT_EQ(true, openTuner());
395 // test setConfiguration
396 mCallbackCalled = false;
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800397 Return<Result> hidlResult = mTuner->setConfiguration(mHalProperties.bands[1]);
Steven Morelandb6438422017-01-03 17:06:57 -0800398 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800399 EXPECT_EQ(Result::OK, hidlResult);
400 EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs));
401 EXPECT_EQ(Result::OK, mResultCallbackData);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800402 EXPECT_EQ(mHalProperties.bands[1], mBandConfigCallbackData);
Eric Laurent566fcda2016-11-23 10:36:36 -0800403
404 // test getConfiguration
405 BandConfig halConfig;
406 Result halResult;
407 Return<void> hidlReturn =
408 mTuner->getConfiguration([&](Result result, const BandConfig& config) {
409 halResult = result;
410 if (result == Result::OK) {
411 halConfig = config;
412 }
413 });
Steven Morelandb6438422017-01-03 17:06:57 -0800414 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800415 EXPECT_EQ(Result::OK, halResult);
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800416 EXPECT_EQ(mHalProperties.bands[1], halConfig);
Eric Laurent566fcda2016-11-23 10:36:36 -0800417}
418
419/**
420 * Test ITuner::scan
421 *
422 * Verifies that:
423 * - the HAL implements the method
424 * - the method returns 0 (no error)
425 * - the tuned callback is received within kTuneCallbacktimeoutNs ns
426 */
427TEST_F(BroadcastRadioHidlTest, Scan) {
428 ASSERT_EQ(true, openTuner());
429 ASSERT_TRUE(checkAntenna());
430 // test scan UP
431 mCallbackCalled = false;
432 Return<Result> hidlResult = mTuner->scan(Direction::UP, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800433 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800434 EXPECT_EQ(Result::OK, hidlResult);
435 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
436
437 // test scan DOWN
438 mCallbackCalled = false;
439 hidlResult = mTuner->scan(Direction::DOWN, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800440 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800441 EXPECT_EQ(Result::OK, hidlResult);
442 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
443}
444
445/**
446 * Test ITuner::step
447 *
448 * Verifies that:
449 * - the HAL implements the method
450 * - the method returns 0 (no error)
451 * - the tuned callback is received within kTuneCallbacktimeoutNs ns
452 */
453TEST_F(BroadcastRadioHidlTest, Step) {
454 ASSERT_EQ(true, openTuner());
455 ASSERT_TRUE(checkAntenna());
456 // test step UP
457 mCallbackCalled = false;
458 Return<Result> hidlResult = mTuner->step(Direction::UP, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800459 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800460 EXPECT_EQ(Result::OK, hidlResult);
461 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
462
463 // test step DOWN
464 mCallbackCalled = false;
465 hidlResult = mTuner->step(Direction::DOWN, true);
Steven Morelandb6438422017-01-03 17:06:57 -0800466 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800467 EXPECT_EQ(Result::OK, hidlResult);
468 EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs));
469}
470
471/**
472 * Test ITuner::tune, getProgramInformation and cancel methods
473 *
474 * Verifies that:
475 * - the HAL implements the methods
476 * - the methods return 0 (no error)
477 * - the tuned callback is received within kTuneCallbacktimeoutNs ns after tune()
478 */
479TEST_F(BroadcastRadioHidlTest, TuneAndGetProgramInformationAndCancel) {
480 ASSERT_EQ(true, openTuner());
481 ASSERT_TRUE(checkAntenna());
482
483 // test tune
484 ASSERT_GT(mHalProperties.bands[0].spacings.size(), 0u);
485 ASSERT_GT(mHalProperties.bands[0].upperLimit, mHalProperties.bands[0].lowerLimit);
486
487 // test scan UP
488 uint32_t lowerLimit = mHalProperties.bands[0].lowerLimit;
489 uint32_t upperLimit = mHalProperties.bands[0].upperLimit;
490 uint32_t spacing = mHalProperties.bands[0].spacings[0];
491
492 uint32_t channel =
493 lowerLimit + (((upperLimit - lowerLimit) / 2 + spacing - 1) / spacing) * spacing;
494 mCallbackCalled = false;
495 mResultCallbackData = Result::NOT_INITIALIZED;
496 Return<Result> hidlResult = mTuner->tune(channel, 0);
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));
Tomasz Wasilczykf3c036d2017-03-03 15:07:50 -0800500 EXPECT_EQ(channel, mProgramInfoCallbackData.channel);
Eric Laurent566fcda2016-11-23 10:36:36 -0800501
502 // test getProgramInformation
503 ProgramInfo halInfo;
504 Result halResult = Result::NOT_INITIALIZED;
505 Return<void> hidlReturn = mTuner->getProgramInformation(
Tomasz Wasilczyk5cc9d862017-01-06 14:19:11 -0800506 [&](Result result, const ProgramInfo& info) {
507 halResult = result;
508 if (result == Result::OK) {
509 halInfo = info;
510 }
Eric Laurent566fcda2016-11-23 10:36:36 -0800511 });
Steven Morelandb6438422017-01-03 17:06:57 -0800512 EXPECT_TRUE(hidlReturn.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800513 EXPECT_EQ(Result::OK, halResult);
514 if (mResultCallbackData == Result::OK) {
515 EXPECT_EQ(true, halInfo.tuned);
516 EXPECT_LE(halInfo.channel, upperLimit);
517 EXPECT_GE(halInfo.channel, lowerLimit);
518 } else {
519 EXPECT_EQ(false, halInfo.tuned);
520 }
521
522 // test cancel
523 mTuner->tune(lowerLimit, 0);
524 hidlResult = mTuner->cancel();
Steven Morelandb6438422017-01-03 17:06:57 -0800525 EXPECT_TRUE(hidlResult.isOk());
Eric Laurent566fcda2016-11-23 10:36:36 -0800526 EXPECT_EQ(Result::OK, hidlResult);
527}
528
Tomasz Wasilczyk59d985d2017-03-03 13:02:15 -0800529/**
530 * Test ITuner::tune failing when channel out of the range is provided.
531 *
532 * Verifies that:
533 * - the method returns INVALID_ARGUMENTS when applicable
534 * - the method recovers and succeeds after passing correct arguments
535 */
536TEST_F(BroadcastRadioHidlTest, TuneFailsOutOfBounds) {
537 ASSERT_TRUE(openTuner());
538 ASSERT_TRUE(checkAntenna());
539
540 // get current channel bounds
541 BandConfig halConfig;
542 Result halResult;
543 auto configResult = mTuner->getConfiguration([&](Result result, const BandConfig& config) {
544 halResult = result;
545 halConfig = config;
546 });
547 ASSERT_TRUE(configResult.isOk());
548 ASSERT_EQ(Result::OK, halResult);
549
550 // try to tune slightly above the limit and expect to fail
551 auto badChannel = halConfig.upperLimit + halConfig.spacings[0];
552 auto tuneResult = mTuner->tune(badChannel, 0);
553 EXPECT_TRUE(tuneResult.isOk());
554 EXPECT_EQ(Result::INVALID_ARGUMENTS, tuneResult);
555 EXPECT_TRUE(waitForCallback(kTuneCallbacktimeoutNs));
556
557 // tuning exactly at the limit should succeed
558 auto goodChannel = halConfig.upperLimit;
559 tuneResult = mTuner->tune(goodChannel, 0);
560 EXPECT_TRUE(tuneResult.isOk());
561 EXPECT_EQ(Result::OK, tuneResult);
562 EXPECT_TRUE(waitForCallback(kTuneCallbacktimeoutNs));
563}
564
Eric Laurent566fcda2016-11-23 10:36:36 -0800565
566int main(int argc, char** argv) {
Eric Laurent566fcda2016-11-23 10:36:36 -0800567 ::testing::AddGlobalTestEnvironment(new BroadcastRadioHidlEnvironment);
568 ::testing::InitGoogleTest(&argc, argv);
569 int status = RUN_ALL_TESTS();
570 ALOGI("Test result = %d", status);
571 return status;
572}