1 /*
2  * Copyright (C) 2018 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 #ifndef VTS_TREBLE_VINTF_TEST_BASE_H_
18 #define VTS_TREBLE_VINTF_TEST_BASE_H_
19 
20 #include <android/hidl/manager/1.0/IServiceManager.h>
21 #include <binder/IBinder.h>
22 #include <gtest/gtest.h>
23 #include <vintf/VintfObject.h>
24 
25 #include <string>
26 #include <vector>
27 
28 #include "utils.h"
29 
30 namespace android {
31 namespace vintf {
32 namespace testing {
33 
34 using android::sp;
35 using android::hidl::base::V1_0::IBase;
36 using android::hidl::manager::V1_0::IServiceManager;
37 
38 // Base class for many test suites. Provides some utility functions.
39 class VtsTrebleVintfTestBase : public ::testing::Test {
40  public:
~VtsTrebleVintfTestBase()41   virtual ~VtsTrebleVintfTestBase() {}
42 
43   // Applies given function to each HAL instance in VINTF.
44   static std::vector<AidlInstance> GetAidlInstances(const HalManifestPtr &);
45   static std::vector<HidlInstance> GetHidlInstances(const HalManifestPtr &);
46   static std::vector<NativeInstance> GetNativeInstances(const HalManifestPtr &);
47 
48   // Retrieves an existing HAL service.
49   static sp<IBase> GetHidlService(const string &fq_name,
50                                   const string &instance_name, Transport,
51                                   bool log = true);
52   static sp<IBase> GetHidlService(const FQName &fq_name,
53                                   const string &instance_name, Transport,
54                                   bool log = true);
55   static sp<IBinder> GetAidlService(const std::string &name);
56 
57   static vector<string> GetInstanceNames(const sp<IServiceManager> &manager,
58                                          const FQName &fq_name);
59 
60   static vector<string> GetInterfaceChain(const sp<IBase> &service);
61 
62   static set<string> GetDeclaredHidlHalsOfTransport(HalManifestPtr manifest,
63                                                 Transport transport);
64 
65   Partition GetPartition(sp<IBase> hal_service);
66 
67   static sp<IServiceManager> default_manager();
68 
69   // List HALs registered through hwservicemanager. Return the list of FQ
70   // instance names.
71   static std::vector<std::string> ListRegisteredHwbinderHals();
72 };
73 
74 }  // namespace testing
75 }  // namespace vintf
76 }  // namespace android
77 
78 #endif  // VTS_TREBLE_VINTF_TEST_BASE_H_
79