• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package apex
2
3import (
4	"testing"
5
6	"github.com/google/blueprint/proptools"
7
8	"android/soong/android"
9)
10
11func TestVndkApexForVndkLite(t *testing.T) {
12	ctx := testApex(t, `
13		apex_vndk {
14			name: "com.android.vndk.current",
15			key: "com.android.vndk.current.key",
16			updatable: false,
17		}
18
19		apex_key {
20			name: "com.android.vndk.current.key",
21			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,
29			product_available: true,
30			vndk: {
31				enabled: true,
32			},
33			system_shared_libs: [],
34			stl: "none",
35			apex_available: [ "com.android.vndk.current" ],
36		}
37
38		cc_library {
39			name: "libvndksp",
40			srcs: ["mylib.cpp"],
41			vendor_available: true,
42			product_available: true,
43			vndk: {
44				enabled: true,
45				support_system_process: true,
46			},
47			system_shared_libs: [],
48			stl: "none",
49			apex_available: [ "com.android.vndk.current" ],
50		}
51	`+vndkLibrariesTxtFiles("current"),
52		android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
53			variables.DeviceVndkVersion = proptools.StringPtr("")
54		}),
55	)
56	// VNDK-Lite contains only core variants of VNDK-Sp libraries
57	ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{
58		"lib/libvndksp.so",
59		"lib/libc++.so",
60		"lib64/libvndksp.so",
61		"lib64/libc++.so",
62		"etc/llndk.libraries.29.txt",
63		"etc/vndkcore.libraries.29.txt",
64		"etc/vndksp.libraries.29.txt",
65		"etc/vndkprivate.libraries.29.txt",
66		"etc/vndkproduct.libraries.29.txt",
67	})
68}
69
70func TestVndkApexUsesVendorVariant(t *testing.T) {
71	bp := `
72		apex_vndk {
73			name: "com.android.vndk.current",
74			key: "mykey",
75			updatable: false,
76		}
77		apex_key {
78			name: "mykey",
79		}
80		cc_library {
81			name: "libfoo",
82			vendor_available: true,
83			product_available: true,
84			vndk: {
85				enabled: true,
86			},
87			system_shared_libs: [],
88			stl: "none",
89		}
90		` + vndkLibrariesTxtFiles("current")
91
92	ensureFileSrc := func(t *testing.T, files []fileInApex, path, src string) {
93		t.Helper()
94		for _, f := range files {
95			if f.path == path {
96				ensureContains(t, f.src, src)
97				return
98			}
99		}
100		t.Errorf("expected path %q not found", path)
101	}
102
103	t.Run("VNDK lib doesn't have an apex variant", func(t *testing.T) {
104		ctx := testApex(t, bp)
105
106		// libfoo doesn't have apex variants
107		for _, variant := range ctx.ModuleVariantsForTests("libfoo") {
108			ensureNotContains(t, variant, "_myapex")
109		}
110
111		// VNDK APEX doesn't create apex variant
112		files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
113		ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared/libfoo.so")
114	})
115
116	t.Run("VNDK APEX gathers only vendor variants even if product variants are available", func(t *testing.T) {
117		ctx := testApex(t, bp,
118			android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
119				// Now product variant is available
120				variables.ProductVndkVersion = proptools.StringPtr("current")
121			}),
122		)
123
124		files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
125		ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared/libfoo.so")
126	})
127
128	t.Run("VNDK APEX supports coverage variants", func(t *testing.T) {
129		ctx := testApex(t, bp,
130			android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
131				variables.GcovCoverage = proptools.BoolPtr(true)
132				variables.Native_coverage = proptools.BoolPtr(true)
133			}),
134		)
135
136		files := getFiles(t, ctx, "com.android.vndk.current", "android_common_image")
137		ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared/libfoo.so")
138
139		files = getFiles(t, ctx, "com.android.vndk.current", "android_common_cov_image")
140		ensureFileSrc(t, files, "lib/libfoo.so", "libfoo/android_vendor.29_arm_armv7-a-neon_shared_cov/libfoo.so")
141	})
142}
143