Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 1 | /* |
| 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" |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 18 | #include <android-base/logging.h> |
| 19 | #include <cutils/native_handle.h> |
| 20 | #include <cutils/properties.h> |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 21 | #include <gtest/gtest.h> |
| 22 | #include <hidl/GtestPrinter.h> |
Martijn Coenen | 0282237 | 2016-12-29 14:03:41 +0100 | [diff] [blame] | 23 | #include <hidl/HidlTransportSupport.h> |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 24 | #include <hidl/ServiceManagement.h> |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 25 | #include <utils/threads.h> |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 26 | |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 27 | #include <android/hardware/broadcastradio/1.0/IBroadcastRadio.h> |
Zhuoyao Zhang | 190548f | 2018-02-08 20:40:23 -0800 | [diff] [blame] | 28 | #include <android/hardware/broadcastradio/1.0/IBroadcastRadioFactory.h> |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 29 | #include <android/hardware/broadcastradio/1.0/ITuner.h> |
| 30 | #include <android/hardware/broadcastradio/1.0/ITunerCallback.h> |
| 31 | #include <android/hardware/broadcastradio/1.0/types.h> |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 32 | #include <broadcastradio-vts-utils/hal-1.x-enum-utils.h> |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 33 | |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 34 | using ::android::Condition; |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 35 | using ::android::Mutex; |
| 36 | using ::android::sp; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 37 | using ::android::hardware::Return; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 38 | using ::android::hardware::Void; |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 39 | using ::android::hardware::broadcastradio::V1_0::Band; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 40 | using ::android::hardware::broadcastradio::V1_0::BandConfig; |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 41 | using ::android::hardware::broadcastradio::V1_0::Class; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 42 | using ::android::hardware::broadcastradio::V1_0::Direction; |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 43 | using ::android::hardware::broadcastradio::V1_0::IBroadcastRadio; |
| 44 | using ::android::hardware::broadcastradio::V1_0::IBroadcastRadioFactory; |
| 45 | using ::android::hardware::broadcastradio::V1_0::ITuner; |
| 46 | using ::android::hardware::broadcastradio::V1_0::ITunerCallback; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 47 | using ::android::hardware::broadcastradio::V1_0::MetaData; |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 48 | using ::android::hardware::broadcastradio::V1_0::MetadataKey; |
| 49 | using ::android::hardware::broadcastradio::V1_0::MetadataType; |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 50 | using ::android::hardware::broadcastradio::V1_0::ProgramInfo; |
| 51 | using ::android::hardware::broadcastradio::V1_0::Properties; |
| 52 | using ::android::hardware::broadcastradio::V1_0::Result; |
| 53 | using ::android::hardware::broadcastradio::V1_0::vts::RadioClassFromString; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 54 | |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 55 | #define RETURN_IF_SKIPPED \ |
| 56 | if (skipped) { \ |
| 57 | std::cout << "[ SKIPPED ] This device class is not supported. " << std::endl; \ |
| 58 | return; \ |
| 59 | } |
| 60 | |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 61 | // The main test class for Broadcast Radio HIDL HAL. |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 62 | class BroadcastRadioHidlTest |
| 63 | : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { |
| 64 | protected: |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 65 | virtual void SetUp() override { |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 66 | ASSERT_EQ(nullptr, mRadio.get()); |
| 67 | |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 68 | radioClass = RadioClassFromString(std::get<1>(GetParam())); |
| 69 | |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 70 | skipped = false; |
| 71 | |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 72 | sp<IBroadcastRadioFactory> factory = |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 73 | IBroadcastRadioFactory::getService(std::get<0>(GetParam())); |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 74 | ASSERT_NE(nullptr, factory.get()); |
| 75 | |
| 76 | Result connectResult; |
| 77 | factory->connectModule(radioClass, [&](Result ret, const sp<IBroadcastRadio>& radio) { |
| 78 | connectResult = ret; |
| 79 | mRadio = radio; |
| 80 | onCallback_l(); |
| 81 | }); |
| 82 | EXPECT_EQ(true, waitForCallback(kConnectCallbacktimeoutNs)); |
| 83 | mCallbackCalled = false; |
| 84 | |
| 85 | if (connectResult == Result::INVALID_ARGUMENTS) { |
| 86 | skipped = true; |
| 87 | return; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 88 | } |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 89 | ASSERT_EQ(connectResult, Result::OK); |
| 90 | |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 91 | mTunerCallback = new MyCallback(this); |
| 92 | ASSERT_NE(nullptr, mRadio.get()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 93 | ASSERT_NE(nullptr, mTunerCallback.get()); |
| 94 | } |
| 95 | |
| 96 | virtual void TearDown() override { |
| 97 | mTuner.clear(); |
| 98 | mRadio.clear(); |
| 99 | } |
| 100 | |
| 101 | class MyCallback : public ITunerCallback { |
| 102 | public: |
| 103 | |
| 104 | // ITunerCallback methods (see doc in ITunerCallback.hal) |
| 105 | virtual Return<void> hardwareFailure() { |
| 106 | ALOGI("%s", __FUNCTION__); |
| 107 | mParentTest->onHwFailureCallback(); |
| 108 | return Void(); |
| 109 | } |
| 110 | |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 111 | virtual Return<void> configChange(Result result, const BandConfig& config) { |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 112 | ALOGI("%s result %d", __FUNCTION__, result); |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 113 | mParentTest->onConfigChangeCallback(result, config); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 114 | return Void(); |
| 115 | } |
| 116 | |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 117 | virtual Return<void> tuneComplete(Result result, const ProgramInfo& info) { |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 118 | ALOGI("%s result %d", __FUNCTION__, result); |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 119 | mParentTest->onTuneCompleteCallback(result, info); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 120 | return Void(); |
| 121 | } |
| 122 | |
| 123 | virtual Return<void> afSwitch(const ProgramInfo& info __unused) { |
| 124 | return Void(); |
| 125 | } |
| 126 | |
| 127 | virtual Return<void> antennaStateChange(bool connected) { |
| 128 | ALOGI("%s connected %d", __FUNCTION__, connected); |
| 129 | return Void(); |
| 130 | } |
| 131 | |
| 132 | virtual Return<void> trafficAnnouncement(bool active) { |
| 133 | ALOGI("%s active %d", __FUNCTION__, active); |
| 134 | return Void(); |
| 135 | } |
| 136 | |
| 137 | virtual Return<void> emergencyAnnouncement(bool active) { |
| 138 | ALOGI("%s active %d", __FUNCTION__, active); |
| 139 | return Void(); |
| 140 | } |
| 141 | |
| 142 | virtual Return<void> newMetadata(uint32_t channel __unused, uint32_t subChannel __unused, |
| 143 | const ::android::hardware::hidl_vec<MetaData>& metadata __unused) { |
| 144 | ALOGI("%s", __FUNCTION__); |
| 145 | return Void(); |
| 146 | } |
| 147 | |
| 148 | MyCallback(BroadcastRadioHidlTest *parentTest) : mParentTest(parentTest) {} |
| 149 | |
| 150 | private: |
| 151 | // BroadcastRadioHidlTest instance to which callbacks will be notified. |
| 152 | BroadcastRadioHidlTest *mParentTest; |
| 153 | }; |
| 154 | |
| 155 | |
| 156 | /** |
| 157 | * Method called by MyCallback when a callback with no status or boolean value is received |
| 158 | */ |
| 159 | void onCallback() { |
| 160 | Mutex::Autolock _l(mLock); |
| 161 | onCallback_l(); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Method called by MyCallback when hardwareFailure() callback is received |
| 166 | */ |
| 167 | void onHwFailureCallback() { |
| 168 | Mutex::Autolock _l(mLock); |
| 169 | mHwFailure = true; |
| 170 | onCallback_l(); |
| 171 | } |
| 172 | |
| 173 | /** |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 174 | * Method called by MyCallback when configChange() callback is received. |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 175 | */ |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 176 | void onConfigChangeCallback(Result result, const BandConfig& config) { |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 177 | Mutex::Autolock _l(mLock); |
| 178 | mResultCallbackData = result; |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 179 | mBandConfigCallbackData = config; |
| 180 | onCallback_l(); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Method called by MyCallback when tuneComplete() callback is received. |
| 185 | */ |
| 186 | void onTuneCompleteCallback(Result result, const ProgramInfo& info) { |
| 187 | Mutex::Autolock _l(mLock); |
| 188 | mResultCallbackData = result; |
| 189 | mProgramInfoCallbackData = info; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 190 | onCallback_l(); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Method called by MyCallback when a boolean indication is received |
| 195 | */ |
| 196 | void onBoolCallback(bool result) { |
| 197 | Mutex::Autolock _l(mLock); |
| 198 | mBoolCallbackData = result; |
| 199 | onCallback_l(); |
| 200 | } |
| 201 | |
| 202 | |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 203 | BroadcastRadioHidlTest() |
| 204 | : mCallbackCalled(false), mBoolCallbackData(false), mResultCallbackData(Result::OK), |
| 205 | mHwFailure(false) {} |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 206 | |
| 207 | void onCallback_l() { |
| 208 | if (!mCallbackCalled) { |
| 209 | mCallbackCalled = true; |
| 210 | mCallbackCond.broadcast(); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | |
| 215 | bool waitForCallback(nsecs_t reltime = 0) { |
| 216 | Mutex::Autolock _l(mLock); |
| 217 | nsecs_t endTime = systemTime() + reltime; |
| 218 | while (!mCallbackCalled) { |
| 219 | if (reltime == 0) { |
| 220 | mCallbackCond.wait(mLock); |
| 221 | } else { |
| 222 | nsecs_t now = systemTime(); |
| 223 | if (now > endTime) { |
| 224 | return false; |
| 225 | } |
| 226 | mCallbackCond.waitRelative(mLock, endTime - now); |
| 227 | } |
| 228 | } |
| 229 | return true; |
| 230 | } |
| 231 | |
| 232 | bool getProperties(); |
| 233 | bool openTuner(); |
| 234 | bool checkAntenna(); |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Retrieves AM/FM band configuration from module properties. |
| 238 | * |
| 239 | * The configuration may not exist: if radio type is other than AM/FM |
| 240 | * or provided index is out of bounds. |
| 241 | * In such case, empty configuration is returned. |
| 242 | * |
| 243 | * @param idx Band index to retrieve. |
| 244 | * @return Band configuration reference. |
| 245 | */ |
| 246 | const BandConfig& getBand(unsigned idx); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 247 | |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 248 | static const nsecs_t kConnectCallbacktimeoutNs = seconds_to_nanoseconds(1); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 249 | static const nsecs_t kConfigCallbacktimeoutNs = seconds_to_nanoseconds(10); |
| 250 | static const nsecs_t kTuneCallbacktimeoutNs = seconds_to_nanoseconds(30); |
| 251 | |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 252 | Class radioClass; |
| 253 | bool skipped; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 254 | sp<IBroadcastRadio> mRadio; |
| 255 | Properties mHalProperties; |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 256 | bool mHalPropertiesInitialized = false; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 257 | sp<ITuner> mTuner; |
| 258 | sp<MyCallback> mTunerCallback; |
| 259 | Mutex mLock; |
| 260 | Condition mCallbackCond; |
| 261 | bool mCallbackCalled; |
| 262 | bool mBoolCallbackData; |
| 263 | Result mResultCallbackData; |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 264 | ProgramInfo mProgramInfoCallbackData; |
| 265 | BandConfig mBandConfigCallbackData; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 266 | bool mHwFailure; |
| 267 | }; |
| 268 | |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 269 | namespace android { |
| 270 | namespace hardware { |
| 271 | namespace broadcastradio { |
| 272 | namespace V1_0 { |
| 273 | |
| 274 | /** |
| 275 | * Compares two BandConfig objects for testing purposes. |
| 276 | */ |
| 277 | static bool operator==(const BandConfig& l, const BandConfig& r) { |
| 278 | if (l.type != r.type) return false; |
| 279 | if (l.antennaConnected != r.antennaConnected) return false; |
| 280 | if (l.lowerLimit != r.lowerLimit) return false; |
| 281 | if (l.upperLimit != r.upperLimit) return false; |
| 282 | if (l.spacings != r.spacings) return false; |
| 283 | if (l.type == Band::AM || l.type == Band::AM_HD) { |
| 284 | return l.ext.am == r.ext.am; |
| 285 | } else if (l.type == Band::FM || l.type == Band::FM_HD) { |
| 286 | return l.ext.fm == r.ext.fm; |
| 287 | } else { |
| 288 | // unsupported type |
| 289 | return false; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | } // V1_0 |
| 294 | } // broadcastradio |
| 295 | } // hardware |
| 296 | } // android |
| 297 | |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 298 | bool BroadcastRadioHidlTest::getProperties() |
| 299 | { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 300 | if (mHalPropertiesInitialized) return true; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 301 | |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 302 | Result halResult = Result::NOT_INITIALIZED; |
| 303 | auto hidlReturn = mRadio->getProperties([&](Result result, const Properties& properties) { |
| 304 | halResult = result; |
| 305 | if (result == Result::OK) { |
| 306 | mHalProperties = properties; |
| 307 | } |
| 308 | }); |
| 309 | |
| 310 | EXPECT_TRUE(hidlReturn.isOk()); |
| 311 | EXPECT_EQ(Result::OK, halResult); |
| 312 | EXPECT_EQ(radioClass, mHalProperties.classId); |
| 313 | EXPECT_GT(mHalProperties.numTuners, 0u); |
| 314 | if (radioClass == Class::AM_FM) { |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 315 | EXPECT_GT(mHalProperties.bands.size(), 0u); |
| 316 | } |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 317 | |
| 318 | if (hidlReturn.isOk() && halResult == Result::OK) { |
| 319 | mHalPropertiesInitialized = true; |
| 320 | return true; |
| 321 | } |
| 322 | return false; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | bool BroadcastRadioHidlTest::openTuner() |
| 326 | { |
| 327 | if (!getProperties()) { |
| 328 | return false; |
| 329 | } |
| 330 | if (mTuner.get() == nullptr) { |
| 331 | Result halResult = Result::NOT_INITIALIZED; |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 332 | auto openCb = [&](Result result, const sp<ITuner>& tuner) { |
| 333 | halResult = result; |
| 334 | if (result == Result::OK) { |
| 335 | mTuner = tuner; |
| 336 | } |
| 337 | }; |
| 338 | auto hidlReturn = mRadio->openTuner(getBand(0), true, mTunerCallback, openCb); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 339 | EXPECT_TRUE(hidlReturn.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 340 | EXPECT_EQ(Result::OK, halResult); |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 341 | if (radioClass == Class::AM_FM) { |
| 342 | EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs)); |
| 343 | } |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 344 | } |
| 345 | EXPECT_NE(nullptr, mTuner.get()); |
| 346 | return nullptr != mTuner.get(); |
| 347 | } |
| 348 | |
| 349 | bool BroadcastRadioHidlTest::checkAntenna() |
| 350 | { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 351 | if (radioClass != Class::AM_FM) return true; |
| 352 | |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 353 | BandConfig halConfig; |
| 354 | Result halResult = Result::NOT_INITIALIZED; |
| 355 | Return<void> hidlReturn = |
| 356 | mTuner->getConfiguration([&](Result result, const BandConfig& config) { |
| 357 | halResult = result; |
| 358 | if (result == Result::OK) { |
| 359 | halConfig = config; |
| 360 | } |
| 361 | }); |
| 362 | |
| 363 | return ((halResult == Result::OK) && (halConfig.antennaConnected == true)); |
| 364 | } |
| 365 | |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 366 | const BandConfig& BroadcastRadioHidlTest::getBand(unsigned idx) { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 367 | static BandConfig dummyBandConfig = {}; |
| 368 | if (radioClass == Class::AM_FM) { |
| 369 | EXPECT_GT(mHalProperties.bands.size(), idx); |
| 370 | if (mHalProperties.bands.size() > idx) { |
| 371 | return mHalProperties.bands[idx]; |
| 372 | } else { |
| 373 | return dummyBandConfig; |
| 374 | } |
| 375 | } else { |
| 376 | return dummyBandConfig; |
| 377 | } |
| 378 | } |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 379 | |
| 380 | /** |
| 381 | * Test IBroadcastRadio::getProperties() method |
| 382 | * |
| 383 | * Verifies that: |
| 384 | * - the HAL implements the method |
| 385 | * - the method returns 0 (no error) |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 386 | * - the implementation class is radioClass |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 387 | * - the implementation supports at least one tuner |
| 388 | * - the implementation supports at one band |
| 389 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 390 | TEST_P(BroadcastRadioHidlTest, GetProperties) { |
| 391 | RETURN_IF_SKIPPED; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 392 | EXPECT_EQ(true, getProperties()); |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Test IBroadcastRadio::openTuner() method |
| 397 | * |
| 398 | * Verifies that: |
| 399 | * - the HAL implements the method |
| 400 | * - the method returns 0 (no error) and a valid ITuner interface |
| 401 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 402 | TEST_P(BroadcastRadioHidlTest, OpenTuner) { |
| 403 | RETURN_IF_SKIPPED; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 404 | EXPECT_EQ(true, openTuner()); |
| 405 | } |
| 406 | |
| 407 | /** |
Tomasz Wasilczyk | be71e9c | 2016-12-22 11:49:17 -0800 | [diff] [blame] | 408 | * Test IBroadcastRadio::openTuner() after ITuner disposal. |
| 409 | * |
| 410 | * Verifies that: |
| 411 | * - ITuner destruction gets propagated through HAL |
| 412 | * - the openTuner method works well when called for the second time |
| 413 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 414 | TEST_P(BroadcastRadioHidlTest, ReopenTuner) { |
| 415 | RETURN_IF_SKIPPED; |
Tomasz Wasilczyk | be71e9c | 2016-12-22 11:49:17 -0800 | [diff] [blame] | 416 | EXPECT_TRUE(openTuner()); |
| 417 | mTuner.clear(); |
| 418 | EXPECT_TRUE(openTuner()); |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Test IBroadcastRadio::openTuner() method called twice. |
| 423 | * |
| 424 | * Verifies that: |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 425 | * - the openTuner method fails with INVALID_STATE or succeeds when called for the second time |
| 426 | * without deleting previous ITuner instance |
Tomasz Wasilczyk | be71e9c | 2016-12-22 11:49:17 -0800 | [diff] [blame] | 427 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 428 | TEST_P(BroadcastRadioHidlTest, OpenTunerTwice) { |
| 429 | RETURN_IF_SKIPPED; |
Tomasz Wasilczyk | be71e9c | 2016-12-22 11:49:17 -0800 | [diff] [blame] | 430 | EXPECT_TRUE(openTuner()); |
| 431 | |
| 432 | Result halResult = Result::NOT_INITIALIZED; |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 433 | auto openCb = [&](Result result, const sp<ITuner>&) { halResult = result; }; |
| 434 | auto hidlReturn = mRadio->openTuner(getBand(0), true, mTunerCallback, openCb); |
Tomasz Wasilczyk | be71e9c | 2016-12-22 11:49:17 -0800 | [diff] [blame] | 435 | EXPECT_TRUE(hidlReturn.isOk()); |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 436 | if (halResult == Result::OK) { |
| 437 | if (radioClass == Class::AM_FM) { |
| 438 | EXPECT_TRUE(waitForCallback(kConfigCallbacktimeoutNs)); |
| 439 | } |
| 440 | } else { |
| 441 | EXPECT_EQ(Result::INVALID_STATE, halResult); |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 442 | } |
Tomasz Wasilczyk | be71e9c | 2016-12-22 11:49:17 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /** |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 446 | * Test ITuner::setConfiguration() and getConfiguration methods |
| 447 | * |
| 448 | * Verifies that: |
| 449 | * - the HAL implements both methods |
| 450 | * - the methods return 0 (no error) |
| 451 | * - the configuration callback is received within kConfigCallbacktimeoutNs ns |
| 452 | * - the configuration read back from HAl has the same class Id |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 453 | * |
| 454 | * Skipped for other radio classes than AM/FM, because setConfiguration |
| 455 | * applies only for these bands. |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 456 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 457 | TEST_P(BroadcastRadioHidlTest, SetAndGetConfiguration) { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 458 | if (radioClass != Class::AM_FM) skipped = true; |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 459 | RETURN_IF_SKIPPED; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 460 | ASSERT_EQ(true, openTuner()); |
| 461 | // test setConfiguration |
| 462 | mCallbackCalled = false; |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 463 | Return<Result> hidlResult = mTuner->setConfiguration(getBand(1)); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 464 | EXPECT_TRUE(hidlResult.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 465 | EXPECT_EQ(Result::OK, hidlResult); |
| 466 | EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs)); |
| 467 | EXPECT_EQ(Result::OK, mResultCallbackData); |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 468 | EXPECT_EQ(getBand(1), mBandConfigCallbackData); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 469 | |
| 470 | // test getConfiguration |
| 471 | BandConfig halConfig; |
| 472 | Result halResult; |
| 473 | Return<void> hidlReturn = |
| 474 | mTuner->getConfiguration([&](Result result, const BandConfig& config) { |
| 475 | halResult = result; |
| 476 | if (result == Result::OK) { |
| 477 | halConfig = config; |
| 478 | } |
| 479 | }); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 480 | EXPECT_TRUE(hidlReturn.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 481 | EXPECT_EQ(Result::OK, halResult); |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 482 | EXPECT_EQ(getBand(1), halConfig); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /** |
Tomasz Wasilczyk | 10877cd | 2017-03-07 17:04:26 -0800 | [diff] [blame] | 486 | * Test ITuner::setConfiguration() with invalid arguments. |
| 487 | * |
| 488 | * Verifies that: |
| 489 | * - the methods returns INVALID_ARGUMENTS on invalid arguments |
| 490 | * - the method recovers and succeeds after passing correct arguments |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 491 | * |
| 492 | * Skipped for other radio classes than AM/FM, because setConfiguration |
| 493 | * applies only for these bands. |
Tomasz Wasilczyk | 10877cd | 2017-03-07 17:04:26 -0800 | [diff] [blame] | 494 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 495 | TEST_P(BroadcastRadioHidlTest, SetConfigurationFails) { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 496 | if (radioClass != Class::AM_FM) skipped = true; |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 497 | RETURN_IF_SKIPPED; |
Tomasz Wasilczyk | 10877cd | 2017-03-07 17:04:26 -0800 | [diff] [blame] | 498 | ASSERT_EQ(true, openTuner()); |
| 499 | |
| 500 | // Let's define a config that's bad for sure. |
| 501 | BandConfig badConfig = {}; |
| 502 | badConfig.type = Band::FM; |
| 503 | badConfig.lowerLimit = 0xFFFFFFFF; |
| 504 | badConfig.upperLimit = 0; |
| 505 | badConfig.spacings = (std::vector<uint32_t>){ 0 }; |
| 506 | |
| 507 | // Test setConfiguration failing on bad data. |
| 508 | mCallbackCalled = false; |
| 509 | auto setResult = mTuner->setConfiguration(badConfig); |
| 510 | EXPECT_TRUE(setResult.isOk()); |
| 511 | EXPECT_EQ(Result::INVALID_ARGUMENTS, setResult); |
| 512 | |
| 513 | // Test setConfiguration recovering after passing good data. |
| 514 | mCallbackCalled = false; |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 515 | setResult = mTuner->setConfiguration(getBand(0)); |
Tomasz Wasilczyk | 10877cd | 2017-03-07 17:04:26 -0800 | [diff] [blame] | 516 | EXPECT_TRUE(setResult.isOk()); |
| 517 | EXPECT_EQ(Result::OK, setResult); |
| 518 | EXPECT_EQ(true, waitForCallback(kConfigCallbacktimeoutNs)); |
| 519 | EXPECT_EQ(Result::OK, mResultCallbackData); |
| 520 | } |
| 521 | |
| 522 | /** |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 523 | * Test ITuner::scan |
| 524 | * |
| 525 | * Verifies that: |
| 526 | * - the HAL implements the method |
| 527 | * - the method returns 0 (no error) |
| 528 | * - the tuned callback is received within kTuneCallbacktimeoutNs ns |
Tomasz Wasilczyk | a8dec0f | 2017-03-14 10:20:53 -0700 | [diff] [blame] | 529 | * - skipping sub-channel or not does not fail the call |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 530 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 531 | TEST_P(BroadcastRadioHidlTest, Scan) { |
| 532 | RETURN_IF_SKIPPED; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 533 | ASSERT_EQ(true, openTuner()); |
| 534 | ASSERT_TRUE(checkAntenna()); |
| 535 | // test scan UP |
| 536 | mCallbackCalled = false; |
| 537 | Return<Result> hidlResult = mTuner->scan(Direction::UP, true); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 538 | EXPECT_TRUE(hidlResult.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 539 | EXPECT_EQ(Result::OK, hidlResult); |
| 540 | EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs)); |
| 541 | |
| 542 | // test scan DOWN |
| 543 | mCallbackCalled = false; |
Tomasz Wasilczyk | a8dec0f | 2017-03-14 10:20:53 -0700 | [diff] [blame] | 544 | hidlResult = mTuner->scan(Direction::DOWN, false); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 545 | EXPECT_TRUE(hidlResult.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 546 | EXPECT_EQ(Result::OK, hidlResult); |
| 547 | EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs)); |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Test ITuner::step |
| 552 | * |
| 553 | * Verifies that: |
| 554 | * - the HAL implements the method |
| 555 | * - the method returns 0 (no error) |
| 556 | * - the tuned callback is received within kTuneCallbacktimeoutNs ns |
Tomasz Wasilczyk | a8dec0f | 2017-03-14 10:20:53 -0700 | [diff] [blame] | 557 | * - skipping sub-channel or not does not fail the call |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 558 | * |
| 559 | * Skipped for other radio classes than AM/FM, because step is not possible |
| 560 | * on DAB nor satellite. |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 561 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 562 | TEST_P(BroadcastRadioHidlTest, Step) { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 563 | if (radioClass != Class::AM_FM) skipped = true; |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 564 | RETURN_IF_SKIPPED; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 565 | ASSERT_EQ(true, openTuner()); |
| 566 | ASSERT_TRUE(checkAntenna()); |
| 567 | // test step UP |
| 568 | mCallbackCalled = false; |
Tomasz Wasilczyk | a8dec0f | 2017-03-14 10:20:53 -0700 | [diff] [blame] | 569 | Return<Result> hidlResult = mTuner->step(Direction::UP, false); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 570 | EXPECT_TRUE(hidlResult.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 571 | EXPECT_EQ(Result::OK, hidlResult); |
| 572 | EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs)); |
| 573 | |
| 574 | // test step DOWN |
| 575 | mCallbackCalled = false; |
| 576 | hidlResult = mTuner->step(Direction::DOWN, true); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 577 | EXPECT_TRUE(hidlResult.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 578 | EXPECT_EQ(Result::OK, hidlResult); |
| 579 | EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs)); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Test ITuner::tune, getProgramInformation and cancel methods |
| 584 | * |
| 585 | * Verifies that: |
| 586 | * - the HAL implements the methods |
| 587 | * - the methods return 0 (no error) |
| 588 | * - the tuned callback is received within kTuneCallbacktimeoutNs ns after tune() |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 589 | * |
| 590 | * Skipped for other radio classes than AM/FM, because tune to frequency |
| 591 | * is not possible on DAB nor satellite. |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 592 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 593 | TEST_P(BroadcastRadioHidlTest, TuneAndGetProgramInformationAndCancel) { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 594 | if (radioClass != Class::AM_FM) skipped = true; |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 595 | RETURN_IF_SKIPPED; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 596 | ASSERT_EQ(true, openTuner()); |
| 597 | ASSERT_TRUE(checkAntenna()); |
| 598 | |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 599 | auto& band = getBand(0); |
| 600 | |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 601 | // test tune |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 602 | ASSERT_GT(band.spacings.size(), 0u); |
| 603 | ASSERT_GT(band.upperLimit, band.lowerLimit); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 604 | |
| 605 | // test scan UP |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 606 | uint32_t lowerLimit = band.lowerLimit; |
| 607 | uint32_t upperLimit = band.upperLimit; |
| 608 | uint32_t spacing = band.spacings[0]; |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 609 | |
| 610 | uint32_t channel = |
| 611 | lowerLimit + (((upperLimit - lowerLimit) / 2 + spacing - 1) / spacing) * spacing; |
| 612 | mCallbackCalled = false; |
| 613 | mResultCallbackData = Result::NOT_INITIALIZED; |
| 614 | Return<Result> hidlResult = mTuner->tune(channel, 0); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 615 | EXPECT_TRUE(hidlResult.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 616 | EXPECT_EQ(Result::OK, hidlResult); |
| 617 | EXPECT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs)); |
Tomasz Wasilczyk | f3c036d | 2017-03-03 15:07:50 -0800 | [diff] [blame] | 618 | EXPECT_EQ(channel, mProgramInfoCallbackData.channel); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 619 | |
| 620 | // test getProgramInformation |
| 621 | ProgramInfo halInfo; |
| 622 | Result halResult = Result::NOT_INITIALIZED; |
| 623 | Return<void> hidlReturn = mTuner->getProgramInformation( |
Tomasz Wasilczyk | 5cc9d86 | 2017-01-06 14:19:11 -0800 | [diff] [blame] | 624 | [&](Result result, const ProgramInfo& info) { |
| 625 | halResult = result; |
| 626 | if (result == Result::OK) { |
| 627 | halInfo = info; |
| 628 | } |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 629 | }); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 630 | EXPECT_TRUE(hidlReturn.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 631 | EXPECT_EQ(Result::OK, halResult); |
| 632 | if (mResultCallbackData == Result::OK) { |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 633 | EXPECT_LE(halInfo.channel, upperLimit); |
| 634 | EXPECT_GE(halInfo.channel, lowerLimit); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | // test cancel |
| 638 | mTuner->tune(lowerLimit, 0); |
| 639 | hidlResult = mTuner->cancel(); |
Steven Moreland | b643842 | 2017-01-03 17:06:57 -0800 | [diff] [blame] | 640 | EXPECT_TRUE(hidlResult.isOk()); |
Eric Laurent | 566fcda | 2016-11-23 10:36:36 -0800 | [diff] [blame] | 641 | EXPECT_EQ(Result::OK, hidlResult); |
| 642 | } |
| 643 | |
Tomasz Wasilczyk | 59d985d | 2017-03-03 13:02:15 -0800 | [diff] [blame] | 644 | /** |
| 645 | * Test ITuner::tune failing when channel out of the range is provided. |
| 646 | * |
| 647 | * Verifies that: |
| 648 | * - the method returns INVALID_ARGUMENTS when applicable |
| 649 | * - the method recovers and succeeds after passing correct arguments |
Tomasz Wasilczyk | 394b343 | 2017-08-07 18:00:28 -0700 | [diff] [blame] | 650 | * |
| 651 | * Skipped for other radio classes than AM/FM, because tune to frequency |
| 652 | * is not possible on DAB nor satellite. |
Tomasz Wasilczyk | 59d985d | 2017-03-03 13:02:15 -0800 | [diff] [blame] | 653 | */ |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 654 | TEST_P(BroadcastRadioHidlTest, TuneFailsOutOfBounds) { |
Tomasz Wasilczyk | da72d37 | 2017-06-26 16:08:51 -0700 | [diff] [blame] | 655 | if (radioClass != Class::AM_FM) skipped = true; |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 656 | RETURN_IF_SKIPPED; |
Tomasz Wasilczyk | 59d985d | 2017-03-03 13:02:15 -0800 | [diff] [blame] | 657 | ASSERT_TRUE(openTuner()); |
| 658 | ASSERT_TRUE(checkAntenna()); |
| 659 | |
| 660 | // get current channel bounds |
| 661 | BandConfig halConfig; |
| 662 | Result halResult; |
| 663 | auto configResult = mTuner->getConfiguration([&](Result result, const BandConfig& config) { |
| 664 | halResult = result; |
| 665 | halConfig = config; |
| 666 | }); |
| 667 | ASSERT_TRUE(configResult.isOk()); |
| 668 | ASSERT_EQ(Result::OK, halResult); |
| 669 | |
| 670 | // try to tune slightly above the limit and expect to fail |
| 671 | auto badChannel = halConfig.upperLimit + halConfig.spacings[0]; |
| 672 | auto tuneResult = mTuner->tune(badChannel, 0); |
| 673 | EXPECT_TRUE(tuneResult.isOk()); |
| 674 | EXPECT_EQ(Result::INVALID_ARGUMENTS, tuneResult); |
| 675 | EXPECT_TRUE(waitForCallback(kTuneCallbacktimeoutNs)); |
| 676 | |
| 677 | // tuning exactly at the limit should succeed |
| 678 | auto goodChannel = halConfig.upperLimit; |
| 679 | tuneResult = mTuner->tune(goodChannel, 0); |
| 680 | EXPECT_TRUE(tuneResult.isOk()); |
| 681 | EXPECT_EQ(Result::OK, tuneResult); |
| 682 | EXPECT_TRUE(waitForCallback(kTuneCallbacktimeoutNs)); |
| 683 | } |
| 684 | |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 685 | /** |
| 686 | * Test proper image format in metadata. |
| 687 | * |
| 688 | * Verifies that: |
| 689 | * - all images in metadata are provided in-band (as a binary blob, not by id) |
| 690 | * |
| 691 | * This is a counter-test for OobImagesOnly from 1.1 VTS. |
| 692 | */ |
| 693 | TEST_P(BroadcastRadioHidlTest, IbImagesOnly) { |
| 694 | RETURN_IF_SKIPPED; |
| 695 | ASSERT_TRUE(openTuner()); |
| 696 | ASSERT_TRUE(checkAntenna()); |
| 697 | |
| 698 | bool firstScan = true; |
| 699 | uint32_t firstChannel, prevChannel; |
| 700 | while (true) { |
| 701 | mCallbackCalled = false; |
| 702 | auto hidlResult = mTuner->scan(Direction::UP, true); |
| 703 | ASSERT_TRUE(hidlResult.isOk()); |
| 704 | if (hidlResult == Result::TIMEOUT) { |
| 705 | ALOGI("Got timeout on scan operation"); |
| 706 | break; |
| 707 | } |
| 708 | ASSERT_EQ(Result::OK, hidlResult); |
| 709 | ASSERT_EQ(true, waitForCallback(kTuneCallbacktimeoutNs)); |
| 710 | |
| 711 | if (firstScan) { |
| 712 | firstScan = false; |
| 713 | firstChannel = mProgramInfoCallbackData.channel; |
| 714 | } else { |
| 715 | // scanned the whole band |
| 716 | if (mProgramInfoCallbackData.channel >= firstChannel && prevChannel <= firstChannel) { |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | prevChannel = mProgramInfoCallbackData.channel; |
| 721 | |
| 722 | for (auto&& entry : mProgramInfoCallbackData.metadata) { |
| 723 | if (entry.key != MetadataKey::ICON && entry.key != MetadataKey::ART) continue; |
| 724 | EXPECT_EQ(MetadataType::RAW, entry.type); |
| 725 | EXPECT_EQ(0, entry.intValue); |
| 726 | EXPECT_GT(entry.rawValue.size(), 0u); |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
Tomasz Wasilczyk | 2f46101 | 2017-03-14 11:19:15 -0700 | [diff] [blame] | 731 | INSTANTIATE_TEST_CASE_P( |
Dan Shi | 170a445 | 2020-04-04 00:59:41 -0700 | [diff] [blame] | 732 | PerInstance, BroadcastRadioHidlTest, |
| 733 | testing::Combine(testing::ValuesIn(android::hardware::getAllHalInstanceNames( |
| 734 | IBroadcastRadioFactory::descriptor)), |
| 735 | ::testing::Values("AM_FM", "SAT", "DT")), |
| 736 | android::hardware::PrintInstanceTupleNameToString<>); |