blob: 8557faee1c5078263890481eb974e145c9409a9a [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 Han65d8a622020-03-27 16:06:55 +090011func TestVndkApexForVndkLite(t *testing.T) {
12 ctx, _ := testApex(t, `
13 apex_vndk {
14 name: "myapex",
15 key: "myapex.key",
16 }
17
18 apex_key {
19 name: "myapex.key",
20 public_key: "testkey.avbpubkey",
21 private_key: "testkey.pem",
22 }
23
24 cc_library {
25 name: "libvndk",
26 srcs: ["mylib.cpp"],
27 vendor_available: true,
28 vndk: {
29 enabled: true,
30 },
31 system_shared_libs: [],
32 stl: "none",
33 apex_available: [ "myapex" ],
34 }
35
36 cc_library {
37 name: "libvndksp",
38 srcs: ["mylib.cpp"],
39 vendor_available: true,
40 vndk: {
41 enabled: true,
42 support_system_process: true,
43 },
44 system_shared_libs: [],
45 stl: "none",
46 apex_available: [ "myapex" ],
47 }
48 `+vndkLibrariesTxtFiles("current"), func(fs map[string][]byte, config android.Config) {
49 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("")
50 })
51 // VNDK-Lite contains only core variants of VNDK-Sp libraries
52 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
53 "lib/libvndksp.so",
54 "lib/libc++.so",
55 "lib64/libvndksp.so",
56 "lib64/libc++.so",
57 "etc/llndk.libraries.VER.txt",
58 "etc/vndkcore.libraries.VER.txt",
59 "etc/vndksp.libraries.VER.txt",
60 "etc/vndkprivate.libraries.VER.txt",
61 })
62}
63
Jooyung Hana57af4a2020-01-23 05:36:59 +000064func TestVndkApexUsesVendorVariant(t *testing.T) {
65 bp := `
66 apex_vndk {
67 name: "myapex",
68 key: "mykey",
69 }
70 apex_key {
71 name: "mykey",
72 }
73 cc_library {
74 name: "libfoo",
75 vendor_available: true,
76 vndk: {
77 enabled: true,
78 },
79 system_shared_libs: [],
80 stl: "none",
81 notice: "custom_notice",
82 }
83 ` + vndkLibrariesTxtFiles("current")
84
85 ensureFileSrc := func(t *testing.T, files []fileInApex, path, src string) {
86 t.Helper()
87 for _, f := range files {
88 if f.path == path {
89 ensureContains(t, f.src, src)
90 return
91 }
92 }
93 t.Fail()
94 }
95
96 t.Run("VNDK lib doesn't have an apex variant", func(t *testing.T) {
97 ctx, _ := testApex(t, bp)
98
99 // libfoo doesn't have apex variants
100 for _, variant := range ctx.ModuleVariantsForTests("libfoo") {
101 ensureNotContains(t, variant, "_myapex")
102 }
103
104 // VNDK APEX doesn't create apex variant
105 files := getFiles(t, ctx, "myapex", "android_common_image")
106 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
107 })
108
109 t.Run("VNDK APEX gathers only vendor variants even if product variants are available", func(t *testing.T) {
110 ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) {
111 // Now product variant is available
112 config.TestProductVariables.ProductVndkVersion = proptools.StringPtr("current")
113 })
114
115 files := getFiles(t, ctx, "myapex", "android_common_image")
116 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
117 })
118
119 t.Run("VNDK APEX supports coverage variants", func(t *testing.T) {
120 ctx, _ := testApex(t, bp+`
121 cc_library {
122 name: "libprofile-extras",
123 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800124 recovery_available: true,
Jooyung Hana57af4a2020-01-23 05:36:59 +0000125 native_coverage: false,
126 system_shared_libs: [],
127 stl: "none",
128 notice: "custom_notice",
129 }
130 cc_library {
131 name: "libprofile-clang-extras",
132 vendor_available: true,
Colin Crossf9aabd72020-02-15 11:29:50 -0800133 recovery_available: true,
134 native_coverage: false,
135 system_shared_libs: [],
136 stl: "none",
137 notice: "custom_notice",
138 }
139 cc_library {
140 name: "libprofile-extras_ndk",
141 vendor_available: true,
142 native_coverage: false,
143 system_shared_libs: [],
144 stl: "none",
145 notice: "custom_notice",
Colin Cross01fd7cc2020-02-19 16:54:04 -0800146 sdk_version: "current",
Colin Crossf9aabd72020-02-15 11:29:50 -0800147 }
148 cc_library {
149 name: "libprofile-clang-extras_ndk",
150 vendor_available: true,
Jooyung Hana57af4a2020-01-23 05:36:59 +0000151 native_coverage: false,
152 system_shared_libs: [],
153 stl: "none",
154 notice: "custom_notice",
Colin Cross01fd7cc2020-02-19 16:54:04 -0800155 sdk_version: "current",
Jooyung Hana57af4a2020-01-23 05:36:59 +0000156 }
157 `, func(fs map[string][]byte, config android.Config) {
Colin Cross72cabc62020-06-16 17:51:46 -0700158 config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true)
Colin Crossd9a121b2020-01-27 13:26:42 -0800159 config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000160 })
161
162 files := getFiles(t, ctx, "myapex", "android_common_image")
163 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
164
165 files = getFiles(t, ctx, "myapex", "android_common_cov_image")
166 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared_cov/libfoo.so")
167 })
168}