Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 17 | #include <android-base/logging.h> |
| 18 | #include <android/hardware/tv/tuner/1.0/IFrontend.h> |
| 19 | #include <android/hardware/tv/tuner/1.0/IFrontendCallback.h> |
| 20 | #include <android/hardware/tv/tuner/1.0/ITuner.h> |
| 21 | #include <android/hardware/tv/tuner/1.0/types.h> |
| 22 | #include <binder/MemoryDealer.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | #include <hidl/GtestPrinter.h> |
| 25 | #include <hidl/HidlSupport.h> |
| 26 | #include <hidl/HidlTransportSupport.h> |
| 27 | #include <hidl/ServiceManagement.h> |
| 28 | #include <hidl/Status.h> |
| 29 | #include <hidlmemory/FrameworkUtils.h> |
| 30 | #include <utils/Condition.h> |
| 31 | #include <utils/Mutex.h> |
| 32 | #include <map> |
| 33 | |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 34 | #include "DvrTests.h" |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 35 | #include "VtsHalTvTunerV1_0TestConfigurations.h" |
| 36 | |
| 37 | #define WAIT_TIMEOUT 3000000000 |
| 38 | #define INVALID_ID -1 |
| 39 | |
| 40 | using android::Condition; |
| 41 | using android::IMemory; |
| 42 | using android::IMemoryHeap; |
| 43 | using android::MemoryDealer; |
| 44 | using android::Mutex; |
| 45 | using android::sp; |
| 46 | using android::hardware::fromHeap; |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 47 | using android::hardware::hidl_vec; |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 48 | using android::hardware::Return; |
| 49 | using android::hardware::Void; |
| 50 | using android::hardware::tv::tuner::V1_0::FrontendAtscModulation; |
| 51 | using android::hardware::tv::tuner::V1_0::FrontendAtscSettings; |
| 52 | using android::hardware::tv::tuner::V1_0::FrontendDvbtSettings; |
| 53 | using android::hardware::tv::tuner::V1_0::FrontendEventType; |
| 54 | using android::hardware::tv::tuner::V1_0::FrontendId; |
| 55 | using android::hardware::tv::tuner::V1_0::FrontendInfo; |
| 56 | using android::hardware::tv::tuner::V1_0::FrontendInnerFec; |
| 57 | using android::hardware::tv::tuner::V1_0::FrontendScanMessage; |
| 58 | using android::hardware::tv::tuner::V1_0::FrontendScanMessageType; |
| 59 | using android::hardware::tv::tuner::V1_0::FrontendScanType; |
| 60 | using android::hardware::tv::tuner::V1_0::FrontendSettings; |
| 61 | using android::hardware::tv::tuner::V1_0::IFrontend; |
| 62 | using android::hardware::tv::tuner::V1_0::IFrontendCallback; |
| 63 | using android::hardware::tv::tuner::V1_0::ITuner; |
| 64 | using android::hardware::tv::tuner::V1_0::Result; |
| 65 | |
| 66 | using ::testing::AssertionResult; |
| 67 | |
Dan Shi | fdbc494 | 2020-04-07 14:38:56 -0700 | [diff] [blame] | 68 | using namespace std; |
| 69 | |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 70 | #define INVALID_ID -1 |
| 71 | #define WAIT_TIMEOUT 3000000000 |
| 72 | |
| 73 | class FrontendCallback : public IFrontendCallback { |
| 74 | public: |
| 75 | virtual Return<void> onEvent(FrontendEventType frontendEventType) override; |
| 76 | virtual Return<void> onScanMessage(FrontendScanMessageType type, |
| 77 | const FrontendScanMessage& message) override; |
| 78 | |
| 79 | void tuneTestOnEventReceive(sp<IFrontend>& frontend, FrontendSettings settings); |
| 80 | void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings); |
| 81 | void scanTest(sp<IFrontend>& frontend, FrontendConfig config, FrontendScanType type); |
| 82 | |
| 83 | // Helper methods |
| 84 | uint32_t getTargetFrequency(FrontendSettings settings, FrontendType type); |
| 85 | void resetBlindScanStartingFrequency(FrontendConfig& config, uint32_t resetingFreq); |
| 86 | |
| 87 | private: |
| 88 | bool mEventReceived = false; |
| 89 | bool mScanMessageReceived = false; |
| 90 | bool mLockMsgReceived = false; |
| 91 | bool mScanMsgProcessed = true; |
| 92 | FrontendScanMessageType mScanMessageType; |
| 93 | FrontendScanMessage mScanMessage; |
| 94 | hidl_vec<uint8_t> mEventMessage; |
| 95 | android::Mutex mMsgLock; |
| 96 | android::Condition mMsgCondition; |
| 97 | android::Condition mLockMsgCondition; |
| 98 | }; |
| 99 | |
| 100 | class FrontendTests { |
| 101 | public: |
| 102 | sp<ITuner> mService; |
| 103 | |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 104 | void setService(sp<ITuner> tuner) { |
| 105 | mService = tuner; |
Hongguang | ac8f96b | 2021-07-02 17:38:58 -0700 | [diff] [blame] | 106 | getDvrTests()->setService(tuner); |
Amy Zhang | 85a9ab3 | 2020-06-19 16:44:52 -0700 | [diff] [blame] | 107 | getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig); |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 108 | } |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 109 | |
| 110 | AssertionResult getFrontendIds(); |
| 111 | AssertionResult getFrontendInfo(uint32_t frontendId); |
| 112 | AssertionResult openFrontendById(uint32_t frontendId); |
| 113 | AssertionResult setFrontendCallback(); |
| 114 | AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type); |
| 115 | AssertionResult stopScanFrontend(); |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 116 | AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux); |
Amy Zhang | cda23ea | 2020-06-02 18:57:42 -0700 | [diff] [blame] | 117 | AssertionResult setLnb(uint32_t lnbId); |
Amy Zhang | 7bfe997 | 2020-05-15 14:56:32 -0700 | [diff] [blame] | 118 | void verifyFrontendStatus(vector<FrontendStatusType> statusTypes, |
| 119 | vector<FrontendStatus> expectStatuses); |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 120 | AssertionResult stopTuneFrontend(bool testWithDemux); |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 121 | AssertionResult closeFrontend(); |
| 122 | |
| 123 | void getFrontendIdByType(FrontendType feType, uint32_t& feId); |
| 124 | void tuneTest(FrontendConfig frontendConf); |
| 125 | void scanTest(FrontendConfig frontend, FrontendScanType type); |
| 126 | |
Hongguang | ac8f96b | 2021-07-02 17:38:58 -0700 | [diff] [blame] | 127 | void setDvrTests(DvrTests* dvrTests) { mExternalDvrTests = dvrTests; } |
| 128 | void setDemux(sp<IDemux> demux) { getDvrTests()->setDemux(demux); } |
Amy Zhang | 85a9ab3 | 2020-06-19 16:44:52 -0700 | [diff] [blame] | 129 | void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; } |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 130 | |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 131 | protected: |
Amy Zhang | cda23ea | 2020-06-02 18:57:42 -0700 | [diff] [blame] | 132 | static AssertionResult failure() { return ::testing::AssertionFailure(); } |
| 133 | static AssertionResult success() { return ::testing::AssertionSuccess(); } |
| 134 | |
Amy Zhang | e691505 | 2021-03-30 13:44:43 -0700 | [diff] [blame] | 135 | // TODO: replace with customized dvr input |
Amy Zhang | 85a9ab3 | 2020-06-19 16:44:52 -0700 | [diff] [blame] | 136 | void getDefaultSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) { |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 137 | PlaybackSettings playbackSettings{ |
| 138 | .statusMask = 0xf, |
| 139 | .lowThreshold = 0x1000, |
| 140 | .highThreshold = 0x07fff, |
| 141 | .dataFormat = DataFormat::TS, |
| 142 | .packetSize = 188, |
| 143 | }; |
| 144 | dvrConfig.type = DvrType::PLAYBACK; |
| 145 | dvrConfig.playbackInputFile = "/data/local/tmp/segment000000.ts"; |
| 146 | dvrConfig.bufferSize = FMQ_SIZE_4M; |
| 147 | dvrConfig.settings.playback(playbackSettings); |
| 148 | } |
| 149 | |
Hongguang | ac8f96b | 2021-07-02 17:38:58 -0700 | [diff] [blame] | 150 | DvrTests* getDvrTests() { |
| 151 | return (mExternalDvrTests != nullptr ? mExternalDvrTests : &mDvrTests); |
| 152 | } |
| 153 | |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 154 | sp<IFrontend> mFrontend; |
| 155 | FrontendInfo mFrontendInfo; |
| 156 | sp<FrontendCallback> mFrontendCallback; |
| 157 | hidl_vec<FrontendId> mFeIds; |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 158 | |
Hongguang | ac8f96b | 2021-07-02 17:38:58 -0700 | [diff] [blame] | 159 | DvrTests* mExternalDvrTests = nullptr; |
Amy Zhang | 6bda639 | 2020-05-26 19:00:46 -0700 | [diff] [blame] | 160 | DvrTests mDvrTests; |
| 161 | bool mIsSoftwareFe = false; |
Amy Zhang | 85a9ab3 | 2020-06-19 16:44:52 -0700 | [diff] [blame] | 162 | DvrConfig mDvrConfig; |
Amy Zhang | b3fb40b | 2020-04-02 13:48:43 -0700 | [diff] [blame] | 163 | }; |