blob: 5e9a11f8c34e99439d55d4d5edc69c158a0b2038 [file] [log] [blame]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001package apex
2
3import (
4 "testing"
5
6 "github.com/google/blueprint/proptools"
7
8 "android/soong/android"
9)
10
Jooyung Han73d20d02020-03-27 16:06:55 +090011func TestVndkApexForVndkLite(t *testing.T) {
12 ctx, _ := testApex(t, `
13 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -080014 name: "com.android.vndk.current",
15 key: "com.android.vndk.current.key",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000016 updatable: false,
Jooyung Han73d20d02020-03-27 16:06:55 +090017 }
18
19 apex_key {
Colin Cross2807f002021-03-02 10:15:29 -080020 name: "com.android.vndk.current.key",
Jooyung Han73d20d02020-03-27 16:06:55 +090021 public_key: "testkey.avbpubkey",
22 private_key: "testkey.pem",
23 }
24
25 cc_library {
26 name: "libvndk",
27 srcs: ["mylib.cpp"],
28 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090029 product_available: true,
Jooyung Han73d20d02020-03-27 16:06:55 +090030 vndk: {
31 enabled: true,
32 },
33 system_shared_libs: [],
34 stl: "none",
Colin Cross2807f002021-03-02 10:15:29 -080035 apex_available: [ "com.android.vndk.current" ],
Jooyung Han73d20d02020-03-27 16:06:55 +090036 }
37
38 cc_library {
39 name: "libvndksp",
40 srcs: ["mylib.cpp"],
41 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090042 product_available: true,
Jooyung Han73d20d02020-03-27 16:06:55 +090043 vndk: {
44 enabled: true,
45 support_system_process: true,
46 },
47 system_shared_libs: [],
48 stl: "none",
Colin Cross2807f002021-03-02 10:15:29 -080049 apex_available: [ "com.android.vndk.current" ],
Jooyung Han73d20d02020-03-27 16:06:55 +090050 }
51 `+vndkLibrariesTxtFiles("current"), func(fs map[string][]byte, config android.Config) {
52 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("")
53 })
54 // VNDK-Lite contains only core variants of VNDK-Sp libraries
Colin Cross2807f002021-03-02 10:15:29 -080055 ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{
Jooyung Han73d20d02020-03-27 16:06:55 +090056 "lib/libvndksp.so",
57 "lib/libc++.so",
58 "lib64/libvndksp.so",
59 "lib64/libc++.so",
60 "etc/llndk.libraries.VER.txt",
61 "etc/vndkcore.libraries.VER.txt",
62 "etc/vndksp.libraries.VER.txt",
63 "etc/vndkprivate.libraries.VER.txt",
Justin Yun8a2600c2020-12-07 12:44:03 +090064 "etc/vndkproduct.libraries.VER.txt",
Jooyung Han73d20d02020-03-27 16:06:55 +090065 })
66}
67
Jooyung Hana57af4a2020-01-23 05:36:59 +000068func TestVndkApexUsesVendorVariant(t *testing.T) {
69 bp := `
70 apex_vndk {
Colin Cross2807f002021-03-02 10:15:29 -080071 name: "com.android.vndk.current",
Jooyung Hana57af4a2020-01-23 05:36:59 +000072 key: "mykey",
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000073 updatable: false,
Jooyung Hana57af4a2020-01-23 05:36:59 +000074 }
75 apex_key {
76 name: "mykey",
77 }
78 cc_library {
79 name: "libfoo",
80 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090081 product_available: true,
Jooyung Hana57af4a2020-01-23 05:36:59 +000082 vndk: {
83 enabled: true,
84 },
85 system_shared_libs: [],
86 stl: "none",
87 notice: "custom_notice",
88 }
89 ` + vndkLibrariesTxtFiles("current")
90
91 ensureFileSrc := func(t *testing.T, files []fileInApex, path, src string) {
92 t.Helper()
93 for _, f := range files {
94 if f.path == path {
95 ensureContains(t, f.src, src)
96 return
97 }
98 }
Colin Cross2807f002021-03-02 10:15:29 -080099 t.Errorf("expected path %q not found", path)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000100 }
101
102 t.Run("VNDK lib doesn't have an apex variant", func(t *testing.T) {
103 ctx, _ := testApex(t, bp)
104
105 // libfoo doesn't have apex variants
106 for _, variant := range ctx.ModuleVariantsForTests("libfoo") {
107 ensureNotContains(t, variant, "_myapex")
108 }
109
110 // VNDK APEX doesn't create apex variant
Colin Cross2807f002021-03-02 10:15:29 -0800111 files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
Jooyung Hana57af4a2020-01-23 05:36:59 +0000112 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
113 })
114
115 t.Run("VNDK APEX gathers only vendor variants even if product variants are available", func(t *testing.T) {
116 ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) {
117 // Now product variant is available
118 config.TestProductVariables.ProductVndkVersion = proptools.StringPtr("current")
119 })
120
Colin Cross2807f002021-03-02 10:15:29 -0800121 files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
Jooyung Hana57af4a2020-01-23 05:36:59 +0000122 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
123 })
124
125 t.Run("VNDK APEX supports coverage variants", func(t *testing.T) {
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400126 ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) {
Colin Cross1a6acd42020-06-16 17:51:46 -0700127 config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true)
Colin Crossd9a121b2020-01-27 13:26:42 -0800128 config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000129 })
130
Colin Cross2807f002021-03-02 10:15:29 -0800131 files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
Jooyung Hana57af4a2020-01-23 05:36:59 +0000132 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
133
Colin Cross2807f002021-03-02 10:15:29 -0800134 files = getFiles(t, ctx, "com.android.vndk.current", "android_common_cov_image")
Jooyung Hana57af4a2020-01-23 05:36:59 +0000135 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared_cov/libfoo.so")
136 })
137}