Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 17 | #define LOG_TAG "broadcastradio.vts" |
| 18 | |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 19 | #include <VtsHalHidlTargetTestBase.h> |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 20 | #include <android/hardware/broadcastradio/1.1/IBroadcastRadio.h> |
| 21 | #include <android/hardware/broadcastradio/1.1/IBroadcastRadioFactory.h> |
| 22 | #include <android/hardware/broadcastradio/1.1/ITuner.h> |
| 23 | #include <android/hardware/broadcastradio/1.1/ITunerCallback.h> |
| 24 | #include <android/hardware/broadcastradio/1.1/types.h> |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 25 | #include <android-base/logging.h> |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 26 | #include <broadcastradio-utils/Utils.h> |
| 27 | #include <broadcastradio-vts-utils/call-barrier.h> |
| 28 | #include <broadcastradio-vts-utils/mock-timeout.h> |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 29 | #include <cutils/native_handle.h> |
| 30 | #include <cutils/properties.h> |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 31 | #include <gmock/gmock.h> |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 32 | #include <hidl/HidlTransportSupport.h> |
| 33 | #include <utils/threads.h> |
| 34 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 35 | #include <chrono> |
| 36 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 37 | namespace android { |
| 38 | namespace hardware { |
| 39 | namespace broadcastradio { |
| 40 | namespace V1_1 { |
| 41 | namespace vts { |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 42 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 43 | using namespace std::chrono_literals; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 44 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 45 | using testing::_; |
| 46 | using testing::AnyNumber; |
| 47 | using testing::ByMove; |
| 48 | using testing::DoAll; |
Tomasz Wasilczyk | 2418009 | 2017-07-14 10:44:52 -0700 | [diff] [blame] | 49 | using testing::Invoke; |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 50 | using testing::SaveArg; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 51 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 52 | using broadcastradio::vts::CallBarrier; |
| 53 | using V1_0::BandConfig; |
| 54 | using V1_0::Class; |
| 55 | using V1_0::MetaData; |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 56 | using V1_0::MetadataKey; |
| 57 | using V1_0::MetadataType; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 58 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 59 | using std::chrono::steady_clock; |
| 60 | using std::this_thread::sleep_for; |
| 61 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 62 | static constexpr auto kConfigTimeout = 10s; |
| 63 | static constexpr auto kConnectModuleTimeout = 1s; |
| 64 | static constexpr auto kTuneTimeout = 30s; |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 65 | static constexpr auto kEventPropagationTimeout = 1s; |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 66 | static constexpr auto kFullScanTimeout = 1min; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 67 | |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 68 | static constexpr ProgramType kStandardProgramTypes[] = { |
| 69 | ProgramType::AM, ProgramType::FM, ProgramType::AM_HD, ProgramType::FM_HD, |
| 70 | ProgramType::DAB, ProgramType::DRMO, ProgramType::SXM}; |
| 71 | |
| 72 | static constexpr IdentifierType kVendorPrimartIds[] = { |
| 73 | IdentifierType::VENDOR1_PRIMARY, IdentifierType::VENDOR2_PRIMARY, |
| 74 | IdentifierType::VENDOR3_PRIMARY, IdentifierType::VENDOR4_PRIMARY}; |
| 75 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 76 | static void printSkipped(std::string msg) { |
| 77 | std::cout << "[ SKIPPED ] " << msg << std::endl; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Tomasz Wasilczyk | 2418009 | 2017-07-14 10:44:52 -0700 | [diff] [blame] | 80 | struct TunerCallbackMock : public ITunerCallback { |
| 81 | TunerCallbackMock() { EXPECT_CALL(*this, hardwareFailure()).Times(0); } |
| 82 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 83 | MOCK_METHOD0(hardwareFailure, Return<void>()); |
| 84 | MOCK_TIMEOUT_METHOD2(configChange, Return<void>(Result, const BandConfig&)); |
| 85 | MOCK_METHOD2(tuneComplete, Return<void>(Result, const V1_0::ProgramInfo&)); |
Tomasz Wasilczyk | f8866e7 | 2017-07-13 15:51:21 -0700 | [diff] [blame] | 86 | MOCK_TIMEOUT_METHOD2(tuneComplete_1_1, Return<void>(Result, const ProgramSelector&)); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 87 | MOCK_METHOD1(afSwitch, Return<void>(const V1_0::ProgramInfo&)); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 88 | MOCK_METHOD1(antennaStateChange, Return<void>(bool connected)); |
| 89 | MOCK_METHOD1(trafficAnnouncement, Return<void>(bool active)); |
| 90 | MOCK_METHOD1(emergencyAnnouncement, Return<void>(bool active)); |
| 91 | MOCK_METHOD3(newMetadata, Return<void>(uint32_t ch, uint32_t subCh, const hidl_vec<MetaData>&)); |
| 92 | MOCK_METHOD1(backgroundScanAvailable, Return<void>(bool)); |
| 93 | MOCK_TIMEOUT_METHOD1(backgroundScanComplete, Return<void>(ProgramListResult)); |
| 94 | MOCK_METHOD0(programListChanged, Return<void>()); |
Tomasz Wasilczyk | dd13066 | 2017-08-03 18:08:57 -0700 | [diff] [blame] | 95 | MOCK_TIMEOUT_METHOD1(currentProgramInfoChanged, Return<void>(const ProgramInfo&)); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | class BroadcastRadioHalTest : public ::testing::VtsHalHidlTargetTestBase, |
| 99 | public ::testing::WithParamInterface<Class> { |
| 100 | protected: |
| 101 | virtual void SetUp() override; |
| 102 | virtual void TearDown() override; |
| 103 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 104 | bool openTuner(); |
| 105 | bool nextBand(); |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 106 | bool getProgramList(std::function<void(const hidl_vec<ProgramInfo>& list)> cb); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 107 | |
| 108 | Class radioClass; |
| 109 | bool skipped = false; |
| 110 | |
| 111 | sp<IBroadcastRadio> mRadioModule; |
| 112 | sp<ITuner> mTuner; |
| 113 | sp<TunerCallbackMock> mCallback = new TunerCallbackMock(); |
| 114 | |
| 115 | private: |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 116 | const BandConfig& getBand(unsigned idx); |
| 117 | |
| 118 | unsigned currentBandIndex = 0; |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 119 | hidl_vec<BandConfig> mBands; |
| 120 | }; |
| 121 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Clears strong pointer and waits until the object gets destroyed. |
| 124 | * |
| 125 | * @param ptr The pointer to get cleared. |
| 126 | * @param timeout Time to wait for other references. |
| 127 | */ |
| 128 | template <typename T> |
| 129 | static void clearAndWait(sp<T>& ptr, std::chrono::milliseconds timeout) { |
| 130 | wp<T> wptr = ptr; |
| 131 | ptr.clear(); |
| 132 | auto limit = steady_clock::now() + timeout; |
| 133 | while (wptr.promote() != nullptr) { |
| 134 | constexpr auto step = 10ms; |
| 135 | if (steady_clock::now() + step > limit) { |
| 136 | FAIL() << "Pointer was not released within timeout"; |
| 137 | break; |
| 138 | } |
| 139 | sleep_for(step); |
| 140 | } |
| 141 | } |
| 142 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 143 | void BroadcastRadioHalTest::SetUp() { |
| 144 | radioClass = GetParam(); |
| 145 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 146 | // lookup HIDL service |
| 147 | auto factory = getService<IBroadcastRadioFactory>(); |
| 148 | ASSERT_NE(nullptr, factory.get()); |
| 149 | |
| 150 | // connect radio module |
| 151 | Result connectResult; |
| 152 | CallBarrier onConnect; |
| 153 | factory->connectModule(radioClass, [&](Result ret, const sp<V1_0::IBroadcastRadio>& radio) { |
| 154 | connectResult = ret; |
| 155 | if (ret == Result::OK) mRadioModule = IBroadcastRadio::castFrom(radio); |
| 156 | onConnect.call(); |
| 157 | }); |
| 158 | ASSERT_TRUE(onConnect.waitForCall(kConnectModuleTimeout)); |
| 159 | |
| 160 | if (connectResult == Result::INVALID_ARGUMENTS) { |
| 161 | printSkipped("This device class is not supported."); |
| 162 | skipped = true; |
| 163 | return; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 164 | } |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 165 | ASSERT_EQ(connectResult, Result::OK); |
| 166 | ASSERT_NE(nullptr, mRadioModule.get()); |
| 167 | |
| 168 | // get module properties |
| 169 | Properties prop11; |
| 170 | auto& prop10 = prop11.base; |
| 171 | auto propResult = |
| 172 | mRadioModule->getProperties_1_1([&](const Properties& properties) { prop11 = properties; }); |
| 173 | |
| 174 | ASSERT_TRUE(propResult.isOk()); |
| 175 | EXPECT_EQ(radioClass, prop10.classId); |
| 176 | EXPECT_GT(prop10.numTuners, 0u); |
Tomasz Wasilczyk | e192c39 | 2017-07-16 15:14:34 -0700 | [diff] [blame] | 177 | EXPECT_GT(prop11.supportedProgramTypes.size(), 0u); |
| 178 | EXPECT_GT(prop11.supportedIdentifierTypes.size(), 0u); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 179 | if (radioClass == Class::AM_FM) { |
| 180 | EXPECT_GT(prop10.bands.size(), 0u); |
| 181 | } |
| 182 | mBands = prop10.bands; |
| 183 | } |
| 184 | |
| 185 | void BroadcastRadioHalTest::TearDown() { |
| 186 | mTuner.clear(); |
| 187 | mRadioModule.clear(); |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 188 | clearAndWait(mCallback, 1s); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 191 | bool BroadcastRadioHalTest::openTuner() { |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 192 | EXPECT_EQ(nullptr, mTuner.get()); |
| 193 | |
| 194 | if (radioClass == Class::AM_FM) { |
| 195 | EXPECT_TIMEOUT_CALL(*mCallback, configChange, Result::OK, _); |
| 196 | } |
| 197 | |
| 198 | Result halResult = Result::NOT_INITIALIZED; |
| 199 | auto openCb = [&](Result result, const sp<V1_0::ITuner>& tuner) { |
| 200 | halResult = result; |
| 201 | if (result != Result::OK) return; |
| 202 | mTuner = ITuner::castFrom(tuner); |
| 203 | }; |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 204 | currentBandIndex = 0; |
| 205 | auto hidlResult = mRadioModule->openTuner(getBand(0), true, mCallback, openCb); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 206 | |
| 207 | EXPECT_TRUE(hidlResult.isOk()); |
| 208 | EXPECT_EQ(Result::OK, halResult); |
| 209 | EXPECT_NE(nullptr, mTuner.get()); |
| 210 | if (radioClass == Class::AM_FM && mTuner != nullptr) { |
| 211 | EXPECT_TIMEOUT_CALL_WAIT(*mCallback, configChange, kConfigTimeout); |
| 212 | |
| 213 | BandConfig halConfig; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 214 | Result halResult = Result::NOT_INITIALIZED; |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 215 | mTuner->getConfiguration([&](Result result, const BandConfig& config) { |
| 216 | halResult = result; |
| 217 | halConfig = config; |
| 218 | }); |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 219 | EXPECT_EQ(Result::OK, halResult); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 220 | EXPECT_TRUE(halConfig.antennaConnected); |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 221 | } |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 222 | |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 223 | EXPECT_NE(nullptr, mTuner.get()); |
| 224 | return nullptr != mTuner.get(); |
| 225 | } |
| 226 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 227 | const BandConfig& BroadcastRadioHalTest::getBand(unsigned idx) { |
| 228 | static const BandConfig dummyBandConfig = {}; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 229 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 230 | if (radioClass != Class::AM_FM) { |
| 231 | ALOGD("Not AM/FM radio, returning dummy band config"); |
| 232 | return dummyBandConfig; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 235 | EXPECT_GT(mBands.size(), idx); |
| 236 | if (mBands.size() <= idx) { |
| 237 | ALOGD("Band index out of bound, returning dummy band config"); |
| 238 | return dummyBandConfig; |
| 239 | } |
| 240 | |
| 241 | auto& band = mBands[idx]; |
| 242 | ALOGD("Returning %s band", toString(band.type).c_str()); |
| 243 | return band; |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 246 | bool BroadcastRadioHalTest::nextBand() { |
| 247 | if (currentBandIndex + 1 >= mBands.size()) return false; |
| 248 | currentBandIndex++; |
| 249 | |
| 250 | BandConfig bandCb; |
| 251 | EXPECT_TIMEOUT_CALL(*mCallback, configChange, Result::OK, _) |
| 252 | .WillOnce(DoAll(SaveArg<1>(&bandCb), testing::Return(ByMove(Void())))); |
| 253 | auto hidlResult = mTuner->setConfiguration(getBand(currentBandIndex)); |
| 254 | EXPECT_EQ(Result::OK, hidlResult); |
| 255 | EXPECT_TIMEOUT_CALL_WAIT(*mCallback, configChange, kConfigTimeout); |
| 256 | EXPECT_EQ(getBand(currentBandIndex), bandCb); |
| 257 | |
| 258 | return true; |
| 259 | } |
| 260 | |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 261 | bool BroadcastRadioHalTest::getProgramList( |
| 262 | std::function<void(const hidl_vec<ProgramInfo>& list)> cb) { |
| 263 | ProgramListResult getListResult = ProgramListResult::NOT_INITIALIZED; |
| 264 | bool isListEmpty = true; |
| 265 | auto getListCb = [&](ProgramListResult result, const hidl_vec<ProgramInfo>& list) { |
| 266 | ALOGD("getListCb(%s, ProgramInfo[%zu])", toString(result).c_str(), list.size()); |
| 267 | getListResult = result; |
| 268 | if (result != ProgramListResult::OK) return; |
| 269 | isListEmpty = (list.size() == 0); |
| 270 | if (!isListEmpty) cb(list); |
| 271 | }; |
| 272 | |
| 273 | // first try... |
| 274 | EXPECT_TIMEOUT_CALL(*mCallback, backgroundScanComplete, ProgramListResult::OK) |
| 275 | .Times(AnyNumber()); |
Tomasz Wasilczyk | fa3a559 | 2017-08-03 11:06:09 -0700 | [diff] [blame] | 276 | auto hidlResult = mTuner->getProgramList({}, getListCb); |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 277 | EXPECT_TRUE(hidlResult.isOk()); |
| 278 | if (!hidlResult.isOk()) return false; |
| 279 | |
| 280 | if (getListResult == ProgramListResult::NOT_STARTED) { |
| 281 | auto result = mTuner->startBackgroundScan(); |
| 282 | EXPECT_EQ(ProgramListResult::OK, result); |
| 283 | getListResult = ProgramListResult::NOT_READY; // continue as in NOT_READY case |
| 284 | } |
| 285 | if (getListResult == ProgramListResult::NOT_READY) { |
| 286 | EXPECT_TIMEOUT_CALL_WAIT(*mCallback, backgroundScanComplete, kFullScanTimeout); |
| 287 | |
| 288 | // second (last) try... |
Tomasz Wasilczyk | fa3a559 | 2017-08-03 11:06:09 -0700 | [diff] [blame] | 289 | hidlResult = mTuner->getProgramList({}, getListCb); |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 290 | EXPECT_TRUE(hidlResult.isOk()); |
| 291 | if (!hidlResult.isOk()) return false; |
| 292 | EXPECT_EQ(ProgramListResult::OK, getListResult); |
| 293 | } |
| 294 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 295 | return !isListEmpty; |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 298 | /** |
| 299 | * Test IBroadcastRadio::openTuner() method called twice. |
| 300 | * |
| 301 | * Verifies that: |
| 302 | * - the openTuner method succeeds when called for the second time without |
| 303 | * deleting previous ITuner instance. |
| 304 | * |
| 305 | * This is a more strict requirement than in 1.0, where a second openTuner |
| 306 | * might fail. |
| 307 | */ |
| 308 | TEST_P(BroadcastRadioHalTest, OpenTunerTwice) { |
| 309 | if (skipped) return; |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 310 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 311 | ASSERT_TRUE(openTuner()); |
| 312 | |
| 313 | auto secondTuner = mTuner; |
| 314 | mTuner.clear(); |
| 315 | |
| 316 | ASSERT_TRUE(openTuner()); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Test tuning to program list entry. |
| 321 | * |
| 322 | * Verifies that: |
| 323 | * - getProgramList either succeeds or returns NOT_STARTED/NOT_READY status; |
| 324 | * - if the program list is NOT_STARTED, startBackgroundScan makes it completed |
| 325 | * within a full scan timeout and the next getProgramList call succeeds; |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 326 | * - if the program list is not empty, tuneByProgramSelector call succeeds; |
| 327 | * - getProgramInformation_1_1 returns the same selector as returned in tuneComplete_1_1 call. |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 328 | */ |
| 329 | TEST_P(BroadcastRadioHalTest, TuneFromProgramList) { |
| 330 | if (skipped) return; |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 331 | ASSERT_TRUE(openTuner()); |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 332 | |
| 333 | ProgramInfo firstProgram; |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 334 | bool foundAny = false; |
| 335 | do { |
| 336 | auto getCb = [&](const hidl_vec<ProgramInfo>& list) { |
| 337 | // don't copy the whole list out, it might be heavy |
| 338 | firstProgram = list[0]; |
| 339 | }; |
| 340 | if (getProgramList(getCb)) foundAny = true; |
| 341 | } while (nextBand()); |
| 342 | if (HasFailure()) return; |
| 343 | if (!foundAny) { |
| 344 | printSkipped("Program list is empty."); |
| 345 | return; |
| 346 | } |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 347 | |
Tomasz Wasilczyk | dd13066 | 2017-08-03 18:08:57 -0700 | [diff] [blame] | 348 | ProgramInfo infoCb; |
Tomasz Wasilczyk | f8866e7 | 2017-07-13 15:51:21 -0700 | [diff] [blame] | 349 | ProgramSelector selCb; |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 350 | EXPECT_CALL(*mCallback, tuneComplete(_, _)).Times(0); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 351 | EXPECT_TIMEOUT_CALL(*mCallback, tuneComplete_1_1, Result::OK, _) |
Tomasz Wasilczyk | f8866e7 | 2017-07-13 15:51:21 -0700 | [diff] [blame] | 352 | .WillOnce(DoAll(SaveArg<1>(&selCb), testing::Return(ByMove(Void())))); |
Tomasz Wasilczyk | dd13066 | 2017-08-03 18:08:57 -0700 | [diff] [blame] | 353 | EXPECT_TIMEOUT_CALL(*mCallback, currentProgramInfoChanged, _) |
| 354 | .WillOnce(DoAll(SaveArg<0>(&infoCb), testing::Return(ByMove(Void())))); |
Tomasz Wasilczyk | b8a2afe | 2017-08-01 10:52:18 -0700 | [diff] [blame] | 355 | auto tuneResult = mTuner->tuneByProgramSelector(firstProgram.selector); |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 356 | ASSERT_EQ(Result::OK, tuneResult); |
| 357 | EXPECT_TIMEOUT_CALL_WAIT(*mCallback, tuneComplete_1_1, kTuneTimeout); |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 358 | EXPECT_TIMEOUT_CALL_WAIT(*mCallback, currentProgramInfoChanged, kEventPropagationTimeout); |
Tomasz Wasilczyk | f8866e7 | 2017-07-13 15:51:21 -0700 | [diff] [blame] | 359 | EXPECT_EQ(firstProgram.selector.primaryId, selCb.primaryId); |
Tomasz Wasilczyk | dd13066 | 2017-08-03 18:08:57 -0700 | [diff] [blame] | 360 | EXPECT_EQ(infoCb.selector, selCb); |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 361 | |
| 362 | bool called = false; |
| 363 | auto getResult = mTuner->getProgramInformation_1_1([&](Result result, ProgramInfo info) { |
| 364 | called = true; |
| 365 | EXPECT_EQ(Result::OK, result); |
| 366 | EXPECT_EQ(selCb, info.selector); |
| 367 | }); |
| 368 | ASSERT_TRUE(getResult.isOk()); |
| 369 | ASSERT_TRUE(called); |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 370 | } |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 371 | |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 372 | /** |
| 373 | * Test that primary vendor identifier isn't used for standard program types. |
| 374 | * |
| 375 | * Verifies that: |
| 376 | * - tuneByProgramSelector fails when VENDORn_PRIMARY is set as a primary |
| 377 | * identifier for program types other than VENDORn. |
| 378 | */ |
| 379 | TEST_P(BroadcastRadioHalTest, TuneFailsForPrimaryVendor) { |
| 380 | if (skipped) return; |
| 381 | ASSERT_TRUE(openTuner()); |
| 382 | |
| 383 | for (auto ptype : kStandardProgramTypes) { |
| 384 | ALOGD("Checking %s...", toString(ptype).c_str()); |
| 385 | for (auto idtype : kVendorPrimartIds) { |
| 386 | ALOGD("...with %s", toString(idtype).c_str()); |
| 387 | ProgramSelector sel = {}; |
| 388 | sel.programType = static_cast<uint32_t>(ptype); |
| 389 | sel.primaryId.type = static_cast<uint32_t>(idtype); |
| 390 | |
| 391 | auto tuneResult = mTuner->tuneByProgramSelector(sel); |
| 392 | ASSERT_NE(Result::OK, tuneResult); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Test that tune with unknown program type fails. |
| 399 | * |
| 400 | * Verifies that: |
| 401 | * - tuneByProgramSelector fails with INVALID_ARGUMENT when unknown program type is passed. |
| 402 | */ |
| 403 | TEST_P(BroadcastRadioHalTest, TuneFailsForUnknownProgram) { |
| 404 | if (skipped) return; |
| 405 | ASSERT_TRUE(openTuner()); |
| 406 | |
| 407 | // Program type is 1-based, so 0 will be always invalid. |
| 408 | ProgramSelector sel = {}; |
| 409 | auto tuneResult = mTuner->tuneByProgramSelector(sel); |
| 410 | ASSERT_EQ(Result::INVALID_ARGUMENTS, tuneResult); |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Test cancelling announcement. |
| 415 | * |
| 416 | * Verifies that: |
| 417 | * - cancelAnnouncement succeeds either when there is an announcement or there is none. |
| 418 | */ |
Tomasz Wasilczyk | 2418009 | 2017-07-14 10:44:52 -0700 | [diff] [blame] | 419 | TEST_P(BroadcastRadioHalTest, CancelAnnouncement) { |
| 420 | if (skipped) return; |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 421 | ASSERT_TRUE(openTuner()); |
Tomasz Wasilczyk | 2418009 | 2017-07-14 10:44:52 -0700 | [diff] [blame] | 422 | |
| 423 | auto hidlResult = mTuner->cancelAnnouncement(); |
| 424 | EXPECT_EQ(Result::OK, hidlResult); |
| 425 | } |
| 426 | |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 427 | /** |
| 428 | * Test getImage call with invalid image ID. |
| 429 | * |
| 430 | * Verifies that: |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 431 | * - getImage call handles argument 0 gracefully. |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 432 | */ |
| 433 | TEST_P(BroadcastRadioHalTest, GetNoImage) { |
| 434 | if (skipped) return; |
| 435 | |
| 436 | size_t len = 0; |
| 437 | auto hidlResult = |
| 438 | mRadioModule->getImage(0, [&](hidl_vec<uint8_t> rawImage) { len = rawImage.size(); }); |
| 439 | |
| 440 | ASSERT_TRUE(hidlResult.isOk()); |
| 441 | ASSERT_EQ(0u, len); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Test proper image format in metadata. |
| 446 | * |
| 447 | * Verifies that: |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 448 | * - all images in metadata are provided out-of-band (by id, not as a binary blob); |
| 449 | * - images are available for getImage call. |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 450 | */ |
| 451 | TEST_P(BroadcastRadioHalTest, OobImagesOnly) { |
| 452 | if (skipped) return; |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 453 | ASSERT_TRUE(openTuner()); |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 454 | |
| 455 | std::vector<int> imageIds; |
| 456 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 457 | do { |
| 458 | auto getCb = [&](const hidl_vec<ProgramInfo>& list) { |
| 459 | for (auto&& program : list) { |
| 460 | for (auto&& entry : program.base.metadata) { |
| 461 | EXPECT_NE(MetadataType::RAW, entry.type); |
| 462 | if (entry.key != MetadataKey::ICON && entry.key != MetadataKey::ART) continue; |
| 463 | EXPECT_NE(0, entry.intValue); |
| 464 | EXPECT_EQ(0u, entry.rawValue.size()); |
| 465 | if (entry.intValue != 0) imageIds.push_back(entry.intValue); |
| 466 | } |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 467 | } |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 468 | }; |
| 469 | getProgramList(getCb); |
| 470 | } while (nextBand()); |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 471 | |
| 472 | if (imageIds.size() == 0) { |
| 473 | printSkipped("No images found"); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | for (auto id : imageIds) { |
| 478 | ALOGD("Checking image %d", id); |
| 479 | |
| 480 | size_t len = 0; |
| 481 | auto hidlResult = |
| 482 | mRadioModule->getImage(id, [&](hidl_vec<uint8_t> rawImage) { len = rawImage.size(); }); |
| 483 | |
| 484 | ASSERT_TRUE(hidlResult.isOk()); |
| 485 | ASSERT_GT(len, 0u); |
| 486 | } |
| 487 | } |
| 488 | |
Tomasz Wasilczyk | 6e93c9c | 2017-07-25 10:53:50 -0700 | [diff] [blame] | 489 | /** |
| 490 | * Test AnalogForced switch. |
| 491 | * |
| 492 | * Verifies that: |
Tomasz Wasilczyk | dd58770 | 2017-07-31 14:28:04 -0700 | [diff] [blame] | 493 | * - setAnalogForced results either with INVALID_STATE, or isAnalogForced replying the same. |
Tomasz Wasilczyk | 6e93c9c | 2017-07-25 10:53:50 -0700 | [diff] [blame] | 494 | */ |
| 495 | TEST_P(BroadcastRadioHalTest, AnalogForcedSwitch) { |
| 496 | if (skipped) return; |
| 497 | ASSERT_TRUE(openTuner()); |
| 498 | |
| 499 | bool forced; |
| 500 | Result halIsResult; |
| 501 | auto isCb = [&](Result result, bool isForced) { |
| 502 | halIsResult = result; |
| 503 | forced = isForced; |
| 504 | }; |
| 505 | |
| 506 | // set analog mode |
| 507 | auto setResult = mTuner->setAnalogForced(true); |
| 508 | ASSERT_TRUE(setResult.isOk()); |
| 509 | if (Result::INVALID_STATE == setResult) { |
| 510 | // if setter fails, getter should fail too - it means the switch is not supported at all |
| 511 | auto isResult = mTuner->isAnalogForced(isCb); |
| 512 | ASSERT_TRUE(isResult.isOk()); |
| 513 | EXPECT_EQ(Result::INVALID_STATE, halIsResult); |
| 514 | return; |
| 515 | } |
| 516 | ASSERT_EQ(Result::OK, setResult); |
| 517 | |
| 518 | // check, if it's analog |
| 519 | auto isResult = mTuner->isAnalogForced(isCb); |
| 520 | ASSERT_TRUE(isResult.isOk()); |
| 521 | EXPECT_EQ(Result::OK, halIsResult); |
| 522 | ASSERT_TRUE(forced); |
| 523 | |
| 524 | // set digital mode |
| 525 | setResult = mTuner->setAnalogForced(false); |
| 526 | ASSERT_EQ(Result::OK, setResult); |
| 527 | |
| 528 | // check, if it's digital |
| 529 | isResult = mTuner->isAnalogForced(isCb); |
| 530 | ASSERT_TRUE(isResult.isOk()); |
| 531 | EXPECT_EQ(Result::OK, halIsResult); |
| 532 | ASSERT_FALSE(forced); |
| 533 | } |
| 534 | |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame] | 535 | INSTANTIATE_TEST_CASE_P(BroadcastRadioHalTestCases, BroadcastRadioHalTest, |
| 536 | ::testing::Values(Class::AM_FM, Class::SAT, Class::DT)); |
| 537 | |
| 538 | } // namespace vts |
| 539 | } // namespace V1_1 |
| 540 | } // namespace broadcastradio |
| 541 | } // namespace hardware |
| 542 | } // namespace android |
| 543 | |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 544 | int main(int argc, char** argv) { |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 545 | ::testing::InitGoogleTest(&argc, argv); |
| 546 | int status = RUN_ALL_TESTS(); |
| 547 | ALOGI("Test result = %d", status); |
| 548 | return status; |
| 549 | } |