1 /* 2 * Copyright (C) 2017 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 UTILS_NATIVE_TESTABILITY_CHECKER_H_ 18 #define UTILS_NATIVE_TESTABILITY_CHECKER_H_ 19 20 #include <set> 21 22 #include <android-base/logging.h> 23 #include <android/hidl/manager/1.0/IServiceManager.h> 24 #include <vintf/CompatibilityMatrix.h> 25 #include <vintf/HalManifest.h> 26 27 using android::hidl::manager::V1_0::IServiceManager; 28 using android::vintf::Arch; 29 using android::vintf::CompatibilityMatrix; 30 using android::vintf::HalManifest; 31 using android::vintf::ManifestHal; 32 using android::vintf::MatrixHal; 33 using android::vintf::Version; 34 using std::set; 35 using std::string; 36 using std::vector; 37 38 namespace android { 39 namespace vts { 40 41 // Library class to decide whether to run a test against given hal based on 42 // the system compatibility matrix and device manifest files. Also collect the 43 // instance names for testing if the decision is true. 44 class VtsTestabilityChecker { 45 public: VtsTestabilityChecker(const CompatibilityMatrix * framework_comp_matrix,const HalManifest * framework_hal_manifest,const HalManifest * device_hal_manifest,sp<IServiceManager> sm)46 VtsTestabilityChecker(const CompatibilityMatrix* framework_comp_matrix, 47 const HalManifest* framework_hal_manifest, 48 const HalManifest* device_hal_manifest, 49 sp<IServiceManager> sm) 50 : framework_comp_matrix_(framework_comp_matrix), 51 framework_hal_manifest_(framework_hal_manifest), 52 device_hal_manifest_(device_hal_manifest), 53 sm_(sm) { 54 CHECK(framework_comp_matrix_) << "framework_comp_matrix null."; 55 CHECK(framework_hal_manifest_) << "framework_hal_manifest null."; 56 CHECK(device_hal_manifest_) << "device_hal_manifest null."; 57 }; 58 59 // Check whether we should run a compliance test against the given hal with 60 // the package name, version and interface name. Arch (32 or 64) info is 61 // required if the hal is a passthrough hal. 62 // Return true to indicate we should run the test, false otherwise. 63 // Store the instances name to run the test, instance should be empty set if 64 // we determine not to run the test (i,e. return value false). 65 bool CheckHalForComplianceTest(const string& hal_package_name, 66 const Version& hal_version, 67 const string& hal_interface_name, 68 const Arch& arch, set<string>* instances); 69 70 // Check whether we should run a non-compliance test against the given hal 71 // with the package name, version and interface name. Arch (32 or 64) info is 72 // required if the hal is a passthrough hal. 73 // Return true to indicate we should run the test, false otherwise. 74 // Store the instances name to run the test, instance should be empty set if 75 // we determine not to run the test (i,e. return value false). 76 bool CheckHalForNonComplianceTest(const string& hal_package_name, 77 const Version& hal_version, 78 const string& hal_interface_name, 79 const Arch& arch, set<string>* instances); 80 private: 81 // Internal method to check the given hal against the framework compatibility 82 // matrix and device manifest. 83 // If the hal is required by the framework, return true with the corresponding 84 // instance names. If the hal is optional for framework, return true if vendor 85 // supports the hal with the corresponding instance names, false otherwise. 86 bool CheckFrameworkCompatibleHal(const string& hal_package_name, 87 const Version& hal_version, 88 const string& hal_interface_name, 89 const Arch& arch, set<string>* instances); 90 91 // Internal method to check whether the given hal is supported by vendor 92 // (i.e exists in the vendor manifest file). Store the corresponding instance 93 // names if supported.. 94 // Arch (32 or 64) info is required if the hal is a passthrough hal. 95 bool CheckVendorManifestHal(const string& hal_package_name, 96 const Version& hal_version, 97 const string& hal_interface_name, 98 const Arch& arch, set<string>* instances); 99 100 // Internal method to check whether the given hal is supported by framework 101 // (i.e exists in the framework manifest file). Store the corresponding 102 // instance names if supported. 103 // Arch (32 or 64) info is required if the hal is a passthrough hal. 104 bool CheckFrameworkManifestHal(const string& hal_package_name, 105 const Version& hal_version, 106 const string& hal_interface_name, 107 const Arch& arch, set<string>* instances); 108 109 // Internal method to check whether the given hal is registered with 110 // hwservicemanager. Store the corresponding instance names if registered. 111 // This is used to check test hals that is not listed in manifest files. 112 // Note this could not check for passthrough hals. 113 bool CheckTestHalWithHwManager(const string& hal_package_name, 114 const Version& hal_version, 115 const string& hal_interface_name, 116 set<string>* instances); 117 118 // Helper method to check whether the hal_manifest support the 119 // package@version::interface and arch (for passthrough hal). Store the 120 // corresponding instance names if supported. 121 bool CheckManifestHal(const HalManifest* hal_manifest, 122 const string& hal_package_name, 123 const Version& hal_version, 124 const string& hal_interface_name, const Arch& arch, 125 set<string>* instances); 126 127 // Helper method to check whether a passthrough hal support the given arch 128 // (32 or 64). 129 bool CheckPassthroughManifestArch(const Arch& manifest_arch, 130 const Arch& arch); 131 132 // Helper method to find matching instances from a list of 133 // manifest_instances. 134 vector<const vintf::ManifestInstance*> FindInstance( 135 const vector<vintf::ManifestInstance>& manifest_instances, 136 const vintf::MatrixInstance& matrix_instance); 137 138 // Helper method to find matching interfaces from a list of 139 // manifest_instances. 140 vector<const vintf::ManifestInstance*> FindInterface( 141 const vector<vintf::ManifestInstance>& manifest_instances, 142 const vintf::MatrixInstance& matrix_instance); 143 144 const CompatibilityMatrix* framework_comp_matrix_; // Do not own. 145 const HalManifest* framework_hal_manifest_; // Do not own. 146 const HalManifest* device_hal_manifest_; // Do not own. 147 sp<IServiceManager> sm_; 148 149 friend class 150 VtsTestabilityCheckerTest_CheckFrameworkCompatibleHalOptional_Test; 151 friend class 152 VtsTestabilityCheckerTest_CheckFrameworkCompatibleHalRequired_Test; 153 }; 154 155 } // namespace vts 156 } // namespace android 157 #endif // UTILS_NATIVE_TESTABILITY_CHECKER_H_ 158