blob: b5022c8d26d1733146eb483f1dda85d3d49adf5c [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 TestVendorSnapshotExclude(t *testing.T) {
1024
1025 // This test verifies that the exclude_from_vendor_snapshot property
1026 // makes its way from the Android.bp source file into the module data
1027 // structure. It also verifies that modules are correctly included or
1028 // excluded in the vendor snapshot based on their path (framework or
1029 // vendor) and the exclude_from_vendor_snapshot property.
1030
1031 frameworkBp := `
1032 cc_library_shared {
1033 name: "libinclude",
1034 srcs: ["src/include.cpp"],
1035 vendor_available: true,
1036 }
1037 cc_library_shared {
1038 name: "libexclude",
1039 srcs: ["src/exclude.cpp"],
1040 vendor: true,
1041 exclude_from_vendor_snapshot: true,
1042 }
1043 cc_library_shared {
1044 name: "libavailable_exclude",
1045 srcs: ["src/exclude.cpp"],
1046 vendor_available: true,
1047 exclude_from_vendor_snapshot: true,
1048 }
1049 `
1050
1051 vendorProprietaryBp := `
1052 cc_library_shared {
1053 name: "libvendor",
1054 srcs: ["vendor.cpp"],
1055 vendor: true,
1056 }
1057 `
1058
1059 depsBp := GatherRequiredDepsForTest(android.Android)
1060
1061 mockFS := map[string][]byte{
1062 "deps/Android.bp": []byte(depsBp),
1063 "framework/Android.bp": []byte(frameworkBp),
1064 "framework/include.cpp": nil,
1065 "framework/exclude.cpp": nil,
1066 "device/Android.bp": []byte(vendorProprietaryBp),
1067 "device/vendor.cpp": nil,
1068 }
1069
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001070 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001071 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001072 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001073 ctx := CreateTestContext(config)
1074 ctx.Register()
1075
1076 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1077 android.FailIfErrored(t, errs)
1078 _, errs = ctx.PrepareBuildActions(config)
1079 android.FailIfErrored(t, errs)
1080
1081 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001082 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1083 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1084 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001085
1086 // A vendor module is excluded, but by its path, not the
1087 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001088 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001089
1090 // Verify the content of the vendor snapshot.
1091
1092 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001093 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001094 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1095
1096 var includeJsonFiles []string
1097 var excludeJsonFiles []string
1098
1099 for _, arch := range [][]string{
1100 []string{"arm64", "armv8-a"},
1101 []string{"arm", "armv7-a-neon"},
1102 } {
1103 archType := arch[0]
1104 archVariant := arch[1]
1105 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1106
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001107 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001108 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1109
1110 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001111 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001112 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1113
1114 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001115 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001116 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001117 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001118 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001119 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001120 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1121 }
1122
1123 // Verify that each json file for an included module has a rule.
1124 for _, jsonFile := range includeJsonFiles {
1125 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1126 t.Errorf("include json file %q not found", jsonFile)
1127 }
1128 }
1129
1130 // Verify that each json file for an excluded module has no rule.
1131 for _, jsonFile := range excludeJsonFiles {
1132 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1133 t.Errorf("exclude json file %q found", jsonFile)
1134 }
1135 }
1136}
1137
1138func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1139
1140 // This test verifies that using the exclude_from_vendor_snapshot
1141 // property on a module in a vendor proprietary path generates an
1142 // error. These modules are already excluded, so we prohibit using the
1143 // property in this way, which could add to confusion.
1144
1145 vendorProprietaryBp := `
1146 cc_library_shared {
1147 name: "libvendor",
1148 srcs: ["vendor.cpp"],
1149 vendor: true,
1150 exclude_from_vendor_snapshot: true,
1151 }
1152 `
1153
1154 depsBp := GatherRequiredDepsForTest(android.Android)
1155
1156 mockFS := map[string][]byte{
1157 "deps/Android.bp": []byte(depsBp),
1158 "device/Android.bp": []byte(vendorProprietaryBp),
1159 "device/vendor.cpp": nil,
1160 }
1161
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001162 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001163 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001164 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001165 ctx := CreateTestContext(config)
1166 ctx.Register()
1167
1168 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1169 android.FailIfErrored(t, errs)
1170
1171 _, errs = ctx.PrepareBuildActions(config)
1172 android.CheckErrorsAgainstExpectations(t, errs, []string{
1173 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1174 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1175 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1176 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1177 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1178 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1179 })
1180}
1181
1182func TestRecoverySnapshotCapture(t *testing.T) {
1183 bp := `
1184 cc_library {
1185 name: "libvndk",
1186 vendor_available: true,
1187 recovery_available: true,
1188 product_available: true,
1189 vndk: {
1190 enabled: true,
1191 },
1192 nocrt: true,
1193 }
1194
1195 cc_library {
1196 name: "librecovery",
1197 recovery: true,
1198 nocrt: true,
1199 }
1200
1201 cc_library {
1202 name: "librecovery_available",
1203 recovery_available: true,
1204 nocrt: true,
1205 }
1206
1207 cc_library_headers {
1208 name: "librecovery_headers",
1209 recovery_available: true,
1210 nocrt: true,
1211 }
1212
1213 cc_binary {
1214 name: "recovery_bin",
1215 recovery: true,
1216 nocrt: true,
1217 }
1218
1219 cc_binary {
1220 name: "recovery_available_bin",
1221 recovery_available: true,
1222 nocrt: true,
1223 }
1224
1225 toolchain_library {
1226 name: "libb",
1227 recovery_available: true,
1228 src: "libb.a",
1229 }
1230
1231 cc_object {
1232 name: "obj",
1233 recovery_available: true,
1234 }
1235`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001236 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001237 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001238 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001239 ctx := testCcWithConfig(t, config)
1240
1241 // Check Recovery snapshot output.
1242
1243 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001244 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001245 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1246
1247 var jsonFiles []string
1248
1249 for _, arch := range [][]string{
1250 []string{"arm64", "armv8-a"},
1251 } {
1252 archType := arch[0]
1253 archVariant := arch[1]
1254 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1255
1256 // For shared libraries, only recovery_available modules are captured.
1257 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1258 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001259 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1260 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1261 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001262 jsonFiles = append(jsonFiles,
1263 filepath.Join(sharedDir, "libvndk.so.json"),
1264 filepath.Join(sharedDir, "librecovery.so.json"),
1265 filepath.Join(sharedDir, "librecovery_available.so.json"))
1266
1267 // For static libraries, all recovery:true and recovery_available modules are captured.
1268 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1269 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001270 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1271 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1272 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001273 jsonFiles = append(jsonFiles,
1274 filepath.Join(staticDir, "libb.a.json"),
1275 filepath.Join(staticDir, "librecovery.a.json"),
1276 filepath.Join(staticDir, "librecovery_available.a.json"))
1277
1278 // For binary executables, all recovery:true and recovery_available modules are captured.
1279 if archType == "arm64" {
1280 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1281 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001282 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1283 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001284 jsonFiles = append(jsonFiles,
1285 filepath.Join(binaryDir, "recovery_bin.json"),
1286 filepath.Join(binaryDir, "recovery_available_bin.json"))
1287 }
1288
1289 // For header libraries, all vendor:true and vendor_available modules are captured.
1290 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1291 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1292
1293 // For object modules, all vendor:true and vendor_available modules are captured.
1294 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1295 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001296 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001297 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1298 }
1299
1300 for _, jsonFile := range jsonFiles {
1301 // verify all json files exist
1302 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1303 t.Errorf("%q expected but not found", jsonFile)
1304 }
1305 }
1306}
1307
1308func TestRecoverySnapshotExclude(t *testing.T) {
1309 // This test verifies that the exclude_from_recovery_snapshot property
1310 // makes its way from the Android.bp source file into the module data
1311 // structure. It also verifies that modules are correctly included or
1312 // excluded in the recovery snapshot based on their path (framework or
1313 // vendor) and the exclude_from_recovery_snapshot property.
1314
1315 frameworkBp := `
1316 cc_library_shared {
1317 name: "libinclude",
1318 srcs: ["src/include.cpp"],
1319 recovery_available: true,
1320 }
1321 cc_library_shared {
1322 name: "libexclude",
1323 srcs: ["src/exclude.cpp"],
1324 recovery: true,
1325 exclude_from_recovery_snapshot: true,
1326 }
1327 cc_library_shared {
1328 name: "libavailable_exclude",
1329 srcs: ["src/exclude.cpp"],
1330 recovery_available: true,
1331 exclude_from_recovery_snapshot: true,
1332 }
1333 `
1334
1335 vendorProprietaryBp := `
1336 cc_library_shared {
1337 name: "librecovery",
1338 srcs: ["recovery.cpp"],
1339 recovery: true,
1340 }
1341 `
1342
1343 depsBp := GatherRequiredDepsForTest(android.Android)
1344
1345 mockFS := map[string][]byte{
1346 "deps/Android.bp": []byte(depsBp),
1347 "framework/Android.bp": []byte(frameworkBp),
1348 "framework/include.cpp": nil,
1349 "framework/exclude.cpp": nil,
1350 "device/Android.bp": []byte(vendorProprietaryBp),
1351 "device/recovery.cpp": nil,
1352 }
1353
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001354 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001355 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001356 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001357 ctx := CreateTestContext(config)
1358 ctx.Register()
1359
1360 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1361 android.FailIfErrored(t, errs)
1362 _, errs = ctx.PrepareBuildActions(config)
1363 android.FailIfErrored(t, errs)
1364
1365 // Test an include and exclude framework module.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001366 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
1367 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
1368 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001369
1370 // A recovery module is excluded, but by its path, not the
1371 // exclude_from_recovery_snapshot property.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001372 AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001373
1374 // Verify the content of the recovery snapshot.
1375
1376 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001377 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001378 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1379
1380 var includeJsonFiles []string
1381 var excludeJsonFiles []string
1382
1383 for _, arch := range [][]string{
1384 []string{"arm64", "armv8-a"},
1385 } {
1386 archType := arch[0]
1387 archVariant := arch[1]
1388 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1389
1390 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1391 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1392
1393 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001394 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001395 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1396
1397 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001398 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001399 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001400 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001401 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001402 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001403 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1404 }
1405
1406 // Verify that each json file for an included module has a rule.
1407 for _, jsonFile := range includeJsonFiles {
1408 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1409 t.Errorf("include json file %q not found", jsonFile)
1410 }
1411 }
1412
1413 // Verify that each json file for an excluded module has no rule.
1414 for _, jsonFile := range excludeJsonFiles {
1415 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1416 t.Errorf("exclude json file %q found", jsonFile)
1417 }
1418 }
1419}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001420
1421func TestRecoverySnapshotDirected(t *testing.T) {
1422 bp := `
1423 cc_library_shared {
1424 name: "librecovery",
1425 recovery: true,
1426 nocrt: true,
1427 }
1428
1429 cc_library_shared {
1430 name: "librecovery_available",
1431 recovery_available: true,
1432 nocrt: true,
1433 }
1434
1435 genrule {
1436 name: "libfoo_gen",
1437 cmd: "",
1438 out: ["libfoo.so"],
1439 }
1440
1441 cc_prebuilt_library_shared {
1442 name: "libfoo",
1443 recovery: true,
1444 prefer: true,
1445 srcs: [":libfoo_gen"],
1446 }
1447
1448 cc_library_shared {
1449 name: "libfoo",
1450 recovery: true,
1451 nocrt: true,
1452 }
1453`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001454 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001455 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1456 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001457 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001458 config.TestProductVariables.DirectedRecoverySnapshot = true
1459 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1460 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1461 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1462 ctx := testCcWithConfig(t, config)
1463
1464 // Check recovery snapshot output.
1465
1466 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001467 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001468 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1469
1470 var includeJsonFiles []string
1471
1472 for _, arch := range [][]string{
1473 []string{"arm64", "armv8-a"},
1474 } {
1475 archType := arch[0]
1476 archVariant := arch[1]
1477 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1478
1479 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1480 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1481
1482 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001483 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001484 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1485 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001486 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001487 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1488
1489 // Excluded modules. Modules not included in the directed recovery snapshot
1490 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001491 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001492 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1493 }
1494
1495 // Verify that each json file for an included module has a rule.
1496 for _, jsonFile := range includeJsonFiles {
1497 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1498 t.Errorf("include json file %q not found", jsonFile)
1499 }
1500 }
1501}