blob: 645b2ccf61282cd776012bc8e5abe5bd2929a39e [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
Liz Kammer718eb272022-01-07 10:53:37 -050068 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -080069 name: "libb",
70 vendor_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -050071 srcs: ["libb.a"],
72 nocrt: true,
73 no_libcrt: true,
74 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -080075 }
76
77 cc_object {
78 name: "obj",
79 vendor_available: true,
80 }
81
82 cc_library {
83 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -070084 llndk: {
85 symbol_file: "libllndk.map.txt",
86 },
Colin Cross0fce0ba2021-01-08 16:40:12 -080087 }
88`
Colin Cross203b4212021-04-26 17:19:41 -070089
Paul Duffinc3e6ce02021-03-22 23:21:32 +000090 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -080091 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +090092 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -080093 ctx := testCcWithConfig(t, config)
94
95 // Check Vendor snapshot output.
96
97 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +000098 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -080099 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
100
101 var jsonFiles []string
102
103 for _, arch := range [][]string{
104 []string{"arm64", "armv8-a"},
105 []string{"arm", "armv7-a-neon"},
106 } {
107 archType := arch[0]
108 archVariant := arch[1]
109 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
110
111 // For shared libraries, only non-VNDK vendor_available modules are captured
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900112 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800113 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400114 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
115 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800116 jsonFiles = append(jsonFiles,
117 filepath.Join(sharedDir, "libvendor.so.json"),
118 filepath.Join(sharedDir, "libvendor_available.so.json"))
119
120 // LLNDK modules are not captured
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400121 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800122
123 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
124 // Also cfi variants are captured, except for prebuilts like toolchain_library
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900125 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
126 staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800127 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400128 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
129 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
130 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
131 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
132 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
133 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
134 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800135 jsonFiles = append(jsonFiles,
136 filepath.Join(staticDir, "libb.a.json"),
137 filepath.Join(staticDir, "libvndk.a.json"),
138 filepath.Join(staticDir, "libvndk.cfi.a.json"),
139 filepath.Join(staticDir, "libvendor.a.json"),
140 filepath.Join(staticDir, "libvendor.cfi.a.json"),
141 filepath.Join(staticDir, "libvendor_available.a.json"),
142 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
143
144 // For binary executables, all vendor:true and vendor_available modules are captured.
145 if archType == "arm64" {
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900146 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800147 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400148 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
149 CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800150 jsonFiles = append(jsonFiles,
151 filepath.Join(binaryDir, "vendor_bin.json"),
152 filepath.Join(binaryDir, "vendor_available_bin.json"))
153 }
154
155 // For header libraries, all vendor:true and vendor_available modules are captured.
156 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
157 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
158
159 // For object modules, all vendor:true and vendor_available modules are captured.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900160 objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800161 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400162 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800163 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
164 }
165
166 for _, jsonFile := range jsonFiles {
167 // verify all json files exist
168 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
169 t.Errorf("%q expected but not found", jsonFile)
170 }
171 }
172
173 // fake snapshot should have all outputs in the normal snapshot.
174 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
175 for _, output := range snapshotSingleton.AllOutputs() {
176 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
177 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
178 t.Errorf("%q expected but not found", fakeOutput)
179 }
180 }
181}
182
183func TestVendorSnapshotDirected(t *testing.T) {
184 bp := `
185 cc_library_shared {
186 name: "libvendor",
187 vendor: true,
188 nocrt: true,
189 }
190
191 cc_library_shared {
192 name: "libvendor_available",
193 vendor_available: true,
194 nocrt: true,
195 }
196
197 genrule {
198 name: "libfoo_gen",
199 cmd: "",
200 out: ["libfoo.so"],
201 }
202
203 cc_prebuilt_library_shared {
204 name: "libfoo",
205 vendor: true,
206 prefer: true,
207 srcs: [":libfoo_gen"],
208 }
209
210 cc_library_shared {
211 name: "libfoo",
212 vendor: true,
213 nocrt: true,
214 }
215`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000216 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800217 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900218 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800219 config.TestProductVariables.DirectedVendorSnapshot = true
220 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
221 config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
222 config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
223 ctx := testCcWithConfig(t, config)
224
225 // Check Vendor snapshot output.
226
227 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000228 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800229 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
230
231 var includeJsonFiles []string
Colin Cross0fce0ba2021-01-08 16:40:12 -0800232
233 for _, arch := range [][]string{
234 []string{"arm64", "armv8-a"},
235 []string{"arm", "armv7-a-neon"},
236 } {
237 archType := arch[0]
238 archVariant := arch[1]
239 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
240
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900241 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800242 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
243
244 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400245 CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800246 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
247 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400248 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800249 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
250
Jose Galmes0a942a02021-02-03 14:23:15 -0800251 // Excluded modules. Modules not included in the directed vendor snapshot
252 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400253 CheckSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
Jose Galmes0a942a02021-02-03 14:23:15 -0800254 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
Colin Cross0fce0ba2021-01-08 16:40:12 -0800255 }
256
257 // Verify that each json file for an included module has a rule.
258 for _, jsonFile := range includeJsonFiles {
259 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
260 t.Errorf("include json file %q not found", jsonFile)
261 }
262 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800263}
264
265func TestVendorSnapshotUse(t *testing.T) {
266 frameworkBp := `
267 cc_library {
268 name: "libvndk",
269 vendor_available: true,
270 product_available: true,
271 vndk: {
272 enabled: true,
273 },
274 nocrt: true,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800275 }
276
277 cc_library {
278 name: "libvendor",
279 vendor: true,
280 nocrt: true,
281 no_libcrt: true,
282 stl: "none",
283 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800284 }
285
Colin Cross2e577f32021-01-22 13:06:25 -0800286 cc_library {
287 name: "libvendor_available",
288 vendor_available: true,
289 nocrt: true,
290 no_libcrt: true,
291 stl: "none",
292 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700293 }
294
295 cc_library {
296 name: "lib32",
297 vendor: true,
298 nocrt: true,
299 no_libcrt: true,
300 stl: "none",
301 system_shared_libs: [],
302 compile_multilib: "32",
303 }
304
305 cc_library {
306 name: "lib64",
307 vendor: true,
308 nocrt: true,
309 no_libcrt: true,
310 stl: "none",
311 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800312 compile_multilib: "64",
313 }
314
Justin Yundee806f2021-05-18 23:10:00 +0900315 cc_library {
316 name: "libllndk",
317 llndk: {
318 symbol_file: "libllndk.map.txt",
319 },
320 }
321
Colin Cross0fce0ba2021-01-08 16:40:12 -0800322 cc_binary {
323 name: "bin",
324 vendor: true,
325 nocrt: true,
326 no_libcrt: true,
327 stl: "none",
328 system_shared_libs: [],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700329 }
330
331 cc_binary {
332 name: "bin32",
333 vendor: true,
334 nocrt: true,
335 no_libcrt: true,
336 stl: "none",
337 system_shared_libs: [],
338 compile_multilib: "32",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800339 }
340`
341
342 vndkBp := `
343 vndk_prebuilt_shared {
344 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900345 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800346 target_arch: "arm64",
347 vendor_available: true,
348 product_available: true,
349 vndk: {
350 enabled: true,
351 },
352 arch: {
353 arm64: {
354 srcs: ["libvndk.so"],
355 export_include_dirs: ["include/libvndk"],
356 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700357 arm: {
358 srcs: ["libvndk.so"],
359 export_include_dirs: ["include/libvndk"],
360 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800361 },
362 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800363
364 // old snapshot module which has to be ignored
365 vndk_prebuilt_shared {
366 name: "libvndk",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900367 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800368 target_arch: "arm64",
369 vendor_available: true,
370 product_available: true,
371 vndk: {
372 enabled: true,
373 },
374 arch: {
375 arm64: {
376 srcs: ["libvndk.so"],
377 export_include_dirs: ["include/libvndk"],
378 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700379 arm: {
380 srcs: ["libvndk.so"],
381 export_include_dirs: ["include/libvndk"],
382 },
383 },
384 }
385
386 // different arch snapshot which has to be ignored
387 vndk_prebuilt_shared {
388 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900389 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700390 target_arch: "arm",
391 vendor_available: true,
392 product_available: true,
393 vndk: {
394 enabled: true,
395 },
396 arch: {
397 arm: {
398 srcs: ["libvndk.so"],
399 export_include_dirs: ["include/libvndk"],
400 },
Colin Crosse0edaf92021-01-11 17:31:17 -0800401 },
402 }
Justin Yundee806f2021-05-18 23:10:00 +0900403
404 vndk_prebuilt_shared {
405 name: "libllndk",
406 version: "31",
407 target_arch: "arm64",
408 vendor_available: true,
409 product_available: true,
410 arch: {
411 arm64: {
412 srcs: ["libllndk.so"],
413 },
414 arm: {
415 srcs: ["libllndk.so"],
416 },
417 },
418 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800419`
420
421 vendorProprietaryBp := `
422 cc_library {
423 name: "libvendor_without_snapshot",
424 vendor: true,
425 nocrt: true,
426 no_libcrt: true,
427 stl: "none",
428 system_shared_libs: [],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800429 }
430
431 cc_library_shared {
432 name: "libclient",
433 vendor: true,
434 nocrt: true,
435 no_libcrt: true,
436 stl: "none",
437 system_shared_libs: [],
Justin Yundee806f2021-05-18 23:10:00 +0900438 shared_libs: ["libvndk", "libvendor_available", "libllndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800439 static_libs: ["libvendor", "libvendor_without_snapshot"],
Jose Galmesf9523ed2021-04-06 19:48:10 -0700440 arch: {
441 arm64: {
442 shared_libs: ["lib64"],
443 },
444 arm: {
445 shared_libs: ["lib32"],
446 },
447 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800448 srcs: ["client.cpp"],
449 }
450
Inseob Kimf7aadf72021-04-13 10:15:31 +0900451 cc_library_shared {
452 name: "libclient_cfi",
453 vendor: true,
454 nocrt: true,
455 no_libcrt: true,
456 stl: "none",
457 system_shared_libs: [],
458 static_libs: ["libvendor"],
459 sanitize: {
460 cfi: true,
461 },
462 srcs: ["client.cpp"],
463 }
464
Justin Yun27b95722021-07-28 17:04:44 +0900465 cc_library_shared {
466 name: "libvndkext",
467 vendor: true,
468 nocrt: true,
469 no_libcrt: true,
470 stl: "none",
471 system_shared_libs: [],
472 vndk: {
473 extends: "libvndk",
474 enabled: true,
475 }
476 }
477
Colin Cross0fce0ba2021-01-08 16:40:12 -0800478 cc_binary {
479 name: "bin_without_snapshot",
480 vendor: true,
481 nocrt: true,
482 no_libcrt: true,
Inseob Kimd4c9f552021-04-08 19:28:28 +0900483 stl: "libc++_static",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800484 system_shared_libs: [],
485 static_libs: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800486 srcs: ["bin.cpp"],
487 }
488
Colin Crosse0edaf92021-01-11 17:31:17 -0800489 vendor_snapshot {
490 name: "vendor_snapshot",
Justin Yundee806f2021-05-18 23:10:00 +0900491 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700492 arch: {
493 arm64: {
494 vndk_libs: [
495 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900496 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700497 ],
498 static_libs: [
Inseob Kimd4c9f552021-04-08 19:28:28 +0900499 "libc++_static",
500 "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900501 "libunwind",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700502 "libvendor",
503 "libvendor_available",
504 "libvndk",
505 "lib64",
506 ],
507 shared_libs: [
508 "libvendor",
509 "libvendor_available",
510 "lib64",
511 ],
512 binaries: [
513 "bin",
514 ],
515 },
516 arm: {
517 vndk_libs: [
518 "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900519 "libllndk",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700520 ],
521 static_libs: [
522 "libvendor",
523 "libvendor_available",
524 "libvndk",
525 "lib32",
526 ],
527 shared_libs: [
528 "libvendor",
529 "libvendor_available",
530 "lib32",
531 ],
532 binaries: [
533 "bin32",
534 ],
535 },
536 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800537 }
538
Colin Cross0fce0ba2021-01-08 16:40:12 -0800539 vendor_snapshot_static {
540 name: "libvndk",
Justin Yundee806f2021-05-18 23:10:00 +0900541 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800542 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700543 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800544 vendor: true,
545 arch: {
546 arm64: {
547 src: "libvndk.a",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800548 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700549 arm: {
550 src: "libvndk.a",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700551 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800552 },
Inseob Kimdd0295d2021-04-12 21:09:59 +0900553 shared_libs: ["libvndk"],
554 export_shared_lib_headers: ["libvndk"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800555 }
556
557 vendor_snapshot_shared {
558 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900559 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800560 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700561 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800562 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900563 shared_libs: [
564 "libvendor_without_snapshot",
565 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900566 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900567 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800568 arch: {
569 arm64: {
570 src: "libvendor.so",
571 export_include_dirs: ["include/libvendor"],
572 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700573 arm: {
574 src: "libvendor.so",
575 export_include_dirs: ["include/libvendor"],
576 },
577 },
578 }
579
580 vendor_snapshot_static {
581 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900582 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700583 target_arch: "arm64",
584 compile_multilib: "32",
585 vendor: true,
586 arch: {
587 arm: {
588 src: "lib32.a",
589 },
590 },
591 }
592
593 vendor_snapshot_shared {
594 name: "lib32",
Justin Yundee806f2021-05-18 23:10:00 +0900595 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700596 target_arch: "arm64",
597 compile_multilib: "32",
598 vendor: true,
599 arch: {
600 arm: {
601 src: "lib32.so",
602 },
603 },
604 }
605
606 vendor_snapshot_static {
607 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900608 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700609 target_arch: "arm64",
610 compile_multilib: "64",
611 vendor: true,
612 arch: {
613 arm64: {
614 src: "lib64.a",
615 },
616 },
617 }
618
619 vendor_snapshot_shared {
620 name: "lib64",
Justin Yundee806f2021-05-18 23:10:00 +0900621 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700622 target_arch: "arm64",
623 compile_multilib: "64",
624 vendor: true,
625 arch: {
626 arm64: {
627 src: "lib64.so",
628 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800629 },
630 }
631
632 vendor_snapshot_static {
633 name: "libvendor",
Justin Yundee806f2021-05-18 23:10:00 +0900634 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800635 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700636 compile_multilib: "both",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800637 vendor: true,
638 arch: {
639 arm64: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900640 cfi: {
641 src: "libvendor.cfi.a",
642 export_include_dirs: ["include/libvendor_cfi"],
643 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800644 src: "libvendor.a",
645 export_include_dirs: ["include/libvendor"],
646 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700647 arm: {
Inseob Kimf7aadf72021-04-13 10:15:31 +0900648 cfi: {
649 src: "libvendor.cfi.a",
650 export_include_dirs: ["include/libvendor_cfi"],
651 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700652 src: "libvendor.a",
653 export_include_dirs: ["include/libvendor"],
654 },
Colin Cross0fce0ba2021-01-08 16:40:12 -0800655 },
656 }
657
Colin Cross2e577f32021-01-22 13:06:25 -0800658 vendor_snapshot_shared {
659 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900660 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800661 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700662 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800663 vendor: true,
664 arch: {
665 arm64: {
666 src: "libvendor_available.so",
667 export_include_dirs: ["include/libvendor"],
668 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700669 arm: {
670 src: "libvendor_available.so",
671 export_include_dirs: ["include/libvendor"],
672 },
Colin Cross2e577f32021-01-22 13:06:25 -0800673 },
674 }
675
676 vendor_snapshot_static {
677 name: "libvendor_available",
Justin Yundee806f2021-05-18 23:10:00 +0900678 version: "31",
Colin Cross2e577f32021-01-22 13:06:25 -0800679 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700680 compile_multilib: "both",
Colin Cross2e577f32021-01-22 13:06:25 -0800681 vendor: true,
682 arch: {
683 arm64: {
684 src: "libvendor_available.a",
685 export_include_dirs: ["include/libvendor"],
686 },
Jose Galmesf9523ed2021-04-06 19:48:10 -0700687 arm: {
688 src: "libvendor_available.so",
689 export_include_dirs: ["include/libvendor"],
690 },
Colin Cross2e577f32021-01-22 13:06:25 -0800691 },
692 }
693
Inseob Kimd4c9f552021-04-08 19:28:28 +0900694 vendor_snapshot_static {
695 name: "libc++_static",
Justin Yundee806f2021-05-18 23:10:00 +0900696 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900697 target_arch: "arm64",
698 compile_multilib: "64",
699 vendor: true,
700 arch: {
701 arm64: {
702 src: "libc++_static.a",
703 },
704 },
705 }
706
707 vendor_snapshot_static {
708 name: "libc++demangle",
Justin Yundee806f2021-05-18 23:10:00 +0900709 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900710 target_arch: "arm64",
711 compile_multilib: "64",
712 vendor: true,
713 arch: {
714 arm64: {
715 src: "libc++demangle.a",
716 },
717 },
718 }
719
720 vendor_snapshot_static {
Justin Yundee806f2021-05-18 23:10:00 +0900721 name: "libunwind",
722 version: "31",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900723 target_arch: "arm64",
724 compile_multilib: "64",
725 vendor: true,
726 arch: {
727 arm64: {
Justin Yundee806f2021-05-18 23:10:00 +0900728 src: "libunwind.a",
Inseob Kimd4c9f552021-04-08 19:28:28 +0900729 },
730 },
731 }
732
Colin Cross0fce0ba2021-01-08 16:40:12 -0800733 vendor_snapshot_binary {
734 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900735 version: "31",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800736 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700737 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800738 vendor: true,
739 arch: {
740 arm64: {
741 src: "bin",
742 },
743 },
744 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800745
Jose Galmesf9523ed2021-04-06 19:48:10 -0700746 vendor_snapshot_binary {
747 name: "bin32",
Justin Yundee806f2021-05-18 23:10:00 +0900748 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700749 target_arch: "arm64",
750 compile_multilib: "32",
751 vendor: true,
752 arch: {
753 arm: {
754 src: "bin32",
755 },
756 },
757 }
758
Colin Crosse0edaf92021-01-11 17:31:17 -0800759 // old snapshot module which has to be ignored
760 vendor_snapshot_binary {
761 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900762 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800763 target_arch: "arm64",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700764 compile_multilib: "first",
765 vendor: true,
766 arch: {
767 arm64: {
768 src: "bin",
769 },
770 },
771 }
772
773 // different arch snapshot which has to be ignored
774 vendor_snapshot_binary {
775 name: "bin",
Justin Yundee806f2021-05-18 23:10:00 +0900776 version: "31",
Jose Galmesf9523ed2021-04-06 19:48:10 -0700777 target_arch: "arm",
778 compile_multilib: "first",
Colin Crosse0edaf92021-01-11 17:31:17 -0800779 vendor: true,
780 arch: {
781 arm64: {
782 src: "bin",
783 },
784 },
785 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800786`
787 depsBp := GatherRequiredDepsForTest(android.Android)
788
789 mockFS := map[string][]byte{
Inseob Kimf7aadf72021-04-13 10:15:31 +0900790 "deps/Android.bp": []byte(depsBp),
791 "framework/Android.bp": []byte(frameworkBp),
792 "framework/symbol.txt": nil,
793 "vendor/Android.bp": []byte(vendorProprietaryBp),
794 "vendor/bin": nil,
795 "vendor/bin32": nil,
796 "vendor/bin.cpp": nil,
797 "vendor/client.cpp": nil,
798 "vendor/include/libvndk/a.h": nil,
799 "vendor/include/libvendor/b.h": nil,
800 "vendor/include/libvendor_cfi/c.h": nil,
801 "vendor/libc++_static.a": nil,
802 "vendor/libc++demangle.a": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900803 "vendor/libunwind.a": nil,
Inseob Kimf7aadf72021-04-13 10:15:31 +0900804 "vendor/libvndk.a": nil,
805 "vendor/libvendor.a": nil,
806 "vendor/libvendor.cfi.a": nil,
807 "vendor/libvendor.so": nil,
808 "vendor/lib32.a": nil,
809 "vendor/lib32.so": nil,
810 "vendor/lib64.a": nil,
811 "vendor/lib64.so": nil,
812 "vndk/Android.bp": []byte(vndkBp),
813 "vndk/include/libvndk/a.h": nil,
814 "vndk/libvndk.so": nil,
Justin Yundee806f2021-05-18 23:10:00 +0900815 "vndk/libllndk.so": nil,
Colin Cross0fce0ba2021-01-08 16:40:12 -0800816 }
817
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000818 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Justin Yundee806f2021-05-18 23:10:00 +0900819 config.TestProductVariables.DeviceVndkVersion = StringPtr("31")
820 config.TestProductVariables.Platform_vndk_version = StringPtr("32")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800821 ctx := CreateTestContext(config)
822 ctx.Register()
823
824 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
825 android.FailIfErrored(t, errs)
826 _, errs = ctx.PrepareBuildActions(config)
827 android.FailIfErrored(t, errs)
828
Justin Yundee806f2021-05-18 23:10:00 +0900829 sharedVariant := "android_vendor.31_arm64_armv8-a_shared"
830 staticVariant := "android_vendor.31_arm64_armv8-a_static"
831 binaryVariant := "android_vendor.31_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800832
Justin Yundee806f2021-05-18 23:10:00 +0900833 sharedCfiVariant := "android_vendor.31_arm64_armv8-a_shared_cfi"
834 staticCfiVariant := "android_vendor.31_arm64_armv8-a_static_cfi"
Inseob Kimf7aadf72021-04-13 10:15:31 +0900835
Justin Yundee806f2021-05-18 23:10:00 +0900836 shared32Variant := "android_vendor.31_arm_armv7-a-neon_shared"
837 binary32Variant := "android_vendor.31_arm_armv7-a-neon"
Jose Galmesf9523ed2021-04-06 19:48:10 -0700838
Justin Yundee806f2021-05-18 23:10:00 +0900839 // libclient uses libvndk.vndk.31.arm64, libvendor.vendor_static.31.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800840 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
841 for _, includeFlags := range []string{
842 "-Ivndk/include/libvndk", // libvndk
843 "-Ivendor/include/libvendor", // libvendor
844 } {
845 if !strings.Contains(libclientCcFlags, includeFlags) {
846 t.Errorf("flags for libclient must contain %#v, but was %#v.",
847 includeFlags, libclientCcFlags)
848 }
849 }
850
851 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
852 for _, input := range [][]string{
Justin Yundee806f2021-05-18 23:10:00 +0900853 []string{sharedVariant, "libvndk.vndk.31.arm64"},
854 []string{sharedVariant, "libllndk.vndk.31.arm64"},
855 []string{staticVariant, "libvendor.vendor_static.31.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800856 []string{staticVariant, "libvendor_without_snapshot"},
857 } {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400858 outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800859 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
860 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
861 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400862
Colin Cross0fce0ba2021-01-08 16:40:12 -0800863 }
864
Colin Cross2e577f32021-01-22 13:06:25 -0800865 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900866 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
Colin Cross2e577f32021-01-22 13:06:25 -0800867 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
868 }
869
870 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
871 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
872 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
873 }
874
Jose Galmesf9523ed2021-04-06 19:48:10 -0700875 libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
Justin Yundee806f2021-05-18 23:10:00 +0900876 if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
Jose Galmesf9523ed2021-04-06 19:48:10 -0700877 t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
878 }
879
Justin Yundee806f2021-05-18 23:10:00 +0900880 // libclient_cfi uses libvendor.vendor_static.31.arm64's cfi variant
Inseob Kimf7aadf72021-04-13 10:15:31 +0900881 libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
882 if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
883 t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
884 "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
885 }
886
887 libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400888 libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"})
Inseob Kimf7aadf72021-04-13 10:15:31 +0900889 if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
890 t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
891 }
892
Justin Yundee806f2021-05-18 23:10:00 +0900893 // bin_without_snapshot uses libvndk.vendor_static.31.arm64 (which reexports vndk's exported headers)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800894 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
Inseob Kimdd0295d2021-04-12 21:09:59 +0900895 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
Colin Cross0fce0ba2021-01-08 16:40:12 -0800896 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
897 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
898 }
899
900 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400901 libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800902 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
903 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
904 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
905 }
906
Justin Yundee806f2021-05-18 23:10:00 +0900907 // libvendor.so is installed by libvendor.vendor_shared.31.arm64
908 ctx.ModuleForTests("libvendor.vendor_shared.31.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800909
Justin Yundee806f2021-05-18 23:10:00 +0900910 // lib64.so is installed by lib64.vendor_shared.31.arm64
911 ctx.ModuleForTests("lib64.vendor_shared.31.arm64", sharedVariant).Output("lib64.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700912
Justin Yundee806f2021-05-18 23:10:00 +0900913 // lib32.so is installed by lib32.vendor_shared.31.arm64
914 ctx.ModuleForTests("lib32.vendor_shared.31.arm64", shared32Variant).Output("lib32.so")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700915
Justin Yundee806f2021-05-18 23:10:00 +0900916 // libvendor_available.so is installed by libvendor_available.vendor_shared.31.arm64
917 ctx.ModuleForTests("libvendor_available.vendor_shared.31.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800918
Colin Cross0fce0ba2021-01-08 16:40:12 -0800919 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
920 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
921
Justin Yundee806f2021-05-18 23:10:00 +0900922 // bin is installed by bin.vendor_binary.31.arm64
923 ctx.ModuleForTests("bin.vendor_binary.31.arm64", binaryVariant).Output("bin")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800924
Justin Yundee806f2021-05-18 23:10:00 +0900925 // bin32 is installed by bin32.vendor_binary.31.arm64
926 ctx.ModuleForTests("bin32.vendor_binary.31.arm64", binary32Variant).Output("bin32")
Jose Galmesf9523ed2021-04-06 19:48:10 -0700927
Colin Cross0fce0ba2021-01-08 16:40:12 -0800928 // bin_without_snapshot is installed by bin_without_snapshot
929 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
930
Justin Yundee806f2021-05-18 23:10:00 +0900931 // libvendor, libvendor_available and bin don't have vendor.31 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800932 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
933 if inList(sharedVariant, libvendorVariants) {
934 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
935 }
936
Colin Cross2e577f32021-01-22 13:06:25 -0800937 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
938 if inList(sharedVariant, libvendorAvailableVariants) {
939 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
940 }
941
Colin Cross0fce0ba2021-01-08 16:40:12 -0800942 binVariants := ctx.ModuleVariantsForTests("bin")
943 if inList(binaryVariant, binVariants) {
944 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
945 }
946}
947
948func TestVendorSnapshotSanitizer(t *testing.T) {
949 bp := `
Inseob Kim253f5212021-04-08 17:10:31 +0900950 vendor_snapshot {
951 name: "vendor_snapshot",
952 version: "28",
953 arch: {
954 arm64: {
955 static_libs: [
956 "libsnapshot",
957 "note_memtag_heap_sync",
958 ],
959 },
960 },
961 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800962 vendor_snapshot_static {
963 name: "libsnapshot",
964 vendor: true,
965 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900966 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800967 arch: {
968 arm64: {
969 src: "libsnapshot.a",
970 cfi: {
971 src: "libsnapshot.cfi.a",
972 }
973 },
974 },
975 }
Inseob Kim253f5212021-04-08 17:10:31 +0900976
977 vendor_snapshot_static {
978 name: "note_memtag_heap_sync",
979 vendor: true,
980 target_arch: "arm64",
981 version: "28",
982 arch: {
983 arm64: {
984 src: "note_memtag_heap_sync.a",
985 },
986 },
987 }
988
989 cc_test {
990 name: "vstest",
991 gtest: false,
992 vendor: true,
993 compile_multilib: "64",
994 nocrt: true,
995 no_libcrt: true,
996 stl: "none",
997 static_libs: ["libsnapshot"],
998 system_shared_libs: [],
999 }
Colin Cross0fce0ba2021-01-08 16:40:12 -08001000`
Inseob Kim253f5212021-04-08 17:10:31 +09001001
1002 mockFS := map[string][]byte{
1003 "vendor/Android.bp": []byte(bp),
1004 "vendor/libc++demangle.a": nil,
1005 "vendor/libsnapshot.a": nil,
1006 "vendor/libsnapshot.cfi.a": nil,
1007 "vendor/note_memtag_heap_sync.a": nil,
1008 }
1009
1010 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001011 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
1012 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001013 ctx := testCcWithConfig(t, config)
1014
1015 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001016 staticVariant := "android_vendor.28_arm64_armv8-a_static"
1017 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -08001018
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001019 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001020 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1021
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001022 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001023 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1024}
1025
Colin Cross0fce0ba2021-01-08 16:40:12 -08001026func TestVendorSnapshotExclude(t *testing.T) {
1027
1028 // This test verifies that the exclude_from_vendor_snapshot property
1029 // makes its way from the Android.bp source file into the module data
1030 // structure. It also verifies that modules are correctly included or
1031 // excluded in the vendor snapshot based on their path (framework or
1032 // vendor) and the exclude_from_vendor_snapshot property.
1033
1034 frameworkBp := `
1035 cc_library_shared {
1036 name: "libinclude",
1037 srcs: ["src/include.cpp"],
1038 vendor_available: true,
1039 }
1040 cc_library_shared {
1041 name: "libexclude",
1042 srcs: ["src/exclude.cpp"],
1043 vendor: true,
1044 exclude_from_vendor_snapshot: true,
1045 }
1046 cc_library_shared {
1047 name: "libavailable_exclude",
1048 srcs: ["src/exclude.cpp"],
1049 vendor_available: true,
1050 exclude_from_vendor_snapshot: true,
1051 }
1052 `
1053
1054 vendorProprietaryBp := `
1055 cc_library_shared {
1056 name: "libvendor",
1057 srcs: ["vendor.cpp"],
1058 vendor: true,
1059 }
1060 `
1061
1062 depsBp := GatherRequiredDepsForTest(android.Android)
1063
1064 mockFS := map[string][]byte{
1065 "deps/Android.bp": []byte(depsBp),
1066 "framework/Android.bp": []byte(frameworkBp),
1067 "framework/include.cpp": nil,
1068 "framework/exclude.cpp": nil,
1069 "device/Android.bp": []byte(vendorProprietaryBp),
1070 "device/vendor.cpp": nil,
1071 }
1072
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001073 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001074 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001075 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001076 ctx := CreateTestContext(config)
1077 ctx.Register()
1078
1079 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1080 android.FailIfErrored(t, errs)
1081 _, errs = ctx.PrepareBuildActions(config)
1082 android.FailIfErrored(t, errs)
1083
1084 // Test an include and exclude framework module.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001085 AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
1086 AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
1087 AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001088
1089 // A vendor module is excluded, but by its path, not the
1090 // exclude_from_vendor_snapshot property.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001091 AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001092
1093 // Verify the content of the vendor snapshot.
1094
1095 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001096 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001097 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1098
1099 var includeJsonFiles []string
1100 var excludeJsonFiles []string
1101
1102 for _, arch := range [][]string{
1103 []string{"arm64", "armv8-a"},
1104 []string{"arm", "armv7-a-neon"},
1105 } {
1106 archType := arch[0]
1107 archVariant := arch[1]
1108 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1109
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001110 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001111 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1112
1113 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001114 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001115 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1116
1117 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001118 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001119 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001120 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001121 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001122 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001123 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1124 }
1125
1126 // Verify that each json file for an included module has a rule.
1127 for _, jsonFile := range includeJsonFiles {
1128 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1129 t.Errorf("include json file %q not found", jsonFile)
1130 }
1131 }
1132
1133 // Verify that each json file for an excluded module has no rule.
1134 for _, jsonFile := range excludeJsonFiles {
1135 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1136 t.Errorf("exclude json file %q found", jsonFile)
1137 }
1138 }
1139}
1140
1141func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1142
1143 // This test verifies that using the exclude_from_vendor_snapshot
1144 // property on a module in a vendor proprietary path generates an
1145 // error. These modules are already excluded, so we prohibit using the
1146 // property in this way, which could add to confusion.
1147
1148 vendorProprietaryBp := `
1149 cc_library_shared {
1150 name: "libvendor",
1151 srcs: ["vendor.cpp"],
1152 vendor: true,
1153 exclude_from_vendor_snapshot: true,
1154 }
1155 `
1156
1157 depsBp := GatherRequiredDepsForTest(android.Android)
1158
1159 mockFS := map[string][]byte{
1160 "deps/Android.bp": []byte(depsBp),
1161 "device/Android.bp": []byte(vendorProprietaryBp),
1162 "device/vendor.cpp": nil,
1163 }
1164
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001165 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001166 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001167 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001168 ctx := CreateTestContext(config)
1169 ctx.Register()
1170
1171 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1172 android.FailIfErrored(t, errs)
1173
1174 _, errs = ctx.PrepareBuildActions(config)
1175 android.CheckErrorsAgainstExpectations(t, errs, []string{
1176 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1177 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1178 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1179 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1180 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1181 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1182 })
1183}
1184
1185func TestRecoverySnapshotCapture(t *testing.T) {
1186 bp := `
1187 cc_library {
1188 name: "libvndk",
1189 vendor_available: true,
1190 recovery_available: true,
1191 product_available: true,
1192 vndk: {
1193 enabled: true,
1194 },
1195 nocrt: true,
1196 }
1197
1198 cc_library {
1199 name: "librecovery",
1200 recovery: true,
1201 nocrt: true,
1202 }
1203
1204 cc_library {
1205 name: "librecovery_available",
1206 recovery_available: true,
1207 nocrt: true,
1208 }
1209
1210 cc_library_headers {
1211 name: "librecovery_headers",
1212 recovery_available: true,
1213 nocrt: true,
1214 }
1215
1216 cc_binary {
1217 name: "recovery_bin",
1218 recovery: true,
1219 nocrt: true,
1220 }
1221
1222 cc_binary {
1223 name: "recovery_available_bin",
1224 recovery_available: true,
1225 nocrt: true,
1226 }
1227
Liz Kammer718eb272022-01-07 10:53:37 -05001228 cc_prebuilt_library_static {
Colin Cross0fce0ba2021-01-08 16:40:12 -08001229 name: "libb",
1230 recovery_available: true,
Liz Kammer718eb272022-01-07 10:53:37 -05001231 srcs: ["libb.a"],
1232 nocrt: true,
1233 no_libcrt: true,
1234 stl: "none",
Colin Cross0fce0ba2021-01-08 16:40:12 -08001235 }
1236
1237 cc_object {
1238 name: "obj",
1239 recovery_available: true,
1240 }
1241`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001242 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001243 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001244 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001245 ctx := testCcWithConfig(t, config)
1246
1247 // Check Recovery snapshot output.
1248
1249 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001250 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001251 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1252
1253 var jsonFiles []string
1254
1255 for _, arch := range [][]string{
1256 []string{"arm64", "armv8-a"},
1257 } {
1258 archType := arch[0]
1259 archVariant := arch[1]
1260 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1261
1262 // For shared libraries, only recovery_available modules are captured.
1263 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1264 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001265 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1266 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1267 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001268 jsonFiles = append(jsonFiles,
1269 filepath.Join(sharedDir, "libvndk.so.json"),
1270 filepath.Join(sharedDir, "librecovery.so.json"),
1271 filepath.Join(sharedDir, "librecovery_available.so.json"))
1272
1273 // For static libraries, all recovery:true and recovery_available modules are captured.
1274 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1275 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001276 CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1277 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1278 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001279 jsonFiles = append(jsonFiles,
1280 filepath.Join(staticDir, "libb.a.json"),
1281 filepath.Join(staticDir, "librecovery.a.json"),
1282 filepath.Join(staticDir, "librecovery_available.a.json"))
1283
1284 // For binary executables, all recovery:true and recovery_available modules are captured.
1285 if archType == "arm64" {
1286 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1287 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001288 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1289 CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001290 jsonFiles = append(jsonFiles,
1291 filepath.Join(binaryDir, "recovery_bin.json"),
1292 filepath.Join(binaryDir, "recovery_available_bin.json"))
1293 }
1294
1295 // For header libraries, all vendor:true and vendor_available modules are captured.
1296 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1297 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1298
1299 // For object modules, all vendor:true and vendor_available modules are captured.
1300 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1301 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001302 CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001303 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1304 }
1305
1306 for _, jsonFile := range jsonFiles {
1307 // verify all json files exist
1308 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1309 t.Errorf("%q expected but not found", jsonFile)
1310 }
1311 }
1312}
1313
1314func TestRecoverySnapshotExclude(t *testing.T) {
1315 // This test verifies that the exclude_from_recovery_snapshot property
1316 // makes its way from the Android.bp source file into the module data
1317 // structure. It also verifies that modules are correctly included or
1318 // excluded in the recovery snapshot based on their path (framework or
1319 // vendor) and the exclude_from_recovery_snapshot property.
1320
1321 frameworkBp := `
1322 cc_library_shared {
1323 name: "libinclude",
1324 srcs: ["src/include.cpp"],
1325 recovery_available: true,
1326 }
1327 cc_library_shared {
1328 name: "libexclude",
1329 srcs: ["src/exclude.cpp"],
1330 recovery: true,
1331 exclude_from_recovery_snapshot: true,
1332 }
1333 cc_library_shared {
1334 name: "libavailable_exclude",
1335 srcs: ["src/exclude.cpp"],
1336 recovery_available: true,
1337 exclude_from_recovery_snapshot: true,
1338 }
1339 `
1340
1341 vendorProprietaryBp := `
1342 cc_library_shared {
1343 name: "librecovery",
1344 srcs: ["recovery.cpp"],
1345 recovery: true,
1346 }
1347 `
1348
1349 depsBp := GatherRequiredDepsForTest(android.Android)
1350
1351 mockFS := map[string][]byte{
1352 "deps/Android.bp": []byte(depsBp),
1353 "framework/Android.bp": []byte(frameworkBp),
1354 "framework/include.cpp": nil,
1355 "framework/exclude.cpp": nil,
1356 "device/Android.bp": []byte(vendorProprietaryBp),
1357 "device/recovery.cpp": nil,
1358 }
1359
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001360 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001361 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001362 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001363 ctx := CreateTestContext(config)
1364 ctx.Register()
1365
1366 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1367 android.FailIfErrored(t, errs)
1368 _, errs = ctx.PrepareBuildActions(config)
1369 android.FailIfErrored(t, errs)
1370
1371 // Test an include and exclude framework module.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001372 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
1373 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
1374 AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001375
1376 // A recovery module is excluded, but by its path, not the
1377 // exclude_from_recovery_snapshot property.
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -05001378 AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001379
1380 // Verify the content of the recovery snapshot.
1381
1382 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001383 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001384 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1385
1386 var includeJsonFiles []string
1387 var excludeJsonFiles []string
1388
1389 for _, arch := range [][]string{
1390 []string{"arm64", "armv8-a"},
1391 } {
1392 archType := arch[0]
1393 archVariant := arch[1]
1394 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1395
1396 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1397 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1398
1399 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001400 CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001401 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1402
1403 // Excluded modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001404 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001405 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001406 CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001407 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001408 CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -08001409 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1410 }
1411
1412 // Verify that each json file for an included module has a rule.
1413 for _, jsonFile := range includeJsonFiles {
1414 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1415 t.Errorf("include json file %q not found", jsonFile)
1416 }
1417 }
1418
1419 // Verify that each json file for an excluded module has no rule.
1420 for _, jsonFile := range excludeJsonFiles {
1421 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1422 t.Errorf("exclude json file %q found", jsonFile)
1423 }
1424 }
1425}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001426
1427func TestRecoverySnapshotDirected(t *testing.T) {
1428 bp := `
1429 cc_library_shared {
1430 name: "librecovery",
1431 recovery: true,
1432 nocrt: true,
1433 }
1434
1435 cc_library_shared {
1436 name: "librecovery_available",
1437 recovery_available: true,
1438 nocrt: true,
1439 }
1440
1441 genrule {
1442 name: "libfoo_gen",
1443 cmd: "",
1444 out: ["libfoo.so"],
1445 }
1446
1447 cc_prebuilt_library_shared {
1448 name: "libfoo",
1449 recovery: true,
1450 prefer: true,
1451 srcs: [":libfoo_gen"],
1452 }
1453
1454 cc_library_shared {
1455 name: "libfoo",
1456 recovery: true,
1457 nocrt: true,
1458 }
1459`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001460 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001461 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1462 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001463 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001464 config.TestProductVariables.DirectedRecoverySnapshot = true
1465 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1466 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1467 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1468 ctx := testCcWithConfig(t, config)
1469
1470 // Check recovery snapshot output.
1471
1472 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001473 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001474 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1475
1476 var includeJsonFiles []string
1477
1478 for _, arch := range [][]string{
1479 []string{"arm64", "armv8-a"},
1480 } {
1481 archType := arch[0]
1482 archVariant := arch[1]
1483 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1484
1485 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1486 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1487
1488 // Included modules
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001489 CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001490 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1491 // Check that snapshot captures "prefer: true" prebuilt
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001492 CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001493 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1494
1495 // Excluded modules. Modules not included in the directed recovery snapshot
1496 // are still include as fake modules.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04001497 CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001498 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1499 }
1500
1501 // Verify that each json file for an included module has a rule.
1502 for _, jsonFile := range includeJsonFiles {
1503 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1504 t.Errorf("include json file %q not found", jsonFile)
1505 }
1506 }
1507}