blob: 4eec7a666c986d7410b6bc1e5ca9b1ccf82d85ac [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;
59using android::hardware::tv::tuner::V1_1::ITuner;
60
61using ::testing::AssertionResult;
62
63using namespace std;
64
65#define INVALID_ID -1
Amy Zhang68afca62020-07-20 18:28:58 -070066#define WAIT_TIMEOUT 3000000000
Amy Zhang45cc57a2020-07-09 22:56:25 -070067
68class 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 Zhang68afca62020-07-20 18:28:58 -070073
Amy Zhang3ea25a62020-08-04 10:23:52 -070074 void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings,
Amy Zhangbc15b592020-09-25 15:35:55 -070075 FrontendSettingsExt1_1 settingsExt1_1);
Amy Zhang3ea25a62020-08-04 10:23:52 -070076 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 Zhang68afca62020-07-20 18:28:58 -070081
82 private:
83 bool mEventReceived = false;
Amy Zhang3ea25a62020-08-04 10:23:52 -070084 bool mScanMessageReceived = false;
Amy Zhang68afca62020-07-20 18:28:58 -070085 bool mLockMsgReceived = false;
Amy Zhang3ea25a62020-08-04 10:23:52 -070086 bool mScanMsgProcessed = true;
87 FrontendScanMessageType mScanMessageType;
88 FrontendScanMessage mScanMessage;
Amy Zhang68afca62020-07-20 18:28:58 -070089 hidl_vec<uint8_t> mEventMessage;
90 android::Mutex mMsgLock;
91 android::Condition mMsgCondition;
92 android::Condition mLockMsgCondition;
Amy Zhang45cc57a2020-07-09 22:56:25 -070093};
94
95class FrontendTests {
96 public:
97 sp<ITuner> mService;
98
Amy Zhang68afca62020-07-20 18:28:58 -070099 void setService(sp<ITuner> tuner) {
100 mService = tuner;
101 mDvrTests.setService(tuner);
102 getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig);
103 }
Amy Zhang45cc57a2020-07-09 22:56:25 -0700104
105 AssertionResult getFrontendIds();
106 AssertionResult getFrontendInfo(uint32_t frontendId);
107 AssertionResult openFrontendById(uint32_t frontendId);
108 AssertionResult setFrontendCallback();
Amy Zhang3ea25a62020-08-04 10:23:52 -0700109 AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type);
110 AssertionResult stopScanFrontend();
Amy Zhang68afca62020-07-20 18:28:58 -0700111 AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700112 void verifyFrontendStatus(vector<FrontendStatusType> statusTypes,
113 vector<FrontendStatus> expectStatuses);
Amy Zhang68afca62020-07-20 18:28:58 -0700114 AssertionResult stopTuneFrontend(bool testWithDemux);
Amy Zhang45cc57a2020-07-09 22:56:25 -0700115 AssertionResult closeFrontend();
116
117 void getFrontendIdByType(FrontendType feType, uint32_t& feId);
Amy Zhang3ea25a62020-08-04 10:23:52 -0700118 void tuneTest(FrontendConfig frontendConf);
119 void scanTest(FrontendConfig frontend, FrontendScanType type);
Amy Zhang45cc57a2020-07-09 22:56:25 -0700120
Amy Zhang68afca62020-07-20 18:28:58 -0700121 void setDvrTests(DvrTests dvrTests) { mDvrTests = dvrTests; }
122 void setDemux(sp<IDemux> demux) { mDvrTests.setDemux(demux); }
123 void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; }
124
Amy Zhang45cc57a2020-07-09 22:56:25 -0700125 protected:
126 static AssertionResult failure() { return ::testing::AssertionFailure(); }
127 static AssertionResult success() { return ::testing::AssertionSuccess(); }
128
Amy Zhang68afca62020-07-20 18:28:58 -0700129 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 Zhang45cc57a2020-07-09 22:56:25 -0700143 sp<IFrontend> mFrontend;
144 FrontendInfo mFrontendInfo;
145 sp<FrontendCallback> mFrontendCallback;
146 hidl_vec<FrontendId> mFeIds;
147
Amy Zhang68afca62020-07-20 18:28:58 -0700148 DvrTests mDvrTests;
Amy Zhang45cc57a2020-07-09 22:56:25 -0700149 bool mIsSoftwareFe = false;
Amy Zhang68afca62020-07-20 18:28:58 -0700150 DvrConfig mDvrConfig;
151};