blob: 91f664afbf25cc5eb7111a4265fea48de71bff7d [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
Sundong Ahnabb64432019-10-22 13:58:29 +0900458 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").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.
Sundong Ahnabb64432019-10-22 13:58:29 +0900463 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/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
Sundong Ahnabb64432019-10-22 13:58:29 +0900511 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700512 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
Sundong Ahnabb64432019-10-22 13:58:29 +0900551 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800552 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
Sundong Ahnabb64432019-10-22 13:58:29 +0900620 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900621 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
Sundong Ahnabb64432019-10-22 13:58:29 +0900694 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900695 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
Sundong Ahnabb64432019-10-22 13:58:29 +0900768 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900769 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
Sundong Ahnabb64432019-10-22 13:58:29 +0900780 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900781 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 }
821
822 `)
823
Sundong Ahnabb64432019-10-22 13:58:29 +0900824 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900825 copyCmds := apexRule.Args["copy_commands"]
826
827 // Ensure that LLNDK dep is not included
828 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
829
Sundong Ahnabb64432019-10-22 13:58:29 +0900830 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900831 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900832
833 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900834 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900835
836}
837
Jiyong Park25fc6a92018-11-18 18:02:45 +0900838func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700839 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900840 apex {
841 name: "myapex",
842 key: "myapex.key",
843 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
844 }
845
846 apex_key {
847 name: "myapex.key",
848 public_key: "testkey.avbpubkey",
849 private_key: "testkey.pem",
850 }
851
852 cc_library {
853 name: "mylib",
854 srcs: ["mylib.cpp"],
855 shared_libs: ["libdl#27"],
856 stl: "none",
857 }
858
859 cc_library_shared {
860 name: "mylib_shared",
861 srcs: ["mylib.cpp"],
862 shared_libs: ["libdl#27"],
863 stl: "none",
864 }
865
866 cc_library {
867 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700868 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900869 nocrt: true,
870 system_shared_libs: [],
871 stl: "none",
872 stubs: {
873 versions: ["27", "28", "29"],
874 },
875 }
876
877 cc_library {
878 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700879 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900880 nocrt: true,
881 system_shared_libs: [],
882 stl: "none",
883 stubs: {
884 versions: ["27", "28", "29"],
885 },
886 }
887
888 cc_library {
889 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700890 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900891 nocrt: true,
892 system_shared_libs: [],
893 stl: "none",
894 stubs: {
895 versions: ["27", "28", "29"],
896 },
897 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900898
899 cc_library {
900 name: "libBootstrap",
901 srcs: ["mylib.cpp"],
902 stl: "none",
903 bootstrap: true,
904 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900905 `)
906
Sundong Ahnabb64432019-10-22 13:58:29 +0900907 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900908 copyCmds := apexRule.Args["copy_commands"]
909
910 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800911 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900912 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
913 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900914
915 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900916 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900917
Jiyong Parkda6eb592018-12-19 17:12:36 +0900918 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
919 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
920 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900921
922 // For dependency to libc
923 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900924 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900925 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900926 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900927 // ... Cflags from stub is correctly exported to mylib
928 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
929 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
930
931 // For dependency to libm
932 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900933 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900934 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900935 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900936 // ... and is not compiling with the stub
937 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
938 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
939
940 // For dependency to libdl
941 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900942 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900943 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900944 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
945 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900946 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900947 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900948 // ... Cflags from stub is correctly exported to mylib
949 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
950 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900951
952 // Ensure that libBootstrap is depending on the platform variant of bionic libs
953 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
954 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
955 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
956 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900957}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900958
959func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700960 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900961 apex {
962 name: "myapex",
963 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900964 native_shared_libs: ["mylib"],
965 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900966 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900967 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900968 }
969
970 apex_key {
971 name: "myapex.key",
972 public_key: "testkey.avbpubkey",
973 private_key: "testkey.pem",
974 }
975
976 prebuilt_etc {
977 name: "myetc",
978 src: "myprebuilt",
979 sub_dir: "foo/bar",
980 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900981
982 cc_library {
983 name: "mylib",
984 srcs: ["mylib.cpp"],
985 relative_install_path: "foo/bar",
986 system_shared_libs: [],
987 stl: "none",
988 }
989
990 cc_binary {
991 name: "mybin",
992 srcs: ["mylib.cpp"],
993 relative_install_path: "foo/bar",
994 system_shared_libs: [],
995 static_executable: true,
996 stl: "none",
997 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900998 `)
999
Sundong Ahnabb64432019-10-22 13:58:29 +09001000 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001001 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1002
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001003 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001004 ensureListContains(t, dirs, "etc")
1005 ensureListContains(t, dirs, "etc/foo")
1006 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001007 ensureListContains(t, dirs, "lib64")
1008 ensureListContains(t, dirs, "lib64/foo")
1009 ensureListContains(t, dirs, "lib64/foo/bar")
1010 ensureListContains(t, dirs, "lib")
1011 ensureListContains(t, dirs, "lib/foo")
1012 ensureListContains(t, dirs, "lib/foo/bar")
1013
Jiyong Parkbd13e442019-03-15 18:10:35 +09001014 ensureListContains(t, dirs, "bin")
1015 ensureListContains(t, dirs, "bin/foo")
1016 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001017}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001018
1019func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001020 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001021 apex {
1022 name: "myapex",
1023 key: "myapex.key",
1024 native_shared_libs: ["mylib"],
1025 use_vendor: true,
1026 }
1027
1028 apex_key {
1029 name: "myapex.key",
1030 public_key: "testkey.avbpubkey",
1031 private_key: "testkey.pem",
1032 }
1033
1034 cc_library {
1035 name: "mylib",
1036 srcs: ["mylib.cpp"],
1037 shared_libs: ["mylib2"],
1038 system_shared_libs: [],
1039 vendor_available: true,
1040 stl: "none",
1041 }
1042
1043 cc_library {
1044 name: "mylib2",
1045 srcs: ["mylib.cpp"],
1046 system_shared_libs: [],
1047 vendor_available: true,
1048 stl: "none",
1049 }
1050 `)
1051
1052 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001053 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001054 for _, implicit := range i.Implicits {
1055 inputsList = append(inputsList, implicit.String())
1056 }
1057 }
1058 inputsString := strings.Join(inputsList, " ")
1059
1060 // ensure that the apex includes vendor variants of the direct and indirect deps
Inseob Kim64c43952019-08-26 16:52:35 +09001061 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib.so")
1062 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001063
1064 // ensure that the apex does not include core variants
1065 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1066 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1067}
Jiyong Park16e91a02018-12-20 18:18:08 +09001068
Jooyung Han5c998b92019-06-27 11:30:33 +09001069func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1070 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1071 apex {
1072 name: "myapex",
1073 key: "myapex.key",
1074 native_shared_libs: ["mylib"],
1075 use_vendor: true,
1076 }
1077
1078 apex_key {
1079 name: "myapex.key",
1080 public_key: "testkey.avbpubkey",
1081 private_key: "testkey.pem",
1082 }
1083
1084 cc_library {
1085 name: "mylib",
1086 srcs: ["mylib.cpp"],
1087 system_shared_libs: [],
1088 stl: "none",
1089 }
1090 `)
1091}
1092
Jiyong Park16e91a02018-12-20 18:18:08 +09001093func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001094 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001095 apex {
1096 name: "myapex",
1097 key: "myapex.key",
1098 native_shared_libs: ["mylib"],
1099 }
1100
1101 apex_key {
1102 name: "myapex.key",
1103 public_key: "testkey.avbpubkey",
1104 private_key: "testkey.pem",
1105 }
1106
1107 cc_library {
1108 name: "mylib",
1109 srcs: ["mylib.cpp"],
1110 system_shared_libs: [],
1111 stl: "none",
1112 stubs: {
1113 versions: ["1", "2", "3"],
1114 },
1115 }
1116
1117 cc_binary {
1118 name: "not_in_apex",
1119 srcs: ["mylib.cpp"],
1120 static_libs: ["mylib"],
1121 static_executable: true,
1122 system_shared_libs: [],
1123 stl: "none",
1124 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001125 `)
1126
1127 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1128
1129 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001130 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001131}
Jiyong Park9335a262018-12-24 11:31:58 +09001132
1133func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001134 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001135 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001136 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001137 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001138 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001139 native_shared_libs: ["mylib"],
1140 }
1141
1142 cc_library {
1143 name: "mylib",
1144 srcs: ["mylib.cpp"],
1145 system_shared_libs: [],
1146 stl: "none",
1147 }
1148
1149 apex_key {
1150 name: "myapex.key",
1151 public_key: "testkey.avbpubkey",
1152 private_key: "testkey.pem",
1153 }
1154
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001155 android_app_certificate {
1156 name: "myapex.certificate",
1157 certificate: "testkey",
1158 }
1159
1160 android_app_certificate {
1161 name: "myapex.certificate.override",
1162 certificate: "testkey.override",
1163 }
1164
Jiyong Park9335a262018-12-24 11:31:58 +09001165 `)
1166
1167 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001168 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001169
1170 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1171 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1172 "vendor/foo/devkeys/testkey.avbpubkey")
1173 }
1174 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1175 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1176 "vendor/foo/devkeys/testkey.pem")
1177 }
1178
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001179 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001180 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001181 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001182 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001183 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001184 }
1185}
Jiyong Park58e364a2019-01-19 19:24:06 +09001186
1187func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001188 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001189 apex {
1190 name: "myapex",
1191 key: "myapex.key",
1192 native_shared_libs: ["mylib"],
1193 }
1194
1195 apex {
1196 name: "otherapex",
1197 key: "myapex.key",
1198 native_shared_libs: ["mylib"],
1199 }
1200
1201 apex_key {
1202 name: "myapex.key",
1203 public_key: "testkey.avbpubkey",
1204 private_key: "testkey.pem",
1205 }
1206
1207 cc_library {
1208 name: "mylib",
1209 srcs: ["mylib.cpp"],
1210 system_shared_libs: [],
1211 stl: "none",
1212 }
1213 `)
1214
Jooyung Han6b8459b2019-10-30 08:29:25 +09001215 // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001216 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001217 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001218 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1219 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001220
Jooyung Han6b8459b2019-10-30 08:29:25 +09001221 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001222 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001223 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001224 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1225 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001226
Jooyung Han6b8459b2019-10-30 08:29:25 +09001227 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001228 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001229 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001230 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1231 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001232}
Jiyong Park7e636d02019-01-28 16:16:54 +09001233
1234func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001235 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001236 apex {
1237 name: "myapex",
1238 key: "myapex.key",
1239 native_shared_libs: ["mylib"],
1240 }
1241
1242 apex_key {
1243 name: "myapex.key",
1244 public_key: "testkey.avbpubkey",
1245 private_key: "testkey.pem",
1246 }
1247
1248 cc_library_headers {
1249 name: "mylib_headers",
1250 export_include_dirs: ["my_include"],
1251 system_shared_libs: [],
1252 stl: "none",
1253 }
1254
1255 cc_library {
1256 name: "mylib",
1257 srcs: ["mylib.cpp"],
1258 system_shared_libs: [],
1259 stl: "none",
1260 header_libs: ["mylib_headers"],
1261 export_header_lib_headers: ["mylib_headers"],
1262 stubs: {
1263 versions: ["1", "2", "3"],
1264 },
1265 }
1266
1267 cc_library {
1268 name: "otherlib",
1269 srcs: ["mylib.cpp"],
1270 system_shared_libs: [],
1271 stl: "none",
1272 shared_libs: ["mylib"],
1273 }
1274 `)
1275
1276 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1277
1278 // Ensure that the include path of the header lib is exported to 'otherlib'
1279 ensureContains(t, cFlags, "-Imy_include")
1280}
Alex Light9670d332019-01-29 18:07:33 -08001281
Jooyung Han31c470b2019-10-18 16:26:59 +09001282func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) {
1283 t.Helper()
Sundong Ahnabb64432019-10-22 13:58:29 +09001284 apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001285 copyCmds := apexRule.Args["copy_commands"]
1286 imageApexDir := "/image.apex/"
1287 dstFiles := []string{}
1288 for _, cmd := range strings.Split(copyCmds, "&&") {
1289 cmd = strings.TrimSpace(cmd)
1290 if cmd == "" {
1291 continue
1292 }
1293 terms := strings.Split(cmd, " ")
1294 switch terms[0] {
1295 case "mkdir":
1296 case "cp":
1297 if len(terms) != 3 {
1298 t.Fatal("copyCmds contains invalid cp command", cmd)
1299 }
1300 dst := terms[2]
1301 index := strings.Index(dst, imageApexDir)
1302 if index == -1 {
1303 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1304 }
1305 dstFile := dst[index+len(imageApexDir):]
1306 dstFiles = append(dstFiles, dstFile)
1307 default:
1308 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1309 }
1310 }
1311 sort.Strings(dstFiles)
1312 sort.Strings(files)
1313 missing := []string{}
1314 surplus := []string{}
1315 i := 0
1316 j := 0
1317 for i < len(dstFiles) && j < len(files) {
1318 if dstFiles[i] == files[j] {
1319 i++
1320 j++
1321 } else if dstFiles[i] < files[j] {
1322 surplus = append(surplus, dstFiles[i])
1323 i++
1324 } else {
1325 missing = append(missing, files[j])
1326 j++
1327 }
1328 }
1329 if i < len(dstFiles) {
1330 surplus = append(surplus, dstFiles[i:]...)
1331 }
1332 if j < len(files) {
1333 missing = append(missing, files[j:]...)
1334 }
1335
1336 failed := false
1337 if len(surplus) > 0 {
1338 t.Log("surplus files", surplus)
1339 failed = true
1340 }
1341 if len(missing) > 0 {
1342 t.Log("missing files", missing)
1343 failed = true
1344 }
1345 if failed {
1346 t.Fail()
1347 }
1348}
1349
Jooyung Han344d5432019-08-23 11:17:39 +09001350func TestVndkApexCurrent(t *testing.T) {
1351 ctx, _ := testApex(t, `
1352 apex_vndk {
1353 name: "myapex",
1354 key: "myapex.key",
1355 file_contexts: "myapex",
1356 }
1357
1358 apex_key {
1359 name: "myapex.key",
1360 public_key: "testkey.avbpubkey",
1361 private_key: "testkey.pem",
1362 }
1363
1364 cc_library {
1365 name: "libvndk",
1366 srcs: ["mylib.cpp"],
1367 vendor_available: true,
1368 vndk: {
1369 enabled: true,
1370 },
1371 system_shared_libs: [],
1372 stl: "none",
1373 }
1374
1375 cc_library {
1376 name: "libvndksp",
1377 srcs: ["mylib.cpp"],
1378 vendor_available: true,
1379 vndk: {
1380 enabled: true,
1381 support_system_process: true,
1382 },
1383 system_shared_libs: [],
1384 stl: "none",
1385 }
1386 `)
1387
Jooyung Han31c470b2019-10-18 16:26:59 +09001388 ensureExactContents(t, ctx, "myapex", []string{
1389 "lib/libvndk.so",
1390 "lib/libvndksp.so",
1391 "lib64/libvndk.so",
1392 "lib64/libvndksp.so",
1393 })
Jooyung Han344d5432019-08-23 11:17:39 +09001394}
1395
1396func TestVndkApexWithPrebuilt(t *testing.T) {
1397 ctx, _ := testApex(t, `
1398 apex_vndk {
1399 name: "myapex",
1400 key: "myapex.key",
1401 file_contexts: "myapex",
1402 }
1403
1404 apex_key {
1405 name: "myapex.key",
1406 public_key: "testkey.avbpubkey",
1407 private_key: "testkey.pem",
1408 }
1409
1410 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001411 name: "libvndk",
1412 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001413 vendor_available: true,
1414 vndk: {
1415 enabled: true,
1416 },
1417 system_shared_libs: [],
1418 stl: "none",
1419 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001420
1421 cc_prebuilt_library_shared {
1422 name: "libvndk.arm",
1423 srcs: ["libvndk.arm.so"],
1424 vendor_available: true,
1425 vndk: {
1426 enabled: true,
1427 },
1428 enabled: false,
1429 arch: {
1430 arm: {
1431 enabled: true,
1432 },
1433 },
1434 system_shared_libs: [],
1435 stl: "none",
1436 }
Jooyung Han344d5432019-08-23 11:17:39 +09001437 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001438 "libvndk.so": nil,
1439 "libvndk.arm.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001440 }))
1441
Jooyung Han31c470b2019-10-18 16:26:59 +09001442 ensureExactContents(t, ctx, "myapex", []string{
1443 "lib/libvndk.so",
1444 "lib/libvndk.arm.so",
1445 "lib64/libvndk.so",
1446 })
Jooyung Han344d5432019-08-23 11:17:39 +09001447}
1448
1449func TestVndkApexVersion(t *testing.T) {
1450 ctx, _ := testApex(t, `
1451 apex_vndk {
1452 name: "myapex_v27",
1453 key: "myapex.key",
1454 file_contexts: "myapex",
1455 vndk_version: "27",
1456 }
1457
1458 apex_key {
1459 name: "myapex.key",
1460 public_key: "testkey.avbpubkey",
1461 private_key: "testkey.pem",
1462 }
1463
Jooyung Han31c470b2019-10-18 16:26:59 +09001464 vndk_prebuilt_shared {
1465 name: "libvndk27",
1466 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001467 vendor_available: true,
1468 vndk: {
1469 enabled: true,
1470 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001471 target_arch: "arm64",
1472 arch: {
1473 arm: {
1474 srcs: ["libvndk27_arm.so"],
1475 },
1476 arm64: {
1477 srcs: ["libvndk27_arm64.so"],
1478 },
1479 },
Jooyung Han344d5432019-08-23 11:17:39 +09001480 }
1481
1482 vndk_prebuilt_shared {
1483 name: "libvndk27",
1484 version: "27",
1485 vendor_available: true,
1486 vndk: {
1487 enabled: true,
1488 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001489 target_arch: "x86_64",
1490 arch: {
1491 x86: {
1492 srcs: ["libvndk27_x86.so"],
1493 },
1494 x86_64: {
1495 srcs: ["libvndk27_x86_64.so"],
1496 },
1497 },
1498 }
Jooyung Han344d5432019-08-23 11:17:39 +09001499 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001500 "libvndk27_arm.so": nil,
1501 "libvndk27_arm64.so": nil,
1502 "libvndk27_x86.so": nil,
1503 "libvndk27_x86_64.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001504 }))
1505
Jooyung Han31c470b2019-10-18 16:26:59 +09001506 ensureExactContents(t, ctx, "myapex_v27", []string{
1507 "lib/libvndk27_arm.so",
1508 "lib64/libvndk27_arm64.so",
1509 })
Jooyung Han344d5432019-08-23 11:17:39 +09001510}
1511
1512func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1513 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1514 apex_vndk {
1515 name: "myapex_v27",
1516 key: "myapex.key",
1517 file_contexts: "myapex",
1518 vndk_version: "27",
1519 }
1520 apex_vndk {
1521 name: "myapex_v27_other",
1522 key: "myapex.key",
1523 file_contexts: "myapex",
1524 vndk_version: "27",
1525 }
1526
1527 apex_key {
1528 name: "myapex.key",
1529 public_key: "testkey.avbpubkey",
1530 private_key: "testkey.pem",
1531 }
1532
1533 cc_library {
1534 name: "libvndk",
1535 srcs: ["mylib.cpp"],
1536 vendor_available: true,
1537 vndk: {
1538 enabled: true,
1539 },
1540 system_shared_libs: [],
1541 stl: "none",
1542 }
1543
1544 vndk_prebuilt_shared {
1545 name: "libvndk",
1546 version: "27",
1547 vendor_available: true,
1548 vndk: {
1549 enabled: true,
1550 },
1551 srcs: ["libvndk.so"],
1552 }
1553 `, withFiles(map[string][]byte{
1554 "libvndk.so": nil,
1555 }))
1556}
1557
Jooyung Han90eee022019-10-01 20:02:42 +09001558func TestVndkApexNameRule(t *testing.T) {
1559 ctx, _ := testApex(t, `
1560 apex_vndk {
1561 name: "myapex",
1562 key: "myapex.key",
1563 file_contexts: "myapex",
1564 }
1565 apex_vndk {
1566 name: "myapex_v28",
1567 key: "myapex.key",
1568 file_contexts: "myapex",
1569 vndk_version: "28",
1570 }
1571 apex_key {
1572 name: "myapex.key",
1573 public_key: "testkey.avbpubkey",
1574 private_key: "testkey.pem",
1575 }`)
1576
1577 assertApexName := func(expected, moduleName string) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001578 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09001579 actual := proptools.String(bundle.properties.Apex_name)
1580 if !reflect.DeepEqual(actual, expected) {
1581 t.Errorf("Got '%v', expected '%v'", actual, expected)
1582 }
1583 }
1584
1585 assertApexName("com.android.vndk.vVER", "myapex")
1586 assertApexName("com.android.vndk.v28", "myapex_v28")
1587}
1588
Jooyung Han344d5432019-08-23 11:17:39 +09001589func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1590 ctx, _ := testApex(t, `
1591 apex_vndk {
1592 name: "myapex",
1593 key: "myapex.key",
1594 file_contexts: "myapex",
1595 }
1596
1597 apex_key {
1598 name: "myapex.key",
1599 public_key: "testkey.avbpubkey",
1600 private_key: "testkey.pem",
1601 }
1602
1603 cc_library {
1604 name: "libvndk",
1605 srcs: ["mylib.cpp"],
1606 vendor_available: true,
1607 native_bridge_supported: true,
1608 host_supported: true,
1609 vndk: {
1610 enabled: true,
1611 },
1612 system_shared_libs: [],
1613 stl: "none",
1614 }
1615 `, withTargets(map[android.OsType][]android.Target{
1616 android.Android: []android.Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -07001617 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1618 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1619 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1620 {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 +09001621 },
1622 }))
1623
Jooyung Han31c470b2019-10-18 16:26:59 +09001624 ensureExactContents(t, ctx, "myapex", []string{
1625 "lib/libvndk.so",
1626 "lib64/libvndk.so",
1627 })
Jooyung Han344d5432019-08-23 11:17:39 +09001628}
1629
1630func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1631 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1632 apex_vndk {
1633 name: "myapex",
1634 key: "myapex.key",
1635 file_contexts: "myapex",
1636 native_bridge_supported: true,
1637 }
1638
1639 apex_key {
1640 name: "myapex.key",
1641 public_key: "testkey.avbpubkey",
1642 private_key: "testkey.pem",
1643 }
1644
1645 cc_library {
1646 name: "libvndk",
1647 srcs: ["mylib.cpp"],
1648 vendor_available: true,
1649 native_bridge_supported: true,
1650 host_supported: true,
1651 vndk: {
1652 enabled: true,
1653 },
1654 system_shared_libs: [],
1655 stl: "none",
1656 }
1657 `)
1658}
1659
Jooyung Han31c470b2019-10-18 16:26:59 +09001660func TestVndkApexWithBinder32(t *testing.T) {
1661 ctx, _ := testApex(t,
1662 `
1663 apex_vndk {
1664 name: "myapex_v27",
1665 key: "myapex.key",
1666 file_contexts: "myapex",
1667 vndk_version: "27",
1668 }
1669
1670 apex_key {
1671 name: "myapex.key",
1672 public_key: "testkey.avbpubkey",
1673 private_key: "testkey.pem",
1674 }
1675
1676 vndk_prebuilt_shared {
1677 name: "libvndk27",
1678 version: "27",
1679 target_arch: "arm",
1680 vendor_available: true,
1681 vndk: {
1682 enabled: true,
1683 },
1684 arch: {
1685 arm: {
1686 srcs: ["libvndk27.so"],
1687 }
1688 },
1689 }
1690
1691 vndk_prebuilt_shared {
1692 name: "libvndk27",
1693 version: "27",
1694 target_arch: "arm",
1695 binder32bit: true,
1696 vendor_available: true,
1697 vndk: {
1698 enabled: true,
1699 },
1700 arch: {
1701 arm: {
1702 srcs: ["libvndk27binder32.so"],
1703 }
1704 },
1705 }
1706 `,
1707 withFiles(map[string][]byte{
1708 "libvndk27.so": nil,
1709 "libvndk27binder32.so": nil,
1710 }),
1711 withBinder32bit,
1712 withTargets(map[android.OsType][]android.Target{
1713 android.Android: []android.Target{
1714 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1715 },
1716 }),
1717 )
1718
1719 ensureExactContents(t, ctx, "myapex_v27", []string{
1720 "lib/libvndk27binder32.so",
1721 })
1722}
1723
Jooyung Hane1633032019-08-01 17:41:43 +09001724func TestDependenciesInApexManifest(t *testing.T) {
1725 ctx, _ := testApex(t, `
1726 apex {
1727 name: "myapex_nodep",
1728 key: "myapex.key",
1729 native_shared_libs: ["lib_nodep"],
1730 compile_multilib: "both",
1731 file_contexts: "myapex",
1732 }
1733
1734 apex {
1735 name: "myapex_dep",
1736 key: "myapex.key",
1737 native_shared_libs: ["lib_dep"],
1738 compile_multilib: "both",
1739 file_contexts: "myapex",
1740 }
1741
1742 apex {
1743 name: "myapex_provider",
1744 key: "myapex.key",
1745 native_shared_libs: ["libfoo"],
1746 compile_multilib: "both",
1747 file_contexts: "myapex",
1748 }
1749
1750 apex {
1751 name: "myapex_selfcontained",
1752 key: "myapex.key",
1753 native_shared_libs: ["lib_dep", "libfoo"],
1754 compile_multilib: "both",
1755 file_contexts: "myapex",
1756 }
1757
1758 apex_key {
1759 name: "myapex.key",
1760 public_key: "testkey.avbpubkey",
1761 private_key: "testkey.pem",
1762 }
1763
1764 cc_library {
1765 name: "lib_nodep",
1766 srcs: ["mylib.cpp"],
1767 system_shared_libs: [],
1768 stl: "none",
1769 }
1770
1771 cc_library {
1772 name: "lib_dep",
1773 srcs: ["mylib.cpp"],
1774 shared_libs: ["libfoo"],
1775 system_shared_libs: [],
1776 stl: "none",
1777 }
1778
1779 cc_library {
1780 name: "libfoo",
1781 srcs: ["mytest.cpp"],
1782 stubs: {
1783 versions: ["1"],
1784 },
1785 system_shared_libs: [],
1786 stl: "none",
1787 }
1788 `)
1789
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001790 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09001791 var provideNativeLibs, requireNativeLibs []string
1792
Sundong Ahnabb64432019-10-22 13:58:29 +09001793 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001794 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1795 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001796 ensureListEmpty(t, provideNativeLibs)
1797 ensureListEmpty(t, requireNativeLibs)
1798
Sundong Ahnabb64432019-10-22 13:58:29 +09001799 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001800 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1801 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001802 ensureListEmpty(t, provideNativeLibs)
1803 ensureListContains(t, requireNativeLibs, "libfoo.so")
1804
Sundong Ahnabb64432019-10-22 13:58:29 +09001805 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001806 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1807 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001808 ensureListContains(t, provideNativeLibs, "libfoo.so")
1809 ensureListEmpty(t, requireNativeLibs)
1810
Sundong Ahnabb64432019-10-22 13:58:29 +09001811 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001812 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1813 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001814 ensureListContains(t, provideNativeLibs, "libfoo.so")
1815 ensureListEmpty(t, requireNativeLibs)
1816}
1817
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001818func TestApexName(t *testing.T) {
1819 ctx, _ := testApex(t, `
1820 apex {
1821 name: "myapex",
1822 key: "myapex.key",
1823 apex_name: "com.android.myapex",
1824 }
1825
1826 apex_key {
1827 name: "myapex.key",
1828 public_key: "testkey.avbpubkey",
1829 private_key: "testkey.pem",
1830 }
1831 `)
1832
Sundong Ahnabb64432019-10-22 13:58:29 +09001833 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001834 apexManifestRule := module.Rule("apexManifestRule")
1835 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
1836 apexRule := module.Rule("apexRule")
1837 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
1838}
1839
Alex Light0851b882019-02-07 13:20:53 -08001840func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001841 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001842 apex {
1843 name: "myapex",
1844 key: "myapex.key",
1845 native_shared_libs: ["mylib_common"],
1846 }
1847
1848 apex_key {
1849 name: "myapex.key",
1850 public_key: "testkey.avbpubkey",
1851 private_key: "testkey.pem",
1852 }
1853
1854 cc_library {
1855 name: "mylib_common",
1856 srcs: ["mylib.cpp"],
1857 system_shared_libs: [],
1858 stl: "none",
1859 }
1860 `)
1861
Sundong Ahnabb64432019-10-22 13:58:29 +09001862 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08001863 apexRule := module.Rule("apexRule")
1864 copyCmds := apexRule.Args["copy_commands"]
1865
1866 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1867 t.Log("Apex was a test apex!")
1868 t.Fail()
1869 }
1870 // Ensure that main rule creates an output
1871 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1872
1873 // Ensure that apex variant is created for the direct dep
1874 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1875
1876 // Ensure that both direct and indirect deps are copied into apex
1877 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1878
1879 // Ensure that the platform variant ends with _core_shared
1880 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1881
1882 if !android.InAnyApex("mylib_common") {
1883 t.Log("Found mylib_common not in any apex!")
1884 t.Fail()
1885 }
1886}
1887
1888func TestTestApex(t *testing.T) {
1889 if android.InAnyApex("mylib_common_test") {
1890 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!")
1891 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001892 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001893 apex_test {
1894 name: "myapex",
1895 key: "myapex.key",
1896 native_shared_libs: ["mylib_common_test"],
1897 }
1898
1899 apex_key {
1900 name: "myapex.key",
1901 public_key: "testkey.avbpubkey",
1902 private_key: "testkey.pem",
1903 }
1904
1905 cc_library {
1906 name: "mylib_common_test",
1907 srcs: ["mylib.cpp"],
1908 system_shared_libs: [],
1909 stl: "none",
1910 }
1911 `)
1912
Sundong Ahnabb64432019-10-22 13:58:29 +09001913 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08001914 apexRule := module.Rule("apexRule")
1915 copyCmds := apexRule.Args["copy_commands"]
1916
1917 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1918 t.Log("Apex was not a test apex!")
1919 t.Fail()
1920 }
1921 // Ensure that main rule creates an output
1922 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1923
1924 // Ensure that apex variant is created for the direct dep
1925 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1926
1927 // Ensure that both direct and indirect deps are copied into apex
1928 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1929
1930 // Ensure that the platform variant ends with _core_shared
1931 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1932
1933 if android.InAnyApex("mylib_common_test") {
1934 t.Log("Found mylib_common_test in some apex!")
1935 t.Fail()
1936 }
1937}
1938
Alex Light9670d332019-01-29 18:07:33 -08001939func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001940 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001941 apex {
1942 name: "myapex",
1943 key: "myapex.key",
1944 multilib: {
1945 first: {
1946 native_shared_libs: ["mylib_common"],
1947 }
1948 },
1949 target: {
1950 android: {
1951 multilib: {
1952 first: {
1953 native_shared_libs: ["mylib"],
1954 }
1955 }
1956 },
1957 host: {
1958 multilib: {
1959 first: {
1960 native_shared_libs: ["mylib2"],
1961 }
1962 }
1963 }
1964 }
1965 }
1966
1967 apex_key {
1968 name: "myapex.key",
1969 public_key: "testkey.avbpubkey",
1970 private_key: "testkey.pem",
1971 }
1972
1973 cc_library {
1974 name: "mylib",
1975 srcs: ["mylib.cpp"],
1976 system_shared_libs: [],
1977 stl: "none",
1978 }
1979
1980 cc_library {
1981 name: "mylib_common",
1982 srcs: ["mylib.cpp"],
1983 system_shared_libs: [],
1984 stl: "none",
1985 compile_multilib: "first",
1986 }
1987
1988 cc_library {
1989 name: "mylib2",
1990 srcs: ["mylib.cpp"],
1991 system_shared_libs: [],
1992 stl: "none",
1993 compile_multilib: "first",
1994 }
1995 `)
1996
Sundong Ahnabb64432019-10-22 13:58:29 +09001997 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08001998 copyCmds := apexRule.Args["copy_commands"]
1999
2000 // Ensure that main rule creates an output
2001 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2002
2003 // Ensure that apex variant is created for the direct dep
2004 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2005 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
2006 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
2007
2008 // Ensure that both direct and indirect deps are copied into apex
2009 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2010 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2011 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2012
2013 // Ensure that the platform variant ends with _core_shared
2014 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
2015 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
2016 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
2017}
Jiyong Park04480cf2019-02-06 00:16:29 +09002018
2019func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002020 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002021 apex {
2022 name: "myapex",
2023 key: "myapex.key",
2024 binaries: ["myscript"],
2025 }
2026
2027 apex_key {
2028 name: "myapex.key",
2029 public_key: "testkey.avbpubkey",
2030 private_key: "testkey.pem",
2031 }
2032
2033 sh_binary {
2034 name: "myscript",
2035 src: "mylib.cpp",
2036 filename: "myscript.sh",
2037 sub_dir: "script",
2038 }
2039 `)
2040
Sundong Ahnabb64432019-10-22 13:58:29 +09002041 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002042 copyCmds := apexRule.Args["copy_commands"]
2043
2044 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2045}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002046
2047func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002048 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002049 apex {
2050 name: "myapex",
2051 key: "myapex.key",
2052 native_shared_libs: ["mylib"],
2053 product_specific: true,
2054 }
2055
2056 apex_key {
2057 name: "myapex.key",
2058 public_key: "testkey.avbpubkey",
2059 private_key: "testkey.pem",
2060 product_specific: true,
2061 }
2062
2063 cc_library {
2064 name: "mylib",
2065 srcs: ["mylib.cpp"],
2066 system_shared_libs: [],
2067 stl: "none",
2068 }
2069 `)
2070
Sundong Ahnabb64432019-10-22 13:58:29 +09002071 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossff6c33d2019-10-02 16:01:35 -07002072 expected := buildDir + "/target/product/test_device/product/apex"
2073 actual := apex.installDir.String()
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002074 if actual != expected {
2075 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2076 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002077}
Jiyong Park67882562019-03-21 01:11:21 +09002078
2079func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002080 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002081 apex_key {
2082 name: "myapex.key",
2083 public_key: ":my.avbpubkey",
2084 private_key: ":my.pem",
2085 product_specific: true,
2086 }
2087
2088 filegroup {
2089 name: "my.avbpubkey",
2090 srcs: ["testkey2.avbpubkey"],
2091 }
2092
2093 filegroup {
2094 name: "my.pem",
2095 srcs: ["testkey2.pem"],
2096 }
2097 `)
2098
2099 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2100 expected_pubkey := "testkey2.avbpubkey"
2101 actual_pubkey := apex_key.public_key_file.String()
2102 if actual_pubkey != expected_pubkey {
2103 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2104 }
2105 expected_privkey := "testkey2.pem"
2106 actual_privkey := apex_key.private_key_file.String()
2107 if actual_privkey != expected_privkey {
2108 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2109 }
2110}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002111
2112func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002113 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002114 prebuilt_apex {
2115 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002116 arch: {
2117 arm64: {
2118 src: "myapex-arm64.apex",
2119 },
2120 arm: {
2121 src: "myapex-arm.apex",
2122 },
2123 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002124 }
2125 `)
2126
2127 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2128
Jiyong Parkc95714e2019-03-29 14:23:10 +09002129 expectedInput := "myapex-arm64.apex"
2130 if prebuilt.inputApex.String() != expectedInput {
2131 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2132 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002133}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002134
2135func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002136 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002137 prebuilt_apex {
2138 name: "myapex",
2139 src: "myapex-arm.apex",
2140 filename: "notmyapex.apex",
2141 }
2142 `)
2143
2144 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2145
2146 expected := "notmyapex.apex"
2147 if p.installFilename != expected {
2148 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2149 }
2150}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002151
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002152func TestPrebuiltOverrides(t *testing.T) {
2153 ctx, config := testApex(t, `
2154 prebuilt_apex {
2155 name: "myapex.prebuilt",
2156 src: "myapex-arm.apex",
2157 overrides: [
2158 "myapex",
2159 ],
2160 }
2161 `)
2162
2163 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2164
2165 expected := []string{"myapex"}
2166 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
2167 if !reflect.DeepEqual(actual, expected) {
2168 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
2169 }
2170}
2171
Roland Levillain630846d2019-06-26 12:48:34 +01002172func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002173 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002174 apex_test {
2175 name: "myapex",
2176 key: "myapex.key",
2177 tests: [
2178 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002179 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002180 ],
2181 }
2182
2183 apex_key {
2184 name: "myapex.key",
2185 public_key: "testkey.avbpubkey",
2186 private_key: "testkey.pem",
2187 }
2188
2189 cc_test {
2190 name: "mytest",
2191 gtest: false,
2192 srcs: ["mytest.cpp"],
2193 relative_install_path: "test",
2194 system_shared_libs: [],
2195 static_executable: true,
2196 stl: "none",
2197 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002198
2199 cc_test {
2200 name: "mytests",
2201 gtest: false,
2202 srcs: [
2203 "mytest1.cpp",
2204 "mytest2.cpp",
2205 "mytest3.cpp",
2206 ],
2207 test_per_src: true,
2208 relative_install_path: "test",
2209 system_shared_libs: [],
2210 static_executable: true,
2211 stl: "none",
2212 }
Roland Levillain630846d2019-06-26 12:48:34 +01002213 `)
2214
Sundong Ahnabb64432019-10-22 13:58:29 +09002215 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002216 copyCmds := apexRule.Args["copy_commands"]
2217
2218 // Ensure that test dep is copied into apex.
2219 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002220
2221 // Ensure that test deps built with `test_per_src` are copied into apex.
2222 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2223 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2224 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002225
2226 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002227 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002228 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2229 name := apexBundle.BaseModuleName()
2230 prefix := "TARGET_"
2231 var builder strings.Builder
2232 data.Custom(&builder, name, prefix, "", data)
2233 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002234 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2235 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2236 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2237 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
2238 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.json.myapex\n")
2239 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002240 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002241}
2242
Jooyung Han5c998b92019-06-27 11:30:33 +09002243func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002244 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002245 apex {
2246 name: "myapex",
2247 key: "myapex.key",
2248 native_shared_libs: ["mylib"],
2249 uses: ["commonapex"],
2250 }
2251
2252 apex {
2253 name: "commonapex",
2254 key: "myapex.key",
2255 native_shared_libs: ["libcommon"],
2256 provide_cpp_shared_libs: true,
2257 }
2258
2259 apex_key {
2260 name: "myapex.key",
2261 public_key: "testkey.avbpubkey",
2262 private_key: "testkey.pem",
2263 }
2264
2265 cc_library {
2266 name: "mylib",
2267 srcs: ["mylib.cpp"],
2268 shared_libs: ["libcommon"],
2269 system_shared_libs: [],
2270 stl: "none",
2271 }
2272
2273 cc_library {
2274 name: "libcommon",
2275 srcs: ["mylib_common.cpp"],
2276 system_shared_libs: [],
2277 stl: "none",
2278 }
2279 `)
2280
Sundong Ahnabb64432019-10-22 13:58:29 +09002281 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002282 apexRule1 := module1.Rule("apexRule")
2283 copyCmds1 := apexRule1.Args["copy_commands"]
2284
Sundong Ahnabb64432019-10-22 13:58:29 +09002285 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002286 apexRule2 := module2.Rule("apexRule")
2287 copyCmds2 := apexRule2.Args["copy_commands"]
2288
2289 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2290 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2291 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2292 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2293 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2294}
2295
2296func TestApexUsesFailsIfNotProvided(t *testing.T) {
2297 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2298 apex {
2299 name: "myapex",
2300 key: "myapex.key",
2301 uses: ["commonapex"],
2302 }
2303
2304 apex {
2305 name: "commonapex",
2306 key: "myapex.key",
2307 }
2308
2309 apex_key {
2310 name: "myapex.key",
2311 public_key: "testkey.avbpubkey",
2312 private_key: "testkey.pem",
2313 }
2314 `)
2315 testApexError(t, `uses: "commonapex" is not a provider`, `
2316 apex {
2317 name: "myapex",
2318 key: "myapex.key",
2319 uses: ["commonapex"],
2320 }
2321
2322 cc_library {
2323 name: "commonapex",
2324 system_shared_libs: [],
2325 stl: "none",
2326 }
2327
2328 apex_key {
2329 name: "myapex.key",
2330 public_key: "testkey.avbpubkey",
2331 private_key: "testkey.pem",
2332 }
2333 `)
2334}
2335
2336func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2337 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2338 apex {
2339 name: "myapex",
2340 key: "myapex.key",
2341 use_vendor: true,
2342 uses: ["commonapex"],
2343 }
2344
2345 apex {
2346 name: "commonapex",
2347 key: "myapex.key",
2348 provide_cpp_shared_libs: true,
2349 }
2350
2351 apex_key {
2352 name: "myapex.key",
2353 public_key: "testkey.avbpubkey",
2354 private_key: "testkey.pem",
2355 }
2356 `)
2357}
2358
Jooyung Hand48f3c32019-08-23 11:18:57 +09002359func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2360 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2361 apex {
2362 name: "myapex",
2363 key: "myapex.key",
2364 native_shared_libs: ["libfoo"],
2365 }
2366
2367 apex_key {
2368 name: "myapex.key",
2369 public_key: "testkey.avbpubkey",
2370 private_key: "testkey.pem",
2371 }
2372
2373 cc_library {
2374 name: "libfoo",
2375 stl: "none",
2376 system_shared_libs: [],
2377 enabled: false,
2378 }
2379 `)
2380 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2381 apex {
2382 name: "myapex",
2383 key: "myapex.key",
2384 java_libs: ["myjar"],
2385 }
2386
2387 apex_key {
2388 name: "myapex.key",
2389 public_key: "testkey.avbpubkey",
2390 private_key: "testkey.pem",
2391 }
2392
2393 java_library {
2394 name: "myjar",
2395 srcs: ["foo/bar/MyClass.java"],
2396 sdk_version: "none",
2397 system_modules: "none",
2398 compile_dex: true,
2399 enabled: false,
2400 }
2401 `)
2402}
2403
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002404func TestApexWithApps(t *testing.T) {
2405 ctx, _ := testApex(t, `
2406 apex {
2407 name: "myapex",
2408 key: "myapex.key",
2409 apps: [
2410 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09002411 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002412 ],
2413 }
2414
2415 apex_key {
2416 name: "myapex.key",
2417 public_key: "testkey.avbpubkey",
2418 private_key: "testkey.pem",
2419 }
2420
2421 android_app {
2422 name: "AppFoo",
2423 srcs: ["foo/bar/MyClass.java"],
2424 sdk_version: "none",
2425 system_modules: "none",
2426 }
Jiyong Parkf7487312019-10-17 12:54:30 +09002427
2428 android_app {
2429 name: "AppFooPriv",
2430 srcs: ["foo/bar/MyClass.java"],
2431 sdk_version: "none",
2432 system_modules: "none",
2433 privileged: true,
2434 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002435 `)
2436
Sundong Ahnabb64432019-10-22 13:58:29 +09002437 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002438 apexRule := module.Rule("apexRule")
2439 copyCmds := apexRule.Args["copy_commands"]
2440
2441 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09002442 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Dario Frenicde2a032019-10-27 00:29:22 +01002443}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002444
Dario Frenicde2a032019-10-27 00:29:22 +01002445func TestApexWithAppImports(t *testing.T) {
2446 ctx, _ := testApex(t, `
2447 apex {
2448 name: "myapex",
2449 key: "myapex.key",
2450 apps: [
2451 "AppFooPrebuilt",
2452 "AppFooPrivPrebuilt",
2453 ],
2454 }
2455
2456 apex_key {
2457 name: "myapex.key",
2458 public_key: "testkey.avbpubkey",
2459 private_key: "testkey.pem",
2460 }
2461
2462 android_app_import {
2463 name: "AppFooPrebuilt",
2464 apk: "PrebuiltAppFoo.apk",
2465 presigned: true,
2466 dex_preopt: {
2467 enabled: false,
2468 },
2469 }
2470
2471 android_app_import {
2472 name: "AppFooPrivPrebuilt",
2473 apk: "PrebuiltAppFooPriv.apk",
2474 privileged: true,
2475 presigned: true,
2476 dex_preopt: {
2477 enabled: false,
2478 },
2479 }
2480 `)
2481
Sundong Ahnabb64432019-10-22 13:58:29 +09002482 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01002483 apexRule := module.Rule("apexRule")
2484 copyCmds := apexRule.Args["copy_commands"]
2485
2486 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
2487 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002488}
2489
Jiyong Park127b40b2019-09-30 16:04:35 +09002490func TestApexAvailable(t *testing.T) {
2491 // libfoo is not available to myapex, but only to otherapex
2492 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
2493 apex {
2494 name: "myapex",
2495 key: "myapex.key",
2496 native_shared_libs: ["libfoo"],
2497 }
2498
2499 apex_key {
2500 name: "myapex.key",
2501 public_key: "testkey.avbpubkey",
2502 private_key: "testkey.pem",
2503 }
2504
2505 apex {
2506 name: "otherapex",
2507 key: "otherapex.key",
2508 native_shared_libs: ["libfoo"],
2509 }
2510
2511 apex_key {
2512 name: "otherapex.key",
2513 public_key: "testkey.avbpubkey",
2514 private_key: "testkey.pem",
2515 }
2516
2517 cc_library {
2518 name: "libfoo",
2519 stl: "none",
2520 system_shared_libs: [],
2521 apex_available: ["otherapex"],
2522 }`)
2523
2524 // libbar is an indirect dep
2525 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
2526 apex {
2527 name: "myapex",
2528 key: "myapex.key",
2529 native_shared_libs: ["libfoo"],
2530 }
2531
2532 apex_key {
2533 name: "myapex.key",
2534 public_key: "testkey.avbpubkey",
2535 private_key: "testkey.pem",
2536 }
2537
2538 apex {
2539 name: "otherapex",
2540 key: "otherapex.key",
2541 native_shared_libs: ["libfoo"],
2542 }
2543
2544 apex_key {
2545 name: "otherapex.key",
2546 public_key: "testkey.avbpubkey",
2547 private_key: "testkey.pem",
2548 }
2549
2550 cc_library {
2551 name: "libfoo",
2552 stl: "none",
2553 shared_libs: ["libbar"],
2554 system_shared_libs: [],
2555 apex_available: ["myapex", "otherapex"],
2556 }
2557
2558 cc_library {
2559 name: "libbar",
2560 stl: "none",
2561 system_shared_libs: [],
2562 apex_available: ["otherapex"],
2563 }`)
2564
2565 testApexError(t, "\"otherapex\" is not a valid module name", `
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 cc_library {
2579 name: "libfoo",
2580 stl: "none",
2581 system_shared_libs: [],
2582 apex_available: ["otherapex"],
2583 }`)
2584
2585 ctx, _ := testApex(t, `
2586 apex {
2587 name: "myapex",
2588 key: "myapex.key",
2589 native_shared_libs: ["libfoo", "libbar"],
2590 }
2591
2592 apex_key {
2593 name: "myapex.key",
2594 public_key: "testkey.avbpubkey",
2595 private_key: "testkey.pem",
2596 }
2597
2598 cc_library {
2599 name: "libfoo",
2600 stl: "none",
2601 system_shared_libs: [],
2602 apex_available: ["myapex"],
2603 }
2604
2605 cc_library {
2606 name: "libbar",
2607 stl: "none",
2608 system_shared_libs: [],
2609 apex_available: ["//apex_available:anyapex"],
2610 }`)
2611
2612 // check that libfoo and libbar are created only for myapex, but not for the platform
2613 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2614 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2615 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared_myapex")
2616 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared")
2617
2618 ctx, _ = testApex(t, `
2619 apex {
2620 name: "myapex",
2621 key: "myapex.key",
2622 }
2623
2624 apex_key {
2625 name: "myapex.key",
2626 public_key: "testkey.avbpubkey",
2627 private_key: "testkey.pem",
2628 }
2629
2630 cc_library {
2631 name: "libfoo",
2632 stl: "none",
2633 system_shared_libs: [],
2634 apex_available: ["//apex_available:platform"],
2635 }`)
2636
2637 // check that libfoo is created only for the platform
2638 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2639 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09002640
2641 ctx, _ = testApex(t, `
2642 apex {
2643 name: "myapex",
2644 key: "myapex.key",
2645 native_shared_libs: ["libfoo"],
2646 }
2647
2648 apex_key {
2649 name: "myapex.key",
2650 public_key: "testkey.avbpubkey",
2651 private_key: "testkey.pem",
2652 }
2653
2654 cc_library {
2655 name: "libfoo",
2656 stl: "none",
2657 system_shared_libs: [],
2658 apex_available: ["myapex"],
2659 static: {
2660 apex_available: ["//apex_available:platform"],
2661 },
2662 }`)
2663
2664 // shared variant of libfoo is only available to myapex
2665 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2666 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2667 // but the static variant is available to both myapex and the platform
2668 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static_myapex")
2669 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09002670}
2671
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002672func TestMain(m *testing.M) {
2673 run := func() int {
2674 setUp()
2675 defer tearDown()
2676
2677 return m.Run()
2678 }
2679
2680 os.Exit(run())
2681}