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