blob: ca2f5692451ce61b672a1cdd00c58c8df465765b [file] [log] [blame]
Colin Cross0fce0ba2021-01-08 16:40:12 -08001// Copyright 2021 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
15package cc
16
17import (
18 "android/soong/android"
19 "fmt"
20 "path/filepath"
Colin Cross2e577f32021-01-22 13:06:25 -080021 "reflect"
Colin Cross0fce0ba2021-01-08 16:40:12 -080022 "strings"
23 "testing"
24)
25
26func TestVendorSnapshotCapture(t *testing.T) {
27 bp := `
28 cc_library {
29 name: "libvndk",
30 vendor_available: true,
31 product_available: true,
32 vndk: {
33 enabled: true,
34 },
35 nocrt: true,
36 }
37
38 cc_library {
39 name: "libvendor",
40 vendor: true,
41 nocrt: true,
42 }
43
44 cc_library {
45 name: "libvendor_available",
46 vendor_available: true,
47 nocrt: true,
48 }
49
50 cc_library_headers {
51 name: "libvendor_headers",
52 vendor_available: true,
53 nocrt: true,
54 }
55
56 cc_binary {
57 name: "vendor_bin",
58 vendor: true,
59 nocrt: true,
60 }
61
62 cc_binary {
63 name: "vendor_available_bin",
64 vendor_available: true,
65 nocrt: true,
66 }
67
68 toolchain_library {
69 name: "libb",
70 vendor_available: true,
71 src: "libb.a",
72 }
73
74 cc_object {
75 name: "obj",
76 vendor_available: true,
77 }
78
79 cc_library {
80 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -070081 llndk: {
82 symbol_file: "libllndk.map.txt",
83 },
Colin Cross0fce0ba2021-01-08 16:40:12 -080084 }
85`
Colin Cross203b4212021-04-26 17:19:41 -070086
Paul Duffinc3e6ce02021-03-22 23:21:32 +000087 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -080088 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +090089 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -080090 ctx := testCcWithConfig(t, config)
91
92 // Check Vendor snapshot output.
93
94 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +000095 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -080096 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
97
98 var jsonFiles []string
99
100 for _, arch := range [][]string{
101 []string{"arm64", "armv8-a"},
102 []string{"arm", "armv7-a-neon"},
103 } {
104 archType := arch[0]
105 archVariant := arch[1]
106 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
107
108 // For shared libraries, only non-VNDK vendor_available modules are captured
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900109 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800110 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400111 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
112 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800113 jsonFiles = append(jsonFiles,
114 filepath.Join(sharedDir, "libvendor.so.json"),
115 filepath.Join(sharedDir, "libvendor_available.so.json"))
116
117 // LLNDK modules are not captured
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400118 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800119
120 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
121 // Also cfi variants are captured, except for prebuilts like toolchain_library
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900122 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
123 staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800124 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400125 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
126 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
127 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
128 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
129 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
130 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
131 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800132 jsonFiles = append(jsonFiles,
133 filepath.Join(staticDir, "libb.a.json"),
134 filepath.Join(staticDir, "libvndk.a.json"),
135 filepath.Join(staticDir, "libvndk.cfi.a.json"),
136 filepath.Join(staticDir, "libvendor.a.json"),
137 filepath.Join(staticDir, "libvendor.cfi.a.json"),
138 filepath.Join(staticDir, "libvendor_available.a.json"),
139 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
140
141 // For binary executables, all vendor:true and vendor_available modules are captured.
142 if archType == "arm64" {
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900143 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800144 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400145 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
146 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800147 jsonFiles = append(jsonFiles,
148 filepath.Join(binaryDir, "vendor_bin.json"),
149 filepath.Join(binaryDir, "vendor_available_bin.json"))
150 }
151
152 // For header libraries, all vendor:true and vendor_available modules are captured.
153 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
154 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
155
156 // For object modules, all vendor:true and vendor_available modules are captured.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900157 objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800158 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400159 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800160 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
161 }
162
163 for _, jsonFile := range jsonFiles {
164 // verify all json files exist
165 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
166 t.Errorf("%q expected but not found", jsonFile)
167 }
168 }
169
170 // fake snapshot should have all outputs in the normal snapshot.
171 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
172 for _, output := range snapshotSingleton.AllOutputs() {
173 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
174 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
175 t.Errorf("%q expected but not found", fakeOutput)
176 }
177 }
178}
179
180func TestVendorSnapshotDirected(t *testing.T) {
181 bp := `
182 cc_library_shared {
183 name: "libvendor",
184 vendor: true,
185 nocrt: true,
186 }
187
188 cc_library_shared {
189 name: "libvendor_available",
190 vendor_available: true,
191 nocrt: true,
192 }
193
194 genrule {
195 name: "libfoo_gen",
196 cmd: "",
197 out: ["libfoo.so"],
198 }
199
200 cc_prebuilt_library_shared {
201 name: "libfoo",
202 vendor: true,
203 prefer: true,
204 srcs: [":libfoo_gen"],
205 }
206
207 cc_library_shared {
208 name: "libfoo",
209 vendor: true,
210 nocrt: true,
211 }
212`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000213 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800214 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900215 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800216 config.TestProductVariables.DirectedVendorSnapshot = true
217 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
218 config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
219 config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
220 ctx := testCcWithConfig(t, config)
221
222 // Check Vendor snapshot output.
223
224 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000225 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800226 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
227
228 var includeJsonFiles []string
Colin Cross0fce0ba2021-01-08 16:40:12 -0800229
230 for _, arch := range [][]string{
231 []string{"arm64", "armv8-a"},
232 []string{"arm", "armv7-a-neon"},
233 } {
234 archType := arch[0]
235 archVariant := arch[1]
236 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
237
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900238 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800239 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
240
241 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400242 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800243 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
244 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400245 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800246 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
247
Jose Galmes0a942a02021-02-03 14:23:15 -0800248 // Excluded modules. Modules not included in the directed vendor snapshot
249 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400250 CheckSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Jose Galmes0a942a02021-02-03 14:23:15 -0800251 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
Colin Cross0fce0ba2021-01-08 16:40:12 -0800252 }
253
254 // Verify that each json file for an included module has a rule.
255 for _, jsonFile := range includeJsonFiles {
256 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
257 t.Errorf("include json file %q not found", jsonFile)
258 }
259 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800260}
261
262func TestVendorSnapshotUse(t *testing.T) {
263 frameworkBp := `
264 cc_library {
265 name: "libvndk",
266 vendor_available: true,
267 product_available: true,
268 vndk: {
269 enabled: true,
270 },
271 nocrt: true,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800272 }
273
274 cc_library {
275 name: "libvendor",
276 vendor: true,
277 nocrt: true,
278 no_libcrt: true,
279 stl: "none",
280 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800281 }
282
Colin Cross2e577f32021-01-22 13:06:25 -0800283 cc_library {
284 name: "libvendor_available",
285 vendor_available: true,
286 nocrt: true,
287 no_libcrt: true,
288 stl: "none",
289 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700290 }
291
292 cc_library {
293 name: "lib32",
294 vendor: true,
295 nocrt: true,
296 no_libcrt: true,
297 stl: "none",
298 system_shared_libs: [],
299 compile_multilib: "32",
300 }
301
302 cc_library {
303 name: "lib64",
304 vendor: true,
305 nocrt: true,
306 no_libcrt: true,
307 stl: "none",
308 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800309 compile_multilib: "64",
310 }
311
Justin Yundee806f2021-05-18 23:10:00 +0900312 cc_library {
313 name: "libllndk",
314 llndk: {
315 symbol_file: "libllndk.map.txt",
316 },
317 }
318
Colin Cross0fce0ba2021-01-08 16:40:12 -0800319 cc_binary {
320 name: "bin",
321 vendor: true,
322 nocrt: true,
323 no_libcrt: true,
324 stl: "none",
325 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700326 }
327
328 cc_binary {
329 name: "bin32",
330 vendor: true,
331 nocrt: true,
332 no_libcrt: true,
333 stl: "none",
334 system_shared_libs: [],
335 compile_multilib: "32",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800336 }
337`
338
339 vndkBp := `
340 vndk_prebuilt_shared {
341 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900342 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800343 target_arch: "arm64",
344 vendor_available: true,
345 product_available: true,
346 vndk: {
347 enabled: true,
348 },
349 arch: {
350 arm64: {
351 srcs: ["libvndk.so"],
352 export_include_dirs: ["include/libvndk"],
353 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700354 arm: {
355 srcs: ["libvndk.so"],
356 export_include_dirs: ["include/libvndk"],
357 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800358 },
359 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800360
361 // old snapshot module which has to be ignored
362 vndk_prebuilt_shared {
363 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900364 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800365 target_arch: "arm64",
366 vendor_available: true,
367 product_available: true,
368 vndk: {
369 enabled: true,
370 },
371 arch: {
372 arm64: {
373 srcs: ["libvndk.so"],
374 export_include_dirs: ["include/libvndk"],
375 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700376 arm: {
377 srcs: ["libvndk.so"],
378 export_include_dirs: ["include/libvndk"],
379 },
380 },
381 }
382
383 // different arch snapshot which has to be ignored
384 vndk_prebuilt_shared {
385 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900386 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700387 target_arch: "arm",
388 vendor_available: true,
389 product_available: true,
390 vndk: {
391 enabled: true,
392 },
393 arch: {
394 arm: {
395 srcs: ["libvndk.so"],
396 export_include_dirs: ["include/libvndk"],
397 },
Colin Crosse0edaf92021-01-11 17:31:17 -0800398 },
399 }
Justin Yundee806f2021-05-18 23:10:00 +0900400
401 vndk_prebuilt_shared {
402 name: "libllndk",
403 version: "31",
404 target_arch: "arm64",
405 vendor_available: true,
406 product_available: true,
407 arch: {
408 arm64: {
409 srcs: ["libllndk.so"],
410 },
411 arm: {
412 srcs: ["libllndk.so"],
413 },
414 },
415 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800416`
417
418 vendorProprietaryBp := `
419 cc_library {
420 name: "libvendor_without_snapshot",
421 vendor: true,
422 nocrt: true,
423 no_libcrt: true,
424 stl: "none",
425 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800426 }
427
428 cc_library_shared {
429 name: "libclient",
430 vendor: true,
431 nocrt: true,
432 no_libcrt: true,
433 stl: "none",
434 system_shared_libs: [],
Justin Yundee806f2021-05-18 23:10:00 +0900435 shared_libs: ["libvndk", "libvendor_available", "libllndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800436 static_libs: ["libvendor", "libvendor_without_snapshot"],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700437 arch: {
438 arm64: {
439 shared_libs: ["lib64"],
440 },
441 arm: {
442 shared_libs: ["lib32"],
443 },
444 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800445 srcs: ["client.cpp"],
446 }
447
Inseob Kimf7aadf72021-04-13 10:15:31 +0900448 cc_library_shared {
449 name: "libclient_cfi",
450 vendor: true,
451 nocrt: true,
452 no_libcrt: true,
453 stl: "none",
454 system_shared_libs: [],
455 static_libs: ["libvendor"],
456 sanitize: {
457 cfi: true,
458 },
459 srcs: ["client.cpp"],
460 }
461
Justin Yun27b95722021-07-28 17:04:44 +0900462 cc_library_shared {
463 name: "libvndkext",
464 vendor: true,
465 nocrt: true,
466 no_libcrt: true,
467 stl: "none",
468 system_shared_libs: [],
469 vndk: {
470 extends: "libvndk",
471 enabled: true,
472 }
473 }
474
Colin Cross0fce0ba2021-01-08 16:40:12 -0800475 cc_binary {
476 name: "bin_without_snapshot",
477 vendor: true,
478 nocrt: true,
479 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900480 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800481 system_shared_libs: [],
482 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800483 srcs: ["bin.cpp"],
484 }
485
Colin Crosse0edaf92021-01-11 17:31:17 -0800486 vendor_snapshot {
487 name: "vendor_snapshot",
Justin Yundee806f2021-05-18 23:10:00 +0900488 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700489 arch: {
490 arm64: {
491 vndk_libs: [
492 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900493 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700494 ],
495 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900496 "libc++_static",
497 "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900498 "libunwind",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700499 "libvendor",
500 "libvendor_available",
501 "libvndk",
502 "lib64",
503 ],
504 shared_libs: [
505 "libvendor",
506 "libvendor_available",
507 "lib64",
508 ],
509 binaries: [
510 "bin",
511 ],
512 },
513 arm: {
514 vndk_libs: [
515 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900516 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700517 ],
518 static_libs: [
519 "libvendor",
520 "libvendor_available",
521 "libvndk",
522 "lib32",
523 ],
524 shared_libs: [
525 "libvendor",
526 "libvendor_available",
527 "lib32",
528 ],
529 binaries: [
530 "bin32",
531 ],
532 },
533 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800534 }
535
Colin Cross0fce0ba2021-01-08 16:40:12 -0800536 vendor_snapshot_static {
537 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900538 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800539 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700540 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800541 vendor: true,
542 arch: {
543 arm64: {
544 src: "libvndk.a",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800545 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700546 arm: {
547 src: "libvndk.a",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700548 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800549 },
Inseob Kimdd0295d2021-04-12 21:09:59 +0900550 shared_libs: ["libvndk"],
551 export_shared_lib_headers: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800552 }
553
554 vendor_snapshot_shared {
555 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900556 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800557 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700558 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800559 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900560 shared_libs: [
561 "libvendor_without_snapshot",
562 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900563 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900564 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800565 arch: {
566 arm64: {
567 src: "libvendor.so",
568 export_include_dirs: ["include/libvendor"],
569 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700570 arm: {
571 src: "libvendor.so",
572 export_include_dirs: ["include/libvendor"],
573 },
574 },
575 }
576
577 vendor_snapshot_static {
578 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900579 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700580 target_arch: "arm64",
581 compile_multilib: "32",
582 vendor: true,
583 arch: {
584 arm: {
585 src: "lib32.a",
586 },
587 },
588 }
589
590 vendor_snapshot_shared {
591 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900592 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700593 target_arch: "arm64",
594 compile_multilib: "32",
595 vendor: true,
596 arch: {
597 arm: {
598 src: "lib32.so",
599 },
600 },
601 }
602
603 vendor_snapshot_static {
604 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900605 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700606 target_arch: "arm64",
607 compile_multilib: "64",
608 vendor: true,
609 arch: {
610 arm64: {
611 src: "lib64.a",
612 },
613 },
614 }
615
616 vendor_snapshot_shared {
617 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900618 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700619 target_arch: "arm64",
620 compile_multilib: "64",
621 vendor: true,
622 arch: {
623 arm64: {
624 src: "lib64.so",
625 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800626 },
627 }
628
629 vendor_snapshot_static {
630 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900631 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800632 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700633 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800634 vendor: true,
635 arch: {
636 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900637 cfi: {
638 src: "libvendor.cfi.a",
639 export_include_dirs: ["include/libvendor_cfi"],
640 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800641 src: "libvendor.a",
642 export_include_dirs: ["include/libvendor"],
643 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700644 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900645 cfi: {
646 src: "libvendor.cfi.a",
647 export_include_dirs: ["include/libvendor_cfi"],
648 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700649 src: "libvendor.a",
650 export_include_dirs: ["include/libvendor"],
651 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800652 },
653 }
654
Colin Cross2e577f32021-01-22 13:06:25 -0800655 vendor_snapshot_shared {
656 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900657 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800658 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700659 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800660 vendor: true,
661 arch: {
662 arm64: {
663 src: "libvendor_available.so",
664 export_include_dirs: ["include/libvendor"],
665 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700666 arm: {
667 src: "libvendor_available.so",
668 export_include_dirs: ["include/libvendor"],
669 },
Colin Cross2e577f32021-01-22 13:06:25 -0800670 },
671 }
672
673 vendor_snapshot_static {
674 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900675 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800676 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700677 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800678 vendor: true,
679 arch: {
680 arm64: {
681 src: "libvendor_available.a",
682 export_include_dirs: ["include/libvendor"],
683 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700684 arm: {
685 src: "libvendor_available.so",
686 export_include_dirs: ["include/libvendor"],
687 },
Colin Cross2e577f32021-01-22 13:06:25 -0800688 },
689 }
690
Inseob Kimd4c9f552021-04-08 19:28:28 +0900691 vendor_snapshot_static {
692 name: "libc++_static",
Justin Yundee806f2021-05-18 23:10:00 +0900693 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900694 target_arch: "arm64",
695 compile_multilib: "64",
696 vendor: true,
697 arch: {
698 arm64: {
699 src: "libc++_static.a",
700 },
701 },
702 }
703
704 vendor_snapshot_static {
705 name: "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900706 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900707 target_arch: "arm64",
708 compile_multilib: "64",
709 vendor: true,
710 arch: {
711 arm64: {
712 src: "libc++demangle.a",
713 },
714 },
715 }
716
717 vendor_snapshot_static {
Justin Yundee806f2021-05-18 23:10:00 +0900718 name: "libunwind",
719 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900720 target_arch: "arm64",
721 compile_multilib: "64",
722 vendor: true,
723 arch: {
724 arm64: {
Justin Yundee806f2021-05-18 23:10:00 +0900725 src: "libunwind.a",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900726 },
727 },
728 }
729
Colin Cross0fce0ba2021-01-08 16:40:12 -0800730 vendor_snapshot_binary {
731 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900732 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800733 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700734 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800735 vendor: true,
736 arch: {
737 arm64: {
738 src: "bin",
739 },
740 },
741 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800742
Jose Galmesf9523ed2021-04-06 19:48:10 -0700743 vendor_snapshot_binary {
744 name: "bin32",
Justin Yundee806f2021-05-18 23:10:00 +0900745 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700746 target_arch: "arm64",
747 compile_multilib: "32",
748 vendor: true,
749 arch: {
750 arm: {
751 src: "bin32",
752 },
753 },
754 }
755
Colin Crosse0edaf92021-01-11 17:31:17 -0800756 // old snapshot module which has to be ignored
757 vendor_snapshot_binary {
758 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900759 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800760 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700761 compile_multilib: "first",
762 vendor: true,
763 arch: {
764 arm64: {
765 src: "bin",
766 },
767 },
768 }
769
770 // different arch snapshot which has to be ignored
771 vendor_snapshot_binary {
772 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900773 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700774 target_arch: "arm",
775 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800776 vendor: true,
777 arch: {
778 arm64: {
779 src: "bin",
780 },
781 },
782 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800783`
784 depsBp := GatherRequiredDepsForTest(android.Android)
785
786 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900787 "deps/Android.bp": []byte(depsBp),
788 "framework/Android.bp": []byte(frameworkBp),
789 "framework/symbol.txt": nil,
790 "vendor/Android.bp": []byte(vendorProprietaryBp),
791 "vendor/bin": nil,
792 "vendor/bin32": nil,
793 "vendor/bin.cpp": nil,
794 "vendor/client.cpp": nil,
795 "vendor/include/libvndk/a.h": nil,
796 "vendor/include/libvendor/b.h": nil,
797 "vendor/include/libvendor_cfi/c.h": nil,
798 "vendor/libc++_static.a": nil,
799 "vendor/libc++demangle.a": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900800 "vendor/libunwind.a": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900801 "vendor/libvndk.a": nil,
802 "vendor/libvendor.a": nil,
803 "vendor/libvendor.cfi.a": nil,
804 "vendor/libvendor.so": nil,
805 "vendor/lib32.a": nil,
806 "vendor/lib32.so": nil,
807 "vendor/lib64.a": nil,
808 "vendor/lib64.so": nil,
809 "vndk/Android.bp": []byte(vndkBp),
810 "vndk/include/libvndk/a.h": nil,
811 "vndk/libvndk.so": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900812 "vndk/libllndk.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800813 }
814
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000815 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Justin Yundee806f2021-05-18 23:10:00 +0900816 config.TestProductVariables.DeviceVndkVersion = StringPtr("31")
817 config.TestProductVariables.Platform_vndk_version = StringPtr("32")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800818 ctx := CreateTestContext(config)
819 ctx.Register()
820
821 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
822 android.FailIfErrored(t, errs)
823 _, errs = ctx.PrepareBuildActions(config)
824 android.FailIfErrored(t, errs)
825
Justin Yundee806f2021-05-18 23:10:00 +0900826 sharedVariant := "android_vendor.31_arm64_armv8-a_shared"
827 staticVariant := "android_vendor.31_arm64_armv8-a_static"
828 binaryVariant := "android_vendor.31_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800829
Justin Yundee806f2021-05-18 23:10:00 +0900830 sharedCfiVariant := "android_vendor.31_arm64_armv8-a_shared_cfi"
831 staticCfiVariant := "android_vendor.31_arm64_armv8-a_static_cfi"
Inseob Kimf7aadf72021-04-13 10:15:31 +0900832
Justin Yundee806f2021-05-18 23:10:00 +0900833 shared32Variant := "android_vendor.31_arm_armv7-a-neon_shared"
834 binary32Variant := "android_vendor.31_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700835
Justin Yundee806f2021-05-18 23:10:00 +0900836 // libclient uses libvndk.vndk.31.arm64, libvendor.vendor_static.31.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800837 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
838 for _, includeFlags := range []string{
839 "-Ivndk/include/libvndk", // libvndk
840 "-Ivendor/include/libvendor", // libvendor
841 } {
842 if !strings.Contains(libclientCcFlags, includeFlags) {
843 t.Errorf("flags for libclient must contain %#v, but was %#v.",
844 includeFlags, libclientCcFlags)
845 }
846 }
847
848 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
849 for _, input := range [][]string{
Justin Yundee806f2021-05-18 23:10:00 +0900850 []string{sharedVariant, "libvndk.vndk.31.arm64"},
851 []string{sharedVariant, "libllndk.vndk.31.arm64"},
852 []string{staticVariant, "libvendor.vendor_static.31.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800853 []string{staticVariant, "libvendor_without_snapshot"},
854 } {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400855 outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800856 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
857 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
858 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400859
Colin Cross0fce0ba2021-01-08 16:40:12 -0800860 }
861
Colin Cross2e577f32021-01-22 13:06:25 -0800862 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900863 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800864 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
865 }
866
867 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
868 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
869 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
870 }
871
Jose Galmesf9523ed2021-04-06 19:48:10 -0700872 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900873 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700874 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
875 }
876
Justin Yundee806f2021-05-18 23:10:00 +0900877 // libclient_cfi uses libvendor.vendor_static.31.arm64's cfi variant
Inseob Kimf7aadf72021-04-13 10:15:31 +0900878 libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
879 if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
880 t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
881 "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
882 }
883
884 libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400885 libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"})
Inseob Kimf7aadf72021-04-13 10:15:31 +0900886 if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
887 t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
888 }
889
Justin Yundee806f2021-05-18 23:10:00 +0900890 // bin_without_snapshot uses libvndk.vendor_static.31.arm64 (which reexports vndk's exported headers)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800891 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
Inseob Kimdd0295d2021-04-12 21:09:59 +0900892 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
Colin Cross0fce0ba2021-01-08 16:40:12 -0800893 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
894 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
895 }
896
897 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400898 libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800899 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
900 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
901 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
902 }
903
Justin Yundee806f2021-05-18 23:10:00 +0900904 // libvendor.so is installed by libvendor.vendor_shared.31.arm64
905 ctx.ModuleForTests("libvendor.vendor_shared.31.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800906
Justin Yundee806f2021-05-18 23:10:00 +0900907 // lib64.so is installed by lib64.vendor_shared.31.arm64
908 ctx.ModuleForTests("lib64.vendor_shared.31.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700909
Justin Yundee806f2021-05-18 23:10:00 +0900910 // lib32.so is installed by lib32.vendor_shared.31.arm64
911 ctx.ModuleForTests("lib32.vendor_shared.31.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700912
Justin Yundee806f2021-05-18 23:10:00 +0900913 // libvendor_available.so is installed by libvendor_available.vendor_shared.31.arm64
914 ctx.ModuleForTests("libvendor_available.vendor_shared.31.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800915
Colin Cross0fce0ba2021-01-08 16:40:12 -0800916 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
917 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
918
Justin Yundee806f2021-05-18 23:10:00 +0900919 // bin is installed by bin.vendor_binary.31.arm64
920 ctx.ModuleForTests("bin.vendor_binary.31.arm64", binaryVariant).Output("bin")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800921
Justin Yundee806f2021-05-18 23:10:00 +0900922 // bin32 is installed by bin32.vendor_binary.31.arm64
923 ctx.ModuleForTests("bin32.vendor_binary.31.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700924
Colin Cross0fce0ba2021-01-08 16:40:12 -0800925 // bin_without_snapshot is installed by bin_without_snapshot
926 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
927
Justin Yundee806f2021-05-18 23:10:00 +0900928 // libvendor, libvendor_available and bin don't have vendor.31 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800929 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
930 if inList(sharedVariant, libvendorVariants) {
931 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
932 }
933
Colin Cross2e577f32021-01-22 13:06:25 -0800934 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
935 if inList(sharedVariant, libvendorAvailableVariants) {
936 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
937 }
938
Colin Cross0fce0ba2021-01-08 16:40:12 -0800939 binVariants := ctx.ModuleVariantsForTests("bin")
940 if inList(binaryVariant, binVariants) {
941 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
942 }
943}
944
945func TestVendorSnapshotSanitizer(t *testing.T) {
946 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +0900947 vendor_snapshot {
948 name: "vendor_snapshot",
949 version: "28",
950 arch: {
951 arm64: {
952 static_libs: [
953 "libsnapshot",
954 "note_memtag_heap_sync",
955 ],
956 },
957 },
958 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800959 vendor_snapshot_static {
960 name: "libsnapshot",
961 vendor: true,
962 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900963 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800964 arch: {
965 arm64: {
966 src: "libsnapshot.a",
967 cfi: {
968 src: "libsnapshot.cfi.a",
969 }
970 },
971 },
972 }
Inseob Kim253f5212021-04-08 17:10:31 +0900973
974 vendor_snapshot_static {
975 name: "note_memtag_heap_sync",
976 vendor: true,
977 target_arch: "arm64",
978 version: "28",
979 arch: {
980 arm64: {
981 src: "note_memtag_heap_sync.a",
982 },
983 },
984 }
985
986 cc_test {
987 name: "vstest",
988 gtest: false,
989 vendor: true,
990 compile_multilib: "64",
991 nocrt: true,
992 no_libcrt: true,
993 stl: "none",
994 static_libs: ["libsnapshot"],
995 system_shared_libs: [],
996 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800997`
Inseob Kim253f5212021-04-08 17:10:31 +0900998
999 mockFS := map[string][]byte{
1000 "vendor/Android.bp": []byte(bp),
1001 "vendor/libc++demangle.a": nil,
1002 "vendor/libsnapshot.a": nil,
1003 "vendor/libsnapshot.cfi.a": nil,
1004 "vendor/note_memtag_heap_sync.a": nil,
1005 }
1006
1007 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001008 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
1009 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001010 ctx := testCcWithConfig(t, config)
1011
1012 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001013 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1014 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001015
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001016 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001017 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1018
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001019 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001020 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1021}
1022
Colin Cross0fce0ba2021-01-08 16:40:12 -08001023func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
1024 t.Helper()
1025 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
1026 if m.ExcludeFromRecoverySnapshot() != expected {
1027 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
1028 }
1029}
1030
1031func TestVendorSnapshotExclude(t *testing.T) {
1032
1033 // This test verifies that the exclude_from_vendor_snapshot property
1034 // makes its way from the Android.bp source file into the module data
1035 // structure. It also verifies that modules are correctly included or
1036 // excluded in the vendor snapshot based on their path (framework or
1037 // vendor) and the exclude_from_vendor_snapshot property.
1038
1039 frameworkBp := `
1040 cc_library_shared {
1041 name: "libinclude",
1042 srcs: ["src/include.cpp"],
1043 vendor_available: true,
1044 }
1045 cc_library_shared {
1046 name: "libexclude",
1047 srcs: ["src/exclude.cpp"],
1048 vendor: true,
1049 exclude_from_vendor_snapshot: true,
1050 }
1051 cc_library_shared {
1052 name: "libavailable_exclude",
1053 srcs: ["src/exclude.cpp"],
1054 vendor_available: true,
1055 exclude_from_vendor_snapshot: true,
1056 }
1057 `
1058
1059 vendorProprietaryBp := `
1060 cc_library_shared {
1061 name: "libvendor",
1062 srcs: ["vendor.cpp"],
1063 vendor: true,
1064 }
1065 `
1066
1067 depsBp := GatherRequiredDepsForTest(android.Android)
1068
1069 mockFS := map[string][]byte{
1070 "deps/Android.bp": []byte(depsBp),
1071 "framework/Android.bp": []byte(frameworkBp),
1072 "framework/include.cpp": nil,
1073 "framework/exclude.cpp": nil,
1074 "device/Android.bp": []byte(vendorProprietaryBp),
1075 "device/vendor.cpp": nil,
1076 }
1077
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001078 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001079 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001080 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001081 ctx := CreateTestContext(config)
1082 ctx.Register()
1083
1084 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1085 android.FailIfErrored(t, errs)
1086 _, errs = ctx.PrepareBuildActions(config)
1087 android.FailIfErrored(t, errs)
1088
1089 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001090 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1091 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1092 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001093
1094 // A vendor module is excluded, but by its path, not the
1095 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001096 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001097
1098 // Verify the content of the vendor snapshot.
1099
1100 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001101 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001102 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1103
1104 var includeJsonFiles []string
1105 var excludeJsonFiles []string
1106
1107 for _, arch := range [][]string{
1108 []string{"arm64", "armv8-a"},
1109 []string{"arm", "armv7-a-neon"},
1110 } {
1111 archType := arch[0]
1112 archVariant := arch[1]
1113 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1114
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001115 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001116 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1117
1118 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001119 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001120 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1121
1122 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001123 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001124 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001125 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001126 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001127 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001128 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1129 }
1130
1131 // Verify that each json file for an included module has a rule.
1132 for _, jsonFile := range includeJsonFiles {
1133 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1134 t.Errorf("include json file %q not found", jsonFile)
1135 }
1136 }
1137
1138 // Verify that each json file for an excluded module has no rule.
1139 for _, jsonFile := range excludeJsonFiles {
1140 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1141 t.Errorf("exclude json file %q found", jsonFile)
1142 }
1143 }
1144}
1145
1146func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1147
1148 // This test verifies that using the exclude_from_vendor_snapshot
1149 // property on a module in a vendor proprietary path generates an
1150 // error. These modules are already excluded, so we prohibit using the
1151 // property in this way, which could add to confusion.
1152
1153 vendorProprietaryBp := `
1154 cc_library_shared {
1155 name: "libvendor",
1156 srcs: ["vendor.cpp"],
1157 vendor: true,
1158 exclude_from_vendor_snapshot: true,
1159 }
1160 `
1161
1162 depsBp := GatherRequiredDepsForTest(android.Android)
1163
1164 mockFS := map[string][]byte{
1165 "deps/Android.bp": []byte(depsBp),
1166 "device/Android.bp": []byte(vendorProprietaryBp),
1167 "device/vendor.cpp": nil,
1168 }
1169
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001170 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001171 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001172 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001173 ctx := CreateTestContext(config)
1174 ctx.Register()
1175
1176 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1177 android.FailIfErrored(t, errs)
1178
1179 _, errs = ctx.PrepareBuildActions(config)
1180 android.CheckErrorsAgainstExpectations(t, errs, []string{
1181 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1182 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1183 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1184 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1185 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1186 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1187 })
1188}
1189
1190func TestRecoverySnapshotCapture(t *testing.T) {
1191 bp := `
1192 cc_library {
1193 name: "libvndk",
1194 vendor_available: true,
1195 recovery_available: true,
1196 product_available: true,
1197 vndk: {
1198 enabled: true,
1199 },
1200 nocrt: true,
1201 }
1202
1203 cc_library {
1204 name: "librecovery",
1205 recovery: true,
1206 nocrt: true,
1207 }
1208
1209 cc_library {
1210 name: "librecovery_available",
1211 recovery_available: true,
1212 nocrt: true,
1213 }
1214
1215 cc_library_headers {
1216 name: "librecovery_headers",
1217 recovery_available: true,
1218 nocrt: true,
1219 }
1220
1221 cc_binary {
1222 name: "recovery_bin",
1223 recovery: true,
1224 nocrt: true,
1225 }
1226
1227 cc_binary {
1228 name: "recovery_available_bin",
1229 recovery_available: true,
1230 nocrt: true,
1231 }
1232
1233 toolchain_library {
1234 name: "libb",
1235 recovery_available: true,
1236 src: "libb.a",
1237 }
1238
1239 cc_object {
1240 name: "obj",
1241 recovery_available: true,
1242 }
1243`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001244 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001245 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001246 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001247 ctx := testCcWithConfig(t, config)
1248
1249 // Check Recovery snapshot output.
1250
1251 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001252 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001253 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1254
1255 var jsonFiles []string
1256
1257 for _, arch := range [][]string{
1258 []string{"arm64", "armv8-a"},
1259 } {
1260 archType := arch[0]
1261 archVariant := arch[1]
1262 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1263
1264 // For shared libraries, only recovery_available modules are captured.
1265 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1266 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001267 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1268 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1269 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001270 jsonFiles = append(jsonFiles,
1271 filepath.Join(sharedDir, "libvndk.so.json"),
1272 filepath.Join(sharedDir, "librecovery.so.json"),
1273 filepath.Join(sharedDir, "librecovery_available.so.json"))
1274
1275 // For static libraries, all recovery:true and recovery_available modules are captured.
1276 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1277 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001278 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1279 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1280 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001281 jsonFiles = append(jsonFiles,
1282 filepath.Join(staticDir, "libb.a.json"),
1283 filepath.Join(staticDir, "librecovery.a.json"),
1284 filepath.Join(staticDir, "librecovery_available.a.json"))
1285
1286 // For binary executables, all recovery:true and recovery_available modules are captured.
1287 if archType == "arm64" {
1288 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1289 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001290 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1291 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001292 jsonFiles = append(jsonFiles,
1293 filepath.Join(binaryDir, "recovery_bin.json"),
1294 filepath.Join(binaryDir, "recovery_available_bin.json"))
1295 }
1296
1297 // For header libraries, all vendor:true and vendor_available modules are captured.
1298 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1299 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1300
1301 // For object modules, all vendor:true and vendor_available modules are captured.
1302 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1303 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001304 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001305 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1306 }
1307
1308 for _, jsonFile := range jsonFiles {
1309 // verify all json files exist
1310 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1311 t.Errorf("%q expected but not found", jsonFile)
1312 }
1313 }
1314}
1315
1316func TestRecoverySnapshotExclude(t *testing.T) {
1317 // This test verifies that the exclude_from_recovery_snapshot property
1318 // makes its way from the Android.bp source file into the module data
1319 // structure. It also verifies that modules are correctly included or
1320 // excluded in the recovery snapshot based on their path (framework or
1321 // vendor) and the exclude_from_recovery_snapshot property.
1322
1323 frameworkBp := `
1324 cc_library_shared {
1325 name: "libinclude",
1326 srcs: ["src/include.cpp"],
1327 recovery_available: true,
1328 }
1329 cc_library_shared {
1330 name: "libexclude",
1331 srcs: ["src/exclude.cpp"],
1332 recovery: true,
1333 exclude_from_recovery_snapshot: true,
1334 }
1335 cc_library_shared {
1336 name: "libavailable_exclude",
1337 srcs: ["src/exclude.cpp"],
1338 recovery_available: true,
1339 exclude_from_recovery_snapshot: true,
1340 }
1341 `
1342
1343 vendorProprietaryBp := `
1344 cc_library_shared {
1345 name: "librecovery",
1346 srcs: ["recovery.cpp"],
1347 recovery: true,
1348 }
1349 `
1350
1351 depsBp := GatherRequiredDepsForTest(android.Android)
1352
1353 mockFS := map[string][]byte{
1354 "deps/Android.bp": []byte(depsBp),
1355 "framework/Android.bp": []byte(frameworkBp),
1356 "framework/include.cpp": nil,
1357 "framework/exclude.cpp": nil,
1358 "device/Android.bp": []byte(vendorProprietaryBp),
1359 "device/recovery.cpp": nil,
1360 }
1361
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001362 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001363 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001364 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001365 ctx := CreateTestContext(config)
1366 ctx.Register()
1367
1368 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1369 android.FailIfErrored(t, errs)
1370 _, errs = ctx.PrepareBuildActions(config)
1371 android.FailIfErrored(t, errs)
1372
1373 // Test an include and exclude framework module.
1374 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1375 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1376 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
1377
1378 // A recovery module is excluded, but by its path, not the
1379 // exclude_from_recovery_snapshot property.
1380 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
1381
1382 // Verify the content of the recovery snapshot.
1383
1384 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001385 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001386 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1387
1388 var includeJsonFiles []string
1389 var excludeJsonFiles []string
1390
1391 for _, arch := range [][]string{
1392 []string{"arm64", "armv8-a"},
1393 } {
1394 archType := arch[0]
1395 archVariant := arch[1]
1396 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1397
1398 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1399 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1400
1401 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001402 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001403 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1404
1405 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001406 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001407 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001408 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001409 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001410 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001411 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1412 }
1413
1414 // Verify that each json file for an included module has a rule.
1415 for _, jsonFile := range includeJsonFiles {
1416 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1417 t.Errorf("include json file %q not found", jsonFile)
1418 }
1419 }
1420
1421 // Verify that each json file for an excluded module has no rule.
1422 for _, jsonFile := range excludeJsonFiles {
1423 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1424 t.Errorf("exclude json file %q found", jsonFile)
1425 }
1426 }
1427}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001428
1429func TestRecoverySnapshotDirected(t *testing.T) {
1430 bp := `
1431 cc_library_shared {
1432 name: "librecovery",
1433 recovery: true,
1434 nocrt: true,
1435 }
1436
1437 cc_library_shared {
1438 name: "librecovery_available",
1439 recovery_available: true,
1440 nocrt: true,
1441 }
1442
1443 genrule {
1444 name: "libfoo_gen",
1445 cmd: "",
1446 out: ["libfoo.so"],
1447 }
1448
1449 cc_prebuilt_library_shared {
1450 name: "libfoo",
1451 recovery: true,
1452 prefer: true,
1453 srcs: [":libfoo_gen"],
1454 }
1455
1456 cc_library_shared {
1457 name: "libfoo",
1458 recovery: true,
1459 nocrt: true,
1460 }
1461`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001462 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001463 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1464 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001465 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001466 config.TestProductVariables.DirectedRecoverySnapshot = true
1467 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1468 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1469 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1470 ctx := testCcWithConfig(t, config)
1471
1472 // Check recovery snapshot output.
1473
1474 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001475 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001476 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1477
1478 var includeJsonFiles []string
1479
1480 for _, arch := range [][]string{
1481 []string{"arm64", "armv8-a"},
1482 } {
1483 archType := arch[0]
1484 archVariant := arch[1]
1485 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1486
1487 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1488 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1489
1490 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001491 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001492 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1493 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001494 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001495 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1496
1497 // Excluded modules. Modules not included in the directed recovery snapshot
1498 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001499 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001500 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1501 }
1502
1503 // Verify that each json file for an included module has a rule.
1504 for _, jsonFile := range includeJsonFiles {
1505 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1506 t.Errorf("include json file %q not found", jsonFile)
1507 }
1508 }
1509}