blob: e68758919dad96e24d6bebc4c1708612ef55ff5d [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>
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/types.h>
21#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
34#include "VtsHalTvTunerV1_1TestConfigurations.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;
46using android::hardware::hidl_vec;
47using android::hardware::Return;
48using android::hardware::Void;
49using android::hardware::tv::tuner::V1_0::FrontendEventType;
50using android::hardware::tv::tuner::V1_0::FrontendId;
51using android::hardware::tv::tuner::V1_0::FrontendInfo;
52using android::hardware::tv::tuner::V1_0::FrontendScanMessage;
53using android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
54using android::hardware::tv::tuner::V1_0::IFrontend;
55using android::hardware::tv::tuner::V1_0::IFrontendCallback;
56using android::hardware::tv::tuner::V1_0::Result;
57using android::hardware::tv::tuner::V1_1::ITuner;
58
59using ::testing::AssertionResult;
60
61using namespace std;
62
63#define INVALID_ID -1
64
65class FrontendCallback : public IFrontendCallback {
66 public:
67 virtual Return<void> onEvent(FrontendEventType frontendEventType) override;
68 virtual Return<void> onScanMessage(FrontendScanMessageType type,
69 const FrontendScanMessage& message) override;
70};
71
72class FrontendTests {
73 public:
74 sp<ITuner> mService;
75
76 void setService(sp<ITuner> tuner) { mService = tuner; }
77
78 AssertionResult getFrontendIds();
79 AssertionResult getFrontendInfo(uint32_t frontendId);
80 AssertionResult openFrontendById(uint32_t frontendId);
81 AssertionResult setFrontendCallback();
82 AssertionResult closeFrontend();
83
84 void getFrontendIdByType(FrontendType feType, uint32_t& feId);
85
86 protected:
87 static AssertionResult failure() { return ::testing::AssertionFailure(); }
88 static AssertionResult success() { return ::testing::AssertionSuccess(); }
89
90 sp<IFrontend> mFrontend;
91 FrontendInfo mFrontendInfo;
92 sp<FrontendCallback> mFrontendCallback;
93 hidl_vec<FrontendId> mFeIds;
94
95 bool mIsSoftwareFe = false;
96};