1"""Copyright (C) 2022 The Android Open Source Project 2 3Licensed under the Apache License, Version 2.0 (the "License"); 4you may not use this file except in compliance with the License. 5You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9Unless required by applicable law or agreed to in writing, software 10distributed under the License is distributed on an "AS IS" BASIS, 11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12See the License for the specific language governing permissions and 13limitations under the License. 14""" 15 16load("@bazel_skylib//lib:paths.bzl", "paths") 17load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") 18load(":hidl_library.bzl", "HidlInfo", "hidl_library") 19 20SRC_NAME = "src.hal" 21DEP1_NAME = "dep1.hal" 22DEP2_NAME = "dep2.hal" 23DEP3_NAME = "dep3.hal" 24ROOT = "android.hardware" 25ROOT_INTERFACE_FILE_LABEL = "//hardware/interfaces:current.txt" 26ROOT_INTERFACE_FILE = "hardware/interfaces/current.txt" 27ROOT_ARGUMENT = "android.hardware:hardware/interfaces" 28ROOT1 = "android.system" 29ROOT1_INTERFACE_FILE_LABEL = "//system/hardware/interfaces:current.txt" 30ROOT1_INTERFACE_FILE = "system/hardware/interfaces/current.txt" 31ROOT1_ARGUMENT = "android.system:system/hardware/interfaces" 32ROOT2 = "android.hidl" 33ROOT2_INTERFACE_FILE_LABEL = "//system/libhidl/transport:current.txt" 34ROOT2_INTERFACE_FILE = "system/libhidl/transport/current.txt" 35ROOT2_ARGUMENT = "android.hidl:system/libhidl/transport" 36 37def _hidl_info_simple_test_impl(ctx): 38 env = analysistest.begin(ctx) 39 target_under_test = analysistest.target_under_test(env) 40 package_root = paths.dirname(ctx.build_file_path) 41 42 asserts.equals( 43 env, 44 expected = [ 45 paths.join(package_root, "src.hal"), 46 ], 47 actual = [ 48 file.short_path 49 for file in target_under_test[HidlInfo].srcs.to_list() 50 ], 51 ) 52 53 asserts.equals( 54 env, 55 expected = sorted([ 56 paths.join(package_root, DEP1_NAME), 57 paths.join(package_root, DEP3_NAME), 58 paths.join(package_root, DEP2_NAME), 59 paths.join(package_root, SRC_NAME), 60 ]), 61 actual = sorted([ 62 file.short_path 63 for file in target_under_test[HidlInfo].transitive_srcs.to_list() 64 ]), 65 ) 66 67 asserts.equals( 68 env, 69 expected = [ 70 ROOT, 71 Label(ROOT_INTERFACE_FILE_LABEL), 72 ], 73 actual = [ 74 target_under_test[HidlInfo].root, 75 target_under_test[HidlInfo].root_interface_file.label, 76 ], 77 ) 78 79 asserts.equals( 80 env, 81 expected = sorted([ 82 ROOT1_ARGUMENT, 83 ROOT2_ARGUMENT, 84 ROOT_ARGUMENT, 85 ]), 86 actual = sorted(target_under_test[HidlInfo].transitive_roots.to_list()), 87 ) 88 89 asserts.equals( 90 env, 91 expected = sorted([ 92 ROOT1_INTERFACE_FILE, 93 ROOT2_INTERFACE_FILE, 94 ROOT_INTERFACE_FILE, 95 ]), 96 actual = sorted([ 97 file.short_path 98 for file in target_under_test[HidlInfo].transitive_root_interface_files.to_list() 99 ]), 100 ) 101 102 return analysistest.end(env) 103 104hidl_info_simple_test = analysistest.make( 105 _hidl_info_simple_test_impl, 106) 107 108def _test_hidl_info_simple(): 109 test_base_name = "hidl_info_simple" 110 test_name = test_base_name + "_test" 111 dep1 = test_base_name + "_dep1" 112 dep2 = test_base_name + "_dep2" 113 dep3 = test_base_name + "_dep3" 114 115 hidl_library( 116 name = test_base_name, 117 srcs = [SRC_NAME], 118 deps = [ 119 ":" + dep1, 120 ":" + dep2, 121 ], 122 root = ROOT, 123 root_interface_file = ROOT_INTERFACE_FILE_LABEL, 124 tags = ["manual"], 125 ) 126 hidl_library( 127 name = dep1, 128 srcs = [DEP1_NAME], 129 root = ROOT1, 130 root_interface_file = ROOT1_INTERFACE_FILE_LABEL, 131 tags = ["manual"], 132 ) 133 hidl_library( 134 name = dep2, 135 srcs = [DEP2_NAME], 136 deps = [ 137 ":" + dep3, 138 ], 139 root = ROOT2, 140 root_interface_file = ROOT2_INTERFACE_FILE_LABEL, 141 tags = ["manual"], 142 ) 143 hidl_library( 144 name = dep3, 145 srcs = [DEP3_NAME], 146 root = ROOT2, 147 root_interface_file = ROOT2_INTERFACE_FILE_LABEL, 148 tags = ["manual"], 149 ) 150 hidl_info_simple_test( 151 name = test_name, 152 target_under_test = test_base_name, 153 ) 154 155 return test_name 156 157def hidl_library_test_suite(name): 158 native.test_suite( 159 name = name, 160 tests = [ 161 _test_hidl_info_simple(), 162 ], 163 ) 164