From e5a9da2e1714e6402c8c0955bebd9ccfe3e00517 Mon Sep 17 00:00:00 2001 From: Amy Zhang Date: Mon, 1 Jun 2020 19:12:29 -0700 Subject: [PATCH] Add ILnb VTS tests Test: atest VtsHalTvTunerV1_0TargetTest Bug: 157955950 Change-Id: Icc2fca6f65e48a05c916a9629913cc7b18a8fd80 --- tv/tuner/1.0/default/Demux.cpp | 2 +- tv/tuner/1.0/vts/functional/Android.bp | 1 + tv/tuner/1.0/vts/functional/DemuxTests.cpp | 12 +- tv/tuner/1.0/vts/functional/DemuxTests.h | 4 +- .../1.0/vts/functional/DescramblerTests.h | 6 +- tv/tuner/1.0/vts/functional/LnbTests.cpp | 116 ++++++++++++++++++ tv/tuner/1.0/vts/functional/LnbTests.h | 84 +++++++++++++ .../VtsHalTvTunerV1_0TargetTest.cpp | 21 ++++ .../functional/VtsHalTvTunerV1_0TargetTest.h | 21 ++++ .../VtsHalTvTunerV1_0TestConfigurations.h | 33 +++++ 10 files changed, 289 insertions(+), 11 deletions(-) create mode 100644 tv/tuner/1.0/vts/functional/LnbTests.cpp create mode 100644 tv/tuner/1.0/vts/functional/LnbTests.h diff --git a/tv/tuner/1.0/default/Demux.cpp b/tv/tuner/1.0/default/Demux.cpp index da56041ba0..b74f6eca20 100644 --- a/tv/tuner/1.0/default/Demux.cpp +++ b/tv/tuner/1.0/default/Demux.cpp @@ -124,12 +124,12 @@ Return Demux::getAvSyncHwId(const sp& filter, getAvSyncHwId_cb _h } if (!mPcrFilterIds.empty()) { - ALOGE("[Demux] No PCR filter opened."); // Return the lowest pcr filter id in the default implementation as the av sync id _hidl_cb(Result::SUCCESS, *mPcrFilterIds.begin()); return Void(); } + ALOGE("[Demux] No PCR filter opened."); _hidl_cb(Result::INVALID_STATE, avSyncHwId); return Void(); } diff --git a/tv/tuner/1.0/vts/functional/Android.bp b/tv/tuner/1.0/vts/functional/Android.bp index 8c08873f58..17659153cf 100644 --- a/tv/tuner/1.0/vts/functional/Android.bp +++ b/tv/tuner/1.0/vts/functional/Android.bp @@ -24,6 +24,7 @@ cc_test { "FilterTests.cpp", "DvrTests.cpp", "DescramblerTests.cpp", + "LnbTests.cpp", ], static_libs: [ "android.hardware.cas@1.0", diff --git a/tv/tuner/1.0/vts/functional/DemuxTests.cpp b/tv/tuner/1.0/vts/functional/DemuxTests.cpp index 393bab50b6..37a47d710e 100644 --- a/tv/tuner/1.0/vts/functional/DemuxTests.cpp +++ b/tv/tuner/1.0/vts/functional/DemuxTests.cpp @@ -53,23 +53,23 @@ AssertionResult DemuxTests::closeDemux() { return AssertionResult(status.isOk()); } -void DemuxTests::getAvSyncId(sp filter, uint32_t& avSyncHwId) { - ASSERT_TRUE(mDemux) << "Demux is not opened yet."; +AssertionResult DemuxTests::getAvSyncId(sp filter, uint32_t& avSyncHwId) { + EXPECT_TRUE(mDemux) << "Demux is not opened yet."; Result status; mDemux->getAvSyncHwId(filter, [&](Result result, uint32_t id) { status = result; avSyncHwId = id; }); - ASSERT_TRUE(status == Result::SUCCESS) << "Fail to get avSyncHwId."; + return AssertionResult(status == Result::SUCCESS); } -void DemuxTests::getAvSyncTime(uint32_t avSyncId) { - ASSERT_TRUE(mDemux) << "Demux is not opened yet."; +AssertionResult DemuxTests::getAvSyncTime(uint32_t avSyncId) { + EXPECT_TRUE(mDemux) << "Demux is not opened yet."; Result status; uint64_t syncTime; mDemux->getAvSyncTime(avSyncId, [&](Result result, uint64_t time) { status = result; syncTime = time; }); - ASSERT_TRUE(status == Result::SUCCESS) << "Fail to get avSyncTime."; + return AssertionResult(status == Result::SUCCESS); } \ No newline at end of file diff --git a/tv/tuner/1.0/vts/functional/DemuxTests.h b/tv/tuner/1.0/vts/functional/DemuxTests.h index 4211ca7e6b..b249ea80e0 100644 --- a/tv/tuner/1.0/vts/functional/DemuxTests.h +++ b/tv/tuner/1.0/vts/functional/DemuxTests.h @@ -44,8 +44,8 @@ class DemuxTests { AssertionResult openDemux(sp& demux, uint32_t& demuxId); AssertionResult setDemuxFrontendDataSource(uint32_t frontendId); - void getAvSyncId(sp filter, uint32_t& avSyncHwId); - void getAvSyncTime(uint32_t avSyncId); + AssertionResult getAvSyncId(sp filter, uint32_t& avSyncHwId); + AssertionResult getAvSyncTime(uint32_t avSyncId); AssertionResult getDemuxCaps(DemuxCapabilities& demuxCaps); AssertionResult closeDemux(); diff --git a/tv/tuner/1.0/vts/functional/DescramblerTests.h b/tv/tuner/1.0/vts/functional/DescramblerTests.h index 31f4663089..16d480db0c 100644 --- a/tv/tuner/1.0/vts/functional/DescramblerTests.h +++ b/tv/tuner/1.0/vts/functional/DescramblerTests.h @@ -14,8 +14,6 @@ * limitations under the License. */ -#include -#include #include #include #include @@ -28,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -69,6 +69,8 @@ using android::hardware::tv::tuner::V1_0::TunerKeyToken; using ::testing::AssertionResult; +using namespace std; + class MediaCasListener : public ICasListener { public: virtual Return onEvent(int32_t /*event*/, int32_t /*arg*/, diff --git a/tv/tuner/1.0/vts/functional/LnbTests.cpp b/tv/tuner/1.0/vts/functional/LnbTests.cpp new file mode 100644 index 0000000000..9080f59762 --- /dev/null +++ b/tv/tuner/1.0/vts/functional/LnbTests.cpp @@ -0,0 +1,116 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LnbTests.h" + +Return LnbCallback::onEvent(LnbEventType lnbEventType) { + android::Mutex::Autolock autoLock(mMsgLock); + ALOGD("[vts] lnb event received. Type: %d", lnbEventType); + mEventReceived = true; + mMsgCondition.signal(); + return Void(); +} + +Return LnbCallback::onDiseqcMessage(const hidl_vec& diseqcMessage) { + string msg(diseqcMessage.begin(), diseqcMessage.end()); + ALOGD("[vts] onDiseqcMessage %s", msg.c_str()); + return Void(); +} + +AssertionResult LnbTests::getLnbIds(vector& ids) { + Result status; + mService->getLnbIds([&](Result result, const hidl_vec& lnbIds) { + status = result; + ids = lnbIds; + }); + return AssertionResult(status == Result::SUCCESS); +} + +AssertionResult LnbTests::openLnbById(uint32_t lnbId) { + Result status; + mService->openLnbById(lnbId, [&](Result result, const sp& lnb) { + mLnb = lnb; + status = result; + }); + return AssertionResult(status == Result::SUCCESS); +} + +AssertionResult LnbTests::openLnbByName(string lnbName) { + Result status; + mService->openLnbByName(lnbName, [&](Result result, uint32_t /*lnbId*/, const sp& lnb) { + mLnb = lnb; + status = result; + }); + + return AssertionResult(status == Result::SUCCESS); +} + +AssertionResult LnbTests::setLnbCallback() { + if (!mLnb) { + ALOGW("[vts] Open Lnb first"); + return failure(); + } + mLnbCallback = new LnbCallback(); + auto callbackStatus = mLnb->setCallback(mLnbCallback); + return AssertionResult(callbackStatus.isOk()); +} + +AssertionResult LnbTests::setVoltage(LnbVoltage voltage) { + if (!mLnb) { + ALOGW("[vts] Open Lnb first"); + return failure(); + } + Result status = mLnb->setVoltage(voltage); + return AssertionResult(status == Result::SUCCESS); +} + +AssertionResult LnbTests::setTone(LnbTone tone) { + if (!mLnb) { + ALOGW("[vts] Open Lnb first"); + return failure(); + } + Result status = mLnb->setTone(tone); + return AssertionResult(status == Result::SUCCESS); +} + +AssertionResult LnbTests::setSatellitePosition(LnbPosition position) { + if (!mLnb) { + ALOGW("[vts] Open Lnb first"); + return failure(); + } + Result status = mLnb->setSatellitePosition(position); + return AssertionResult(status == Result::SUCCESS); +} + +AssertionResult LnbTests::sendDiseqcMessage(vector diseqcMsg) { + if (!mLnb) { + ALOGW("[vts] Open Lnb first"); + return failure(); + } + Result status = mLnb->sendDiseqcMessage(diseqcMsg); + return AssertionResult(status == Result::SUCCESS); +} + +AssertionResult LnbTests::closeLnb() { + if (!mLnb) { + ALOGW("[vts] Open Lnb first"); + return failure(); + } + Result status = mLnb->close(); + mLnb = nullptr; + mLnbCallback = nullptr; + return AssertionResult(status == Result::SUCCESS); +} diff --git a/tv/tuner/1.0/vts/functional/LnbTests.h b/tv/tuner/1.0/vts/functional/LnbTests.h new file mode 100644 index 0000000000..2fdbe2ce26 --- /dev/null +++ b/tv/tuner/1.0/vts/functional/LnbTests.h @@ -0,0 +1,84 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using android::Condition; +using android::Mutex; +using android::sp; +using android::hardware::hidl_vec; +using android::hardware::Return; +using android::hardware::Void; +using android::hardware::tv::tuner::V1_0::ILnb; +using android::hardware::tv::tuner::V1_0::ILnbCallback; +using android::hardware::tv::tuner::V1_0::ITuner; +using android::hardware::tv::tuner::V1_0::LnbEventType; +using android::hardware::tv::tuner::V1_0::LnbPosition; +using android::hardware::tv::tuner::V1_0::LnbTone; +using android::hardware::tv::tuner::V1_0::LnbVoltage; +using android::hardware::tv::tuner::V1_0::Result; + +using ::testing::AssertionResult; + +using namespace std; + +class LnbCallback : public ILnbCallback { + public: + virtual Return onEvent(LnbEventType lnbEventType) override; + virtual Return onDiseqcMessage(const hidl_vec& diseqcMessage) override; + + private: + bool mEventReceived = false; + android::Mutex mMsgLock; + android::Condition mMsgCondition; +}; + +class LnbTests { + public: + void setService(sp tuner) { mService = tuner; } + + AssertionResult getLnbIds(vector& ids); + AssertionResult openLnbById(uint32_t lnbId); + AssertionResult openLnbByName(string lnbName); + AssertionResult setLnbCallback(); + AssertionResult setVoltage(LnbVoltage voltage); + AssertionResult setTone(LnbTone tone); + AssertionResult setSatellitePosition(LnbPosition position); + AssertionResult sendDiseqcMessage(vector diseqcMsg); + AssertionResult closeLnb(); + + protected: + static AssertionResult failure() { return ::testing::AssertionFailure(); } + + static AssertionResult success() { return ::testing::AssertionSuccess(); } + + sp mService; + sp mLnb; + sp mLnbCallback; + hidl_vec mLnbIds; +}; diff --git a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp index 882a5119ad..583fce9ed3 100644 --- a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp +++ b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp @@ -275,6 +275,22 @@ TEST_P(TunerFrontendHidlTest, BlindScanFrontend) { mFrontendTests.scanTest(frontendScanArray[SCAN_DVBT], FrontendScanType::SCAN_BLIND); } +TEST_P(TunerLnbHidlTest, SendDiseqcMessageToLnb) { + description("Open and configure an Lnb with specific settings then send a diseqc msg to it."); + vector ids; + ASSERT_TRUE(mLnbTests.getLnbIds(ids)); + if (ids.size() == 0) { + return; + } + ASSERT_TRUE(mLnbTests.openLnbById(ids[0])); + ASSERT_TRUE(mLnbTests.setLnbCallback()); + ASSERT_TRUE(mLnbTests.setVoltage(lnbArray[LNB0].voltage)); + ASSERT_TRUE(mLnbTests.setTone(lnbArray[LNB0].tone)); + ASSERT_TRUE(mLnbTests.setSatellitePosition(lnbArray[LNB0].position)); + ASSERT_TRUE(mLnbTests.sendDiseqcMessage(diseqcMsgArray[DISEQC_POWER_ON])); + ASSERT_TRUE(mLnbTests.closeLnb()); +} + TEST_P(TunerDemuxHidlTest, openDemux) { description("Open and close a Demux."); uint32_t feId; @@ -428,6 +444,11 @@ INSTANTIATE_TEST_SUITE_P( testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITuner::descriptor)), android::hardware::PrintInstanceNameToString); +INSTANTIATE_TEST_SUITE_P( + PerInstance, TunerLnbHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITuner::descriptor)), + android::hardware::PrintInstanceNameToString); + INSTANTIATE_TEST_SUITE_P( PerInstance, TunerDemuxHidlTest, testing::ValuesIn(android::hardware::getAllHalInstanceNames(ITuner::descriptor)), diff --git a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.h b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.h index 2bdb537850..c8a23aada6 100644 --- a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.h +++ b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.h @@ -18,6 +18,7 @@ #include "DescramblerTests.h" #include "DvrTests.h" #include "FrontendTests.h" +#include "LnbTests.h" using android::hardware::tv::tuner::V1_0::DataFormat; using android::hardware::tv::tuner::V1_0::IDescrambler; @@ -31,6 +32,7 @@ namespace { void initConfiguration() { initFrontendConfig(); initFrontendScanConfig(); + initLnbConfig(); initFilterConfig(); initDvrConfig(); initDescramblerConfig(); @@ -65,6 +67,25 @@ class TunerFrontendHidlTest : public testing::TestWithParam { FrontendTests mFrontendTests; }; +class TunerLnbHidlTest : public testing::TestWithParam { + public: + virtual void SetUp() override { + mService = ITuner::getService(GetParam()); + ASSERT_NE(mService, nullptr); + initConfiguration(); + + mLnbTests.setService(mService); + } + + protected: + static void description(const std::string& description) { + RecordProperty("description", description); + } + + sp mService; + LnbTests mLnbTests; +}; + class TunerDemuxHidlTest : public testing::TestWithParam { public: virtual void SetUp() override { diff --git a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TestConfigurations.h b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TestConfigurations.h index 9f24eef4e9..1941773e6a 100644 --- a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TestConfigurations.h +++ b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TestConfigurations.h @@ -47,6 +47,9 @@ using android::hardware::tv::tuner::V1_0::FrontendSettings; using android::hardware::tv::tuner::V1_0::FrontendStatus; using android::hardware::tv::tuner::V1_0::FrontendStatusType; using android::hardware::tv::tuner::V1_0::FrontendType; +using android::hardware::tv::tuner::V1_0::LnbPosition; +using android::hardware::tv::tuner::V1_0::LnbTone; +using android::hardware::tv::tuner::V1_0::LnbVoltage; using android::hardware::tv::tuner::V1_0::PlaybackSettings; using android::hardware::tv::tuner::V1_0::RecordSettings; @@ -94,6 +97,16 @@ typedef enum { FRONTEND_MAX, } Frontend; +typedef enum { + LNB0, + LNB_MAX, +} Lnb; + +typedef enum { + DISEQC_POWER_ON, + DISEQC_MAX, +} Diseqc; + typedef enum { SCAN_DVBT, SCAN_MAX, @@ -125,6 +138,12 @@ struct FrontendConfig { vector expectTuneStatuses; }; +struct LnbConfig { + LnbVoltage voltage; + LnbTone tone; + LnbPosition position; +}; + struct ChannelConfig { int32_t frontendId; int32_t channelId; @@ -148,6 +167,8 @@ struct DescramblerConfig { static FrontendConfig frontendArray[FILTER_MAX]; static FrontendConfig frontendScanArray[SCAN_MAX]; +static LnbConfig lnbArray[LNB_MAX]; +static vector diseqcMsgArray[DISEQC_MAX]; static ChannelConfig channelArray[FRONTEND_MAX]; static FilterConfig filterArray[FILTER_MAX]; static DemuxFilterType filterLinkageTypes[LINKAGE_DIR][FILTER_MAIN_TYPE_BIT_COUNT]; @@ -198,6 +219,18 @@ inline void initFrontendScanConfig() { }); }; +/** Configuration array for the Lnb test */ +inline void initLnbConfig() { + lnbArray[LNB0].voltage = LnbVoltage::VOLTAGE_12V; + lnbArray[LNB0].tone = LnbTone::NONE; + lnbArray[LNB0].position = LnbPosition::UNDEFINED; +}; + +/** Diseqc messages array for the Lnb test */ +inline void initDiseqcMsg() { + diseqcMsgArray[DISEQC_POWER_ON] = {0xE, 0x0, 0x0, 0x0, 0x0, 0x3}; +}; + /** Configuration array for the filter test */ inline void initFilterConfig() { // TS VIDEO filter setting for default implementation testing