Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -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 | |
| 17 | #include <android-base/logging.h> |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 18 | #include <android/hardware/tv/tuner/1.0/IFrontendCallback.h> |
| 19 | #include <android/hardware/tv/tuner/1.0/types.h> |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 20 | #include <android/hardware/tv/tuner/1.1/IFrontend.h> |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 21 | #include <android/hardware/tv/tuner/1.1/ITuner.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 | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 34 | #include "DvrTests.h" |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 35 | #include "VtsHalTvTunerV1_1TestConfigurations.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; |
| 47 | using android::hardware::hidl_vec; |
| 48 | using android::hardware::Return; |
| 49 | using android::hardware::Void; |
| 50 | using android::hardware::tv::tuner::V1_0::FrontendEventType; |
| 51 | using android::hardware::tv::tuner::V1_0::FrontendId; |
| 52 | using android::hardware::tv::tuner::V1_0::FrontendInfo; |
| 53 | using android::hardware::tv::tuner::V1_0::FrontendScanMessage; |
| 54 | using android::hardware::tv::tuner::V1_0::FrontendScanMessageType; |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 55 | using android::hardware::tv::tuner::V1_0::FrontendScanType; |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 56 | using android::hardware::tv::tuner::V1_0::IFrontend; |
| 57 | using android::hardware::tv::tuner::V1_0::IFrontendCallback; |
| 58 | using android::hardware::tv::tuner::V1_0::Result; |
| 59 | using android::hardware::tv::tuner::V1_1::ITuner; |
| 60 | |
| 61 | using ::testing::AssertionResult; |
| 62 | |
| 63 | using namespace std; |
| 64 | |
| 65 | #define INVALID_ID -1 |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 66 | #define WAIT_TIMEOUT 3000000000 |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 67 | |
| 68 | class FrontendCallback : public IFrontendCallback { |
| 69 | public: |
| 70 | virtual Return<void> onEvent(FrontendEventType frontendEventType) override; |
| 71 | virtual Return<void> onScanMessage(FrontendScanMessageType type, |
| 72 | const FrontendScanMessage& message) override; |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 73 | |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 74 | void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings, |
| 75 | FrontendSettingsExt settingsExt); |
| 76 | void scanTest(sp<IFrontend>& frontend, FrontendConfig config, FrontendScanType type); |
| 77 | |
| 78 | // Helper methods |
| 79 | uint32_t getTargetFrequency(FrontendSettings settings, FrontendType type); |
| 80 | void resetBlindScanStartingFrequency(FrontendConfig& config, uint32_t resetingFreq); |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 81 | |
| 82 | private: |
| 83 | bool mEventReceived = false; |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 84 | bool mScanMessageReceived = false; |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 85 | bool mLockMsgReceived = false; |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 86 | bool mScanMsgProcessed = true; |
| 87 | FrontendScanMessageType mScanMessageType; |
| 88 | FrontendScanMessage mScanMessage; |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 89 | hidl_vec<uint8_t> mEventMessage; |
| 90 | android::Mutex mMsgLock; |
| 91 | android::Condition mMsgCondition; |
| 92 | android::Condition mLockMsgCondition; |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | class FrontendTests { |
| 96 | public: |
| 97 | sp<ITuner> mService; |
| 98 | |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 99 | void setService(sp<ITuner> tuner) { |
| 100 | mService = tuner; |
| 101 | mDvrTests.setService(tuner); |
| 102 | getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig); |
| 103 | } |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 104 | |
| 105 | AssertionResult getFrontendIds(); |
| 106 | AssertionResult getFrontendInfo(uint32_t frontendId); |
| 107 | AssertionResult openFrontendById(uint32_t frontendId); |
| 108 | AssertionResult setFrontendCallback(); |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 109 | AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type); |
| 110 | AssertionResult stopScanFrontend(); |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 111 | AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux); |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 112 | void verifyFrontendStatus(vector<FrontendStatusType> statusTypes, |
| 113 | vector<FrontendStatus> expectStatuses); |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 114 | AssertionResult stopTuneFrontend(bool testWithDemux); |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 115 | AssertionResult closeFrontend(); |
| 116 | |
| 117 | void getFrontendIdByType(FrontendType feType, uint32_t& feId); |
Amy Zhang | 3ea25a6 | 2020-08-04 10:23:52 -0700 | [diff] [blame] | 118 | void tuneTest(FrontendConfig frontendConf); |
| 119 | void scanTest(FrontendConfig frontend, FrontendScanType type); |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 120 | |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 121 | void setDvrTests(DvrTests dvrTests) { mDvrTests = dvrTests; } |
| 122 | void setDemux(sp<IDemux> demux) { mDvrTests.setDemux(demux); } |
| 123 | void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; } |
| 124 | |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 125 | protected: |
| 126 | static AssertionResult failure() { return ::testing::AssertionFailure(); } |
| 127 | static AssertionResult success() { return ::testing::AssertionSuccess(); } |
| 128 | |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 129 | void getDefaultSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) { |
| 130 | PlaybackSettings playbackSettings{ |
| 131 | .statusMask = 0xf, |
| 132 | .lowThreshold = 0x1000, |
| 133 | .highThreshold = 0x07fff, |
| 134 | .dataFormat = DataFormat::ES, |
| 135 | .packetSize = 188, |
| 136 | }; |
| 137 | dvrConfig.type = DvrType::PLAYBACK; |
| 138 | dvrConfig.playbackInputFile = "/data/local/tmp/test.es"; |
| 139 | dvrConfig.bufferSize = FMQ_SIZE_4M; |
| 140 | dvrConfig.settings.playback(playbackSettings); |
| 141 | } |
| 142 | |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 143 | sp<IFrontend> mFrontend; |
| 144 | FrontendInfo mFrontendInfo; |
| 145 | sp<FrontendCallback> mFrontendCallback; |
| 146 | hidl_vec<FrontendId> mFeIds; |
| 147 | |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 148 | DvrTests mDvrTests; |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 149 | bool mIsSoftwareFe = false; |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame] | 150 | DvrConfig mDvrConfig; |
| 151 | }; |