diff options
author | Steven Moreland <smoreland@google.com> | 2019-08-26 19:57:44 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-08-26 19:57:44 +0000 |
commit | a3c1ad15b2d12ffe9e23c998a5cfcedd1ad7f823 (patch) | |
tree | 3aa44522a8865e328b7c780f50940e46a3af52e3 | |
parent | e5f126ba18b600c48eaed0922d90194012a9a148 (diff) | |
parent | e695c3e907c922fdefb6a6d0d653feb7a75e19f6 (diff) | |
download | libhidl-a3c1ad15b2d12ffe9e23c998a5cfcedd1ad7f823.tar.gz |
Merge changes from topic "parameterized-vts-tests"
* changes:
Helper library for tests.
Add helper API to get all HAL instances.
-rw-r--r-- | Android.bp | 5 | ||||
-rw-r--r-- | gtest_helpers/hidl/GtestPrinter.h | 36 | ||||
-rw-r--r-- | transport/ServiceManagement.cpp | 12 | ||||
-rw-r--r-- | transport/include/hidl/ServiceManagement.h | 9 |
4 files changed, 62 insertions, 0 deletions
@@ -30,6 +30,11 @@ phony { ], } +cc_library_headers { + name: "libhidl_gtest_helpers", + export_include_dirs: ["gtest_helpers"], +} + cc_test { name: "libhidl_test", defaults: ["libhidl-defaults"], diff --git a/gtest_helpers/hidl/GtestPrinter.h b/gtest_helpers/hidl/GtestPrinter.h new file mode 100644 index 0000000..c9f5dd3 --- /dev/null +++ b/gtest_helpers/hidl/GtestPrinter.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <gtest/gtest.h> + +namespace android { +namespace hardware { + +static inline std::string PrintInstanceNameToString( + const testing::TestParamInfo<std::string>& info) { + // test names need to be unique -> index prefix + std::string name = std::to_string(info.index) + "/" + info.param; + + for (size_t i = 0; i < name.size(); i++) { + // gtest test names must only contain alphanumeric characters + if (!std::isalnum(name[i])) name[i] = '_'; + } + + return name; +} + +} // namespace hardware +} // namespace android diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp index ab216ae..2187740 100644 --- a/transport/ServiceManagement.cpp +++ b/transport/ServiceManagement.cpp @@ -559,6 +559,18 @@ sp<IServiceManager1_1> getPassthroughServiceManager1_1() { return manager; } +std::vector<std::string> getAllHalInstanceNames(const std::string& descriptor) { + std::vector<std::string> ret; + auto sm = defaultServiceManager1_2(); + sm->listManifestByInterface(descriptor, [&](const auto& instances) { + ret.reserve(instances.size()); + for (const auto& i : instances) { + ret.push_back(i); + } + }); + return ret; +} + namespace details { void preloadPassthroughService(const std::string &descriptor) { diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h index a962034..4573a25 100644 --- a/transport/include/hidl/ServiceManagement.h +++ b/transport/include/hidl/ServiceManagement.h @@ -18,6 +18,7 @@ #define ANDROID_HARDWARE_ISERVICE_MANAGER_H #include <string> +#include <vector> #include <android/hidl/base/1.0/IBase.h> #include <utils/StrongPointer.h> @@ -71,6 +72,14 @@ sp<::android::hidl::manager::V1_0::IServiceManager> getPassthroughServiceManager sp<::android::hidl::manager::V1_1::IServiceManager> getPassthroughServiceManager1_1(); /** + * Given a descriptor (e.g. from IFoo::descriptor), return a list of all instance names + * on a device (e.g. the VINTF manifest). These HALs may not be currently running, but + * the expectation is that if they aren't running, they should start as lazy HALs. + * So, getService should return for each of these instance names. + */ +std::vector<std::string> getAllHalInstanceNames(const std::string& descriptor); + +/** * Given a service that is in passthrough mode, this function will go ahead and load the * required passthrough module library (but not call HIDL_FETCH_I* functions to instantiate it). * |