blob: cb238e8d0096c70838a724287919dbeeafe3b09a [file] [log] [blame]
Amy Zhang45cc57a2020-07-09 22:56:25 -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
17#include <android-base/logging.h>
Amy Zhang45cc57a2020-07-09 22:56:25 -070018#include <android/hardware/tv/tuner/1.0/IFrontendCallback.h>
19#include <android/hardware/tv/tuner/1.0/types.h>
Amy Zhang3ea25a62020-08-04 10:23:52 -070020#include <android/hardware/tv/tuner/1.1/IFrontend.h>
Amy Zhang45cc57a2020-07-09 22:56:25 -070021#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 Zhang68afca62020-07-20 18:28:58 -070034#include "DvrTests.h"
Amy Zhang45cc57a2020-07-09 22:56:25 -070035#include "VtsHalTvTunerV1_1TestConfigurations.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;
47using android::hardware::hidl_vec;
48using android::hardware::Return;
49using android::hardware::Void;
50using android::hardware::tv::tuner::V1_0::FrontendEventType;
51using android::hardware::tv::tuner::V1_0::FrontendId;
52using android::hardware::tv::tuner::V1_0::FrontendInfo;
53using android::hardware::tv::tuner::V1_0::FrontendScanMessage;
54using android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
Amy Zhang3ea25a62020-08-04 10:23:52 -070055using android::hardware::tv::tuner::V1_0::FrontendScanType;
Amy Zhang45cc57a2020-07-09 22:56:25 -070056using android::hardware::tv::tuner::V1_0::IFrontend;
57using android::hardware::tv::tuner::V1_0::IFrontendCallback;
58using android::hardware::tv::tuner::V1_0::Result;
Amy Zhang4c49c152020-08-25 21:08:19 -070059using android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
Amy Zhang45cc57a2020-07-09 22:56:25 -070060using android::hardware::tv::tuner::V1_1::ITuner;
61
62using ::testing::AssertionResult;
63
64using namespace std;
65
66#define INVALID_ID -1
Amy Zhang68afca62020-07-20 18:28:58 -070067#define WAIT_TIMEOUT 3000000000
Amy Zhang45cc57a2020-07-09 22:56:25 -070068
69class 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 Zhang68afca62020-07-20 18:28:58 -070074
Amy Zhang3ea25a62020-08-04 10:23:52 -070075 void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings,
Amy Zhangbc15b592020-09-25 15:35:55 -070076 FrontendSettingsExt1_1 settingsExt1_1);
Amy Zhang3ea25a62020-08-04 10:23:52 -070077 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 Zhang68afca62020-07-20 18:28:58 -070082
83 private:
84 bool mEventReceived = false;
Amy Zhang3ea25a62020-08-04 10:23:52 -070085 bool mScanMessageReceived = false;
Amy Zhang68afca62020-07-20 18:28:58 -070086 bool mLockMsgReceived = false;
Amy Zhang3ea25a62020-08-04 10:23:52 -070087 bool mScanMsgProcessed = true;
88 FrontendScanMessageType mScanMessageType;
89 FrontendScanMessage mScanMessage;
Amy Zhang68afca62020-07-20 18:28:58 -070090 hidl_vec<uint8_t> mEventMessage;
91 android::Mutex mMsgLock;
92 android::Condition mMsgCondition;
93 android::Condition mLockMsgCondition;
Amy Zhang45cc57a2020-07-09 22:56:25 -070094};
95
96class FrontendTests {
97 public:
98 sp<ITuner> mService;
99
Amy Zhang68afca62020-07-20 18:28:58 -0700100 void setService(sp<ITuner> tuner) {
101 mService = tuner;
102 mDvrTests.setService(tuner);
103 getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig);
104 }
Amy Zhang45cc57a2020-07-09 22:56:25 -0700105
106 AssertionResult getFrontendIds();
107 AssertionResult getFrontendInfo(uint32_t frontendId);
108 AssertionResult openFrontendById(uint32_t frontendId);
109 AssertionResult setFrontendCallback();
Amy Zhang3ea25a62020-08-04 10:23:52 -0700110 AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type);
111 AssertionResult stopScanFrontend();
Amy Zhang68afca62020-07-20 18:28:58 -0700112 AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700113 void verifyFrontendStatus(vector<FrontendStatusType> statusTypes,
114 vector<FrontendStatus> expectStatuses);
Amy Zhang68afca62020-07-20 18:28:58 -0700115 AssertionResult stopTuneFrontend(bool testWithDemux);
Amy Zhang45cc57a2020-07-09 22:56:25 -0700116 AssertionResult closeFrontend();
Amy Zhang4c49c152020-08-25 21:08:19 -0700117 AssertionResult getFrontendDtmbCaps(uint32_t);
Amy Zhang45cc57a2020-07-09 22:56:25 -0700118
119 void getFrontendIdByType(FrontendType feType, uint32_t& feId);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700120 void tuneTest(FrontendConfig frontendConf);
121 void scanTest(FrontendConfig frontend, FrontendScanType type);
Amy Zhang4c49c152020-08-25 21:08:19 -0700122 void getFrontendDtmbCapsTest();
Amy Zhang45cc57a2020-07-09 22:56:25 -0700123
Amy Zhang68afca62020-07-20 18:28:58 -0700124 void setDvrTests(DvrTests dvrTests) { mDvrTests = dvrTests; }
125 void setDemux(sp<IDemux> demux) { mDvrTests.setDemux(demux); }
126 void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; }
127
Amy Zhang45cc57a2020-07-09 22:56:25 -0700128 protected:
129 static AssertionResult failure() { return ::testing::AssertionFailure(); }
130 static AssertionResult success() { return ::testing::AssertionSuccess(); }
131
Amy Zhang68afca62020-07-20 18:28:58 -0700132 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 Zhang45cc57a2020-07-09 22:56:25 -0700146 sp<IFrontend> mFrontend;
147 FrontendInfo mFrontendInfo;
148 sp<FrontendCallback> mFrontendCallback;
149 hidl_vec<FrontendId> mFeIds;
150
Amy Zhang68afca62020-07-20 18:28:58 -0700151 DvrTests mDvrTests;
Amy Zhang45cc57a2020-07-09 22:56:25 -0700152 bool mIsSoftwareFe = false;
Amy Zhang68afca62020-07-20 18:28:58 -0700153 DvrConfig mDvrConfig;
154};