blob: 2a9292c54aacf5616aef979273f141f7df2f1414 [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")
Jiyong Parkf58c46e2021-04-01 21:35:20 +090091 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -080092 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
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900111 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800112 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
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900124 staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
125 staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800126 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" {
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900145 binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800146 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.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900159 objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800160 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")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900217 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800218 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
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900240 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800241 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",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900311 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800312 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",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900329 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800330 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",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900384 version: "28",
Colin Crosse0edaf92021-01-11 17:31:17 -0800385 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",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900404 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800405 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",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900417 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800418 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",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900436 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800437 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",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900449 version: "28",
Colin Cross2e577f32021-01-22 13:06:25 -0800450 target_arch: "arm64",
451 vendor: true,
452 arch: {
453 arm64: {
454 src: "libvendor_available.so",
455 export_include_dirs: ["include/libvendor"],
456 },
457 },
458 }
459
460 vendor_snapshot_static {
461 name: "libvendor_available",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900462 version: "28",
Colin Cross2e577f32021-01-22 13:06:25 -0800463 target_arch: "arm64",
464 vendor: true,
465 arch: {
466 arm64: {
467 src: "libvendor_available.a",
468 export_include_dirs: ["include/libvendor"],
469 },
470 },
471 }
472
Colin Cross0fce0ba2021-01-08 16:40:12 -0800473 vendor_snapshot_binary {
474 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900475 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800476 target_arch: "arm64",
477 vendor: true,
478 arch: {
479 arm64: {
480 src: "bin",
481 },
482 },
483 }
Colin Crosse0edaf92021-01-11 17:31:17 -0800484
485 // old snapshot module which has to be ignored
486 vendor_snapshot_binary {
487 name: "bin",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900488 version: "26",
Colin Crosse0edaf92021-01-11 17:31:17 -0800489 target_arch: "arm64",
490 vendor: true,
491 arch: {
492 arm64: {
493 src: "bin",
494 },
495 },
496 }
Colin Cross0fce0ba2021-01-08 16:40:12 -0800497`
498 depsBp := GatherRequiredDepsForTest(android.Android)
499
500 mockFS := map[string][]byte{
501 "deps/Android.bp": []byte(depsBp),
502 "framework/Android.bp": []byte(frameworkBp),
503 "vendor/Android.bp": []byte(vendorProprietaryBp),
504 "vendor/bin": nil,
505 "vendor/bin.cpp": nil,
506 "vendor/client.cpp": nil,
507 "vendor/include/libvndk/a.h": nil,
508 "vendor/include/libvendor/b.h": nil,
509 "vendor/libvndk.a": nil,
510 "vendor/libvendor.a": nil,
511 "vendor/libvendor.so": nil,
512 "vndk/Android.bp": []byte(vndkBp),
513 "vndk/include/libvndk/a.h": nil,
514 "vndk/libvndk.so": nil,
515 }
516
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000517 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900518 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
519 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800520 ctx := CreateTestContext(config)
521 ctx.Register()
522
523 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
524 android.FailIfErrored(t, errs)
525 _, errs = ctx.PrepareBuildActions(config)
526 android.FailIfErrored(t, errs)
527
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900528 sharedVariant := "android_vendor.28_arm64_armv8-a_shared"
529 staticVariant := "android_vendor.28_arm64_armv8-a_static"
530 binaryVariant := "android_vendor.28_arm64_armv8-a"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800531
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900532 // libclient uses libvndk.vndk.28.arm64, libvendor.vendor_static.28.arm64, libvendor_without_snapshot
Colin Cross0fce0ba2021-01-08 16:40:12 -0800533 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
534 for _, includeFlags := range []string{
535 "-Ivndk/include/libvndk", // libvndk
536 "-Ivendor/include/libvendor", // libvendor
537 } {
538 if !strings.Contains(libclientCcFlags, includeFlags) {
539 t.Errorf("flags for libclient must contain %#v, but was %#v.",
540 includeFlags, libclientCcFlags)
541 }
542 }
543
544 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
545 for _, input := range [][]string{
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900546 []string{sharedVariant, "libvndk.vndk.28.arm64"},
547 []string{staticVariant, "libvendor.vendor_static.28.arm64"},
Colin Cross0fce0ba2021-01-08 16:40:12 -0800548 []string{staticVariant, "libvendor_without_snapshot"},
549 } {
550 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
551 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
552 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
553 }
554 }
555
Colin Cross2e577f32021-01-22 13:06:25 -0800556 libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
557 if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor"}; !reflect.DeepEqual(g, w) {
558 t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
559 }
560
561 libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
562 if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
563 t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
564 }
565
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900566 // bin_without_snapshot uses libvndk.vendor_static.28.arm64
Colin Cross0fce0ba2021-01-08 16:40:12 -0800567 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
568 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
569 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
570 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
571 }
572
573 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900574 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.28.arm64"})
Colin Cross0fce0ba2021-01-08 16:40:12 -0800575 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
576 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
577 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
578 }
579
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900580 // libvendor.so is installed by libvendor.vendor_shared.28.arm64
581 ctx.ModuleForTests("libvendor.vendor_shared.28.arm64", sharedVariant).Output("libvendor.so")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800582
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900583 // libvendor_available.so is installed by libvendor_available.vendor_shared.28.arm64
584 ctx.ModuleForTests("libvendor_available.vendor_shared.28.arm64", sharedVariant).Output("libvendor_available.so")
Colin Cross2e577f32021-01-22 13:06:25 -0800585
Colin Cross0fce0ba2021-01-08 16:40:12 -0800586 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
587 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
588
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900589 // bin is installed by bin.vendor_binary.28.arm64
590 ctx.ModuleForTests("bin.vendor_binary.28.arm64", binaryVariant).Output("bin")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800591
592 // bin_without_snapshot is installed by bin_without_snapshot
593 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
594
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900595 // libvendor, libvendor_available and bin don't have vendor.28 variant
Colin Cross0fce0ba2021-01-08 16:40:12 -0800596 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
597 if inList(sharedVariant, libvendorVariants) {
598 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
599 }
600
Colin Cross2e577f32021-01-22 13:06:25 -0800601 libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
602 if inList(sharedVariant, libvendorAvailableVariants) {
603 t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
604 }
605
Colin Cross0fce0ba2021-01-08 16:40:12 -0800606 binVariants := ctx.ModuleVariantsForTests("bin")
607 if inList(binaryVariant, binVariants) {
608 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
609 }
610}
611
612func TestVendorSnapshotSanitizer(t *testing.T) {
613 bp := `
614 vendor_snapshot_static {
615 name: "libsnapshot",
616 vendor: true,
617 target_arch: "arm64",
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900618 version: "28",
Colin Cross0fce0ba2021-01-08 16:40:12 -0800619 arch: {
620 arm64: {
621 src: "libsnapshot.a",
622 cfi: {
623 src: "libsnapshot.cfi.a",
624 }
625 },
626 },
627 }
628`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000629 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900630 config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
631 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800632 ctx := testCcWithConfig(t, config)
633
634 // Check non-cfi and cfi variant.
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900635 staticVariant := "android_vendor.28_arm64_armv8-a_static"
636 staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
Colin Cross0fce0ba2021-01-08 16:40:12 -0800637
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900638 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800639 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
640
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900641 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800642 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
643}
644
645func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
646 t.Helper()
647 m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
648 if m.ExcludeFromVendorSnapshot() != expected {
649 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
650 }
651}
652
653func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
654 t.Helper()
655 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
656 if m.ExcludeFromRecoverySnapshot() != expected {
657 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
658 }
659}
660
661func TestVendorSnapshotExclude(t *testing.T) {
662
663 // This test verifies that the exclude_from_vendor_snapshot property
664 // makes its way from the Android.bp source file into the module data
665 // structure. It also verifies that modules are correctly included or
666 // excluded in the vendor snapshot based on their path (framework or
667 // vendor) and the exclude_from_vendor_snapshot property.
668
669 frameworkBp := `
670 cc_library_shared {
671 name: "libinclude",
672 srcs: ["src/include.cpp"],
673 vendor_available: true,
674 }
675 cc_library_shared {
676 name: "libexclude",
677 srcs: ["src/exclude.cpp"],
678 vendor: true,
679 exclude_from_vendor_snapshot: true,
680 }
681 cc_library_shared {
682 name: "libavailable_exclude",
683 srcs: ["src/exclude.cpp"],
684 vendor_available: true,
685 exclude_from_vendor_snapshot: true,
686 }
687 `
688
689 vendorProprietaryBp := `
690 cc_library_shared {
691 name: "libvendor",
692 srcs: ["vendor.cpp"],
693 vendor: true,
694 }
695 `
696
697 depsBp := GatherRequiredDepsForTest(android.Android)
698
699 mockFS := map[string][]byte{
700 "deps/Android.bp": []byte(depsBp),
701 "framework/Android.bp": []byte(frameworkBp),
702 "framework/include.cpp": nil,
703 "framework/exclude.cpp": nil,
704 "device/Android.bp": []byte(vendorProprietaryBp),
705 "device/vendor.cpp": nil,
706 }
707
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000708 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800709 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900710 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800711 ctx := CreateTestContext(config)
712 ctx.Register()
713
714 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
715 android.FailIfErrored(t, errs)
716 _, errs = ctx.PrepareBuildActions(config)
717 android.FailIfErrored(t, errs)
718
719 // Test an include and exclude framework module.
720 assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false)
721 assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true)
722 assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true)
723
724 // A vendor module is excluded, but by its path, not the
725 // exclude_from_vendor_snapshot property.
726 assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false)
727
728 // Verify the content of the vendor snapshot.
729
730 snapshotDir := "vendor-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000731 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800732 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
733
734 var includeJsonFiles []string
735 var excludeJsonFiles []string
736
737 for _, arch := range [][]string{
738 []string{"arm64", "armv8-a"},
739 []string{"arm", "armv7-a-neon"},
740 } {
741 archType := arch[0]
742 archVariant := arch[1]
743 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
744
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900745 sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800746 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
747
748 // Included modules
749 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
750 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
751
752 // Excluded modules
753 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
754 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
755 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
756 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
757 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
758 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
759 }
760
761 // Verify that each json file for an included module has a rule.
762 for _, jsonFile := range includeJsonFiles {
763 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
764 t.Errorf("include json file %q not found", jsonFile)
765 }
766 }
767
768 // Verify that each json file for an excluded module has no rule.
769 for _, jsonFile := range excludeJsonFiles {
770 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
771 t.Errorf("exclude json file %q found", jsonFile)
772 }
773 }
774}
775
776func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
777
778 // This test verifies that using the exclude_from_vendor_snapshot
779 // property on a module in a vendor proprietary path generates an
780 // error. These modules are already excluded, so we prohibit using the
781 // property in this way, which could add to confusion.
782
783 vendorProprietaryBp := `
784 cc_library_shared {
785 name: "libvendor",
786 srcs: ["vendor.cpp"],
787 vendor: true,
788 exclude_from_vendor_snapshot: true,
789 }
790 `
791
792 depsBp := GatherRequiredDepsForTest(android.Android)
793
794 mockFS := map[string][]byte{
795 "deps/Android.bp": []byte(depsBp),
796 "device/Android.bp": []byte(vendorProprietaryBp),
797 "device/vendor.cpp": nil,
798 }
799
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000800 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800801 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900802 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800803 ctx := CreateTestContext(config)
804 ctx.Register()
805
806 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
807 android.FailIfErrored(t, errs)
808
809 _, errs = ctx.PrepareBuildActions(config)
810 android.CheckErrorsAgainstExpectations(t, errs, []string{
811 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
812 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
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 })
818}
819
820func TestRecoverySnapshotCapture(t *testing.T) {
821 bp := `
822 cc_library {
823 name: "libvndk",
824 vendor_available: true,
825 recovery_available: true,
826 product_available: true,
827 vndk: {
828 enabled: true,
829 },
830 nocrt: true,
831 }
832
833 cc_library {
834 name: "librecovery",
835 recovery: true,
836 nocrt: true,
837 }
838
839 cc_library {
840 name: "librecovery_available",
841 recovery_available: true,
842 nocrt: true,
843 }
844
845 cc_library_headers {
846 name: "librecovery_headers",
847 recovery_available: true,
848 nocrt: true,
849 }
850
851 cc_binary {
852 name: "recovery_bin",
853 recovery: true,
854 nocrt: true,
855 }
856
857 cc_binary {
858 name: "recovery_available_bin",
859 recovery_available: true,
860 nocrt: true,
861 }
862
863 toolchain_library {
864 name: "libb",
865 recovery_available: true,
866 src: "libb.a",
867 }
868
869 cc_object {
870 name: "obj",
871 recovery_available: true,
872 }
873`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000874 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800875 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900876 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800877 ctx := testCcWithConfig(t, config)
878
879 // Check Recovery snapshot output.
880
881 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000882 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800883 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
884
885 var jsonFiles []string
886
887 for _, arch := range [][]string{
888 []string{"arm64", "armv8-a"},
889 } {
890 archType := arch[0]
891 archVariant := arch[1]
892 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
893
894 // For shared libraries, only recovery_available modules are captured.
895 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
896 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
897 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
898 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
899 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
900 jsonFiles = append(jsonFiles,
901 filepath.Join(sharedDir, "libvndk.so.json"),
902 filepath.Join(sharedDir, "librecovery.so.json"),
903 filepath.Join(sharedDir, "librecovery_available.so.json"))
904
905 // For static libraries, all recovery:true and recovery_available modules are captured.
906 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
907 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
908 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
909 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
910 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
911 jsonFiles = append(jsonFiles,
912 filepath.Join(staticDir, "libb.a.json"),
913 filepath.Join(staticDir, "librecovery.a.json"),
914 filepath.Join(staticDir, "librecovery_available.a.json"))
915
916 // For binary executables, all recovery:true and recovery_available modules are captured.
917 if archType == "arm64" {
918 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
919 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
920 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
921 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
922 jsonFiles = append(jsonFiles,
923 filepath.Join(binaryDir, "recovery_bin.json"),
924 filepath.Join(binaryDir, "recovery_available_bin.json"))
925 }
926
927 // For header libraries, all vendor:true and vendor_available modules are captured.
928 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
929 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
930
931 // For object modules, all vendor:true and vendor_available modules are captured.
932 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
933 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
934 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
935 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
936 }
937
938 for _, jsonFile := range jsonFiles {
939 // verify all json files exist
940 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
941 t.Errorf("%q expected but not found", jsonFile)
942 }
943 }
944}
945
946func TestRecoverySnapshotExclude(t *testing.T) {
947 // This test verifies that the exclude_from_recovery_snapshot property
948 // makes its way from the Android.bp source file into the module data
949 // structure. It also verifies that modules are correctly included or
950 // excluded in the recovery snapshot based on their path (framework or
951 // vendor) and the exclude_from_recovery_snapshot property.
952
953 frameworkBp := `
954 cc_library_shared {
955 name: "libinclude",
956 srcs: ["src/include.cpp"],
957 recovery_available: true,
958 }
959 cc_library_shared {
960 name: "libexclude",
961 srcs: ["src/exclude.cpp"],
962 recovery: true,
963 exclude_from_recovery_snapshot: true,
964 }
965 cc_library_shared {
966 name: "libavailable_exclude",
967 srcs: ["src/exclude.cpp"],
968 recovery_available: true,
969 exclude_from_recovery_snapshot: true,
970 }
971 `
972
973 vendorProprietaryBp := `
974 cc_library_shared {
975 name: "librecovery",
976 srcs: ["recovery.cpp"],
977 recovery: true,
978 }
979 `
980
981 depsBp := GatherRequiredDepsForTest(android.Android)
982
983 mockFS := map[string][]byte{
984 "deps/Android.bp": []byte(depsBp),
985 "framework/Android.bp": []byte(frameworkBp),
986 "framework/include.cpp": nil,
987 "framework/exclude.cpp": nil,
988 "device/Android.bp": []byte(vendorProprietaryBp),
989 "device/recovery.cpp": nil,
990 }
991
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000992 config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
Colin Cross0fce0ba2021-01-08 16:40:12 -0800993 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900994 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross0fce0ba2021-01-08 16:40:12 -0800995 ctx := CreateTestContext(config)
996 ctx.Register()
997
998 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
999 android.FailIfErrored(t, errs)
1000 _, errs = ctx.PrepareBuildActions(config)
1001 android.FailIfErrored(t, errs)
1002
1003 // Test an include and exclude framework module.
1004 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1005 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1006 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
1007
1008 // A recovery module is excluded, but by its path, not the
1009 // exclude_from_recovery_snapshot property.
1010 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
1011
1012 // Verify the content of the recovery snapshot.
1013
1014 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001015 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Colin Cross0fce0ba2021-01-08 16:40:12 -08001016 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1017
1018 var includeJsonFiles []string
1019 var excludeJsonFiles []string
1020
1021 for _, arch := range [][]string{
1022 []string{"arm64", "armv8-a"},
1023 } {
1024 archType := arch[0]
1025 archVariant := arch[1]
1026 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1027
1028 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1029 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1030
1031 // Included modules
1032 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1033 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1034
1035 // Excluded modules
1036 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1037 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1038 checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1039 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1040 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1041 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
1042 }
1043
1044 // Verify that each json file for an included module has a rule.
1045 for _, jsonFile := range includeJsonFiles {
1046 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1047 t.Errorf("include json file %q not found", jsonFile)
1048 }
1049 }
1050
1051 // Verify that each json file for an excluded module has no rule.
1052 for _, jsonFile := range excludeJsonFiles {
1053 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1054 t.Errorf("exclude json file %q found", jsonFile)
1055 }
1056 }
1057}
Jose Galmes4c6895e2021-02-09 07:44:30 -08001058
1059func TestRecoverySnapshotDirected(t *testing.T) {
1060 bp := `
1061 cc_library_shared {
1062 name: "librecovery",
1063 recovery: true,
1064 nocrt: true,
1065 }
1066
1067 cc_library_shared {
1068 name: "librecovery_available",
1069 recovery_available: true,
1070 nocrt: true,
1071 }
1072
1073 genrule {
1074 name: "libfoo_gen",
1075 cmd: "",
1076 out: ["libfoo.so"],
1077 }
1078
1079 cc_prebuilt_library_shared {
1080 name: "libfoo",
1081 recovery: true,
1082 prefer: true,
1083 srcs: [":libfoo_gen"],
1084 }
1085
1086 cc_library_shared {
1087 name: "libfoo",
1088 recovery: true,
1089 nocrt: true,
1090 }
1091`
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001092 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jose Galmes4c6895e2021-02-09 07:44:30 -08001093 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1094 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001095 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001096 config.TestProductVariables.DirectedRecoverySnapshot = true
1097 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
1098 config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
1099 config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
1100 ctx := testCcWithConfig(t, config)
1101
1102 // Check recovery snapshot output.
1103
1104 snapshotDir := "recovery-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001105 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Jose Galmes4c6895e2021-02-09 07:44:30 -08001106 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1107
1108 var includeJsonFiles []string
1109
1110 for _, arch := range [][]string{
1111 []string{"arm64", "armv8-a"},
1112 } {
1113 archType := arch[0]
1114 archVariant := arch[1]
1115 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1116
1117 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1118 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1119
1120 // Included modules
1121 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1122 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
1123 // Check that snapshot captures "prefer: true" prebuilt
1124 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
1125 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1126
1127 // Excluded modules. Modules not included in the directed recovery snapshot
1128 // are still include as fake modules.
1129 checkSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1130 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
1131 }
1132
1133 // Verify that each json file for an included module has a rule.
1134 for _, jsonFile := range includeJsonFiles {
1135 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1136 t.Errorf("include json file %q not found", jsonFile)
1137 }
1138 }
1139}