1*70a7ec85SAndroid Build Coastguard Worker /*
2*70a7ec85SAndroid Build Coastguard Worker * Copyright (C) 2019 The Android Open Source Project
3*70a7ec85SAndroid Build Coastguard Worker *
4*70a7ec85SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*70a7ec85SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*70a7ec85SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*70a7ec85SAndroid Build Coastguard Worker *
8*70a7ec85SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*70a7ec85SAndroid Build Coastguard Worker *
10*70a7ec85SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*70a7ec85SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*70a7ec85SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*70a7ec85SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*70a7ec85SAndroid Build Coastguard Worker * limitations under the License.
15*70a7ec85SAndroid Build Coastguard Worker */
16*70a7ec85SAndroid Build Coastguard Worker
17*70a7ec85SAndroid Build Coastguard Worker #include <aidl/Vintf.h>
18*70a7ec85SAndroid Build Coastguard Worker
19*70a7ec85SAndroid Build Coastguard Worker #include <android-base/logging.h>
20*70a7ec85SAndroid Build Coastguard Worker #include <android-base/strings.h>
21*70a7ec85SAndroid Build Coastguard Worker #include <gtest/gtest.h>
22*70a7ec85SAndroid Build Coastguard Worker #include <vintf/VintfObject.h>
23*70a7ec85SAndroid Build Coastguard Worker
24*70a7ec85SAndroid Build Coastguard Worker namespace android {
25*70a7ec85SAndroid Build Coastguard Worker
26*70a7ec85SAndroid Build Coastguard Worker static std::vector<std::string> gUnimplementedInterfaces;
27*70a7ec85SAndroid Build Coastguard Worker
28*70a7ec85SAndroid Build Coastguard Worker // b/290539746. getAidlHalInstanceNames is usually used for parameters
29*70a7ec85SAndroid Build Coastguard Worker // to create parameterized tests, so if it returns an empty list, then
30*70a7ec85SAndroid Build Coastguard Worker // oftentimes the test will report no test results. This is confusing
31*70a7ec85SAndroid Build Coastguard Worker // and it appears like a test error.
32*70a7ec85SAndroid Build Coastguard Worker //
33*70a7ec85SAndroid Build Coastguard Worker // Due to translation units defining other tests that will be instantiated
34*70a7ec85SAndroid Build Coastguard Worker // in another order, we can't instantiate a test suite based on the set
35*70a7ec85SAndroid Build Coastguard Worker // of unimplemented interfaces, so we can only have one test which shows
36*70a7ec85SAndroid Build Coastguard Worker // the result.
TEST(AidlTestHelper,CheckNoUnimplementedInterfaces)37*70a7ec85SAndroid Build Coastguard Worker TEST(AidlTestHelper, CheckNoUnimplementedInterfaces) {
38*70a7ec85SAndroid Build Coastguard Worker if (gUnimplementedInterfaces.empty()) {
39*70a7ec85SAndroid Build Coastguard Worker // all interfaces are implemented, so no error
40*70a7ec85SAndroid Build Coastguard Worker return;
41*70a7ec85SAndroid Build Coastguard Worker }
42*70a7ec85SAndroid Build Coastguard Worker
43*70a7ec85SAndroid Build Coastguard Worker GTEST_SKIP()
44*70a7ec85SAndroid Build Coastguard Worker << "These interfaces are unimplemented on this device, so other tests may be skipped: "
45*70a7ec85SAndroid Build Coastguard Worker << android::base::Join(gUnimplementedInterfaces, ", ");
46*70a7ec85SAndroid Build Coastguard Worker }
47*70a7ec85SAndroid Build Coastguard Worker
getAidlHalInstanceNames(const std::string & descriptor)48*70a7ec85SAndroid Build Coastguard Worker std::vector<std::string> getAidlHalInstanceNames(const std::string& descriptor) {
49*70a7ec85SAndroid Build Coastguard Worker size_t lastDot = descriptor.rfind('.');
50*70a7ec85SAndroid Build Coastguard Worker CHECK(lastDot != std::string::npos) << "Invalid descriptor: " << descriptor;
51*70a7ec85SAndroid Build Coastguard Worker const std::string package = descriptor.substr(0, lastDot);
52*70a7ec85SAndroid Build Coastguard Worker const std::string iface = descriptor.substr(lastDot + 1);
53*70a7ec85SAndroid Build Coastguard Worker
54*70a7ec85SAndroid Build Coastguard Worker std::vector<std::string> ret;
55*70a7ec85SAndroid Build Coastguard Worker
56*70a7ec85SAndroid Build Coastguard Worker auto deviceManifest = vintf::VintfObject::GetDeviceHalManifest();
57*70a7ec85SAndroid Build Coastguard Worker for (const std::string& instance : deviceManifest->getAidlInstances(package, iface)) {
58*70a7ec85SAndroid Build Coastguard Worker ret.push_back(descriptor + "/" + instance);
59*70a7ec85SAndroid Build Coastguard Worker }
60*70a7ec85SAndroid Build Coastguard Worker
61*70a7ec85SAndroid Build Coastguard Worker auto frameworkManifest = vintf::VintfObject::GetFrameworkHalManifest();
62*70a7ec85SAndroid Build Coastguard Worker for (const std::string& instance : frameworkManifest->getAidlInstances(package, iface)) {
63*70a7ec85SAndroid Build Coastguard Worker ret.push_back(descriptor + "/" + instance);
64*70a7ec85SAndroid Build Coastguard Worker }
65*70a7ec85SAndroid Build Coastguard Worker
66*70a7ec85SAndroid Build Coastguard Worker if (ret.size() == 0) {
67*70a7ec85SAndroid Build Coastguard Worker std::cerr << "WARNING: There are no instances of AIDL service '" << descriptor
68*70a7ec85SAndroid Build Coastguard Worker << "' declared on this device." << std::endl;
69*70a7ec85SAndroid Build Coastguard Worker
70*70a7ec85SAndroid Build Coastguard Worker gUnimplementedInterfaces.push_back(descriptor);
71*70a7ec85SAndroid Build Coastguard Worker }
72*70a7ec85SAndroid Build Coastguard Worker
73*70a7ec85SAndroid Build Coastguard Worker return ret;
74*70a7ec85SAndroid Build Coastguard Worker }
75*70a7ec85SAndroid Build Coastguard Worker
getAidlHalInstanceNames(const String16 & descriptor)76*70a7ec85SAndroid Build Coastguard Worker std::vector<std::string> getAidlHalInstanceNames(const String16& descriptor) {
77*70a7ec85SAndroid Build Coastguard Worker return getAidlHalInstanceNames(String8(descriptor).c_str());
78*70a7ec85SAndroid Build Coastguard Worker }
79*70a7ec85SAndroid Build Coastguard Worker
80*70a7ec85SAndroid Build Coastguard Worker } // namespace android
81