blob: b8b9f476ca36387732ade2100e6a83690c691a42 [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
34#include "VtsHalTvTunerV1_0TestConfigurations.h"
35
36#define WAIT_TIMEOUT 3000000000
37#define INVALID_ID -1
38
39using android::Condition;
40using android::IMemory;
41using android::IMemoryHeap;
42using android::MemoryDealer;
43using android::Mutex;
44using android::sp;
45using android::hardware::fromHeap;
Amy Zhangb3fb40b2020-04-02 13:48:43 -070046using android::hardware::hidl_vec;
Amy Zhangb3fb40b2020-04-02 13:48:43 -070047using android::hardware::Return;
48using android::hardware::Void;
49using android::hardware::tv::tuner::V1_0::FrontendAtscModulation;
50using android::hardware::tv::tuner::V1_0::FrontendAtscSettings;
51using android::hardware::tv::tuner::V1_0::FrontendDvbtSettings;
52using android::hardware::tv::tuner::V1_0::FrontendEventType;
53using android::hardware::tv::tuner::V1_0::FrontendId;
54using android::hardware::tv::tuner::V1_0::FrontendInfo;
55using android::hardware::tv::tuner::V1_0::FrontendInnerFec;
56using android::hardware::tv::tuner::V1_0::FrontendScanMessage;
57using android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
58using android::hardware::tv::tuner::V1_0::FrontendScanType;
59using android::hardware::tv::tuner::V1_0::FrontendSettings;
60using android::hardware::tv::tuner::V1_0::IFrontend;
61using android::hardware::tv::tuner::V1_0::IFrontendCallback;
62using android::hardware::tv::tuner::V1_0::ITuner;
63using android::hardware::tv::tuner::V1_0::Result;
64
65using ::testing::AssertionResult;
66
Dan Shifdbc4942020-04-07 14:38:56 -070067using namespace std;
68
Amy Zhangb3fb40b2020-04-02 13:48:43 -070069#define INVALID_ID -1
70#define WAIT_TIMEOUT 3000000000
71
72class FrontendCallback : public IFrontendCallback {
73 public:
74 virtual Return<void> onEvent(FrontendEventType frontendEventType) override;
75 virtual Return<void> onScanMessage(FrontendScanMessageType type,
76 const FrontendScanMessage& message) override;
77
78 void tuneTestOnEventReceive(sp<IFrontend>& frontend, FrontendSettings settings);
79 void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings);
80 void scanTest(sp<IFrontend>& frontend, FrontendConfig config, FrontendScanType type);
81
82 // Helper methods
83 uint32_t getTargetFrequency(FrontendSettings settings, FrontendType type);
84 void resetBlindScanStartingFrequency(FrontendConfig& config, uint32_t resetingFreq);
85
86 private:
87 bool mEventReceived = false;
88 bool mScanMessageReceived = false;
89 bool mLockMsgReceived = false;
90 bool mScanMsgProcessed = true;
91 FrontendScanMessageType mScanMessageType;
92 FrontendScanMessage mScanMessage;
93 hidl_vec<uint8_t> mEventMessage;
94 android::Mutex mMsgLock;
95 android::Condition mMsgCondition;
96 android::Condition mLockMsgCondition;
97};
98
99class FrontendTests {
100 public:
101 sp<ITuner> mService;
102
103 void setService(sp<ITuner> tuner) { mService = tuner; }
104
105 AssertionResult getFrontendIds();
106 AssertionResult getFrontendInfo(uint32_t frontendId);
107 AssertionResult openFrontendById(uint32_t frontendId);
108 AssertionResult setFrontendCallback();
109 AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type);
110 AssertionResult stopScanFrontend();
111 AssertionResult tuneFrontend(FrontendConfig config);
Amy Zhangcda23ea2020-06-02 18:57:42 -0700112 AssertionResult setLnb(uint32_t lnbId);
Amy Zhang7bfe9972020-05-15 14:56:32 -0700113 void verifyFrontendStatus(vector<FrontendStatusType> statusTypes,
114 vector<FrontendStatus> expectStatuses);
Amy Zhangb3fb40b2020-04-02 13:48:43 -0700115 AssertionResult stopTuneFrontend();
116 AssertionResult closeFrontend();
117
118 void getFrontendIdByType(FrontendType feType, uint32_t& feId);
119 void tuneTest(FrontendConfig frontendConf);
120 void scanTest(FrontendConfig frontend, FrontendScanType type);
121
122 protected:
Amy Zhangcda23ea2020-06-02 18:57:42 -0700123 static AssertionResult failure() { return ::testing::AssertionFailure(); }
124 static AssertionResult success() { return ::testing::AssertionSuccess(); }
125
Amy Zhangb3fb40b2020-04-02 13:48:43 -0700126 sp<IFrontend> mFrontend;
127 FrontendInfo mFrontendInfo;
128 sp<FrontendCallback> mFrontendCallback;
129 hidl_vec<FrontendId> mFeIds;
130};