blob: ceffb29c7d05a4f170873c51ee3ced05bab18941 [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
Colin Cross0fce0ba2021-01-08 16:40:12 -0800462 cc_binary {
463 name: "bin_without_snapshot",
464 vendor: true,
465 nocrt: true,
466 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900467 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800468 system_shared_libs: [],
469 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800470 srcs: ["bin.cpp"],
471 }
472
Colin Crosse0edaf92021-01-11 17:31:17 -0800473 vendor_snapshot {
474 name: "vendor_snapshot",
Justin Yundee806f2021-05-18 23:10:00 +0900475 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700476 arch: {
477 arm64: {
478 vndk_libs: [
479 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900480 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700481 ],
482 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900483 "libc++_static",
484 "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900485 "libunwind",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700486 "libvendor",
487 "libvendor_available",
488 "libvndk",
489 "lib64",
490 ],
491 shared_libs: [
492 "libvendor",
493 "libvendor_available",
494 "lib64",
495 ],
496 binaries: [
497 "bin",
498 ],
499 },
500 arm: {
501 vndk_libs: [
502 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900503 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700504 ],
505 static_libs: [
506 "libvendor",
507 "libvendor_available",
508 "libvndk",
509 "lib32",
510 ],
511 shared_libs: [
512 "libvendor",
513 "libvendor_available",
514 "lib32",
515 ],
516 binaries: [
517 "bin32",
518 ],
519 },
520 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800521 }
522
Colin Cross0fce0ba2021-01-08 16:40:12 -0800523 vendor_snapshot_static {
524 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900525 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800526 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700527 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800528 vendor: true,
529 arch: {
530 arm64: {
531 src: "libvndk.a",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800532 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700533 arm: {
534 src: "libvndk.a",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700535 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800536 },
Inseob Kimdd0295d2021-04-12 21:09:59 +0900537 shared_libs: ["libvndk"],
538 export_shared_lib_headers: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800539 }
540
541 vendor_snapshot_shared {
542 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900543 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800544 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700545 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800546 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900547 shared_libs: [
548 "libvendor_without_snapshot",
549 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900550 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900551 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800552 arch: {
553 arm64: {
554 src: "libvendor.so",
555 export_include_dirs: ["include/libvendor"],
556 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700557 arm: {
558 src: "libvendor.so",
559 export_include_dirs: ["include/libvendor"],
560 },
561 },
562 }
563
564 vendor_snapshot_static {
565 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900566 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700567 target_arch: "arm64",
568 compile_multilib: "32",
569 vendor: true,
570 arch: {
571 arm: {
572 src: "lib32.a",
573 },
574 },
575 }
576
577 vendor_snapshot_shared {
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.so",
586 },
587 },
588 }
589
590 vendor_snapshot_static {
591 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900592 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700593 target_arch: "arm64",
594 compile_multilib: "64",
595 vendor: true,
596 arch: {
597 arm64: {
598 src: "lib64.a",
599 },
600 },
601 }
602
603 vendor_snapshot_shared {
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.so",
612 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800613 },
614 }
615
616 vendor_snapshot_static {
617 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900618 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800619 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700620 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800621 vendor: true,
622 arch: {
623 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900624 cfi: {
625 src: "libvendor.cfi.a",
626 export_include_dirs: ["include/libvendor_cfi"],
627 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800628 src: "libvendor.a",
629 export_include_dirs: ["include/libvendor"],
630 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700631 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900632 cfi: {
633 src: "libvendor.cfi.a",
634 export_include_dirs: ["include/libvendor_cfi"],
635 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700636 src: "libvendor.a",
637 export_include_dirs: ["include/libvendor"],
638 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800639 },
640 }
641
Colin Cross2e577f32021-01-22 13:06:25 -0800642 vendor_snapshot_shared {
643 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900644 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800645 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700646 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800647 vendor: true,
648 arch: {
649 arm64: {
650 src: "libvendor_available.so",
651 export_include_dirs: ["include/libvendor"],
652 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700653 arm: {
654 src: "libvendor_available.so",
655 export_include_dirs: ["include/libvendor"],
656 },
Colin Cross2e577f32021-01-22 13:06:25 -0800657 },
658 }
659
660 vendor_snapshot_static {
661 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900662 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800663 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700664 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800665 vendor: true,
666 arch: {
667 arm64: {
668 src: "libvendor_available.a",
669 export_include_dirs: ["include/libvendor"],
670 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700671 arm: {
672 src: "libvendor_available.so",
673 export_include_dirs: ["include/libvendor"],
674 },
Colin Cross2e577f32021-01-22 13:06:25 -0800675 },
676 }
677
Inseob Kimd4c9f552021-04-08 19:28:28 +0900678 vendor_snapshot_static {
679 name: "libc++_static",
Justin Yundee806f2021-05-18 23:10:00 +0900680 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900681 target_arch: "arm64",
682 compile_multilib: "64",
683 vendor: true,
684 arch: {
685 arm64: {
686 src: "libc++_static.a",
687 },
688 },
689 }
690
691 vendor_snapshot_static {
692 name: "libc++demangle",
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++demangle.a",
700 },
701 },
702 }
703
704 vendor_snapshot_static {
Justin Yundee806f2021-05-18 23:10:00 +0900705 name: "libunwind",
706 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900707 target_arch: "arm64",
708 compile_multilib: "64",
709 vendor: true,
710 arch: {
711 arm64: {
Justin Yundee806f2021-05-18 23:10:00 +0900712 src: "libunwind.a",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900713 },
714 },
715 }
716
Colin Cross0fce0ba2021-01-08 16:40:12 -0800717 vendor_snapshot_binary {
718 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900719 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800720 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700721 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800722 vendor: true,
723 arch: {
724 arm64: {
725 src: "bin",
726 },
727 },
728 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800729
Jose Galmesf9523ed2021-04-06 19:48:10 -0700730 vendor_snapshot_binary {
731 name: "bin32",
Justin Yundee806f2021-05-18 23:10:00 +0900732 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700733 target_arch: "arm64",
734 compile_multilib: "32",
735 vendor: true,
736 arch: {
737 arm: {
738 src: "bin32",
739 },
740 },
741 }
742
Colin Crosse0edaf92021-01-11 17:31:17 -0800743 // old snapshot module which has to be ignored
744 vendor_snapshot_binary {
745 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900746 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800747 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700748 compile_multilib: "first",
749 vendor: true,
750 arch: {
751 arm64: {
752 src: "bin",
753 },
754 },
755 }
756
757 // different arch snapshot which has to be ignored
758 vendor_snapshot_binary {
759 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900760 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700761 target_arch: "arm",
762 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800763 vendor: true,
764 arch: {
765 arm64: {
766 src: "bin",
767 },
768 },
769 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800770`
771 depsBp := GatherRequiredDepsForTest(android.Android)
772
773 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900774 "deps/Android.bp": []byte(depsBp),
775 "framework/Android.bp": []byte(frameworkBp),
776 "framework/symbol.txt": nil,
777 "vendor/Android.bp": []byte(vendorProprietaryBp),
778 "vendor/bin": nil,
779 "vendor/bin32": nil,
780 "vendor/bin.cpp": nil,
781 "vendor/client.cpp": nil,
782 "vendor/include/libvndk/a.h": nil,
783 "vendor/include/libvendor/b.h": nil,
784 "vendor/include/libvendor_cfi/c.h": nil,
785 "vendor/libc++_static.a": nil,
786 "vendor/libc++demangle.a": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900787 "vendor/libunwind.a": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900788 "vendor/libvndk.a": nil,
789 "vendor/libvendor.a": nil,
790 "vendor/libvendor.cfi.a": nil,
791 "vendor/libvendor.so": nil,
792 "vendor/lib32.a": nil,
793 "vendor/lib32.so": nil,
794 "vendor/lib64.a": nil,
795 "vendor/lib64.so": nil,
796 "vndk/Android.bp": []byte(vndkBp),
797 "vndk/include/libvndk/a.h": nil,
798 "vndk/libvndk.so": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900799 "vndk/libllndk.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800800 }
801
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000802 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Justin Yundee806f2021-05-18 23:10:00 +0900803 config.TestProductVariables.DeviceVndkVersion = StringPtr("31")
804 config.TestProductVariables.Platform_vndk_version = StringPtr("32")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800805 ctx := CreateTestContext(config)
806 ctx.Register()
807
808 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
809 android.FailIfErrored(t, errs)
810 _, errs = ctx.PrepareBuildActions(config)
811 android.FailIfErrored(t, errs)
812
Justin Yundee806f2021-05-18 23:10:00 +0900813 sharedVariant := "android_vendor.31_arm64_armv8-a_shared"
814 staticVariant := "android_vendor.31_arm64_armv8-a_static"
815 binaryVariant := "android_vendor.31_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800816
Justin Yundee806f2021-05-18 23:10:00 +0900817 sharedCfiVariant := "android_vendor.31_arm64_armv8-a_shared_cfi"
818 staticCfiVariant := "android_vendor.31_arm64_armv8-a_static_cfi"
Inseob Kimf7aadf72021-04-13 10:15:31 +0900819
Justin Yundee806f2021-05-18 23:10:00 +0900820 shared32Variant := "android_vendor.31_arm_armv7-a-neon_shared"
821 binary32Variant := "android_vendor.31_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700822
Justin Yundee806f2021-05-18 23:10:00 +0900823 // libclient uses libvndk.vndk.31.arm64, libvendor.vendor_static.31.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800824 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
825 for _, includeFlags := range []string{
826 "-Ivndk/include/libvndk", // libvndk
827 "-Ivendor/include/libvendor", // libvendor
828 } {
829 if !strings.Contains(libclientCcFlags, includeFlags) {
830 t.Errorf("flags for libclient must contain %#v, but was %#v.",
831 includeFlags, libclientCcFlags)
832 }
833 }
834
835 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
836 for _, input := range [][]string{
Justin Yundee806f2021-05-18 23:10:00 +0900837 []string{sharedVariant, "libvndk.vndk.31.arm64"},
838 []string{sharedVariant, "libllndk.vndk.31.arm64"},
839 []string{staticVariant, "libvendor.vendor_static.31.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800840 []string{staticVariant, "libvendor_without_snapshot"},
841 } {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400842 outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800843 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
844 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
845 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400846
Colin Cross0fce0ba2021-01-08 16:40:12 -0800847 }
848
Colin Cross2e577f32021-01-22 13:06:25 -0800849 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900850 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800851 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
852 }
853
854 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
855 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
856 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
857 }
858
Jose Galmesf9523ed2021-04-06 19:48:10 -0700859 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900860 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700861 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
862 }
863
Justin Yundee806f2021-05-18 23:10:00 +0900864 // libclient_cfi uses libvendor.vendor_static.31.arm64's cfi variant
Inseob Kimf7aadf72021-04-13 10:15:31 +0900865 libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
866 if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
867 t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
868 "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
869 }
870
871 libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400872 libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"})
Inseob Kimf7aadf72021-04-13 10:15:31 +0900873 if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
874 t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
875 }
876
Justin Yundee806f2021-05-18 23:10:00 +0900877 // bin_without_snapshot uses libvndk.vendor_static.31.arm64 (which reexports vndk's exported headers)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800878 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
Inseob Kimdd0295d2021-04-12 21:09:59 +0900879 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
Colin Cross0fce0ba2021-01-08 16:40:12 -0800880 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
881 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
882 }
883
884 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400885 libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800886 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
887 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
888 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
889 }
890
Justin Yundee806f2021-05-18 23:10:00 +0900891 // libvendor.so is installed by libvendor.vendor_shared.31.arm64
892 ctx.ModuleForTests("libvendor.vendor_shared.31.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800893
Justin Yundee806f2021-05-18 23:10:00 +0900894 // lib64.so is installed by lib64.vendor_shared.31.arm64
895 ctx.ModuleForTests("lib64.vendor_shared.31.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700896
Justin Yundee806f2021-05-18 23:10:00 +0900897 // lib32.so is installed by lib32.vendor_shared.31.arm64
898 ctx.ModuleForTests("lib32.vendor_shared.31.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700899
Justin Yundee806f2021-05-18 23:10:00 +0900900 // libvendor_available.so is installed by libvendor_available.vendor_shared.31.arm64
901 ctx.ModuleForTests("libvendor_available.vendor_shared.31.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800902
Colin Cross0fce0ba2021-01-08 16:40:12 -0800903 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
904 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
905
Justin Yundee806f2021-05-18 23:10:00 +0900906 // bin is installed by bin.vendor_binary.31.arm64
907 ctx.ModuleForTests("bin.vendor_binary.31.arm64", binaryVariant).Output("bin")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800908
Justin Yundee806f2021-05-18 23:10:00 +0900909 // bin32 is installed by bin32.vendor_binary.31.arm64
910 ctx.ModuleForTests("bin32.vendor_binary.31.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700911
Colin Cross0fce0ba2021-01-08 16:40:12 -0800912 // bin_without_snapshot is installed by bin_without_snapshot
913 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
914
Justin Yundee806f2021-05-18 23:10:00 +0900915 // libvendor, libvendor_available and bin don't have vendor.31 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800916 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
917 if inList(sharedVariant, libvendorVariants) {
918 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
919 }
920
Colin Cross2e577f32021-01-22 13:06:25 -0800921 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
922 if inList(sharedVariant, libvendorAvailableVariants) {
923 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
924 }
925
Colin Cross0fce0ba2021-01-08 16:40:12 -0800926 binVariants := ctx.ModuleVariantsForTests("bin")
927 if inList(binaryVariant, binVariants) {
928 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
929 }
930}
931
932func TestVendorSnapshotSanitizer(t *testing.T) {
933 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +0900934 vendor_snapshot {
935 name: "vendor_snapshot",
936 version: "28",
937 arch: {
938 arm64: {
939 static_libs: [
940 "libsnapshot",
941 "note_memtag_heap_sync",
942 ],
943 },
944 },
945 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800946 vendor_snapshot_static {
947 name: "libsnapshot",
948 vendor: true,
949 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900950 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800951 arch: {
952 arm64: {
953 src: "libsnapshot.a",
954 cfi: {
955 src: "libsnapshot.cfi.a",
956 }
957 },
958 },
959 }
Inseob Kim253f5212021-04-08 17:10:31 +0900960
961 vendor_snapshot_static {
962 name: "note_memtag_heap_sync",
963 vendor: true,
964 target_arch: "arm64",
965 version: "28",
966 arch: {
967 arm64: {
968 src: "note_memtag_heap_sync.a",
969 },
970 },
971 }
972
973 cc_test {
974 name: "vstest",
975 gtest: false,
976 vendor: true,
977 compile_multilib: "64",
978 nocrt: true,
979 no_libcrt: true,
980 stl: "none",
981 static_libs: ["libsnapshot"],
982 system_shared_libs: [],
983 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800984`
Inseob Kim253f5212021-04-08 17:10:31 +0900985
986 mockFS := map[string][]byte{
987 "vendor/Android.bp": []byte(bp),
988 "vendor/libc++demangle.a": nil,
989 "vendor/libsnapshot.a": nil,
990 "vendor/libsnapshot.cfi.a": nil,
991 "vendor/note_memtag_heap_sync.a": nil,
992 }
993
994 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900995 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
996 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800997 ctx := testCcWithConfig(t, config)
998
999 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001000 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1001 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001002
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001003 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001004 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1005
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001006 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001007 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1008}
1009
Colin Cross0fce0ba2021-01-08 16:40:12 -08001010func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
1011 t.Helper()
1012 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
1013 if m.ExcludeFromRecoverySnapshot() != expected {
1014 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
1015 }
1016}
1017
1018func TestVendorSnapshotExclude(t *testing.T) {
1019
1020 // This test verifies that the exclude_from_vendor_snapshot property
1021 // makes its way from the Android.bp source file into the module data
1022 // structure. It also verifies that modules are correctly included or
1023 // excluded in the vendor snapshot based on their path (framework or
1024 // vendor) and the exclude_from_vendor_snapshot property.
1025
1026 frameworkBp := `
1027 cc_library_shared {
1028 name: "libinclude",
1029 srcs: ["src/include.cpp"],
1030 vendor_available: true,
1031 }
1032 cc_library_shared {
1033 name: "libexclude",
1034 srcs: ["src/exclude.cpp"],
1035 vendor: true,
1036 exclude_from_vendor_snapshot: true,
1037 }
1038 cc_library_shared {
1039 name: "libavailable_exclude",
1040 srcs: ["src/exclude.cpp"],
1041 vendor_available: true,
1042 exclude_from_vendor_snapshot: true,
1043 }
1044 `
1045
1046 vendorProprietaryBp := `
1047 cc_library_shared {
1048 name: "libvendor",
1049 srcs: ["vendor.cpp"],
1050 vendor: true,
1051 }
1052 `
1053
1054 depsBp := GatherRequiredDepsForTest(android.Android)
1055
1056 mockFS := map[string][]byte{
1057 "deps/Android.bp": []byte(depsBp),
1058 "framework/Android.bp": []byte(frameworkBp),
1059 "framework/include.cpp": nil,
1060 "framework/exclude.cpp": nil,
1061 "device/Android.bp": []byte(vendorProprietaryBp),
1062 "device/vendor.cpp": nil,
1063 }
1064
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001065 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001066 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001067 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001068 ctx := CreateTestContext(config)
1069 ctx.Register()
1070
1071 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1072 android.FailIfErrored(t, errs)
1073 _, errs = ctx.PrepareBuildActions(config)
1074 android.FailIfErrored(t, errs)
1075
1076 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001077 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1078 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1079 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001080
1081 // A vendor module is excluded, but by its path, not the
1082 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001083 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001084
1085 // Verify the content of the vendor snapshot.
1086
1087 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001088 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001089 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1090
1091 var includeJsonFiles []string
1092 var excludeJsonFiles []string
1093
1094 for _, arch := range [][]string{
1095 []string{"arm64", "armv8-a"},
1096 []string{"arm", "armv7-a-neon"},
1097 } {
1098 archType := arch[0]
1099 archVariant := arch[1]
1100 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1101
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001102 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001103 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1104
1105 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001106 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001107 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1108
1109 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001110 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001111 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001112 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001113 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001114 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001115 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1116 }
1117
1118 // Verify that each json file for an included module has a rule.
1119 for _, jsonFile := range includeJsonFiles {
1120 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1121 t.Errorf("include json file %q not found", jsonFile)
1122 }
1123 }
1124
1125 // Verify that each json file for an excluded module has no rule.
1126 for _, jsonFile := range excludeJsonFiles {
1127 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1128 t.Errorf("exclude json file %q found", jsonFile)
1129 }
1130 }
1131}
1132
1133func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1134
1135 // This test verifies that using the exclude_from_vendor_snapshot
1136 // property on a module in a vendor proprietary path generates an
1137 // error. These modules are already excluded, so we prohibit using the
1138 // property in this way, which could add to confusion.
1139
1140 vendorProprietaryBp := `
1141 cc_library_shared {
1142 name: "libvendor",
1143 srcs: ["vendor.cpp"],
1144 vendor: true,
1145 exclude_from_vendor_snapshot: true,
1146 }
1147 `
1148
1149 depsBp := GatherRequiredDepsForTest(android.Android)
1150
1151 mockFS := map[string][]byte{
1152 "deps/Android.bp": []byte(depsBp),
1153 "device/Android.bp": []byte(vendorProprietaryBp),
1154 "device/vendor.cpp": nil,
1155 }
1156
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001157 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001158 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001159 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001160 ctx := CreateTestContext(config)
1161 ctx.Register()
1162
1163 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1164 android.FailIfErrored(t, errs)
1165
1166 _, errs = ctx.PrepareBuildActions(config)
1167 android.CheckErrorsAgainstExpectations(t, errs, []string{
1168 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1169 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1170 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1171 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1172 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1173 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1174 })
1175}
1176
1177func TestRecoverySnapshotCapture(t *testing.T) {
1178 bp := `
1179 cc_library {
1180 name: "libvndk",
1181 vendor_available: true,
1182 recovery_available: true,
1183 product_available: true,
1184 vndk: {
1185 enabled: true,
1186 },
1187 nocrt: true,
1188 }
1189
1190 cc_library {
1191 name: "librecovery",
1192 recovery: true,
1193 nocrt: true,
1194 }
1195
1196 cc_library {
1197 name: "librecovery_available",
1198 recovery_available: true,
1199 nocrt: true,
1200 }
1201
1202 cc_library_headers {
1203 name: "librecovery_headers",
1204 recovery_available: true,
1205 nocrt: true,
1206 }
1207
1208 cc_binary {
1209 name: "recovery_bin",
1210 recovery: true,
1211 nocrt: true,
1212 }
1213
1214 cc_binary {
1215 name: "recovery_available_bin",
1216 recovery_available: true,
1217 nocrt: true,
1218 }
1219
1220 toolchain_library {
1221 name: "libb",
1222 recovery_available: true,
1223 src: "libb.a",
1224 }
1225
1226 cc_object {
1227 name: "obj",
1228 recovery_available: true,
1229 }
1230`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001231 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001232 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001233 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001234 ctx := testCcWithConfig(t, config)
1235
1236 // Check Recovery snapshot output.
1237
1238 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001239 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001240 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1241
1242 var jsonFiles []string
1243
1244 for _, arch := range [][]string{
1245 []string{"arm64", "armv8-a"},
1246 } {
1247 archType := arch[0]
1248 archVariant := arch[1]
1249 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1250
1251 // For shared libraries, only recovery_available modules are captured.
1252 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1253 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001254 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1255 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1256 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001257 jsonFiles = append(jsonFiles,
1258 filepath.Join(sharedDir, "libvndk.so.json"),
1259 filepath.Join(sharedDir, "librecovery.so.json"),
1260 filepath.Join(sharedDir, "librecovery_available.so.json"))
1261
1262 // For static libraries, all recovery:true and recovery_available modules are captured.
1263 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1264 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001265 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1266 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1267 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001268 jsonFiles = append(jsonFiles,
1269 filepath.Join(staticDir, "libb.a.json"),
1270 filepath.Join(staticDir, "librecovery.a.json"),
1271 filepath.Join(staticDir, "librecovery_available.a.json"))
1272
1273 // For binary executables, all recovery:true and recovery_available modules are captured.
1274 if archType == "arm64" {
1275 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1276 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001277 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1278 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001279 jsonFiles = append(jsonFiles,
1280 filepath.Join(binaryDir, "recovery_bin.json"),
1281 filepath.Join(binaryDir, "recovery_available_bin.json"))
1282 }
1283
1284 // For header libraries, all vendor:true and vendor_available modules are captured.
1285 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1286 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1287
1288 // For object modules, all vendor:true and vendor_available modules are captured.
1289 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1290 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001291 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001292 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1293 }
1294
1295 for _, jsonFile := range jsonFiles {
1296 // verify all json files exist
1297 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1298 t.Errorf("%q expected but not found", jsonFile)
1299 }
1300 }
1301}
1302
1303func TestRecoverySnapshotExclude(t *testing.T) {
1304 // This test verifies that the exclude_from_recovery_snapshot property
1305 // makes its way from the Android.bp source file into the module data
1306 // structure. It also verifies that modules are correctly included or
1307 // excluded in the recovery snapshot based on their path (framework or
1308 // vendor) and the exclude_from_recovery_snapshot property.
1309
1310 frameworkBp := `
1311 cc_library_shared {
1312 name: "libinclude",
1313 srcs: ["src/include.cpp"],
1314 recovery_available: true,
1315 }
1316 cc_library_shared {
1317 name: "libexclude",
1318 srcs: ["src/exclude.cpp"],
1319 recovery: true,
1320 exclude_from_recovery_snapshot: true,
1321 }
1322 cc_library_shared {
1323 name: "libavailable_exclude",
1324 srcs: ["src/exclude.cpp"],
1325 recovery_available: true,
1326 exclude_from_recovery_snapshot: true,
1327 }
1328 `
1329
1330 vendorProprietaryBp := `
1331 cc_library_shared {
1332 name: "librecovery",
1333 srcs: ["recovery.cpp"],
1334 recovery: true,
1335 }
1336 `
1337
1338 depsBp := GatherRequiredDepsForTest(android.Android)
1339
1340 mockFS := map[string][]byte{
1341 "deps/Android.bp": []byte(depsBp),
1342 "framework/Android.bp": []byte(frameworkBp),
1343 "framework/include.cpp": nil,
1344 "framework/exclude.cpp": nil,
1345 "device/Android.bp": []byte(vendorProprietaryBp),
1346 "device/recovery.cpp": nil,
1347 }
1348
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001349 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001350 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001351 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001352 ctx := CreateTestContext(config)
1353 ctx.Register()
1354
1355 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1356 android.FailIfErrored(t, errs)
1357 _, errs = ctx.PrepareBuildActions(config)
1358 android.FailIfErrored(t, errs)
1359
1360 // Test an include and exclude framework module.
1361 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1362 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1363 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
1364
1365 // A recovery module is excluded, but by its path, not the
1366 // exclude_from_recovery_snapshot property.
1367 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
1368
1369 // Verify the content of the recovery snapshot.
1370
1371 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001372 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001373 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1374
1375 var includeJsonFiles []string
1376 var excludeJsonFiles []string
1377
1378 for _, arch := range [][]string{
1379 []string{"arm64", "armv8-a"},
1380 } {
1381 archType := arch[0]
1382 archVariant := arch[1]
1383 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1384
1385 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1386 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1387
1388 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001389 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001390 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1391
1392 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001393 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001394 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001395 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001396 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001397 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001398 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1399 }
1400
1401 // Verify that each json file for an included module has a rule.
1402 for _, jsonFile := range includeJsonFiles {
1403 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1404 t.Errorf("include json file %q not found", jsonFile)
1405 }
1406 }
1407
1408 // Verify that each json file for an excluded module has no rule.
1409 for _, jsonFile := range excludeJsonFiles {
1410 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1411 t.Errorf("exclude json file %q found", jsonFile)
1412 }
1413 }
1414}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001415
1416func TestRecoverySnapshotDirected(t *testing.T) {
1417 bp := `
1418 cc_library_shared {
1419 name: "librecovery",
1420 recovery: true,
1421 nocrt: true,
1422 }
1423
1424 cc_library_shared {
1425 name: "librecovery_available",
1426 recovery_available: true,
1427 nocrt: true,
1428 }
1429
1430 genrule {
1431 name: "libfoo_gen",
1432 cmd: "",
1433 out: ["libfoo.so"],
1434 }
1435
1436 cc_prebuilt_library_shared {
1437 name: "libfoo",
1438 recovery: true,
1439 prefer: true,
1440 srcs: [":libfoo_gen"],
1441 }
1442
1443 cc_library_shared {
1444 name: "libfoo",
1445 recovery: true,
1446 nocrt: true,
1447 }
1448`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001449 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001450 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1451 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001452 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001453 config.TestProductVariables.DirectedRecoverySnapshot = true
1454 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1455 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1456 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1457 ctx := testCcWithConfig(t, config)
1458
1459 // Check recovery snapshot output.
1460
1461 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001462 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001463 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1464
1465 var includeJsonFiles []string
1466
1467 for _, arch := range [][]string{
1468 []string{"arm64", "armv8-a"},
1469 } {
1470 archType := arch[0]
1471 archVariant := arch[1]
1472 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1473
1474 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1475 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1476
1477 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001478 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001479 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1480 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001481 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001482 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1483
1484 // Excluded modules. Modules not included in the directed recovery snapshot
1485 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001486 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001487 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1488 }
1489
1490 // Verify that each json file for an included module has a rule.
1491 for _, jsonFile := range includeJsonFiles {
1492 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1493 t.Errorf("include json file %q not found", jsonFile)
1494 }
1495 }
1496}