Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
Liz Kammer | a3d7915 | 2021-10-28 18:14:04 -0400 | [diff] [blame^] | 18 | "regexp" |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 19 | "testing" |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 20 | |
| 21 | "github.com/google/blueprint" |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | var neverallowTests = []struct { |
Paul Duffin | 115445b | 2019-08-07 15:31:07 +0100 | [diff] [blame] | 25 | // The name of the test. |
| 26 | name string |
| 27 | |
| 28 | // Optional test specific rules. If specified then they are used instead of the default rules. |
| 29 | rules []Rule |
| 30 | |
| 31 | // Additional contents to add to the virtual filesystem used by the tests. |
Paul Duffin | 3c6a4ea | 2021-03-16 23:41:40 +0000 | [diff] [blame] | 32 | fs MockFS |
Paul Duffin | 115445b | 2019-08-07 15:31:07 +0100 | [diff] [blame] | 33 | |
| 34 | // The expected error patterns. If empty then no errors are expected, otherwise each error |
| 35 | // reported must be matched by at least one of these patterns. A pattern matches if the error |
| 36 | // message contains the pattern. A pattern does not have to match the whole error message. |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 37 | expectedErrors []string |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 38 | }{ |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 39 | // Test General Functionality |
| 40 | |
| 41 | // in direct deps tests |
| 42 | { |
| 43 | name: "not_allowed_in_direct_deps", |
Paul Duffin | 115445b | 2019-08-07 15:31:07 +0100 | [diff] [blame] | 44 | rules: []Rule{ |
| 45 | NeverAllow().InDirectDeps("not_allowed_in_direct_deps"), |
| 46 | }, |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 47 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 48 | "top/Android.bp": []byte(` |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 49 | cc_library { |
| 50 | name: "not_allowed_in_direct_deps", |
| 51 | }`), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 52 | "other/Android.bp": []byte(` |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 53 | cc_library { |
| 54 | name: "libother", |
| 55 | static_libs: ["not_allowed_in_direct_deps"], |
| 56 | }`), |
| 57 | }, |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 58 | expectedErrors: []string{ |
Liz Kammer | a3d7915 | 2021-10-28 18:14:04 -0400 | [diff] [blame^] | 59 | regexp.QuoteMeta("module \"libother\": violates neverallow requirements. Not allowed:\n\tdep(s): [\"not_allowed_in_direct_deps\"]"), |
| 60 | }, |
| 61 | }, |
| 62 | { |
| 63 | name: "multiple constraints", |
| 64 | rules: []Rule{ |
| 65 | NeverAllow(). |
| 66 | InDirectDeps("not_allowed_in_direct_deps"). |
| 67 | In("other"). |
| 68 | ModuleType("cc_library"). |
| 69 | NotIn("top"). |
| 70 | NotModuleType("cc_binary"), |
| 71 | }, |
| 72 | fs: map[string][]byte{ |
| 73 | "top/Android.bp": []byte(` |
| 74 | cc_library { |
| 75 | name: "not_allowed_in_direct_deps", |
| 76 | }`), |
| 77 | "other/Android.bp": []byte(` |
| 78 | cc_library { |
| 79 | name: "libother", |
| 80 | static_libs: ["not_allowed_in_direct_deps"], |
| 81 | }`), |
| 82 | }, |
| 83 | expectedErrors: []string{ |
| 84 | regexp.QuoteMeta(`module "libother": violates neverallow requirements. Not allowed: |
| 85 | in dirs: ["other/"] |
| 86 | module types: ["cc_library"] |
| 87 | dep(s): ["not_allowed_in_direct_deps"] |
| 88 | EXCEPT in dirs: ["top/"] |
| 89 | EXCEPT module types: ["cc_binary"]`), |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 90 | }, |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 91 | }, |
| 92 | |
Paul Duffin | 115445b | 2019-08-07 15:31:07 +0100 | [diff] [blame] | 93 | // Test android specific rules |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 94 | |
Paul Duffin | c811170 | 2019-07-22 12:13:55 +0100 | [diff] [blame] | 95 | // include_dir rule tests |
| 96 | { |
| 97 | name: "include_dir not allowed to reference art", |
| 98 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 99 | "other/Android.bp": []byte(` |
Paul Duffin | c811170 | 2019-07-22 12:13:55 +0100 | [diff] [blame] | 100 | cc_library { |
| 101 | name: "libother", |
| 102 | include_dirs: ["art/libdexfile/include"], |
| 103 | }`), |
| 104 | }, |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 105 | expectedErrors: []string{ |
| 106 | "all usages of 'art' have been migrated", |
| 107 | }, |
Paul Duffin | c811170 | 2019-07-22 12:13:55 +0100 | [diff] [blame] | 108 | }, |
| 109 | { |
Steven Moreland | 8fc8dbf | 2021-04-27 02:31:07 +0000 | [diff] [blame] | 110 | name: "include_dir not allowed to reference art", |
| 111 | fs: map[string][]byte{ |
| 112 | "system/libfmq/Android.bp": []byte(` |
| 113 | cc_library { |
| 114 | name: "libother", |
| 115 | include_dirs: ["any/random/file"], |
| 116 | }`), |
| 117 | }, |
| 118 | expectedErrors: []string{ |
| 119 | "all usages of them in 'system/libfmq' have been migrated", |
| 120 | }, |
| 121 | }, |
| 122 | { |
| 123 | name: "include_dir can work", |
Paul Duffin | c811170 | 2019-07-22 12:13:55 +0100 | [diff] [blame] | 124 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 125 | "other/Android.bp": []byte(` |
Paul Duffin | c811170 | 2019-07-22 12:13:55 +0100 | [diff] [blame] | 126 | cc_library { |
| 127 | name: "libother", |
| 128 | include_dirs: ["another/include"], |
| 129 | }`), |
| 130 | }, |
| 131 | }, |
| 132 | // Treble rule tests |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 133 | { |
| 134 | name: "no vndk.enabled under vendor directory", |
| 135 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 136 | "vendor/Android.bp": []byte(` |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 137 | cc_library { |
| 138 | name: "libvndk", |
| 139 | vendor_available: true, |
| 140 | vndk: { |
| 141 | enabled: true, |
| 142 | }, |
| 143 | }`), |
| 144 | }, |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 145 | expectedErrors: []string{ |
| 146 | "VNDK can never contain a library that is device dependent", |
| 147 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 148 | }, |
| 149 | { |
| 150 | name: "no vndk.enabled under device directory", |
| 151 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 152 | "device/Android.bp": []byte(` |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 153 | cc_library { |
| 154 | name: "libvndk", |
| 155 | vendor_available: true, |
| 156 | vndk: { |
| 157 | enabled: true, |
| 158 | }, |
| 159 | }`), |
| 160 | }, |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 161 | expectedErrors: []string{ |
| 162 | "VNDK can never contain a library that is device dependent", |
| 163 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 164 | }, |
Logan Chien | af29bad | 2018-03-12 16:35:58 +0800 | [diff] [blame] | 165 | { |
| 166 | name: "vndk-ext under vendor or device directory", |
| 167 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 168 | "device/Android.bp": []byte(` |
Logan Chien | af29bad | 2018-03-12 16:35:58 +0800 | [diff] [blame] | 169 | cc_library { |
| 170 | name: "libvndk1_ext", |
| 171 | vendor: true, |
| 172 | vndk: { |
| 173 | enabled: true, |
| 174 | }, |
| 175 | }`), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 176 | "vendor/Android.bp": []byte(` |
Logan Chien | af29bad | 2018-03-12 16:35:58 +0800 | [diff] [blame] | 177 | cc_library { |
| 178 | name: "libvndk2_ext", |
| 179 | vendor: true, |
| 180 | vndk: { |
| 181 | enabled: true, |
| 182 | }, |
| 183 | }`), |
| 184 | }, |
Logan Chien | af29bad | 2018-03-12 16:35:58 +0800 | [diff] [blame] | 185 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 186 | |
| 187 | { |
| 188 | name: "no enforce_vintf_manifest.cflags", |
| 189 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 190 | "Android.bp": []byte(` |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 191 | cc_library { |
| 192 | name: "libexample", |
| 193 | product_variables: { |
| 194 | enforce_vintf_manifest: { |
| 195 | cflags: ["-DSHOULD_NOT_EXIST"], |
| 196 | }, |
| 197 | }, |
| 198 | }`), |
| 199 | }, |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 200 | expectedErrors: []string{ |
| 201 | "manifest enforcement should be independent", |
| 202 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 203 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 204 | |
| 205 | { |
| 206 | name: "no treble_linker_namespaces.cflags", |
| 207 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 208 | "Android.bp": []byte(` |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 209 | cc_library { |
| 210 | name: "libexample", |
| 211 | product_variables: { |
| 212 | treble_linker_namespaces: { |
| 213 | cflags: ["-DSHOULD_NOT_EXIST"], |
| 214 | }, |
| 215 | }, |
| 216 | }`), |
| 217 | }, |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 218 | expectedErrors: []string{ |
| 219 | "nothing should care if linker namespaces are enabled or not", |
| 220 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 221 | }, |
| 222 | { |
| 223 | name: "libc_bionic_ndk treble_linker_namespaces.cflags", |
| 224 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 225 | "Android.bp": []byte(` |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 226 | cc_library { |
| 227 | name: "libc_bionic_ndk", |
| 228 | product_variables: { |
| 229 | treble_linker_namespaces: { |
| 230 | cflags: ["-DSHOULD_NOT_EXIST"], |
| 231 | }, |
| 232 | }, |
| 233 | }`), |
| 234 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 235 | }, |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 236 | { |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 237 | name: "java_device_for_host", |
| 238 | fs: map[string][]byte{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 239 | "Android.bp": []byte(` |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 240 | java_device_for_host { |
| 241 | name: "device_for_host", |
| 242 | libs: ["core-libart"], |
| 243 | }`), |
| 244 | }, |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 245 | expectedErrors: []string{ |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 246 | "java_device_for_host can only be used in allowed projects", |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 247 | }, |
Colin Cross | fd4f743 | 2019-03-05 15:06:16 -0800 | [diff] [blame] | 248 | }, |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 249 | // CC sdk rule tests |
| 250 | { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 251 | name: `"sdk_variant_only" outside allowed list`, |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 252 | fs: map[string][]byte{ |
| 253 | "Android.bp": []byte(` |
| 254 | cc_library { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 255 | name: "outside_allowed_list", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 256 | sdk_version: "current", |
| 257 | sdk_variant_only: true, |
| 258 | }`), |
| 259 | }, |
| 260 | expectedErrors: []string{ |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 261 | `module "outside_allowed_list": violates neverallow`, |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 262 | }, |
| 263 | }, |
| 264 | { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 265 | name: `"sdk_variant_only: false" outside allowed list`, |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 266 | fs: map[string][]byte{ |
| 267 | "Android.bp": []byte(` |
| 268 | cc_library { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 269 | name: "outside_allowed_list", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 270 | sdk_version: "current", |
| 271 | sdk_variant_only: false, |
| 272 | }`), |
| 273 | }, |
| 274 | expectedErrors: []string{ |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 275 | `module "outside_allowed_list": violates neverallow`, |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 276 | }, |
| 277 | }, |
| 278 | { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 279 | name: `"platform" outside allowed list`, |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 280 | fs: map[string][]byte{ |
| 281 | "Android.bp": []byte(` |
| 282 | cc_library { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 283 | name: "outside_allowed_list", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 284 | platform: { |
| 285 | shared_libs: ["libfoo"], |
| 286 | }, |
| 287 | }`), |
| 288 | }, |
| 289 | expectedErrors: []string{ |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 290 | `module "outside_allowed_list": violates neverallow`, |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 291 | }, |
| 292 | }, |
David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 293 | { |
| 294 | name: "uncompress_dex inside art", |
| 295 | fs: map[string][]byte{ |
| 296 | "art/Android.bp": []byte(` |
| 297 | java_library { |
| 298 | name: "inside_art_libraries", |
| 299 | uncompress_dex: true, |
| 300 | }`), |
| 301 | }, |
| 302 | }, |
| 303 | { |
| 304 | name: "uncompress_dex outside art", |
| 305 | fs: map[string][]byte{ |
| 306 | "other/Android.bp": []byte(` |
| 307 | java_library { |
| 308 | name: "outside_art_libraries", |
| 309 | uncompress_dex: true, |
| 310 | }`), |
| 311 | }, |
| 312 | expectedErrors: []string{ |
| 313 | "module \"outside_art_libraries\": violates neverallow", |
| 314 | }, |
| 315 | }, |
Yifan Hong | 696ed4d | 2020-07-27 12:59:58 -0700 | [diff] [blame] | 316 | { |
| 317 | name: "disallowed makefile_goal", |
| 318 | fs: map[string][]byte{ |
| 319 | "Android.bp": []byte(` |
| 320 | makefile_goal { |
| 321 | name: "foo", |
| 322 | product_out_path: "boot/trap.img" |
| 323 | } |
| 324 | `), |
| 325 | }, |
| 326 | expectedErrors: []string{ |
Yuntao Xu | feb0756 | 2021-11-18 22:33:02 +0000 | [diff] [blame] | 327 | "Only boot images and seapp contexts may be imported as a makefile goal.", |
Yifan Hong | 696ed4d | 2020-07-27 12:59:58 -0700 | [diff] [blame] | 328 | }, |
| 329 | }, |
Remi NGUYEN VAN | 1fdd6ca | 2021-12-02 19:39:35 +0900 | [diff] [blame] | 330 | { |
| 331 | name: "min_sdk too low", |
| 332 | fs: map[string][]byte{ |
| 333 | "Android.bp": []byte(` |
| 334 | java_library { |
| 335 | name: "min_sdk_too_low", |
| 336 | min_sdk_version: "30", |
| 337 | }`), |
| 338 | }, |
| 339 | rules: []Rule{ |
| 340 | NeverAllow().WithMatcher("min_sdk_version", LessThanSdkVersion("31")), |
| 341 | }, |
| 342 | expectedErrors: []string{ |
| 343 | "module \"min_sdk_too_low\": violates neverallow", |
| 344 | }, |
| 345 | }, |
| 346 | { |
| 347 | name: "min_sdk high enough", |
| 348 | fs: map[string][]byte{ |
| 349 | "Android.bp": []byte(` |
| 350 | java_library { |
| 351 | name: "min_sdk_high_enough", |
| 352 | min_sdk_version: "31", |
| 353 | }`), |
| 354 | }, |
| 355 | rules: []Rule{ |
| 356 | NeverAllow().WithMatcher("min_sdk_version", LessThanSdkVersion("31")), |
| 357 | }, |
| 358 | }, |
| 359 | { |
| 360 | name: "current min_sdk high enough", |
| 361 | fs: map[string][]byte{ |
| 362 | "Android.bp": []byte(` |
| 363 | java_library { |
| 364 | name: "current_min_sdk_high_enough", |
| 365 | min_sdk_version: "current", |
| 366 | }`), |
| 367 | }, |
| 368 | rules: []Rule{ |
| 369 | NeverAllow().WithMatcher("min_sdk_version", LessThanSdkVersion("31")), |
| 370 | }, |
| 371 | }, |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 372 | } |
| 373 | |
Paul Duffin | 3c6a4ea | 2021-03-16 23:41:40 +0000 | [diff] [blame] | 374 | var prepareForNeverAllowTest = GroupFixturePreparers( |
| 375 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 376 | ctx.RegisterModuleType("cc_library", newMockCcLibraryModule) |
| 377 | ctx.RegisterModuleType("java_library", newMockJavaLibraryModule) |
| 378 | ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule) |
| 379 | ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule) |
| 380 | ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule) |
Paul Duffin | 3c6a4ea | 2021-03-16 23:41:40 +0000 | [diff] [blame] | 381 | }), |
| 382 | ) |
| 383 | |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 384 | func TestNeverallow(t *testing.T) { |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 385 | for _, test := range neverallowTests { |
Paul Duffin | b5af620 | 2019-08-05 15:07:57 +0100 | [diff] [blame] | 386 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 387 | GroupFixturePreparers( |
| 388 | prepareForNeverAllowTest, |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 389 | PrepareForTestWithNeverallowRules(test.rules), |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 390 | test.fs.AddToFixture(), |
Paul Duffin | 3cb2c06 | 2021-03-22 19:24:26 +0000 | [diff] [blame] | 391 | ). |
| 392 | ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)). |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 393 | RunTest(t) |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 394 | }) |
| 395 | } |
| 396 | } |
| 397 | |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 398 | type mockCcLibraryProperties struct { |
Paul Duffin | c811170 | 2019-07-22 12:13:55 +0100 | [diff] [blame] | 399 | Include_dirs []string |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 400 | Vendor_available *bool |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 401 | Static_libs []string |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 402 | Sdk_version *string |
| 403 | Sdk_variant_only *bool |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 404 | |
| 405 | Vndk struct { |
| 406 | Enabled *bool |
| 407 | Support_system_process *bool |
| 408 | Extends *string |
| 409 | } |
| 410 | |
| 411 | Product_variables struct { |
| 412 | Enforce_vintf_manifest struct { |
| 413 | Cflags []string |
| 414 | } |
| 415 | |
| 416 | Treble_linker_namespaces struct { |
| 417 | Cflags []string |
| 418 | } |
| 419 | } |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 420 | |
| 421 | Platform struct { |
| 422 | Shared_libs []string |
| 423 | } |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | type mockCcLibraryModule struct { |
| 427 | ModuleBase |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 428 | properties mockCcLibraryProperties |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | func newMockCcLibraryModule() Module { |
| 432 | m := &mockCcLibraryModule{} |
| 433 | m.AddProperties(&m.properties) |
| 434 | InitAndroidModule(m) |
| 435 | return m |
| 436 | } |
| 437 | |
Paul Duffin | 3578188 | 2019-07-25 15:41:09 +0100 | [diff] [blame] | 438 | type neverallowTestDependencyTag struct { |
| 439 | blueprint.BaseDependencyTag |
| 440 | name string |
| 441 | } |
| 442 | |
| 443 | var staticDepTag = neverallowTestDependencyTag{name: "static"} |
| 444 | |
| 445 | func (c *mockCcLibraryModule) DepsMutator(ctx BottomUpMutatorContext) { |
| 446 | for _, lib := range c.properties.Static_libs { |
| 447 | ctx.AddDependency(ctx.Module(), staticDepTag, lib) |
| 448 | } |
| 449 | } |
| 450 | |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 451 | func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) { |
| 452 | } |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 453 | |
| 454 | type mockJavaLibraryProperties struct { |
Remi NGUYEN VAN | 1fdd6ca | 2021-12-02 19:39:35 +0900 | [diff] [blame] | 455 | Libs []string |
| 456 | Min_sdk_version *string |
| 457 | Sdk_version *string |
| 458 | Uncompress_dex *bool |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | type mockJavaLibraryModule struct { |
| 462 | ModuleBase |
| 463 | properties mockJavaLibraryProperties |
| 464 | } |
| 465 | |
| 466 | func newMockJavaLibraryModule() Module { |
| 467 | m := &mockJavaLibraryModule{} |
| 468 | m.AddProperties(&m.properties) |
| 469 | InitAndroidModule(m) |
| 470 | return m |
| 471 | } |
| 472 | |
Neil Fuller | df5f356 | 2018-10-21 17:19:10 +0100 | [diff] [blame] | 473 | func (p *mockJavaLibraryModule) GenerateAndroidBuildActions(ModuleContext) { |
| 474 | } |
Yifan Hong | 696ed4d | 2020-07-27 12:59:58 -0700 | [diff] [blame] | 475 | |
| 476 | type mockMakefileGoalProperties struct { |
| 477 | Product_out_path *string |
| 478 | } |
| 479 | |
| 480 | type mockMakefileGoalModule struct { |
| 481 | ModuleBase |
| 482 | properties mockMakefileGoalProperties |
| 483 | } |
| 484 | |
| 485 | func newMockMakefileGoalModule() Module { |
| 486 | m := &mockMakefileGoalModule{} |
| 487 | m.AddProperties(&m.properties) |
| 488 | InitAndroidModule(m) |
| 489 | return m |
| 490 | } |
| 491 | |
| 492 | func (p *mockMakefileGoalModule) GenerateAndroidBuildActions(ModuleContext) { |
| 493 | } |