1 /* 2 * Copyright 2021 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 #pragma once 18 19 #include <aidl/android/hardware/tv/tuner/BnFrontendCallback.h> 20 #include <aidl/android/hardware/tv/tuner/IFrontend.h> 21 #include <aidl/android/hardware/tv/tuner/ITuner.h> 22 23 #include <gtest/gtest.h> 24 #include <log/log.h> 25 #include <utils/Condition.h> 26 #include <utils/Mutex.h> 27 28 #include "DvrTests.h" 29 #include "VtsHalTvTunerTestConfigurations.h" 30 31 #define WAIT_TIMEOUT 3000000000 32 #define INVALID_ID -1 33 34 using android::Condition; 35 using android::Mutex; 36 37 using ::testing::AssertionResult; 38 39 using namespace aidl::android::hardware::tv::tuner; 40 using namespace std; 41 42 #define INVALID_ID -1 43 #define WAIT_TIMEOUT 3000000000 44 45 class FrontendCallback : public BnFrontendCallback { 46 public: 47 virtual ndk::ScopedAStatus onEvent(FrontendEventType frontendEventType) override; 48 virtual ndk::ScopedAStatus onScanMessage(FrontendScanMessageType type, 49 const FrontendScanMessage& message) override; 50 51 void tuneTestOnLock(std::shared_ptr<IFrontend>& frontend, FrontendSettings settings); 52 void scanTest(std::shared_ptr<IFrontend>& frontend, FrontendConfig config, 53 FrontendScanType type); 54 55 // Helper methods 56 int64_t getTargetFrequency(FrontendSettings& settings); 57 void resetBlindScanStartingFrequency(FrontendConfig& config, int64_t resetingFreq); 58 59 private: 60 void readFrontendScanMessage_Modulation(FrontendModulation modulation); 61 62 bool mEventReceived = false; 63 bool mScanMessageReceived = false; 64 bool mLockMsgReceived = false; 65 bool mScanMsgProcessed = true; 66 FrontendScanMessageType mScanMessageType; 67 FrontendScanMessage mScanMessage; 68 vector<int8_t> mEventMessage; 69 android::Mutex mMsgLock; 70 android::Condition mMsgCondition; 71 android::Condition mLockMsgCondition; 72 }; 73 74 class FrontendTests { 75 public: setService(std::shared_ptr<ITuner> tuner)76 void setService(std::shared_ptr<ITuner> tuner) { 77 mService = tuner; 78 getDvrTests()->setService(tuner); 79 getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig); 80 } 81 82 AssertionResult getFrontendIds(); 83 AssertionResult getFrontendInfo(int32_t frontendId); 84 AssertionResult openFrontendById(int32_t frontendId); 85 AssertionResult setFrontendCallback(); 86 AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type); 87 AssertionResult stopScanFrontend(); 88 AssertionResult setLnb(int32_t lnbId); 89 AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux); 90 void verifyFrontendStatus(vector<FrontendStatusType> statusTypes, 91 vector<FrontendStatus> expectStatuses); 92 AssertionResult stopTuneFrontend(bool testWithDemux); 93 AssertionResult closeFrontend(); 94 95 AssertionResult linkCiCam(int32_t ciCamId); 96 AssertionResult unlinkCiCam(int32_t ciCamId); 97 AssertionResult verifyHardwareInfo(); 98 AssertionResult removeOutputPid(int32_t removePid); 99 100 void getFrontendIdByType(FrontendType feType, int32_t& feId); 101 void tuneTest(FrontendConfig frontendConf); 102 void scanTest(FrontendConfig frontend, FrontendScanType type); 103 void debugInfoTest(FrontendConfig frontendConf); 104 void maxNumberOfFrontendsTest(); 105 void statusReadinessTest(FrontendConfig frontendConf); 106 setDvrTests(DvrTests * dvrTests)107 void setDvrTests(DvrTests* dvrTests) { mExternalDvrTests = dvrTests; } setDemux(std::shared_ptr<IDemux> demux)108 void setDemux(std::shared_ptr<IDemux> demux) { getDvrTests()->setDemux(demux); } setSoftwareFrontendDvrConfig(DvrConfig conf)109 void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; } 110 111 protected: failure()112 static AssertionResult failure() { return ::testing::AssertionFailure(); } success()113 static AssertionResult success() { return ::testing::AssertionSuccess(); } 114 getDefaultSoftwareFrontendPlaybackConfig(DvrConfig & dvrConfig)115 void getDefaultSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) { 116 PlaybackSettings playbackSettings{ 117 .statusMask = 0xf, 118 .lowThreshold = 0x1000, 119 .highThreshold = 0x07fff, 120 .dataFormat = DataFormat::ES, 121 .packetSize = static_cast<int64_t>(188), 122 }; 123 dvrConfig.type = DvrType::PLAYBACK; 124 dvrConfig.playbackInputFile = "/data/local/tmp/test.es"; 125 dvrConfig.bufferSize = FMQ_SIZE_4M; 126 dvrConfig.settings.set<DvrSettings::playback>(playbackSettings); 127 } 128 getDvrTests()129 DvrTests* getDvrTests() { 130 return (mExternalDvrTests != nullptr ? mExternalDvrTests : &mDvrTests); 131 } 132 133 std::shared_ptr<ITuner> mService; 134 std::shared_ptr<IFrontend> mFrontend; 135 FrontendInfo mFrontendInfo; 136 std::shared_ptr<FrontendCallback> mFrontendCallback; 137 vector<int32_t> mFeIds; 138 139 DvrTests mDvrTests; 140 DvrTests* mExternalDvrTests = nullptr; 141 bool mIsSoftwareFe = false; 142 DvrConfig mDvrConfig; 143 }; 144