blob: 27d93ee0a718a8aef63b532a4f8990f468e22fee [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 {
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,
Justin Yun63e9ec72020-10-29 16:49:43 +090028 product_available: true,
Jooyung Han73d20d02020-03-27 16:06:55 +090029 vndk: {
30 enabled: true,
31 },
32 system_shared_libs: [],
33 stl: "none",
34 apex_available: [ "myapex" ],
35 }
36
37 cc_library {
38 name: "libvndksp",
39 srcs: ["mylib.cpp"],
40 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090041 product_available: true,
Jooyung Han73d20d02020-03-27 16:06:55 +090042 vndk: {
43 enabled: true,
44 support_system_process: true,
45 },
46 system_shared_libs: [],
47 stl: "none",
48 apex_available: [ "myapex" ],
49 }
50 `+vndkLibrariesTxtFiles("current"), func(fs map[string][]byte, config android.Config) {
51 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("")
52 })
53 // VNDK-Lite contains only core variants of VNDK-Sp libraries
54 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
55 "lib/libvndksp.so",
56 "lib/libc++.so",
57 "lib64/libvndksp.so",
58 "lib64/libc++.so",
59 "etc/llndk.libraries.VER.txt",
60 "etc/vndkcore.libraries.VER.txt",
61 "etc/vndksp.libraries.VER.txt",
62 "etc/vndkprivate.libraries.VER.txt",
63 })
64}
65
Jooyung Hana57af4a2020-01-23 05:36:59 +000066func TestVndkApexUsesVendorVariant(t *testing.T) {
67 bp := `
68 apex_vndk {
69 name: "myapex",
70 key: "mykey",
71 }
72 apex_key {
73 name: "mykey",
74 }
75 cc_library {
76 name: "libfoo",
77 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +090078 product_available: true,
Jooyung Hana57af4a2020-01-23 05:36:59 +000079 vndk: {
80 enabled: true,
81 },
82 system_shared_libs: [],
83 stl: "none",
84 notice: "custom_notice",
85 }
86 ` + vndkLibrariesTxtFiles("current")
87
88 ensureFileSrc := func(t *testing.T, files []fileInApex, path, src string) {
89 t.Helper()
90 for _, f := range files {
91 if f.path == path {
92 ensureContains(t, f.src, src)
93 return
94 }
95 }
96 t.Fail()
97 }
98
99 t.Run("VNDK lib doesn't have an apex variant", func(t *testing.T) {
100 ctx, _ := testApex(t, bp)
101
102 // libfoo doesn't have apex variants
103 for _, variant := range ctx.ModuleVariantsForTests("libfoo") {
104 ensureNotContains(t, variant, "_myapex")
105 }
106
107 // VNDK APEX doesn't create apex variant
108 files := getFiles(t, ctx, "myapex", "android_common_image")
109 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
110 })
111
112 t.Run("VNDK APEX gathers only vendor variants even if product variants are available", func(t *testing.T) {
113 ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) {
114 // Now product variant is available
115 config.TestProductVariables.ProductVndkVersion = proptools.StringPtr("current")
116 })
117
118 files := getFiles(t, ctx, "myapex", "android_common_image")
119 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
120 })
121
122 t.Run("VNDK APEX supports coverage variants", func(t *testing.T) {
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400123 ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) {
Colin Cross1a6acd42020-06-16 17:51:46 -0700124 config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true)
Colin Crossd9a121b2020-01-27 13:26:42 -0800125 config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000126 })
127
128 files := getFiles(t, ctx, "myapex", "android_common_image")
129 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared/libfoo.so")
130
131 files = getFiles(t, ctx, "myapex", "android_common_cov_image")
132 ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.VER_arm_armv7-a-neon_shared_cov/libfoo.so")
133 })
134}