blob: 8f769a00046f3a164a0c8ec78198a2b610fdbe7e [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"
30
31#define WAIT_TIMEOUT 3000000000
32#define INVALID_ID -1
33
34using android::Condition;
35using android::Mutex;
36
37using ::testing::AssertionResult;
38
39using namespace aidl::android::hardware::tv::tuner;
40using namespace std;
41
42#define INVALID_ID -1
43#define WAIT_TIMEOUT 3000000000
44
45class 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
Hongguang11da2cb2021-08-05 19:05:12 -070056 int64_t getTargetFrequency(FrontendSettings& settings);
57 void resetBlindScanStartingFrequency(FrontendConfig& config, int64_t resetingFreq);
Hongguang600a6ae2021-07-08 18:51:51 -070058
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
74class FrontendTests {
75 public:
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);
Hongguangfcedda02021-12-13 17:08:02 -080097 AssertionResult verifyHardwareInfo();
Hongguang600a6ae2021-07-08 18:51:51 -070098
99 void getFrontendIdByType(FrontendType feType, int32_t& feId);
100 void tuneTest(FrontendConfig frontendConf);
101 void scanTest(FrontendConfig frontend, FrontendScanType type);
Hongguangfcedda02021-12-13 17:08:02 -0800102 void debugInfoTest(FrontendConfig frontendConf);
Hongguang600a6ae2021-07-08 18:51:51 -0700103
104 void setDvrTests(DvrTests* dvrTests) { mExternalDvrTests = dvrTests; }
105 void setDemux(std::shared_ptr<IDemux> demux) { getDvrTests()->setDemux(demux); }
106 void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; }
107
108 protected:
109 static AssertionResult failure() { return ::testing::AssertionFailure(); }
110 static AssertionResult success() { return ::testing::AssertionSuccess(); }
111
112 void getDefaultSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) {
113 PlaybackSettings playbackSettings{
114 .statusMask = 0xf,
115 .lowThreshold = 0x1000,
116 .highThreshold = 0x07fff,
117 .dataFormat = DataFormat::ES,
Hongguang11da2cb2021-08-05 19:05:12 -0700118 .packetSize = static_cast<int64_t>(188),
Hongguang600a6ae2021-07-08 18:51:51 -0700119 };
120 dvrConfig.type = DvrType::PLAYBACK;
121 dvrConfig.playbackInputFile = "/data/local/tmp/test.es";
122 dvrConfig.bufferSize = FMQ_SIZE_4M;
123 dvrConfig.settings.set<DvrSettings::playback>(playbackSettings);
124 }
125
126 DvrTests* getDvrTests() {
127 return (mExternalDvrTests != nullptr ? mExternalDvrTests : &mDvrTests);
128 }
129
130 std::shared_ptr<ITuner> mService;
131 std::shared_ptr<IFrontend> mFrontend;
132 FrontendInfo mFrontendInfo;
133 std::shared_ptr<FrontendCallback> mFrontendCallback;
134 vector<int32_t> mFeIds;
135
136 DvrTests mDvrTests;
137 DvrTests* mExternalDvrTests = nullptr;
138 bool mIsSoftwareFe = false;
139 DvrConfig mDvrConfig;
140};