1 /* 2 * Copyright (C) 2016 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_SYSFUZZER_COMMON_UTILS_IFSPECUTIL_H__ 18 #define __VTS_SYSFUZZER_COMMON_UTILS_IFSPECUTIL_H__ 19 20 #include <string> 21 22 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 23 24 #define VTS_INTERFACE_SPECIFICATION_FUNCTION_NAME_PREFIX "vts_func_" 25 26 using namespace std; 27 28 namespace android { 29 namespace vts { 30 31 // Reads the given file and parse the file contents into a 32 // ComponentSpecificationMessage. 33 bool ParseInterfaceSpec(const char* file_path, 34 ComponentSpecificationMessage* message); 35 36 // Returns the function name prefix of a given interface specification. 37 string GetFunctionNamePrefix(const ComponentSpecificationMessage& message); 38 39 // Get HAL version (represented by two integers) string to be used to 40 // build a relevant dir path. 41 // 42 // Args: 43 // version_major: int, HAL major version, e.g. 1.10 -> 1. 44 // version_minor: int, HAL minor version, e.g. 1.10 -> 10. 45 // for_macro: bool, if true, it returns version 1.10 as V1_10 46 // 47 // Returns: 48 // string, for version 1.10, if for_macro is true, it returns V1_10, 49 // otherwise, it returns 1.10. 50 string GetVersionString(int version_major, int version_minor, 51 bool for_macro = false); 52 53 // deprecated 54 // Get HAL version string to be used to build a relevant dir path. 55 // 56 // Args: 57 // version: float, HAL version, e.g. 1.10. 58 // for_macro: bool, if true, it returns version 1.10 as V1_10. 59 // 60 // Returns: 61 // string, for version 1.10, if for_macro is true, it returns V1_10, 62 // otherwise, it returns 1.10. 63 string GetVersionString(float version, bool for_macro=false); 64 65 // Get the driver library name for a given HIDL HAL. 66 // 67 // Args: 68 // package_name: string, name of target package. 69 // version_major: int, hal major version, e.g. 1.10 -> 1. 70 // version_minor: int, hal minor version, e.g. 1.10 -> 10. 71 // 72 // Returns: 73 // string, the driver lib name built from the arguments. 74 string GetHidlHalDriverLibName(const string& package_name, 75 const int version_major, 76 const int version_minor); 77 78 // Get the FQName for a given HIDL HAL. 79 // 80 // Args: 81 // package_name: string, name of target package. 82 // version_major: int, hal major version, e.g. 1.10 -> 1. 83 // version_minor: int, hal minor version, e.g. 1.10 -> 10. 84 // interface_name: string, name of target interface. 85 // 86 // Returns: 87 // string, the interface FQ name built from the arguments. 88 string GetInterfaceFQName(const string& package_name, const int version_major, 89 const int version_minor, 90 const string& interface_name); 91 92 // Extract package name from full hidl type name 93 // e.g. ::android::hardware::nfc::V1_0::INfc -> android.hardware.nfc 94 string GetPackageName(const string& type_name); 95 96 // Extract version from full hidl type name 97 // e.g. ::android::hardware::nfc::V1_0::INfc -> "1_0" 98 string GetVersion(const string& type_name); 99 100 // Extract major version from version string 101 // for_macro is true if the input version string has "_" 102 // e.g. "1_10" -> 1 if for_macro is true 103 // "1.10" -> 1 if for_macro is false 104 int GetVersionMajor(const string& version, bool for_macro = false); 105 106 // Extract minor version from version string 107 // for_macro is true if the input version string has "_" 108 // e.g. "1_10" -> 10 if for_macro is true 109 // "1.10" -> 10 if for_macro is false 110 int GetVersionMinor(const string& version, bool for_macro = false); 111 112 // Extract component name from full hidl type name 113 // e.g. ::android::hardware::nfc::V1_0::INfc -> INfc 114 string GetComponentName(const string& type_name); 115 116 } // namespace vts 117 } // namespace android 118 119 #endif // __VTS_SYSFUZZER_COMMON_UTILS_IFSPECUTIL_H__ 120