blob: 8d13cebe69024829cb61d8dd330c761ec5026611 [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",
81 llndk_stubs: "libllndk.llndk",
82 }
83
84 llndk_library {
85 name: "libllndk.llndk",
86 symbol_file: "",
87 }
88`
Paul Duffinc3e6ce02021-03-22 23:21:32 +000089 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -080090 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
91 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
92 ctx := testCcWithConfig(t, config)
93
94 // Check Vendor snapshot output.
95
96 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +000097 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -080098 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
99
100 var jsonFiles []string
101
102 for _, arch := range [][]string{
103 []string{"arm64", "armv8-a"},
104 []string{"arm", "armv7-a-neon"},
105 } {
106 archType := arch[0]
107 archVariant := arch[1]
108 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
109
110 // For shared libraries, only non-VNDK vendor_available modules are captured
111 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
112 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
113 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
114 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
115 jsonFiles = append(jsonFiles,
116 filepath.Join(sharedDir, "libvendor.so.json"),
117 filepath.Join(sharedDir, "libvendor_available.so.json"))
118
119 // LLNDK modules are not captured
120 checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
121
122 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
123 // Also cfi variants are captured, except for prebuilts like toolchain_library
124 staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
125 staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant)
126 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
127 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
128 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
129 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
130 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
131 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
132 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
133 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
134 jsonFiles = append(jsonFiles,
135 filepath.Join(staticDir, "libb.a.json"),
136 filepath.Join(staticDir, "libvndk.a.json"),
137 filepath.Join(staticDir, "libvndk.cfi.a.json"),
138 filepath.Join(staticDir, "libvendor.a.json"),
139 filepath.Join(staticDir, "libvendor.cfi.a.json"),
140 filepath.Join(staticDir, "libvendor_available.a.json"),
141 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
142
143 // For binary executables, all vendor:true and vendor_available modules are captured.
144 if archType == "arm64" {
145 binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
146 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
147 checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
148 checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
149 jsonFiles = append(jsonFiles,
150 filepath.Join(binaryDir, "vendor_bin.json"),
151 filepath.Join(binaryDir, "vendor_available_bin.json"))
152 }
153
154 // For header libraries, all vendor:true and vendor_available modules are captured.
155 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
156 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
157
158 // For object modules, all vendor:true and vendor_available modules are captured.
159 objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
160 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
161 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
162 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
163 }
164
165 for _, jsonFile := range jsonFiles {
166 // verify all json files exist
167 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
168 t.Errorf("%q expected but not found", jsonFile)
169 }
170 }
171
172 // fake snapshot should have all outputs in the normal snapshot.
173 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
174 for _, output := range snapshotSingleton.AllOutputs() {
175 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
176 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
177 t.Errorf("%q expected but not found", fakeOutput)
178 }
179 }
180}
181
182func TestVendorSnapshotDirected(t *testing.T) {
183 bp := `
184 cc_library_shared {
185 name: "libvendor",
186 vendor: true,
187 nocrt: true,
188 }
189
190 cc_library_shared {
191 name: "libvendor_available",
192 vendor_available: true,
193 nocrt: true,
194 }
195
196 genrule {
197 name: "libfoo_gen",
198 cmd: "",
199 out: ["libfoo.so"],
200 }
201
202 cc_prebuilt_library_shared {
203 name: "libfoo",
204 vendor: true,
205 prefer: true,
206 srcs: [":libfoo_gen"],
207 }
208
209 cc_library_shared {
210 name: "libfoo",
211 vendor: true,
212 nocrt: true,
213 }
214`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000215 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800216 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
217 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
218 config.TestProductVariables.DirectedVendorSnapshot = true
219 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
220 config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
221 config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
222 ctx := testCcWithConfig(t, config)
223
224 // Check Vendor snapshot output.
225
226 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000227 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800228 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
229
230 var includeJsonFiles []string
Colin Cross0fce0ba2021-01-08 16:40:12 -0800231
232 for _, arch := range [][]string{
233 []string{"arm64", "armv8-a"},
234 []string{"arm", "armv7-a-neon"},
235 } {
236 archType := arch[0]
237 archVariant := arch[1]
238 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
239
240 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
241 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
242
243 // Included modules
244 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
245 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
246 // Check that snapshot captures "prefer: true" prebuilt
247 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
248 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
249
Jose Galmes0a942a02021-02-03 14:23:15 -0800250 // Excluded modules. Modules not included in the directed vendor snapshot
251 // are still include as fake modules.
252 checkSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
253 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
Colin Cross0fce0ba2021-01-08 16:40:12 -0800254 }
255
256 // Verify that each json file for an included module has a rule.
257 for _, jsonFile := range includeJsonFiles {
258 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
259 t.Errorf("include json file %q not found", jsonFile)
260 }
261 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800262}
263
264func TestVendorSnapshotUse(t *testing.T) {
265 frameworkBp := `
266 cc_library {
267 name: "libvndk",
268 vendor_available: true,
269 product_available: true,
270 vndk: {
271 enabled: true,
272 },
273 nocrt: true,
274 compile_multilib: "64",
275 }
276
277 cc_library {
278 name: "libvendor",
279 vendor: true,
280 nocrt: true,
281 no_libcrt: true,
282 stl: "none",
283 system_shared_libs: [],
284 compile_multilib: "64",
285 }
286
Colin Cross2e577f32021-01-22 13:06:25 -0800287 cc_library {
288 name: "libvendor_available",
289 vendor_available: true,
290 nocrt: true,
291 no_libcrt: true,
292 stl: "none",
293 system_shared_libs: [],
294 compile_multilib: "64",
295 }
296
Colin Cross0fce0ba2021-01-08 16:40:12 -0800297 cc_binary {
298 name: "bin",
299 vendor: true,
300 nocrt: true,
301 no_libcrt: true,
302 stl: "none",
303 system_shared_libs: [],
304 compile_multilib: "64",
305 }
306`
307
308 vndkBp := `
309 vndk_prebuilt_shared {
310 name: "libvndk",
311 version: "BOARD",
312 target_arch: "arm64",
313 vendor_available: true,
314 product_available: true,
315 vndk: {
316 enabled: true,
317 },
318 arch: {
319 arm64: {
320 srcs: ["libvndk.so"],
321 export_include_dirs: ["include/libvndk"],
322 },
323 },
324 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800325
326 // old snapshot module which has to be ignored
327 vndk_prebuilt_shared {
328 name: "libvndk",
329 version: "OLD",
330 target_arch: "arm64",
331 vendor_available: true,
332 product_available: true,
333 vndk: {
334 enabled: true,
335 },
336 arch: {
337 arm64: {
338 srcs: ["libvndk.so"],
339 export_include_dirs: ["include/libvndk"],
340 },
341 },
342 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800343`
344
345 vendorProprietaryBp := `
346 cc_library {
347 name: "libvendor_without_snapshot",
348 vendor: true,
349 nocrt: true,
350 no_libcrt: true,
351 stl: "none",
352 system_shared_libs: [],
353 compile_multilib: "64",
354 }
355
356 cc_library_shared {
357 name: "libclient",
358 vendor: true,
359 nocrt: true,
360 no_libcrt: true,
361 stl: "none",
362 system_shared_libs: [],
Colin Cross2e577f32021-01-22 13:06:25 -0800363 shared_libs: ["libvndk", "libvendor_available"],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800364 static_libs: ["libvendor", "libvendor_without_snapshot"],
365 compile_multilib: "64",
366 srcs: ["client.cpp"],
367 }
368
369 cc_binary {
370 name: "bin_without_snapshot",
371 vendor: true,
372 nocrt: true,
373 no_libcrt: true,
374 stl: "none",
375 system_shared_libs: [],
376 static_libs: ["libvndk"],
377 compile_multilib: "64",
378 srcs: ["bin.cpp"],
379 }
380
Colin Crosse0edaf92021-01-11 17:31:17 -0800381 vendor_snapshot {
382 name: "vendor_snapshot",
383 compile_multilib: "first",
384 version: "BOARD",
385 vndk_libs: [
386 "libvndk",
387 ],
388 static_libs: [
389 "libvendor",
390 "libvendor_available",
391 "libvndk",
392 ],
393 shared_libs: [
394 "libvendor",
395 "libvendor_available",
396 ],
397 binaries: [
398 "bin",
399 ],
400 }
401
Colin Cross0fce0ba2021-01-08 16:40:12 -0800402 vendor_snapshot_static {
403 name: "libvndk",
404 version: "BOARD",
405 target_arch: "arm64",
406 vendor: true,
407 arch: {
408 arm64: {
409 src: "libvndk.a",
410 export_include_dirs: ["include/libvndk"],
411 },
412 },
413 }
414
415 vendor_snapshot_shared {
416 name: "libvendor",
417 version: "BOARD",
418 target_arch: "arm64",
Justin Yun48138672021-02-25 18:21:27 +0900419 compile_multilib: "64",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800420 vendor: true,
Justin Yun48138672021-02-25 18:21:27 +0900421 shared_libs: [
422 "libvendor_without_snapshot",
423 "libvendor_available",
Justin Yun07b9f862021-02-26 14:00:03 +0900424 "libvndk",
Justin Yun48138672021-02-25 18:21:27 +0900425 ],
Colin Cross0fce0ba2021-01-08 16:40:12 -0800426 arch: {
427 arm64: {
428 src: "libvendor.so",
429 export_include_dirs: ["include/libvendor"],
430 },
431 },
432 }
433
434 vendor_snapshot_static {
435 name: "libvendor",
436 version: "BOARD",
437 target_arch: "arm64",
438 vendor: true,
439 arch: {
440 arm64: {
441 src: "libvendor.a",
442 export_include_dirs: ["include/libvendor"],
443 },
444 },
445 }
446
Colin Cross2e577f32021-01-22 13:06:25 -0800447 vendor_snapshot_shared {
448 name: "libvendor_available",
Colin Crossa8890802021-01-22 14:06:33 -0800449 androidmk_suffix: ".vendor",
Colin Cross2e577f32021-01-22 13:06:25 -0800450 version: "BOARD",
451 target_arch: "arm64",
452 vendor: true,
453 arch: {
454 arm64: {
455 src: "libvendor_available.so",
456 export_include_dirs: ["include/libvendor"],
457 },
458 },
459 }
460
461 vendor_snapshot_static {
462 name: "libvendor_available",
Colin Crossa8890802021-01-22 14:06:33 -0800463 androidmk_suffix: ".vendor",
Colin Cross2e577f32021-01-22 13:06:25 -0800464 version: "BOARD",
465 target_arch: "arm64",
466 vendor: true,
467 arch: {
468 arm64: {
469 src: "libvendor_available.a",
470 export_include_dirs: ["include/libvendor"],
471 },
472 },
473 }
474
Colin Cross0fce0ba2021-01-08 16:40:12 -0800475 vendor_snapshot_binary {
476 name: "bin",
477 version: "BOARD",
478 target_arch: "arm64",
479 vendor: true,
480 arch: {
481 arm64: {
482 src: "bin",
483 },
484 },
485 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800486
487 // old snapshot module which has to be ignored
488 vendor_snapshot_binary {
489 name: "bin",
490 version: "OLD",
491 target_arch: "arm64",
492 vendor: true,
493 arch: {
494 arm64: {
495 src: "bin",
496 },
497 },
498 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800499`
500 depsBp := GatherRequiredDepsForTest(android.Android)
501
502 mockFS := map[string][]byte{
503 "deps/Android.bp": []byte(depsBp),
504 "framework/Android.bp": []byte(frameworkBp),
505 "vendor/Android.bp": []byte(vendorProprietaryBp),
506 "vendor/bin": nil,
507 "vendor/bin.cpp": nil,
508 "vendor/client.cpp": nil,
509 "vendor/include/libvndk/a.h": nil,
510 "vendor/include/libvendor/b.h": nil,
511 "vendor/libvndk.a": nil,
512 "vendor/libvendor.a": nil,
513 "vendor/libvendor.so": nil,
514 "vndk/Android.bp": []byte(vndkBp),
515 "vndk/include/libvndk/a.h": nil,
516 "vndk/libvndk.so": nil,
517 }
518
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000519 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800520 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
521 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
522 ctx := CreateTestContext(config)
523 ctx.Register()
524
525 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
526 android.FailIfErrored(t, errs)
527 _, errs = ctx.PrepareBuildActions(config)
528 android.FailIfErrored(t, errs)
529
530 sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared"
531 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
532 binaryVariant := "android_vendor.BOARD_arm64_armv8-a"
533
534 // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot
535 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
536 for _, includeFlags := range []string{
537 "-Ivndk/include/libvndk", // libvndk
538 "-Ivendor/include/libvendor", // libvendor
539 } {
540 if !strings.Contains(libclientCcFlags, includeFlags) {
541 t.Errorf("flags for libclient must contain %#v, but was %#v.",
542 includeFlags, libclientCcFlags)
543 }
544 }
545
546 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
547 for _, input := range [][]string{
548 []string{sharedVariant, "libvndk.vndk.BOARD.arm64"},
549 []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"},
550 []string{staticVariant, "libvendor_without_snapshot"},
551 } {
552 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
553 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
554 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
555 }
556 }
557
Colin Cross2e577f32021-01-22 13:06:25 -0800558 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
559 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor"}; !reflect.DeepEqual(g, w) {
560 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
561 }
562
563 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
564 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
565 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
566 }
567
Colin Cross0fce0ba2021-01-08 16:40:12 -0800568 // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64
569 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
570 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
571 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
572 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
573 }
574
575 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
576 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"})
577 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
578 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
579 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
580 }
581
582 // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64
583 ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so")
584
Colin Cross2e577f32021-01-22 13:06:25 -0800585 // libvendor_available.so is installed by libvendor_available.vendor_shared.BOARD.arm64
586 ctx.ModuleForTests("libvendor_available.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor_available.so")
587
Colin Cross0fce0ba2021-01-08 16:40:12 -0800588 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
589 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
590
591 // bin is installed by bin.vendor_binary.BOARD.arm64
592 ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin")
593
594 // bin_without_snapshot is installed by bin_without_snapshot
595 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
596
Colin Cross2e577f32021-01-22 13:06:25 -0800597 // libvendor, libvendor_available and bin don't have vendor.BOARD variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800598 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
599 if inList(sharedVariant, libvendorVariants) {
600 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
601 }
602
Colin Cross2e577f32021-01-22 13:06:25 -0800603 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
604 if inList(sharedVariant, libvendorAvailableVariants) {
605 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
606 }
607
Colin Cross0fce0ba2021-01-08 16:40:12 -0800608 binVariants := ctx.ModuleVariantsForTests("bin")
609 if inList(binaryVariant, binVariants) {
610 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
611 }
612}
613
614func TestVendorSnapshotSanitizer(t *testing.T) {
615 bp := `
616 vendor_snapshot_static {
617 name: "libsnapshot",
618 vendor: true,
619 target_arch: "arm64",
620 version: "BOARD",
621 arch: {
622 arm64: {
623 src: "libsnapshot.a",
624 cfi: {
625 src: "libsnapshot.cfi.a",
626 }
627 },
628 },
629 }
630`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000631 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800632 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
633 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
634 ctx := testCcWithConfig(t, config)
635
636 // Check non-cfi and cfi variant.
637 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
638 staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi"
639
640 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module)
641 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
642
643 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module)
644 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
645}
646
647func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
648 t.Helper()
649 m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
650 if m.ExcludeFromVendorSnapshot() != expected {
651 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
652 }
653}
654
655func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
656 t.Helper()
657 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
658 if m.ExcludeFromRecoverySnapshot() != expected {
659 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
660 }
661}
662
663func TestVendorSnapshotExclude(t *testing.T) {
664
665 // This test verifies that the exclude_from_vendor_snapshot property
666 // makes its way from the Android.bp source file into the module data
667 // structure. It also verifies that modules are correctly included or
668 // excluded in the vendor snapshot based on their path (framework or
669 // vendor) and the exclude_from_vendor_snapshot property.
670
671 frameworkBp := `
672 cc_library_shared {
673 name: "libinclude",
674 srcs: ["src/include.cpp"],
675 vendor_available: true,
676 }
677 cc_library_shared {
678 name: "libexclude",
679 srcs: ["src/exclude.cpp"],
680 vendor: true,
681 exclude_from_vendor_snapshot: true,
682 }
683 cc_library_shared {
684 name: "libavailable_exclude",
685 srcs: ["src/exclude.cpp"],
686 vendor_available: true,
687 exclude_from_vendor_snapshot: true,
688 }
689 `
690
691 vendorProprietaryBp := `
692 cc_library_shared {
693 name: "libvendor",
694 srcs: ["vendor.cpp"],
695 vendor: true,
696 }
697 `
698
699 depsBp := GatherRequiredDepsForTest(android.Android)
700
701 mockFS := map[string][]byte{
702 "deps/Android.bp": []byte(depsBp),
703 "framework/Android.bp": []byte(frameworkBp),
704 "framework/include.cpp": nil,
705 "framework/exclude.cpp": nil,
706 "device/Android.bp": []byte(vendorProprietaryBp),
707 "device/vendor.cpp": nil,
708 }
709
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000710 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800711 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
712 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
713 ctx := CreateTestContext(config)
714 ctx.Register()
715
716 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
717 android.FailIfErrored(t, errs)
718 _, errs = ctx.PrepareBuildActions(config)
719 android.FailIfErrored(t, errs)
720
721 // Test an include and exclude framework module.
722 assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false)
723 assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true)
724 assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true)
725
726 // A vendor module is excluded, but by its path, not the
727 // exclude_from_vendor_snapshot property.
728 assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false)
729
730 // Verify the content of the vendor snapshot.
731
732 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000733 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800734 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
735
736 var includeJsonFiles []string
737 var excludeJsonFiles []string
738
739 for _, arch := range [][]string{
740 []string{"arm64", "armv8-a"},
741 []string{"arm", "armv7-a-neon"},
742 } {
743 archType := arch[0]
744 archVariant := arch[1]
745 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
746
747 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
748 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
749
750 // Included modules
751 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
752 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
753
754 // Excluded modules
755 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
756 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
757 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
758 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
759 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
760 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
761 }
762
763 // Verify that each json file for an included module has a rule.
764 for _, jsonFile := range includeJsonFiles {
765 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
766 t.Errorf("include json file %q not found", jsonFile)
767 }
768 }
769
770 // Verify that each json file for an excluded module has no rule.
771 for _, jsonFile := range excludeJsonFiles {
772 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
773 t.Errorf("exclude json file %q found", jsonFile)
774 }
775 }
776}
777
778func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
779
780 // This test verifies that using the exclude_from_vendor_snapshot
781 // property on a module in a vendor proprietary path generates an
782 // error. These modules are already excluded, so we prohibit using the
783 // property in this way, which could add to confusion.
784
785 vendorProprietaryBp := `
786 cc_library_shared {
787 name: "libvendor",
788 srcs: ["vendor.cpp"],
789 vendor: true,
790 exclude_from_vendor_snapshot: true,
791 }
792 `
793
794 depsBp := GatherRequiredDepsForTest(android.Android)
795
796 mockFS := map[string][]byte{
797 "deps/Android.bp": []byte(depsBp),
798 "device/Android.bp": []byte(vendorProprietaryBp),
799 "device/vendor.cpp": nil,
800 }
801
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000802 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800803 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
804 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
805 ctx := CreateTestContext(config)
806 ctx.Register()
807
808 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
809 android.FailIfErrored(t, errs)
810
811 _, errs = ctx.PrepareBuildActions(config)
812 android.CheckErrorsAgainstExpectations(t, errs, []string{
813 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
814 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
815 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
816 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
817 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
818 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
819 })
820}
821
822func TestRecoverySnapshotCapture(t *testing.T) {
823 bp := `
824 cc_library {
825 name: "libvndk",
826 vendor_available: true,
827 recovery_available: true,
828 product_available: true,
829 vndk: {
830 enabled: true,
831 },
832 nocrt: true,
833 }
834
835 cc_library {
836 name: "librecovery",
837 recovery: true,
838 nocrt: true,
839 }
840
841 cc_library {
842 name: "librecovery_available",
843 recovery_available: true,
844 nocrt: true,
845 }
846
847 cc_library_headers {
848 name: "librecovery_headers",
849 recovery_available: true,
850 nocrt: true,
851 }
852
853 cc_binary {
854 name: "recovery_bin",
855 recovery: true,
856 nocrt: true,
857 }
858
859 cc_binary {
860 name: "recovery_available_bin",
861 recovery_available: true,
862 nocrt: true,
863 }
864
865 toolchain_library {
866 name: "libb",
867 recovery_available: true,
868 src: "libb.a",
869 }
870
871 cc_object {
872 name: "obj",
873 recovery_available: true,
874 }
875`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000876 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800877 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
878 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
879 ctx := testCcWithConfig(t, config)
880
881 // Check Recovery snapshot output.
882
883 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000884 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800885 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
886
887 var jsonFiles []string
888
889 for _, arch := range [][]string{
890 []string{"arm64", "armv8-a"},
891 } {
892 archType := arch[0]
893 archVariant := arch[1]
894 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
895
896 // For shared libraries, only recovery_available modules are captured.
897 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
898 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
899 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
900 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
901 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
902 jsonFiles = append(jsonFiles,
903 filepath.Join(sharedDir, "libvndk.so.json"),
904 filepath.Join(sharedDir, "librecovery.so.json"),
905 filepath.Join(sharedDir, "librecovery_available.so.json"))
906
907 // For static libraries, all recovery:true and recovery_available modules are captured.
908 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
909 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
910 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
911 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
912 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
913 jsonFiles = append(jsonFiles,
914 filepath.Join(staticDir, "libb.a.json"),
915 filepath.Join(staticDir, "librecovery.a.json"),
916 filepath.Join(staticDir, "librecovery_available.a.json"))
917
918 // For binary executables, all recovery:true and recovery_available modules are captured.
919 if archType == "arm64" {
920 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
921 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
922 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
923 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
924 jsonFiles = append(jsonFiles,
925 filepath.Join(binaryDir, "recovery_bin.json"),
926 filepath.Join(binaryDir, "recovery_available_bin.json"))
927 }
928
929 // For header libraries, all vendor:true and vendor_available modules are captured.
930 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
931 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
932
933 // For object modules, all vendor:true and vendor_available modules are captured.
934 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
935 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
936 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
937 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
938 }
939
940 for _, jsonFile := range jsonFiles {
941 // verify all json files exist
942 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
943 t.Errorf("%q expected but not found", jsonFile)
944 }
945 }
946}
947
948func TestRecoverySnapshotExclude(t *testing.T) {
949 // This test verifies that the exclude_from_recovery_snapshot property
950 // makes its way from the Android.bp source file into the module data
951 // structure. It also verifies that modules are correctly included or
952 // excluded in the recovery snapshot based on their path (framework or
953 // vendor) and the exclude_from_recovery_snapshot property.
954
955 frameworkBp := `
956 cc_library_shared {
957 name: "libinclude",
958 srcs: ["src/include.cpp"],
959 recovery_available: true,
960 }
961 cc_library_shared {
962 name: "libexclude",
963 srcs: ["src/exclude.cpp"],
964 recovery: true,
965 exclude_from_recovery_snapshot: true,
966 }
967 cc_library_shared {
968 name: "libavailable_exclude",
969 srcs: ["src/exclude.cpp"],
970 recovery_available: true,
971 exclude_from_recovery_snapshot: true,
972 }
973 `
974
975 vendorProprietaryBp := `
976 cc_library_shared {
977 name: "librecovery",
978 srcs: ["recovery.cpp"],
979 recovery: true,
980 }
981 `
982
983 depsBp := GatherRequiredDepsForTest(android.Android)
984
985 mockFS := map[string][]byte{
986 "deps/Android.bp": []byte(depsBp),
987 "framework/Android.bp": []byte(frameworkBp),
988 "framework/include.cpp": nil,
989 "framework/exclude.cpp": nil,
990 "device/Android.bp": []byte(vendorProprietaryBp),
991 "device/recovery.cpp": nil,
992 }
993
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000994 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800995 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
996 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
997 ctx := CreateTestContext(config)
998 ctx.Register()
999
1000 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1001 android.FailIfErrored(t, errs)
1002 _, errs = ctx.PrepareBuildActions(config)
1003 android.FailIfErrored(t, errs)
1004
1005 // Test an include and exclude framework module.
1006 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1007 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1008 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
1009
1010 // A recovery module is excluded, but by its path, not the
1011 // exclude_from_recovery_snapshot property.
1012 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
1013
1014 // Verify the content of the recovery snapshot.
1015
1016 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001017 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001018 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1019
1020 var includeJsonFiles []string
1021 var excludeJsonFiles []string
1022
1023 for _, arch := range [][]string{
1024 []string{"arm64", "armv8-a"},
1025 } {
1026 archType := arch[0]
1027 archVariant := arch[1]
1028 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1029
1030 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1031 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1032
1033 // Included modules
1034 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1035 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1036
1037 // Excluded modules
1038 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1039 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1040 checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1041 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1042 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1043 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1044 }
1045
1046 // Verify that each json file for an included module has a rule.
1047 for _, jsonFile := range includeJsonFiles {
1048 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1049 t.Errorf("include json file %q not found", jsonFile)
1050 }
1051 }
1052
1053 // Verify that each json file for an excluded module has no rule.
1054 for _, jsonFile := range excludeJsonFiles {
1055 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1056 t.Errorf("exclude json file %q found", jsonFile)
1057 }
1058 }
1059}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001060
1061func TestRecoverySnapshotDirected(t *testing.T) {
1062 bp := `
1063 cc_library_shared {
1064 name: "librecovery",
1065 recovery: true,
1066 nocrt: true,
1067 }
1068
1069 cc_library_shared {
1070 name: "librecovery_available",
1071 recovery_available: true,
1072 nocrt: true,
1073 }
1074
1075 genrule {
1076 name: "libfoo_gen",
1077 cmd: "",
1078 out: ["libfoo.so"],
1079 }
1080
1081 cc_prebuilt_library_shared {
1082 name: "libfoo",
1083 recovery: true,
1084 prefer: true,
1085 srcs: [":libfoo_gen"],
1086 }
1087
1088 cc_library_shared {
1089 name: "libfoo",
1090 recovery: true,
1091 nocrt: true,
1092 }
1093`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001094 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001095 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1096 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
1097 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1098 config.TestProductVariables.DirectedRecoverySnapshot = true
1099 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1100 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1101 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1102 ctx := testCcWithConfig(t, config)
1103
1104 // Check recovery snapshot output.
1105
1106 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001107 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001108 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1109
1110 var includeJsonFiles []string
1111
1112 for _, arch := range [][]string{
1113 []string{"arm64", "armv8-a"},
1114 } {
1115 archType := arch[0]
1116 archVariant := arch[1]
1117 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1118
1119 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1120 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1121
1122 // Included modules
1123 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1124 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1125 // Check that snapshot captures "prefer: true" prebuilt
1126 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
1127 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1128
1129 // Excluded modules. Modules not included in the directed recovery snapshot
1130 // are still include as fake modules.
1131 checkSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1132 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1133 }
1134
1135 // Verify that each json file for an included module has a rule.
1136 for _, jsonFile := range includeJsonFiles {
1137 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1138 t.Errorf("include json file %q not found", jsonFile)
1139 }
1140 }
1141}