blob: c789d94c2b618546ff52b9fd642b04ee05e5c307 [file] [log] [blame]
Amy Zhangb3fb40b2020-04-02 13:48:43 -07001/*
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 Zhangb3fb40b2020-04-02 13:48:43 -070017#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 Zhang6bda6392020-05-26 19:00:46 -070034#include "DvrTests.h"
Amy Zhangb3fb40b2020-04-02 13:48:43 -070035#include "VtsHalTvTunerV1_0TestConfigurations.h"
36
37#define WAIT_TIMEOUT 3000000000
38#define INVALID_ID -1
39
40using android::Condition;
41using android::IMemory;
42using android::IMemoryHeap;
43using android::MemoryDealer;
44using android::Mutex;
45using android::sp;
46using android::hardware::fromHeap;
Amy Zhangb3fb40b2020-04-02 13:48:43 -070047using android::hardware::hidl_vec;
Amy Zhangb3fb40b2020-04-02 13:48:43 -070048using android::hardware::Return;
49using android::hardware::Void;
50using android::hardware::tv::tuner::V1_0::FrontendAtscModulation;
51using android::hardware::tv::tuner::V1_0::FrontendAtscSettings;
52using android::hardware::tv::tuner::V1_0::FrontendDvbtSettings;
53using android::hardware::tv::tuner::V1_0::FrontendEventType;
54using android::hardware::tv::tuner::V1_0::FrontendId;
55using android::hardware::tv::tuner::V1_0::FrontendInfo;
56using android::hardware::tv::tuner::V1_0::FrontendInnerFec;
57using android::hardware::tv::tuner::V1_0::FrontendScanMessage;
58using android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
59using android::hardware::tv::tuner::V1_0::FrontendScanType;
60using android::hardware::tv::tuner::V1_0::FrontendSettings;
61using android::hardware::tv::tuner::V1_0::IFrontend;
62using android::hardware::tv::tuner::V1_0::IFrontendCallback;
63using android::hardware::tv::tuner::V1_0::ITuner;
64using android::hardware::tv::tuner::V1_0::Result;
65
66using ::testing::AssertionResult;
67
Dan Shifdbc4942020-04-07 14:38:56 -070068using namespace std;
69
Amy Zhangb3fb40b2020-04-02 13:48:43 -070070#define INVALID_ID -1
71#define WAIT_TIMEOUT 3000000000
72
73class 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
100class FrontendTests {
101 public:
102 sp<ITuner> mService;
103
Amy Zhang6bda6392020-05-26 19:00:46 -0700104 void setService(sp<ITuner> tuner) {
105 mService = tuner;
Hongguangac8f96b2021-07-02 17:38:58 -0700106 getDvrTests()->setService(tuner);
Amy Zhang85a9ab32020-06-19 16:44:52 -0700107 getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig);
Amy Zhang6bda6392020-05-26 19:00:46 -0700108 }
Amy Zhangb3fb40b2020-04-02 13:48:43 -0700109
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 Zhang6bda6392020-05-26 19:00:46 -0700116 AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux);
Amy Zhangcda23ea2020-06-02 18:57:42 -0700117 AssertionResult setLnb(uint32_t lnbId);
Amy Zhang7bfe9972020-05-15 14:56:32 -0700118 void verifyFrontendStatus(vector<FrontendStatusType> statusTypes,
119 vector<FrontendStatus> expectStatuses);
Amy Zhang6bda6392020-05-26 19:00:46 -0700120 AssertionResult stopTuneFrontend(bool testWithDemux);
Amy Zhangb3fb40b2020-04-02 13:48:43 -0700121 AssertionResult closeFrontend();
122
123 void getFrontendIdByType(FrontendType feType, uint32_t& feId);
124 void tuneTest(FrontendConfig frontendConf);
125 void scanTest(FrontendConfig frontend, FrontendScanType type);
126
Hongguangac8f96b2021-07-02 17:38:58 -0700127 void setDvrTests(DvrTests* dvrTests) { mExternalDvrTests = dvrTests; }
128 void setDemux(sp<IDemux> demux) { getDvrTests()->setDemux(demux); }
Amy Zhang85a9ab32020-06-19 16:44:52 -0700129 void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; }
Amy Zhang6bda6392020-05-26 19:00:46 -0700130
Amy Zhangb3fb40b2020-04-02 13:48:43 -0700131 protected:
Amy Zhangcda23ea2020-06-02 18:57:42 -0700132 static AssertionResult failure() { return ::testing::AssertionFailure(); }
133 static AssertionResult success() { return ::testing::AssertionSuccess(); }
134
Amy Zhange6915052021-03-30 13:44:43 -0700135 // TODO: replace with customized dvr input
Amy Zhang85a9ab32020-06-19 16:44:52 -0700136 void getDefaultSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) {
Amy Zhang6bda6392020-05-26 19:00:46 -0700137 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
Hongguangac8f96b2021-07-02 17:38:58 -0700150 DvrTests* getDvrTests() {
151 return (mExternalDvrTests != nullptr ? mExternalDvrTests : &mDvrTests);
152 }
153
Amy Zhangb3fb40b2020-04-02 13:48:43 -0700154 sp<IFrontend> mFrontend;
155 FrontendInfo mFrontendInfo;
156 sp<FrontendCallback> mFrontendCallback;
157 hidl_vec<FrontendId> mFeIds;
Amy Zhang6bda6392020-05-26 19:00:46 -0700158
Hongguangac8f96b2021-07-02 17:38:58 -0700159 DvrTests* mExternalDvrTests = nullptr;
Amy Zhang6bda6392020-05-26 19:00:46 -0700160 DvrTests mDvrTests;
161 bool mIsSoftwareFe = false;
Amy Zhang85a9ab32020-06-19 16:44:52 -0700162 DvrConfig mDvrConfig;
Amy Zhangb3fb40b2020-04-02 13:48:43 -0700163};