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 virtual void SetUp() override; 43 44 // Applies given function to each HAL instance in VINTF. 45 static void ForEachAidlHalInstance(const HalManifestPtr &, AidlVerifyFn); 46 static void ForEachHidlHalInstance(const HalManifestPtr &, HidlVerifyFn); 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> GetPassthroughHals(HalManifestPtr manifest); 63 static set<string> GetHwbinderHals(HalManifestPtr manifest); 64 Partition GetPartition(sp<IBase> hal_service); 65 66 // Default service manager. 67 sp<IServiceManager> default_manager_; 68 }; 69 70 } // namespace testing 71 } // namespace vintf 72 } // namespace android 73 74 #endif // VTS_TREBLE_VINTF_TEST_BASE_H_ 75