blob: ea479aa404f750810b7f8ec9658b7ecdf7ae4ec9 [file] [log] [blame]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001// Copyright 2018 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 apex
16
17import (
Jiyong Park25fc6a92018-11-18 18:02:45 +090018 "io/ioutil"
19 "os"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070020 "reflect"
Jooyung Han31c470b2019-10-18 16:26:59 +090021 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090022 "strings"
23 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090024
25 "github.com/google/blueprint/proptools"
26
27 "android/soong/android"
28 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090029 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090030)
31
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070032var buildDir string
33
Jooyung Hand3639552019-08-09 12:57:43 +090034// names returns name list from white space separated string
35func names(s string) (ns []string) {
36 for _, n := range strings.Split(s, " ") {
37 if len(n) > 0 {
38 ns = append(ns, n)
39 }
40 }
41 return
42}
43
Jooyung Han344d5432019-08-23 11:17:39 +090044func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
45 t.Helper()
46 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090047 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
48 if len(errs) > 0 {
49 android.FailIfNoMatchingErrors(t, pattern, errs)
50 return
51 }
52 _, errs = ctx.PrepareBuildActions(config)
53 if len(errs) > 0 {
54 android.FailIfNoMatchingErrors(t, pattern, errs)
55 return
56 }
57
58 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
59}
60
Jooyung Han344d5432019-08-23 11:17:39 +090061func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
62 t.Helper()
63 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090064 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
65 android.FailIfErrored(t, errs)
66 _, errs = ctx.PrepareBuildActions(config)
67 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070068 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090069}
70
Jooyung Han344d5432019-08-23 11:17:39 +090071type testCustomizer func(fs map[string][]byte, config android.Config)
72
73func withFiles(files map[string][]byte) testCustomizer {
74 return func(fs map[string][]byte, config android.Config) {
75 for k, v := range files {
76 fs[k] = v
77 }
78 }
79}
80
81func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
82 return func(fs map[string][]byte, config android.Config) {
83 for k, v := range targets {
84 config.Targets[k] = v
85 }
86 }
87}
88
Jooyung Han31c470b2019-10-18 16:26:59 +090089func withBinder32bit(fs map[string][]byte, config android.Config) {
90 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
91}
92
Jooyung Han344d5432019-08-23 11:17:39 +090093func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -070094 config := android.TestArchConfig(buildDir, nil)
95 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
96 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
97 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
98 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
99 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
Jooyung Han344d5432019-08-23 11:17:39 +0900100 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900101
102 ctx := android.NewTestArchContext()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900103 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(BundleFactory))
Alex Light0851b882019-02-07 13:20:53 -0800104 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900105 ctx.RegisterModuleType("apex_vndk", android.ModuleFactoryAdaptor(vndkApexBundleFactory))
Jiyong Parkd1063c12019-07-17 20:08:41 +0900106 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(ApexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +0900107 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700108 ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900109
110 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
111 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +0900112 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900113 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory))
114 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +0900115 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900116 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Roland Levillain630846d2019-06-26 12:48:34 +0100117 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +0900118 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900119 ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900120 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +0900121 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +0900122 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900123 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +0900124 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900125 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
Jiyong Park9e6c2422019-08-09 20:39:45 +0900126 ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory))
Dario Frenicde2a032019-10-27 00:29:22 +0100127 ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900128 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
Dario Frenicde2a032019-10-27 00:29:22 +0100129 ctx.RegisterModuleType("android_app_import", android.ModuleFactoryAdaptor(java.AndroidAppImportFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900130
Jooyung Han344d5432019-08-23 11:17:39 +0900131 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700132 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
133 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
134 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900135 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900136 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900137 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900138 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100139 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900140 ctx.BottomUp("version", cc.VersionMutator).Parallel()
141 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Jooyung Han344d5432019-08-23 11:17:39 +0900142 })
Jooyung Han31c470b2019-10-18 16:26:59 +0900143 ctx.PreDepsMutators(RegisterPreDepsMutators)
144 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han344d5432019-08-23 11:17:39 +0900145 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jooyung Han344d5432019-08-23 11:17:39 +0900146 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
147 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900148 })
149
150 ctx.Register()
151
152 bp = bp + `
153 toolchain_library {
154 name: "libcompiler_rt-extras",
155 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900156 vendor_available: true,
157 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900158 }
159
160 toolchain_library {
161 name: "libatomic",
162 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900163 vendor_available: true,
164 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900165 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900166 }
167
168 toolchain_library {
169 name: "libgcc",
170 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900171 vendor_available: true,
172 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900173 }
174
175 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700176 name: "libgcc_stripped",
177 src: "",
178 vendor_available: true,
179 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900180 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700181 }
182
183 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900184 name: "libclang_rt.builtins-aarch64-android",
185 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900186 vendor_available: true,
187 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900188 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900189 }
190
191 toolchain_library {
192 name: "libclang_rt.builtins-arm-android",
193 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900194 vendor_available: true,
195 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900196 native_bridge_supported: true,
197 }
198
199 toolchain_library {
200 name: "libclang_rt.builtins-x86_64-android",
201 src: "",
202 vendor_available: true,
203 recovery_available: true,
204 native_bridge_supported: true,
205 }
206
207 toolchain_library {
208 name: "libclang_rt.builtins-i686-android",
209 src: "",
210 vendor_available: true,
211 recovery_available: true,
212 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900213 }
214
215 cc_object {
216 name: "crtbegin_so",
217 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900218 vendor_available: true,
219 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900220 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900221 }
222
223 cc_object {
224 name: "crtend_so",
225 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900226 vendor_available: true,
227 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900228 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900229 }
230
Alex Light3d673592019-01-18 14:37:31 -0800231 cc_object {
232 name: "crtbegin_static",
233 stl: "none",
234 }
235
236 cc_object {
237 name: "crtend_android",
238 stl: "none",
239 }
240
Jiyong Parkda6eb592018-12-19 17:12:36 +0900241 llndk_library {
242 name: "libc",
243 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900244 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900245 }
246
247 llndk_library {
248 name: "libm",
249 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900250 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900251 }
252
253 llndk_library {
254 name: "libdl",
255 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900256 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900257 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900258 `
Dario Frenicde2a032019-10-27 00:29:22 +0100259 bp = bp + java.GatherRequiredDepsForTest()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900260
Jooyung Han344d5432019-08-23 11:17:39 +0900261 fs := map[string][]byte{
Dario Frenicde2a032019-10-27 00:29:22 +0100262 "Android.bp": []byte(bp),
263 "a.java": nil,
264 "PrebuiltAppFoo.apk": nil,
265 "PrebuiltAppFooPriv.apk": nil,
266 "build/make/target/product/security": nil,
267 "apex_manifest.json": nil,
268 "AndroidManifest.xml": nil,
269 "system/sepolicy/apex/myapex-file_contexts": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900270 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
271 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900272 "system/sepolicy/apex/commonapex-file_contexts": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900273 "mylib.cpp": nil,
274 "mylib_common.cpp": nil,
275 "mytest.cpp": nil,
276 "mytest1.cpp": nil,
277 "mytest2.cpp": nil,
278 "mytest3.cpp": nil,
279 "myprebuilt": nil,
280 "my_include": nil,
281 "foo/bar/MyClass.java": nil,
282 "prebuilt.jar": nil,
283 "vendor/foo/devkeys/test.x509.pem": nil,
284 "vendor/foo/devkeys/test.pk8": nil,
285 "testkey.x509.pem": nil,
286 "testkey.pk8": nil,
287 "testkey.override.x509.pem": nil,
288 "testkey.override.pk8": nil,
289 "vendor/foo/devkeys/testkey.avbpubkey": nil,
290 "vendor/foo/devkeys/testkey.pem": nil,
291 "NOTICE": nil,
292 "custom_notice": nil,
293 "testkey2.avbpubkey": nil,
294 "testkey2.pem": nil,
295 "myapex-arm64.apex": nil,
296 "myapex-arm.apex": nil,
297 "frameworks/base/api/current.txt": nil,
Dario Frenicde2a032019-10-27 00:29:22 +0100298 "framework/aidl/a.aidl": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900299 "build/make/core/proguard.flags": nil,
300 "build/make/core/proguard_basic_keeps.flags": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900301 }
302
303 for _, handler := range handlers {
304 handler(fs, config)
305 }
306
307 ctx.MockFileSystem(fs)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900308
Jooyung Han5c998b92019-06-27 11:30:33 +0900309 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900310}
311
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700312func setUp() {
313 var err error
314 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900315 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700316 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900317 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900318}
319
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700320func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900321 os.RemoveAll(buildDir)
322}
323
324// ensure that 'result' contains 'expected'
325func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900326 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900327 if !strings.Contains(result, expected) {
328 t.Errorf("%q is not found in %q", expected, result)
329 }
330}
331
332// ensures that 'result' does not contain 'notExpected'
333func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900334 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900335 if strings.Contains(result, notExpected) {
336 t.Errorf("%q is found in %q", notExpected, result)
337 }
338}
339
340func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900341 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900342 if !android.InList(expected, result) {
343 t.Errorf("%q is not found in %v", expected, result)
344 }
345}
346
347func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900348 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900349 if android.InList(notExpected, result) {
350 t.Errorf("%q is found in %v", notExpected, result)
351 }
352}
353
Jooyung Hane1633032019-08-01 17:41:43 +0900354func ensureListEmpty(t *testing.T, result []string) {
355 t.Helper()
356 if len(result) > 0 {
357 t.Errorf("%q is expected to be empty", result)
358 }
359}
360
Jiyong Park25fc6a92018-11-18 18:02:45 +0900361// Minimal test
362func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700363 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900364 apex_defaults {
365 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900366 manifest: ":myapex.manifest",
367 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900368 key: "myapex.key",
369 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800370 multilib: {
371 both: {
372 binaries: ["foo",],
373 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900374 },
Jiyong Park9e6c2422019-08-09 20:39:45 +0900375 java_libs: ["myjar", "myprebuiltjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900376 }
377
Jiyong Park30ca9372019-02-07 16:27:23 +0900378 apex {
379 name: "myapex",
380 defaults: ["myapex-defaults"],
381 }
382
Jiyong Park25fc6a92018-11-18 18:02:45 +0900383 apex_key {
384 name: "myapex.key",
385 public_key: "testkey.avbpubkey",
386 private_key: "testkey.pem",
387 }
388
Jiyong Park809bb722019-02-13 21:33:49 +0900389 filegroup {
390 name: "myapex.manifest",
391 srcs: ["apex_manifest.json"],
392 }
393
394 filegroup {
395 name: "myapex.androidmanifest",
396 srcs: ["AndroidManifest.xml"],
397 }
398
Jiyong Park25fc6a92018-11-18 18:02:45 +0900399 cc_library {
400 name: "mylib",
401 srcs: ["mylib.cpp"],
402 shared_libs: ["mylib2"],
403 system_shared_libs: [],
404 stl: "none",
405 }
406
Alex Light3d673592019-01-18 14:37:31 -0800407 cc_binary {
408 name: "foo",
409 srcs: ["mylib.cpp"],
410 compile_multilib: "both",
411 multilib: {
412 lib32: {
413 suffix: "32",
414 },
415 lib64: {
416 suffix: "64",
417 },
418 },
419 symlinks: ["foo_link_"],
420 symlink_preferred_arch: true,
421 system_shared_libs: [],
422 static_executable: true,
423 stl: "none",
424 }
425
Jiyong Park25fc6a92018-11-18 18:02:45 +0900426 cc_library {
427 name: "mylib2",
428 srcs: ["mylib.cpp"],
429 system_shared_libs: [],
430 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900431 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900432 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900433
434 java_library {
435 name: "myjar",
436 srcs: ["foo/bar/MyClass.java"],
437 sdk_version: "none",
438 system_modules: "none",
439 compile_dex: true,
440 static_libs: ["myotherjar"],
441 }
442
443 java_library {
444 name: "myotherjar",
445 srcs: ["foo/bar/MyClass.java"],
446 sdk_version: "none",
447 system_modules: "none",
448 compile_dex: true,
449 }
Jiyong Park9e6c2422019-08-09 20:39:45 +0900450
451 java_import {
452 name: "myprebuiltjar",
453 jars: ["prebuilt.jar"],
454 installable: true,
455 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900456 `)
457
458 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900459
460 optFlags := apexRule.Args["opt_flags"]
461 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700462 // Ensure that the NOTICE output is being packaged as an asset.
463 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900464
Jiyong Park25fc6a92018-11-18 18:02:45 +0900465 copyCmds := apexRule.Args["copy_commands"]
466
467 // Ensure that main rule creates an output
468 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
469
470 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900471 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900472 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900473 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900474
475 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900476 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900477 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900478
479 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800480 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
481 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900482 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900483 ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900484 // .. but not for java libs
485 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800486
Jiyong Park7f7766d2019-07-25 22:02:35 +0900487 // Ensure that the platform variant ends with _core_shared or _common
Logan Chien3aeedc92018-12-26 15:32:21 +0800488 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
489 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900490 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
491 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900492 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common")
Alex Light3d673592019-01-18 14:37:31 -0800493
494 // Ensure that all symlinks are present.
495 found_foo_link_64 := false
496 found_foo := false
497 for _, cmd := range strings.Split(copyCmds, " && ") {
498 if strings.HasPrefix(cmd, "ln -s foo64") {
499 if strings.HasSuffix(cmd, "bin/foo") {
500 found_foo = true
501 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
502 found_foo_link_64 = true
503 }
504 }
505 }
506 good := found_foo && found_foo_link_64
507 if !good {
508 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
509 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900510
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700511 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
512 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700513 if len(noticeInputs) != 2 {
514 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900515 }
516 ensureListContains(t, noticeInputs, "NOTICE")
517 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800518}
519
520func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700521 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800522 apex {
523 name: "myapex",
524 key: "myapex.key",
525 payload_type: "zip",
526 native_shared_libs: ["mylib"],
527 }
528
529 apex_key {
530 name: "myapex.key",
531 public_key: "testkey.avbpubkey",
532 private_key: "testkey.pem",
533 }
534
535 cc_library {
536 name: "mylib",
537 srcs: ["mylib.cpp"],
538 shared_libs: ["mylib2"],
539 system_shared_libs: [],
540 stl: "none",
541 }
542
543 cc_library {
544 name: "mylib2",
545 srcs: ["mylib.cpp"],
546 system_shared_libs: [],
547 stl: "none",
548 }
549 `)
550
551 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
552 copyCmds := zipApexRule.Args["copy_commands"]
553
554 // Ensure that main rule creates an output
555 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
556
557 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900558 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800559
560 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900561 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800562
563 // Ensure that both direct and indirect deps are copied into apex
564 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
565 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900566}
567
568func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700569 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900570 apex {
571 name: "myapex",
572 key: "myapex.key",
573 native_shared_libs: ["mylib", "mylib3"],
574 }
575
576 apex_key {
577 name: "myapex.key",
578 public_key: "testkey.avbpubkey",
579 private_key: "testkey.pem",
580 }
581
582 cc_library {
583 name: "mylib",
584 srcs: ["mylib.cpp"],
585 shared_libs: ["mylib2", "mylib3"],
586 system_shared_libs: [],
587 stl: "none",
588 }
589
590 cc_library {
591 name: "mylib2",
592 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900593 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900594 system_shared_libs: [],
595 stl: "none",
596 stubs: {
597 versions: ["1", "2", "3"],
598 },
599 }
600
601 cc_library {
602 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900603 srcs: ["mylib.cpp"],
604 shared_libs: ["mylib4"],
605 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900606 stl: "none",
607 stubs: {
608 versions: ["10", "11", "12"],
609 },
610 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900611
612 cc_library {
613 name: "mylib4",
614 srcs: ["mylib.cpp"],
615 system_shared_libs: [],
616 stl: "none",
617 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900618 `)
619
620 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
621 copyCmds := apexRule.Args["copy_commands"]
622
623 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800624 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900625
626 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800627 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900628
629 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800630 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900631
Jiyong Parkda6eb592018-12-19 17:12:36 +0900632 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900633
634 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900635 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900636 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900637 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900638
639 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900640 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900641 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900642 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900643
644 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900645 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900646 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900647
648 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900649 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"])
Jiyong Park25fc6a92018-11-18 18:02:45 +0900650}
651
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900652func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700653 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900654 apex {
655 name: "myapex",
656 key: "myapex.key",
657 native_shared_libs: ["mylib"],
658 }
659
660 apex_key {
661 name: "myapex.key",
662 public_key: "testkey.avbpubkey",
663 private_key: "testkey.pem",
664 }
665
666 cc_library {
667 name: "mylib",
668 srcs: ["mylib.cpp"],
669 shared_libs: ["libfoo#10"],
670 system_shared_libs: [],
671 stl: "none",
672 }
673
674 cc_library {
675 name: "libfoo",
676 srcs: ["mylib.cpp"],
677 shared_libs: ["libbar"],
678 system_shared_libs: [],
679 stl: "none",
680 stubs: {
681 versions: ["10", "20", "30"],
682 },
683 }
684
685 cc_library {
686 name: "libbar",
687 srcs: ["mylib.cpp"],
688 system_shared_libs: [],
689 stl: "none",
690 }
691
692 `)
693
694 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
695 copyCmds := apexRule.Args["copy_commands"]
696
697 // Ensure that direct non-stubs dep is always included
698 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
699
700 // Ensure that indirect stubs dep is not included
701 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
702
703 // Ensure that dependency of stubs is not included
704 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
705
Jiyong Parkda6eb592018-12-19 17:12:36 +0900706 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900707
708 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900709 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900710 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900711 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900712
Jiyong Parkda6eb592018-12-19 17:12:36 +0900713 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900714
715 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
716 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
717}
718
Jooyung Hand3639552019-08-09 12:57:43 +0900719func TestApexWithRuntimeLibsDependency(t *testing.T) {
720 /*
721 myapex
722 |
723 v (runtime_libs)
724 mylib ------+------> libfoo [provides stub]
725 |
726 `------> libbar
727 */
728 ctx, _ := testApex(t, `
729 apex {
730 name: "myapex",
731 key: "myapex.key",
732 native_shared_libs: ["mylib"],
733 }
734
735 apex_key {
736 name: "myapex.key",
737 public_key: "testkey.avbpubkey",
738 private_key: "testkey.pem",
739 }
740
741 cc_library {
742 name: "mylib",
743 srcs: ["mylib.cpp"],
744 runtime_libs: ["libfoo", "libbar"],
745 system_shared_libs: [],
746 stl: "none",
747 }
748
749 cc_library {
750 name: "libfoo",
751 srcs: ["mylib.cpp"],
752 system_shared_libs: [],
753 stl: "none",
754 stubs: {
755 versions: ["10", "20", "30"],
756 },
757 }
758
759 cc_library {
760 name: "libbar",
761 srcs: ["mylib.cpp"],
762 system_shared_libs: [],
763 stl: "none",
764 }
765
766 `)
767
768 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
769 copyCmds := apexRule.Args["copy_commands"]
770
771 // Ensure that direct non-stubs dep is always included
772 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
773
774 // Ensure that indirect stubs dep is not included
775 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
776
777 // Ensure that runtime_libs dep in included
778 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
779
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900780 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
781 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
782 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900783
784}
785
Jooyung Han9c80bae2019-08-20 17:30:57 +0900786func TestApexDependencyToLLNDK(t *testing.T) {
787 ctx, _ := testApex(t, `
788 apex {
789 name: "myapex",
790 key: "myapex.key",
791 use_vendor: true,
792 native_shared_libs: ["mylib"],
793 }
794
795 apex_key {
796 name: "myapex.key",
797 public_key: "testkey.avbpubkey",
798 private_key: "testkey.pem",
799 }
800
801 cc_library {
802 name: "mylib",
803 srcs: ["mylib.cpp"],
804 vendor_available: true,
805 shared_libs: ["libbar"],
806 system_shared_libs: [],
807 stl: "none",
808 }
809
810 cc_library {
811 name: "libbar",
812 srcs: ["mylib.cpp"],
813 system_shared_libs: [],
814 stl: "none",
815 }
816
817 llndk_library {
818 name: "libbar",
819 symbol_file: "",
820 }
Jooyung Handc782442019-11-01 03:14:38 +0900821 `, func(fs map[string][]byte, config android.Config) {
822 setUseVendorWhitelistForTest(config, []string{"myapex"})
823 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900824
825 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
826 copyCmds := apexRule.Args["copy_commands"]
827
828 // Ensure that LLNDK dep is not included
829 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
830
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900831 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
832 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900833
834 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900835 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900836
837}
838
Jiyong Park25fc6a92018-11-18 18:02:45 +0900839func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700840 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900841 apex {
842 name: "myapex",
843 key: "myapex.key",
844 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
845 }
846
847 apex_key {
848 name: "myapex.key",
849 public_key: "testkey.avbpubkey",
850 private_key: "testkey.pem",
851 }
852
853 cc_library {
854 name: "mylib",
855 srcs: ["mylib.cpp"],
856 shared_libs: ["libdl#27"],
857 stl: "none",
858 }
859
860 cc_library_shared {
861 name: "mylib_shared",
862 srcs: ["mylib.cpp"],
863 shared_libs: ["libdl#27"],
864 stl: "none",
865 }
866
867 cc_library {
868 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700869 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900870 nocrt: true,
871 system_shared_libs: [],
872 stl: "none",
873 stubs: {
874 versions: ["27", "28", "29"],
875 },
876 }
877
878 cc_library {
879 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700880 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900881 nocrt: true,
882 system_shared_libs: [],
883 stl: "none",
884 stubs: {
885 versions: ["27", "28", "29"],
886 },
887 }
888
889 cc_library {
890 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700891 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900892 nocrt: true,
893 system_shared_libs: [],
894 stl: "none",
895 stubs: {
896 versions: ["27", "28", "29"],
897 },
898 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900899
900 cc_library {
901 name: "libBootstrap",
902 srcs: ["mylib.cpp"],
903 stl: "none",
904 bootstrap: true,
905 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900906 `)
907
908 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
909 copyCmds := apexRule.Args["copy_commands"]
910
911 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800912 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900913 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
914 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900915
916 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900917 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900918
Jiyong Parkda6eb592018-12-19 17:12:36 +0900919 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
920 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
921 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900922
923 // For dependency to libc
924 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900925 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900926 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900927 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900928 // ... Cflags from stub is correctly exported to mylib
929 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
930 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
931
932 // For dependency to libm
933 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900934 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900935 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900936 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900937 // ... and is not compiling with the stub
938 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
939 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
940
941 // For dependency to libdl
942 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900943 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900944 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900945 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
946 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900947 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900948 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900949 // ... Cflags from stub is correctly exported to mylib
950 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
951 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900952
953 // Ensure that libBootstrap is depending on the platform variant of bionic libs
954 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
955 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
956 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
957 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900958}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900959
960func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700961 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900962 apex {
963 name: "myapex",
964 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900965 native_shared_libs: ["mylib"],
966 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900967 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900968 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900969 }
970
971 apex_key {
972 name: "myapex.key",
973 public_key: "testkey.avbpubkey",
974 private_key: "testkey.pem",
975 }
976
977 prebuilt_etc {
978 name: "myetc",
979 src: "myprebuilt",
980 sub_dir: "foo/bar",
981 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900982
983 cc_library {
984 name: "mylib",
985 srcs: ["mylib.cpp"],
986 relative_install_path: "foo/bar",
987 system_shared_libs: [],
988 stl: "none",
989 }
990
991 cc_binary {
992 name: "mybin",
993 srcs: ["mylib.cpp"],
994 relative_install_path: "foo/bar",
995 system_shared_libs: [],
996 static_executable: true,
997 stl: "none",
998 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900999 `)
1000
1001 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
1002 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1003
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001004 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001005 ensureListContains(t, dirs, "etc")
1006 ensureListContains(t, dirs, "etc/foo")
1007 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001008 ensureListContains(t, dirs, "lib64")
1009 ensureListContains(t, dirs, "lib64/foo")
1010 ensureListContains(t, dirs, "lib64/foo/bar")
1011 ensureListContains(t, dirs, "lib")
1012 ensureListContains(t, dirs, "lib/foo")
1013 ensureListContains(t, dirs, "lib/foo/bar")
1014
Jiyong Parkbd13e442019-03-15 18:10:35 +09001015 ensureListContains(t, dirs, "bin")
1016 ensureListContains(t, dirs, "bin/foo")
1017 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001018}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001019
1020func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001021 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001022 apex {
1023 name: "myapex",
1024 key: "myapex.key",
1025 native_shared_libs: ["mylib"],
1026 use_vendor: true,
1027 }
1028
1029 apex_key {
1030 name: "myapex.key",
1031 public_key: "testkey.avbpubkey",
1032 private_key: "testkey.pem",
1033 }
1034
1035 cc_library {
1036 name: "mylib",
1037 srcs: ["mylib.cpp"],
1038 shared_libs: ["mylib2"],
1039 system_shared_libs: [],
1040 vendor_available: true,
1041 stl: "none",
1042 }
1043
1044 cc_library {
1045 name: "mylib2",
1046 srcs: ["mylib.cpp"],
1047 system_shared_libs: [],
1048 vendor_available: true,
1049 stl: "none",
1050 }
Jooyung Handc782442019-11-01 03:14:38 +09001051 `, func(fs map[string][]byte, config android.Config) {
1052 setUseVendorWhitelistForTest(config, []string{"myapex"})
1053 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001054
1055 inputsList := []string{}
1056 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
1057 for _, implicit := range i.Implicits {
1058 inputsList = append(inputsList, implicit.String())
1059 }
1060 }
1061 inputsString := strings.Join(inputsList, " ")
1062
1063 // ensure that the apex includes vendor variants of the direct and indirect deps
Inseob Kim64c43952019-08-26 16:52:35 +09001064 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib.so")
1065 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001066
1067 // ensure that the apex does not include core variants
1068 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1069 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1070}
Jiyong Park16e91a02018-12-20 18:18:08 +09001071
Jooyung Handc782442019-11-01 03:14:38 +09001072func TestUseVendorRestriction(t *testing.T) {
1073 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1074 apex {
1075 name: "myapex",
1076 key: "myapex.key",
1077 use_vendor: true,
1078 }
1079 apex_key {
1080 name: "myapex.key",
1081 public_key: "testkey.avbpubkey",
1082 private_key: "testkey.pem",
1083 }
1084 `, func(fs map[string][]byte, config android.Config) {
1085 setUseVendorWhitelistForTest(config, []string{""})
1086 })
1087 // no error with whitelist
1088 testApex(t, `
1089 apex {
1090 name: "myapex",
1091 key: "myapex.key",
1092 use_vendor: true,
1093 }
1094 apex_key {
1095 name: "myapex.key",
1096 public_key: "testkey.avbpubkey",
1097 private_key: "testkey.pem",
1098 }
1099 `, func(fs map[string][]byte, config android.Config) {
1100 setUseVendorWhitelistForTest(config, []string{"myapex"})
1101 })
1102}
1103
Jooyung Han5c998b92019-06-27 11:30:33 +09001104func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1105 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1106 apex {
1107 name: "myapex",
1108 key: "myapex.key",
1109 native_shared_libs: ["mylib"],
1110 use_vendor: true,
1111 }
1112
1113 apex_key {
1114 name: "myapex.key",
1115 public_key: "testkey.avbpubkey",
1116 private_key: "testkey.pem",
1117 }
1118
1119 cc_library {
1120 name: "mylib",
1121 srcs: ["mylib.cpp"],
1122 system_shared_libs: [],
1123 stl: "none",
1124 }
1125 `)
1126}
1127
Jiyong Park16e91a02018-12-20 18:18:08 +09001128func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001129 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001130 apex {
1131 name: "myapex",
1132 key: "myapex.key",
1133 native_shared_libs: ["mylib"],
1134 }
1135
1136 apex_key {
1137 name: "myapex.key",
1138 public_key: "testkey.avbpubkey",
1139 private_key: "testkey.pem",
1140 }
1141
1142 cc_library {
1143 name: "mylib",
1144 srcs: ["mylib.cpp"],
1145 system_shared_libs: [],
1146 stl: "none",
1147 stubs: {
1148 versions: ["1", "2", "3"],
1149 },
1150 }
1151
1152 cc_binary {
1153 name: "not_in_apex",
1154 srcs: ["mylib.cpp"],
1155 static_libs: ["mylib"],
1156 static_executable: true,
1157 system_shared_libs: [],
1158 stl: "none",
1159 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001160 `)
1161
1162 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1163
1164 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001165 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001166}
Jiyong Park9335a262018-12-24 11:31:58 +09001167
1168func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001169 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001170 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001171 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001172 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001173 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001174 native_shared_libs: ["mylib"],
1175 }
1176
1177 cc_library {
1178 name: "mylib",
1179 srcs: ["mylib.cpp"],
1180 system_shared_libs: [],
1181 stl: "none",
1182 }
1183
1184 apex_key {
1185 name: "myapex.key",
1186 public_key: "testkey.avbpubkey",
1187 private_key: "testkey.pem",
1188 }
1189
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001190 android_app_certificate {
1191 name: "myapex.certificate",
1192 certificate: "testkey",
1193 }
1194
1195 android_app_certificate {
1196 name: "myapex.certificate.override",
1197 certificate: "testkey.override",
1198 }
1199
Jiyong Park9335a262018-12-24 11:31:58 +09001200 `)
1201
1202 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001203 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001204
1205 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1206 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1207 "vendor/foo/devkeys/testkey.avbpubkey")
1208 }
1209 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1210 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1211 "vendor/foo/devkeys/testkey.pem")
1212 }
1213
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001214 // check the APK certs. It should be overridden to myapex.certificate.override
1215 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
1216 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001217 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001218 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001219 }
1220}
Jiyong Park58e364a2019-01-19 19:24:06 +09001221
1222func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001223 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001224 apex {
1225 name: "myapex",
1226 key: "myapex.key",
1227 native_shared_libs: ["mylib"],
1228 }
1229
1230 apex {
1231 name: "otherapex",
1232 key: "myapex.key",
1233 native_shared_libs: ["mylib"],
1234 }
1235
1236 apex_key {
1237 name: "myapex.key",
1238 public_key: "testkey.avbpubkey",
1239 private_key: "testkey.pem",
1240 }
1241
1242 cc_library {
1243 name: "mylib",
1244 srcs: ["mylib.cpp"],
1245 system_shared_libs: [],
1246 stl: "none",
1247 }
1248 `)
1249
1250 // non-APEX variant does not have __ANDROID__APEX__ defined
1251 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1252 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1253 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
Jooyung Han77988572019-10-18 16:26:16 +09001254 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1255 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001256
1257 // APEX variant has __ANDROID_APEX__=<apexname> defined
1258 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
1259 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1260 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
Jooyung Han77988572019-10-18 16:26:16 +09001261 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1262 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001263
1264 // APEX variant has __ANDROID_APEX__=<apexname> defined
1265 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
1266 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1267 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
Jooyung Han77988572019-10-18 16:26:16 +09001268 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1269 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001270}
Jiyong Park7e636d02019-01-28 16:16:54 +09001271
1272func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001273 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001274 apex {
1275 name: "myapex",
1276 key: "myapex.key",
1277 native_shared_libs: ["mylib"],
1278 }
1279
1280 apex_key {
1281 name: "myapex.key",
1282 public_key: "testkey.avbpubkey",
1283 private_key: "testkey.pem",
1284 }
1285
1286 cc_library_headers {
1287 name: "mylib_headers",
1288 export_include_dirs: ["my_include"],
1289 system_shared_libs: [],
1290 stl: "none",
1291 }
1292
1293 cc_library {
1294 name: "mylib",
1295 srcs: ["mylib.cpp"],
1296 system_shared_libs: [],
1297 stl: "none",
1298 header_libs: ["mylib_headers"],
1299 export_header_lib_headers: ["mylib_headers"],
1300 stubs: {
1301 versions: ["1", "2", "3"],
1302 },
1303 }
1304
1305 cc_library {
1306 name: "otherlib",
1307 srcs: ["mylib.cpp"],
1308 system_shared_libs: [],
1309 stl: "none",
1310 shared_libs: ["mylib"],
1311 }
1312 `)
1313
1314 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1315
1316 // Ensure that the include path of the header lib is exported to 'otherlib'
1317 ensureContains(t, cFlags, "-Imy_include")
1318}
Alex Light9670d332019-01-29 18:07:33 -08001319
Jooyung Han31c470b2019-10-18 16:26:59 +09001320func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) {
1321 t.Helper()
1322 apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName).Rule("apexRule")
1323 copyCmds := apexRule.Args["copy_commands"]
1324 imageApexDir := "/image.apex/"
1325 dstFiles := []string{}
1326 for _, cmd := range strings.Split(copyCmds, "&&") {
1327 cmd = strings.TrimSpace(cmd)
1328 if cmd == "" {
1329 continue
1330 }
1331 terms := strings.Split(cmd, " ")
1332 switch terms[0] {
1333 case "mkdir":
1334 case "cp":
1335 if len(terms) != 3 {
1336 t.Fatal("copyCmds contains invalid cp command", cmd)
1337 }
1338 dst := terms[2]
1339 index := strings.Index(dst, imageApexDir)
1340 if index == -1 {
1341 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1342 }
1343 dstFile := dst[index+len(imageApexDir):]
1344 dstFiles = append(dstFiles, dstFile)
1345 default:
1346 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1347 }
1348 }
1349 sort.Strings(dstFiles)
1350 sort.Strings(files)
1351 missing := []string{}
1352 surplus := []string{}
1353 i := 0
1354 j := 0
1355 for i < len(dstFiles) && j < len(files) {
1356 if dstFiles[i] == files[j] {
1357 i++
1358 j++
1359 } else if dstFiles[i] < files[j] {
1360 surplus = append(surplus, dstFiles[i])
1361 i++
1362 } else {
1363 missing = append(missing, files[j])
1364 j++
1365 }
1366 }
1367 if i < len(dstFiles) {
1368 surplus = append(surplus, dstFiles[i:]...)
1369 }
1370 if j < len(files) {
1371 missing = append(missing, files[j:]...)
1372 }
1373
1374 failed := false
1375 if len(surplus) > 0 {
1376 t.Log("surplus files", surplus)
1377 failed = true
1378 }
1379 if len(missing) > 0 {
1380 t.Log("missing files", missing)
1381 failed = true
1382 }
1383 if failed {
1384 t.Fail()
1385 }
1386}
1387
Jooyung Han344d5432019-08-23 11:17:39 +09001388func TestVndkApexCurrent(t *testing.T) {
1389 ctx, _ := testApex(t, `
1390 apex_vndk {
1391 name: "myapex",
1392 key: "myapex.key",
1393 file_contexts: "myapex",
1394 }
1395
1396 apex_key {
1397 name: "myapex.key",
1398 public_key: "testkey.avbpubkey",
1399 private_key: "testkey.pem",
1400 }
1401
1402 cc_library {
1403 name: "libvndk",
1404 srcs: ["mylib.cpp"],
1405 vendor_available: true,
1406 vndk: {
1407 enabled: true,
1408 },
1409 system_shared_libs: [],
1410 stl: "none",
1411 }
1412
1413 cc_library {
1414 name: "libvndksp",
1415 srcs: ["mylib.cpp"],
1416 vendor_available: true,
1417 vndk: {
1418 enabled: true,
1419 support_system_process: true,
1420 },
1421 system_shared_libs: [],
1422 stl: "none",
1423 }
1424 `)
1425
Jooyung Han31c470b2019-10-18 16:26:59 +09001426 ensureExactContents(t, ctx, "myapex", []string{
1427 "lib/libvndk.so",
1428 "lib/libvndksp.so",
1429 "lib64/libvndk.so",
1430 "lib64/libvndksp.so",
1431 })
Jooyung Han344d5432019-08-23 11:17:39 +09001432}
1433
1434func TestVndkApexWithPrebuilt(t *testing.T) {
1435 ctx, _ := testApex(t, `
1436 apex_vndk {
1437 name: "myapex",
1438 key: "myapex.key",
1439 file_contexts: "myapex",
1440 }
1441
1442 apex_key {
1443 name: "myapex.key",
1444 public_key: "testkey.avbpubkey",
1445 private_key: "testkey.pem",
1446 }
1447
1448 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001449 name: "libvndk",
1450 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001451 vendor_available: true,
1452 vndk: {
1453 enabled: true,
1454 },
1455 system_shared_libs: [],
1456 stl: "none",
1457 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001458
1459 cc_prebuilt_library_shared {
1460 name: "libvndk.arm",
1461 srcs: ["libvndk.arm.so"],
1462 vendor_available: true,
1463 vndk: {
1464 enabled: true,
1465 },
1466 enabled: false,
1467 arch: {
1468 arm: {
1469 enabled: true,
1470 },
1471 },
1472 system_shared_libs: [],
1473 stl: "none",
1474 }
Jooyung Han344d5432019-08-23 11:17:39 +09001475 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001476 "libvndk.so": nil,
1477 "libvndk.arm.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001478 }))
1479
Jooyung Han31c470b2019-10-18 16:26:59 +09001480 ensureExactContents(t, ctx, "myapex", []string{
1481 "lib/libvndk.so",
1482 "lib/libvndk.arm.so",
1483 "lib64/libvndk.so",
1484 })
Jooyung Han344d5432019-08-23 11:17:39 +09001485}
1486
1487func TestVndkApexVersion(t *testing.T) {
1488 ctx, _ := testApex(t, `
1489 apex_vndk {
1490 name: "myapex_v27",
1491 key: "myapex.key",
1492 file_contexts: "myapex",
1493 vndk_version: "27",
1494 }
1495
1496 apex_key {
1497 name: "myapex.key",
1498 public_key: "testkey.avbpubkey",
1499 private_key: "testkey.pem",
1500 }
1501
Jooyung Han31c470b2019-10-18 16:26:59 +09001502 vndk_prebuilt_shared {
1503 name: "libvndk27",
1504 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001505 vendor_available: true,
1506 vndk: {
1507 enabled: true,
1508 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001509 target_arch: "arm64",
1510 arch: {
1511 arm: {
1512 srcs: ["libvndk27_arm.so"],
1513 },
1514 arm64: {
1515 srcs: ["libvndk27_arm64.so"],
1516 },
1517 },
Jooyung Han344d5432019-08-23 11:17:39 +09001518 }
1519
1520 vndk_prebuilt_shared {
1521 name: "libvndk27",
1522 version: "27",
1523 vendor_available: true,
1524 vndk: {
1525 enabled: true,
1526 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001527 target_arch: "x86_64",
1528 arch: {
1529 x86: {
1530 srcs: ["libvndk27_x86.so"],
1531 },
1532 x86_64: {
1533 srcs: ["libvndk27_x86_64.so"],
1534 },
1535 },
1536 }
Jooyung Han344d5432019-08-23 11:17:39 +09001537 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001538 "libvndk27_arm.so": nil,
1539 "libvndk27_arm64.so": nil,
1540 "libvndk27_x86.so": nil,
1541 "libvndk27_x86_64.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001542 }))
1543
Jooyung Han31c470b2019-10-18 16:26:59 +09001544 ensureExactContents(t, ctx, "myapex_v27", []string{
1545 "lib/libvndk27_arm.so",
1546 "lib64/libvndk27_arm64.so",
1547 })
Jooyung Han344d5432019-08-23 11:17:39 +09001548}
1549
1550func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1551 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1552 apex_vndk {
1553 name: "myapex_v27",
1554 key: "myapex.key",
1555 file_contexts: "myapex",
1556 vndk_version: "27",
1557 }
1558 apex_vndk {
1559 name: "myapex_v27_other",
1560 key: "myapex.key",
1561 file_contexts: "myapex",
1562 vndk_version: "27",
1563 }
1564
1565 apex_key {
1566 name: "myapex.key",
1567 public_key: "testkey.avbpubkey",
1568 private_key: "testkey.pem",
1569 }
1570
1571 cc_library {
1572 name: "libvndk",
1573 srcs: ["mylib.cpp"],
1574 vendor_available: true,
1575 vndk: {
1576 enabled: true,
1577 },
1578 system_shared_libs: [],
1579 stl: "none",
1580 }
1581
1582 vndk_prebuilt_shared {
1583 name: "libvndk",
1584 version: "27",
1585 vendor_available: true,
1586 vndk: {
1587 enabled: true,
1588 },
1589 srcs: ["libvndk.so"],
1590 }
1591 `, withFiles(map[string][]byte{
1592 "libvndk.so": nil,
1593 }))
1594}
1595
Jooyung Han90eee022019-10-01 20:02:42 +09001596func TestVndkApexNameRule(t *testing.T) {
1597 ctx, _ := testApex(t, `
1598 apex_vndk {
1599 name: "myapex",
1600 key: "myapex.key",
1601 file_contexts: "myapex",
1602 }
1603 apex_vndk {
1604 name: "myapex_v28",
1605 key: "myapex.key",
1606 file_contexts: "myapex",
1607 vndk_version: "28",
1608 }
1609 apex_key {
1610 name: "myapex.key",
1611 public_key: "testkey.avbpubkey",
1612 private_key: "testkey.pem",
1613 }`)
1614
1615 assertApexName := func(expected, moduleName string) {
1616 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName).Module().(*apexBundle)
1617 actual := proptools.String(bundle.properties.Apex_name)
1618 if !reflect.DeepEqual(actual, expected) {
1619 t.Errorf("Got '%v', expected '%v'", actual, expected)
1620 }
1621 }
1622
1623 assertApexName("com.android.vndk.vVER", "myapex")
1624 assertApexName("com.android.vndk.v28", "myapex_v28")
1625}
1626
Jooyung Han344d5432019-08-23 11:17:39 +09001627func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1628 ctx, _ := testApex(t, `
1629 apex_vndk {
1630 name: "myapex",
1631 key: "myapex.key",
1632 file_contexts: "myapex",
1633 }
1634
1635 apex_key {
1636 name: "myapex.key",
1637 public_key: "testkey.avbpubkey",
1638 private_key: "testkey.pem",
1639 }
1640
1641 cc_library {
1642 name: "libvndk",
1643 srcs: ["mylib.cpp"],
1644 vendor_available: true,
1645 native_bridge_supported: true,
1646 host_supported: true,
1647 vndk: {
1648 enabled: true,
1649 },
1650 system_shared_libs: [],
1651 stl: "none",
1652 }
1653 `, withTargets(map[android.OsType][]android.Target{
1654 android.Android: []android.Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -07001655 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1656 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1657 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1658 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
Jooyung Han344d5432019-08-23 11:17:39 +09001659 },
1660 }))
1661
Jooyung Han31c470b2019-10-18 16:26:59 +09001662 ensureExactContents(t, ctx, "myapex", []string{
1663 "lib/libvndk.so",
1664 "lib64/libvndk.so",
1665 })
Jooyung Han344d5432019-08-23 11:17:39 +09001666}
1667
1668func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1669 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1670 apex_vndk {
1671 name: "myapex",
1672 key: "myapex.key",
1673 file_contexts: "myapex",
1674 native_bridge_supported: true,
1675 }
1676
1677 apex_key {
1678 name: "myapex.key",
1679 public_key: "testkey.avbpubkey",
1680 private_key: "testkey.pem",
1681 }
1682
1683 cc_library {
1684 name: "libvndk",
1685 srcs: ["mylib.cpp"],
1686 vendor_available: true,
1687 native_bridge_supported: true,
1688 host_supported: true,
1689 vndk: {
1690 enabled: true,
1691 },
1692 system_shared_libs: [],
1693 stl: "none",
1694 }
1695 `)
1696}
1697
Jooyung Han31c470b2019-10-18 16:26:59 +09001698func TestVndkApexWithBinder32(t *testing.T) {
1699 ctx, _ := testApex(t,
1700 `
1701 apex_vndk {
1702 name: "myapex_v27",
1703 key: "myapex.key",
1704 file_contexts: "myapex",
1705 vndk_version: "27",
1706 }
1707
1708 apex_key {
1709 name: "myapex.key",
1710 public_key: "testkey.avbpubkey",
1711 private_key: "testkey.pem",
1712 }
1713
1714 vndk_prebuilt_shared {
1715 name: "libvndk27",
1716 version: "27",
1717 target_arch: "arm",
1718 vendor_available: true,
1719 vndk: {
1720 enabled: true,
1721 },
1722 arch: {
1723 arm: {
1724 srcs: ["libvndk27.so"],
1725 }
1726 },
1727 }
1728
1729 vndk_prebuilt_shared {
1730 name: "libvndk27",
1731 version: "27",
1732 target_arch: "arm",
1733 binder32bit: true,
1734 vendor_available: true,
1735 vndk: {
1736 enabled: true,
1737 },
1738 arch: {
1739 arm: {
1740 srcs: ["libvndk27binder32.so"],
1741 }
1742 },
1743 }
1744 `,
1745 withFiles(map[string][]byte{
1746 "libvndk27.so": nil,
1747 "libvndk27binder32.so": nil,
1748 }),
1749 withBinder32bit,
1750 withTargets(map[android.OsType][]android.Target{
1751 android.Android: []android.Target{
1752 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1753 },
1754 }),
1755 )
1756
1757 ensureExactContents(t, ctx, "myapex_v27", []string{
1758 "lib/libvndk27binder32.so",
1759 })
1760}
1761
Jooyung Hane1633032019-08-01 17:41:43 +09001762func TestDependenciesInApexManifest(t *testing.T) {
1763 ctx, _ := testApex(t, `
1764 apex {
1765 name: "myapex_nodep",
1766 key: "myapex.key",
1767 native_shared_libs: ["lib_nodep"],
1768 compile_multilib: "both",
1769 file_contexts: "myapex",
1770 }
1771
1772 apex {
1773 name: "myapex_dep",
1774 key: "myapex.key",
1775 native_shared_libs: ["lib_dep"],
1776 compile_multilib: "both",
1777 file_contexts: "myapex",
1778 }
1779
1780 apex {
1781 name: "myapex_provider",
1782 key: "myapex.key",
1783 native_shared_libs: ["libfoo"],
1784 compile_multilib: "both",
1785 file_contexts: "myapex",
1786 }
1787
1788 apex {
1789 name: "myapex_selfcontained",
1790 key: "myapex.key",
1791 native_shared_libs: ["lib_dep", "libfoo"],
1792 compile_multilib: "both",
1793 file_contexts: "myapex",
1794 }
1795
1796 apex_key {
1797 name: "myapex.key",
1798 public_key: "testkey.avbpubkey",
1799 private_key: "testkey.pem",
1800 }
1801
1802 cc_library {
1803 name: "lib_nodep",
1804 srcs: ["mylib.cpp"],
1805 system_shared_libs: [],
1806 stl: "none",
1807 }
1808
1809 cc_library {
1810 name: "lib_dep",
1811 srcs: ["mylib.cpp"],
1812 shared_libs: ["libfoo"],
1813 system_shared_libs: [],
1814 stl: "none",
1815 }
1816
1817 cc_library {
1818 name: "libfoo",
1819 srcs: ["mytest.cpp"],
1820 stubs: {
1821 versions: ["1"],
1822 },
1823 system_shared_libs: [],
1824 stl: "none",
1825 }
1826 `)
1827
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001828 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09001829 var provideNativeLibs, requireNativeLibs []string
1830
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001831 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("apexManifestRule")
1832 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1833 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001834 ensureListEmpty(t, provideNativeLibs)
1835 ensureListEmpty(t, requireNativeLibs)
1836
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001837 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("apexManifestRule")
1838 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1839 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001840 ensureListEmpty(t, provideNativeLibs)
1841 ensureListContains(t, requireNativeLibs, "libfoo.so")
1842
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001843 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("apexManifestRule")
1844 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1845 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001846 ensureListContains(t, provideNativeLibs, "libfoo.so")
1847 ensureListEmpty(t, requireNativeLibs)
1848
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001849 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("apexManifestRule")
1850 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1851 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001852 ensureListContains(t, provideNativeLibs, "libfoo.so")
1853 ensureListEmpty(t, requireNativeLibs)
1854}
1855
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001856func TestApexName(t *testing.T) {
1857 ctx, _ := testApex(t, `
1858 apex {
1859 name: "myapex",
1860 key: "myapex.key",
1861 apex_name: "com.android.myapex",
1862 }
1863
1864 apex_key {
1865 name: "myapex.key",
1866 public_key: "testkey.avbpubkey",
1867 private_key: "testkey.pem",
1868 }
1869 `)
1870
1871 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1872 apexManifestRule := module.Rule("apexManifestRule")
1873 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
1874 apexRule := module.Rule("apexRule")
1875 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
1876}
1877
Alex Light0851b882019-02-07 13:20:53 -08001878func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001879 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001880 apex {
1881 name: "myapex",
1882 key: "myapex.key",
1883 native_shared_libs: ["mylib_common"],
1884 }
1885
1886 apex_key {
1887 name: "myapex.key",
1888 public_key: "testkey.avbpubkey",
1889 private_key: "testkey.pem",
1890 }
1891
1892 cc_library {
1893 name: "mylib_common",
1894 srcs: ["mylib.cpp"],
1895 system_shared_libs: [],
1896 stl: "none",
1897 }
1898 `)
1899
1900 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1901 apexRule := module.Rule("apexRule")
1902 copyCmds := apexRule.Args["copy_commands"]
1903
1904 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1905 t.Log("Apex was a test apex!")
1906 t.Fail()
1907 }
1908 // Ensure that main rule creates an output
1909 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1910
1911 // Ensure that apex variant is created for the direct dep
1912 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1913
1914 // Ensure that both direct and indirect deps are copied into apex
1915 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1916
1917 // Ensure that the platform variant ends with _core_shared
1918 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1919
1920 if !android.InAnyApex("mylib_common") {
1921 t.Log("Found mylib_common not in any apex!")
1922 t.Fail()
1923 }
1924}
1925
1926func TestTestApex(t *testing.T) {
1927 if android.InAnyApex("mylib_common_test") {
1928 t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!")
1929 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001930 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001931 apex_test {
1932 name: "myapex",
1933 key: "myapex.key",
1934 native_shared_libs: ["mylib_common_test"],
1935 }
1936
1937 apex_key {
1938 name: "myapex.key",
1939 public_key: "testkey.avbpubkey",
1940 private_key: "testkey.pem",
1941 }
1942
1943 cc_library {
1944 name: "mylib_common_test",
1945 srcs: ["mylib.cpp"],
1946 system_shared_libs: [],
1947 stl: "none",
1948 }
1949 `)
1950
1951 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1952 apexRule := module.Rule("apexRule")
1953 copyCmds := apexRule.Args["copy_commands"]
1954
1955 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1956 t.Log("Apex was not a test apex!")
1957 t.Fail()
1958 }
1959 // Ensure that main rule creates an output
1960 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1961
1962 // Ensure that apex variant is created for the direct dep
1963 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1964
1965 // Ensure that both direct and indirect deps are copied into apex
1966 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1967
1968 // Ensure that the platform variant ends with _core_shared
1969 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1970
1971 if android.InAnyApex("mylib_common_test") {
1972 t.Log("Found mylib_common_test in some apex!")
1973 t.Fail()
1974 }
1975}
1976
Alex Light9670d332019-01-29 18:07:33 -08001977func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001978 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001979 apex {
1980 name: "myapex",
1981 key: "myapex.key",
1982 multilib: {
1983 first: {
1984 native_shared_libs: ["mylib_common"],
1985 }
1986 },
1987 target: {
1988 android: {
1989 multilib: {
1990 first: {
1991 native_shared_libs: ["mylib"],
1992 }
1993 }
1994 },
1995 host: {
1996 multilib: {
1997 first: {
1998 native_shared_libs: ["mylib2"],
1999 }
2000 }
2001 }
2002 }
2003 }
2004
2005 apex_key {
2006 name: "myapex.key",
2007 public_key: "testkey.avbpubkey",
2008 private_key: "testkey.pem",
2009 }
2010
2011 cc_library {
2012 name: "mylib",
2013 srcs: ["mylib.cpp"],
2014 system_shared_libs: [],
2015 stl: "none",
2016 }
2017
2018 cc_library {
2019 name: "mylib_common",
2020 srcs: ["mylib.cpp"],
2021 system_shared_libs: [],
2022 stl: "none",
2023 compile_multilib: "first",
2024 }
2025
2026 cc_library {
2027 name: "mylib2",
2028 srcs: ["mylib.cpp"],
2029 system_shared_libs: [],
2030 stl: "none",
2031 compile_multilib: "first",
2032 }
2033 `)
2034
2035 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
2036 copyCmds := apexRule.Args["copy_commands"]
2037
2038 // Ensure that main rule creates an output
2039 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2040
2041 // Ensure that apex variant is created for the direct dep
2042 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2043 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
2044 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
2045
2046 // Ensure that both direct and indirect deps are copied into apex
2047 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2048 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2049 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2050
2051 // Ensure that the platform variant ends with _core_shared
2052 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
2053 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
2054 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
2055}
Jiyong Park04480cf2019-02-06 00:16:29 +09002056
2057func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002058 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002059 apex {
2060 name: "myapex",
2061 key: "myapex.key",
2062 binaries: ["myscript"],
2063 }
2064
2065 apex_key {
2066 name: "myapex.key",
2067 public_key: "testkey.avbpubkey",
2068 private_key: "testkey.pem",
2069 }
2070
2071 sh_binary {
2072 name: "myscript",
2073 src: "mylib.cpp",
2074 filename: "myscript.sh",
2075 sub_dir: "script",
2076 }
2077 `)
2078
2079 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
2080 copyCmds := apexRule.Args["copy_commands"]
2081
2082 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2083}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002084
2085func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002086 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002087 apex {
2088 name: "myapex",
2089 key: "myapex.key",
2090 native_shared_libs: ["mylib"],
2091 product_specific: true,
2092 }
2093
2094 apex_key {
2095 name: "myapex.key",
2096 public_key: "testkey.avbpubkey",
2097 private_key: "testkey.pem",
2098 product_specific: true,
2099 }
2100
2101 cc_library {
2102 name: "mylib",
2103 srcs: ["mylib.cpp"],
2104 system_shared_libs: [],
2105 stl: "none",
2106 }
2107 `)
2108
2109 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
Colin Crossff6c33d2019-10-02 16:01:35 -07002110 expected := buildDir + "/target/product/test_device/product/apex"
2111 actual := apex.installDir.String()
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002112 if actual != expected {
2113 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2114 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002115}
Jiyong Park67882562019-03-21 01:11:21 +09002116
2117func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002118 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002119 apex_key {
2120 name: "myapex.key",
2121 public_key: ":my.avbpubkey",
2122 private_key: ":my.pem",
2123 product_specific: true,
2124 }
2125
2126 filegroup {
2127 name: "my.avbpubkey",
2128 srcs: ["testkey2.avbpubkey"],
2129 }
2130
2131 filegroup {
2132 name: "my.pem",
2133 srcs: ["testkey2.pem"],
2134 }
2135 `)
2136
2137 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2138 expected_pubkey := "testkey2.avbpubkey"
2139 actual_pubkey := apex_key.public_key_file.String()
2140 if actual_pubkey != expected_pubkey {
2141 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2142 }
2143 expected_privkey := "testkey2.pem"
2144 actual_privkey := apex_key.private_key_file.String()
2145 if actual_privkey != expected_privkey {
2146 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2147 }
2148}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002149
2150func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002151 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002152 prebuilt_apex {
2153 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002154 arch: {
2155 arm64: {
2156 src: "myapex-arm64.apex",
2157 },
2158 arm: {
2159 src: "myapex-arm.apex",
2160 },
2161 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002162 }
2163 `)
2164
2165 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2166
Jiyong Parkc95714e2019-03-29 14:23:10 +09002167 expectedInput := "myapex-arm64.apex"
2168 if prebuilt.inputApex.String() != expectedInput {
2169 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2170 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002171}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002172
2173func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002174 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002175 prebuilt_apex {
2176 name: "myapex",
2177 src: "myapex-arm.apex",
2178 filename: "notmyapex.apex",
2179 }
2180 `)
2181
2182 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2183
2184 expected := "notmyapex.apex"
2185 if p.installFilename != expected {
2186 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2187 }
2188}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002189
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002190func TestPrebuiltOverrides(t *testing.T) {
2191 ctx, config := testApex(t, `
2192 prebuilt_apex {
2193 name: "myapex.prebuilt",
2194 src: "myapex-arm.apex",
2195 overrides: [
2196 "myapex",
2197 ],
2198 }
2199 `)
2200
2201 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2202
2203 expected := []string{"myapex"}
2204 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
2205 if !reflect.DeepEqual(actual, expected) {
2206 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
2207 }
2208}
2209
Roland Levillain630846d2019-06-26 12:48:34 +01002210func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002211 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002212 apex_test {
2213 name: "myapex",
2214 key: "myapex.key",
2215 tests: [
2216 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002217 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002218 ],
2219 }
2220
2221 apex_key {
2222 name: "myapex.key",
2223 public_key: "testkey.avbpubkey",
2224 private_key: "testkey.pem",
2225 }
2226
2227 cc_test {
2228 name: "mytest",
2229 gtest: false,
2230 srcs: ["mytest.cpp"],
2231 relative_install_path: "test",
2232 system_shared_libs: [],
2233 static_executable: true,
2234 stl: "none",
2235 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002236
2237 cc_test {
2238 name: "mytests",
2239 gtest: false,
2240 srcs: [
2241 "mytest1.cpp",
2242 "mytest2.cpp",
2243 "mytest3.cpp",
2244 ],
2245 test_per_src: true,
2246 relative_install_path: "test",
2247 system_shared_libs: [],
2248 static_executable: true,
2249 stl: "none",
2250 }
Roland Levillain630846d2019-06-26 12:48:34 +01002251 `)
2252
2253 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
2254 copyCmds := apexRule.Args["copy_commands"]
2255
2256 // Ensure that test dep is copied into apex.
2257 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002258
2259 // Ensure that test deps built with `test_per_src` are copied into apex.
2260 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2261 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2262 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002263
2264 // Ensure the module is correctly translated.
2265 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
2266 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2267 name := apexBundle.BaseModuleName()
2268 prefix := "TARGET_"
2269 var builder strings.Builder
2270 data.Custom(&builder, name, prefix, "", data)
2271 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002272 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2273 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2274 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2275 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
2276 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.json.myapex\n")
2277 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002278 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002279}
2280
Jooyung Han5c998b92019-06-27 11:30:33 +09002281func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002282 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002283 apex {
2284 name: "myapex",
2285 key: "myapex.key",
2286 native_shared_libs: ["mylib"],
2287 uses: ["commonapex"],
2288 }
2289
2290 apex {
2291 name: "commonapex",
2292 key: "myapex.key",
2293 native_shared_libs: ["libcommon"],
2294 provide_cpp_shared_libs: true,
2295 }
2296
2297 apex_key {
2298 name: "myapex.key",
2299 public_key: "testkey.avbpubkey",
2300 private_key: "testkey.pem",
2301 }
2302
2303 cc_library {
2304 name: "mylib",
2305 srcs: ["mylib.cpp"],
2306 shared_libs: ["libcommon"],
2307 system_shared_libs: [],
2308 stl: "none",
2309 }
2310
2311 cc_library {
2312 name: "libcommon",
2313 srcs: ["mylib_common.cpp"],
2314 system_shared_libs: [],
2315 stl: "none",
2316 }
2317 `)
2318
2319 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
2320 apexRule1 := module1.Rule("apexRule")
2321 copyCmds1 := apexRule1.Args["copy_commands"]
2322
2323 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
2324 apexRule2 := module2.Rule("apexRule")
2325 copyCmds2 := apexRule2.Args["copy_commands"]
2326
2327 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2328 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2329 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2330 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2331 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2332}
2333
2334func TestApexUsesFailsIfNotProvided(t *testing.T) {
2335 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2336 apex {
2337 name: "myapex",
2338 key: "myapex.key",
2339 uses: ["commonapex"],
2340 }
2341
2342 apex {
2343 name: "commonapex",
2344 key: "myapex.key",
2345 }
2346
2347 apex_key {
2348 name: "myapex.key",
2349 public_key: "testkey.avbpubkey",
2350 private_key: "testkey.pem",
2351 }
2352 `)
2353 testApexError(t, `uses: "commonapex" is not a provider`, `
2354 apex {
2355 name: "myapex",
2356 key: "myapex.key",
2357 uses: ["commonapex"],
2358 }
2359
2360 cc_library {
2361 name: "commonapex",
2362 system_shared_libs: [],
2363 stl: "none",
2364 }
2365
2366 apex_key {
2367 name: "myapex.key",
2368 public_key: "testkey.avbpubkey",
2369 private_key: "testkey.pem",
2370 }
2371 `)
2372}
2373
2374func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2375 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2376 apex {
2377 name: "myapex",
2378 key: "myapex.key",
2379 use_vendor: true,
2380 uses: ["commonapex"],
2381 }
2382
2383 apex {
2384 name: "commonapex",
2385 key: "myapex.key",
2386 provide_cpp_shared_libs: true,
2387 }
2388
2389 apex_key {
2390 name: "myapex.key",
2391 public_key: "testkey.avbpubkey",
2392 private_key: "testkey.pem",
2393 }
Jooyung Handc782442019-11-01 03:14:38 +09002394 `, func(fs map[string][]byte, config android.Config) {
2395 setUseVendorWhitelistForTest(config, []string{"myapex"})
2396 })
Jooyung Han5c998b92019-06-27 11:30:33 +09002397}
2398
Jooyung Hand48f3c32019-08-23 11:18:57 +09002399func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2400 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2401 apex {
2402 name: "myapex",
2403 key: "myapex.key",
2404 native_shared_libs: ["libfoo"],
2405 }
2406
2407 apex_key {
2408 name: "myapex.key",
2409 public_key: "testkey.avbpubkey",
2410 private_key: "testkey.pem",
2411 }
2412
2413 cc_library {
2414 name: "libfoo",
2415 stl: "none",
2416 system_shared_libs: [],
2417 enabled: false,
2418 }
2419 `)
2420 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2421 apex {
2422 name: "myapex",
2423 key: "myapex.key",
2424 java_libs: ["myjar"],
2425 }
2426
2427 apex_key {
2428 name: "myapex.key",
2429 public_key: "testkey.avbpubkey",
2430 private_key: "testkey.pem",
2431 }
2432
2433 java_library {
2434 name: "myjar",
2435 srcs: ["foo/bar/MyClass.java"],
2436 sdk_version: "none",
2437 system_modules: "none",
2438 compile_dex: true,
2439 enabled: false,
2440 }
2441 `)
2442}
2443
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002444func TestApexWithApps(t *testing.T) {
2445 ctx, _ := testApex(t, `
2446 apex {
2447 name: "myapex",
2448 key: "myapex.key",
2449 apps: [
2450 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09002451 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002452 ],
2453 }
2454
2455 apex_key {
2456 name: "myapex.key",
2457 public_key: "testkey.avbpubkey",
2458 private_key: "testkey.pem",
2459 }
2460
2461 android_app {
2462 name: "AppFoo",
2463 srcs: ["foo/bar/MyClass.java"],
2464 sdk_version: "none",
2465 system_modules: "none",
2466 }
Jiyong Parkf7487312019-10-17 12:54:30 +09002467
2468 android_app {
2469 name: "AppFooPriv",
2470 srcs: ["foo/bar/MyClass.java"],
2471 sdk_version: "none",
2472 system_modules: "none",
2473 privileged: true,
2474 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002475 `)
2476
2477 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2478 apexRule := module.Rule("apexRule")
2479 copyCmds := apexRule.Args["copy_commands"]
2480
2481 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09002482 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Dario Frenicde2a032019-10-27 00:29:22 +01002483}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002484
Dario Frenicde2a032019-10-27 00:29:22 +01002485func TestApexWithAppImports(t *testing.T) {
2486 ctx, _ := testApex(t, `
2487 apex {
2488 name: "myapex",
2489 key: "myapex.key",
2490 apps: [
2491 "AppFooPrebuilt",
2492 "AppFooPrivPrebuilt",
2493 ],
2494 }
2495
2496 apex_key {
2497 name: "myapex.key",
2498 public_key: "testkey.avbpubkey",
2499 private_key: "testkey.pem",
2500 }
2501
2502 android_app_import {
2503 name: "AppFooPrebuilt",
2504 apk: "PrebuiltAppFoo.apk",
2505 presigned: true,
2506 dex_preopt: {
2507 enabled: false,
2508 },
2509 }
2510
2511 android_app_import {
2512 name: "AppFooPrivPrebuilt",
2513 apk: "PrebuiltAppFooPriv.apk",
2514 privileged: true,
2515 presigned: true,
2516 dex_preopt: {
2517 enabled: false,
2518 },
2519 }
2520 `)
2521
2522 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2523 apexRule := module.Rule("apexRule")
2524 copyCmds := apexRule.Args["copy_commands"]
2525
2526 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
2527 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002528}
2529
Jiyong Park127b40b2019-09-30 16:04:35 +09002530func TestApexAvailable(t *testing.T) {
2531 // libfoo is not available to myapex, but only to otherapex
2532 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
2533 apex {
2534 name: "myapex",
2535 key: "myapex.key",
2536 native_shared_libs: ["libfoo"],
2537 }
2538
2539 apex_key {
2540 name: "myapex.key",
2541 public_key: "testkey.avbpubkey",
2542 private_key: "testkey.pem",
2543 }
2544
2545 apex {
2546 name: "otherapex",
2547 key: "otherapex.key",
2548 native_shared_libs: ["libfoo"],
2549 }
2550
2551 apex_key {
2552 name: "otherapex.key",
2553 public_key: "testkey.avbpubkey",
2554 private_key: "testkey.pem",
2555 }
2556
2557 cc_library {
2558 name: "libfoo",
2559 stl: "none",
2560 system_shared_libs: [],
2561 apex_available: ["otherapex"],
2562 }`)
2563
2564 // libbar is an indirect dep
2565 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
2566 apex {
2567 name: "myapex",
2568 key: "myapex.key",
2569 native_shared_libs: ["libfoo"],
2570 }
2571
2572 apex_key {
2573 name: "myapex.key",
2574 public_key: "testkey.avbpubkey",
2575 private_key: "testkey.pem",
2576 }
2577
2578 apex {
2579 name: "otherapex",
2580 key: "otherapex.key",
2581 native_shared_libs: ["libfoo"],
2582 }
2583
2584 apex_key {
2585 name: "otherapex.key",
2586 public_key: "testkey.avbpubkey",
2587 private_key: "testkey.pem",
2588 }
2589
2590 cc_library {
2591 name: "libfoo",
2592 stl: "none",
2593 shared_libs: ["libbar"],
2594 system_shared_libs: [],
2595 apex_available: ["myapex", "otherapex"],
2596 }
2597
2598 cc_library {
2599 name: "libbar",
2600 stl: "none",
2601 system_shared_libs: [],
2602 apex_available: ["otherapex"],
2603 }`)
2604
2605 testApexError(t, "\"otherapex\" is not a valid module name", `
2606 apex {
2607 name: "myapex",
2608 key: "myapex.key",
2609 native_shared_libs: ["libfoo"],
2610 }
2611
2612 apex_key {
2613 name: "myapex.key",
2614 public_key: "testkey.avbpubkey",
2615 private_key: "testkey.pem",
2616 }
2617
2618 cc_library {
2619 name: "libfoo",
2620 stl: "none",
2621 system_shared_libs: [],
2622 apex_available: ["otherapex"],
2623 }`)
2624
2625 ctx, _ := testApex(t, `
2626 apex {
2627 name: "myapex",
2628 key: "myapex.key",
2629 native_shared_libs: ["libfoo", "libbar"],
2630 }
2631
2632 apex_key {
2633 name: "myapex.key",
2634 public_key: "testkey.avbpubkey",
2635 private_key: "testkey.pem",
2636 }
2637
2638 cc_library {
2639 name: "libfoo",
2640 stl: "none",
2641 system_shared_libs: [],
2642 apex_available: ["myapex"],
2643 }
2644
2645 cc_library {
2646 name: "libbar",
2647 stl: "none",
2648 system_shared_libs: [],
2649 apex_available: ["//apex_available:anyapex"],
2650 }`)
2651
2652 // check that libfoo and libbar are created only for myapex, but not for the platform
2653 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2654 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2655 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared_myapex")
2656 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared")
2657
2658 ctx, _ = testApex(t, `
2659 apex {
2660 name: "myapex",
2661 key: "myapex.key",
2662 }
2663
2664 apex_key {
2665 name: "myapex.key",
2666 public_key: "testkey.avbpubkey",
2667 private_key: "testkey.pem",
2668 }
2669
2670 cc_library {
2671 name: "libfoo",
2672 stl: "none",
2673 system_shared_libs: [],
2674 apex_available: ["//apex_available:platform"],
2675 }`)
2676
2677 // check that libfoo is created only for the platform
2678 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2679 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09002680
2681 ctx, _ = testApex(t, `
2682 apex {
2683 name: "myapex",
2684 key: "myapex.key",
2685 native_shared_libs: ["libfoo"],
2686 }
2687
2688 apex_key {
2689 name: "myapex.key",
2690 public_key: "testkey.avbpubkey",
2691 private_key: "testkey.pem",
2692 }
2693
2694 cc_library {
2695 name: "libfoo",
2696 stl: "none",
2697 system_shared_libs: [],
2698 apex_available: ["myapex"],
2699 static: {
2700 apex_available: ["//apex_available:platform"],
2701 },
2702 }`)
2703
2704 // shared variant of libfoo is only available to myapex
2705 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2706 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2707 // but the static variant is available to both myapex and the platform
2708 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static_myapex")
2709 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09002710}
2711
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002712func TestMain(m *testing.M) {
2713 run := func() int {
2714 setUp()
2715 defer tearDown()
2716
2717 return m.Run()
2718 }
2719
2720 os.Exit(run())
2721}