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