Brian Duddie | 01eb01a | 2020-02-14 15:35:57 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include <android/hardware/contexthub/1.0/IContexthub.h> |
| 19 | #include <gtest/gtest.h> |
| 20 | #include <hidl/HidlSupport.h> |
| 21 | #include <hidl/ServiceManagement.h> |
| 22 | #include <utils/StrongPointer.h> |
| 23 | |
| 24 | #include <chrono> |
| 25 | #include <future> |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace android { |
| 29 | namespace hardware { |
| 30 | namespace contexthub { |
| 31 | namespace vts_utils { |
| 32 | |
| 33 | #define ASSERT_OK(result) ASSERT_EQ(result, ::android::hardware::contexthub::V1_0::Result::OK) |
| 34 | #define EXPECT_OK(result) EXPECT_EQ(result, ::android::hardware::contexthub::V1_0::Result::OK) |
| 35 | |
| 36 | // Helper that does explicit conversion of an enum class to its underlying/base |
| 37 | // type. Useful for stream output of enum values. |
| 38 | template <typename EnumType> |
| 39 | inline constexpr typename std::underlying_type<EnumType>::type asBaseType(EnumType value) { |
| 40 | return static_cast<typename std::underlying_type<EnumType>::type>(value); |
| 41 | } |
| 42 | |
| 43 | // Synchronously queries IContexthub::getHubs() and returns the result |
| 44 | hidl_vec<V1_0::ContextHub> getHubsSync(V1_0::IContexthub* hubApi); |
| 45 | |
| 46 | // Create a vector of tuples that include each IContexthub service paired with each hub ID it |
| 47 | // exposes via getHubs(). Each tuple represents a test target that we should run the VTS suite |
| 48 | // against. |
| 49 | template <class IContexthubVersion> |
| 50 | static std::vector<std::tuple<std::string, std::string>> getHalAndHubIdList() { |
| 51 | std::vector<std::tuple<std::string, std::string>> parameters; |
| 52 | std::vector<std::string> serviceNames = |
| 53 | ::android::hardware::getAllHalInstanceNames(IContexthubVersion::descriptor); |
| 54 | for (const std::string& serviceName : serviceNames) { |
| 55 | sp<IContexthubVersion> hubApi = IContexthubVersion::getService(serviceName); |
| 56 | if (hubApi != nullptr) { |
| 57 | hidl_vec<V1_0::ContextHub> hubs = getHubsSync(hubApi.get()); |
| 58 | for (const V1_0::ContextHub& hub : hubs) { |
| 59 | parameters.push_back(std::make_tuple(serviceName, std::to_string(hub.hubId))); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return parameters; |
| 65 | } |
| 66 | |
| 67 | } // namespace vts_utils |
| 68 | } // namespace contexthub |
| 69 | } // namespace hardware |
| 70 | } // namespace android |