blob: c79afc85cfe22b1c6c4cc4e1651336796c3c9195 [file] [log] [blame]
Brian Duddie01eb01a2020-02-14 15:35:57 -08001/*
2 * Copyright (C) 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 */
Arthur Ishigurofe0f98e2021-08-12 14:43:39 -070016
17/**
18 * Utils file for HIDL related VTS code.
19 */
Brian Duddie01eb01a2020-02-14 15:35:57 -080020#pragma once
21
22#include <android/hardware/contexthub/1.0/IContexthub.h>
23#include <gtest/gtest.h>
24#include <hidl/HidlSupport.h>
25#include <hidl/ServiceManagement.h>
26#include <utils/StrongPointer.h>
27
Brian Duddie01eb01a2020-02-14 15:35:57 -080028#include <vector>
29
30namespace android {
31namespace hardware {
32namespace contexthub {
33namespace vts_utils {
34
35#define ASSERT_OK(result) ASSERT_EQ(result, ::android::hardware::contexthub::V1_0::Result::OK)
36#define EXPECT_OK(result) EXPECT_EQ(result, ::android::hardware::contexthub::V1_0::Result::OK)
37
Brian Duddie01eb01a2020-02-14 15:35:57 -080038// Synchronously queries IContexthub::getHubs() and returns the result
39hidl_vec<V1_0::ContextHub> getHubsSync(V1_0::IContexthub* hubApi);
40
41// Create a vector of tuples that include each IContexthub service paired with each hub ID it
42// exposes via getHubs(). Each tuple represents a test target that we should run the VTS suite
43// against.
44template <class IContexthubVersion>
45static std::vector<std::tuple<std::string, std::string>> getHalAndHubIdList() {
46 std::vector<std::tuple<std::string, std::string>> parameters;
47 std::vector<std::string> serviceNames =
48 ::android::hardware::getAllHalInstanceNames(IContexthubVersion::descriptor);
49 for (const std::string& serviceName : serviceNames) {
50 sp<IContexthubVersion> hubApi = IContexthubVersion::getService(serviceName);
51 if (hubApi != nullptr) {
52 hidl_vec<V1_0::ContextHub> hubs = getHubsSync(hubApi.get());
53 for (const V1_0::ContextHub& hub : hubs) {
54 parameters.push_back(std::make_tuple(serviceName, std::to_string(hub.hubId)));
55 }
56 }
57 }
58
59 return parameters;
60}
61
Brian Duddie01eb01a2020-02-14 15:35:57 -080062} // namespace vts_utils
63} // namespace contexthub
64} // namespace hardware
65} // namespace android