blob: 754b6a62a3f60146f98456729008e952afac050d [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 }
Jooyung Handc782442019-11-01 03:14:38 +0900821 `, func(fs map[string][]byte, config android.Config) {
822 setUseVendorWhitelistForTest(config, []string{"myapex"})
823 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900824
Sundong Ahnabb64432019-10-22 13:58:29 +0900825 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900826 copyCmds := apexRule.Args["copy_commands"]
827
828 // Ensure that LLNDK dep is not included
829 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
830
Sundong Ahnabb64432019-10-22 13:58:29 +0900831 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900832 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900833
834 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900835 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900836
837}
838
Jiyong Park25fc6a92018-11-18 18:02:45 +0900839func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700840 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900841 apex {
842 name: "myapex",
843 key: "myapex.key",
844 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
845 }
846
847 apex_key {
848 name: "myapex.key",
849 public_key: "testkey.avbpubkey",
850 private_key: "testkey.pem",
851 }
852
853 cc_library {
854 name: "mylib",
855 srcs: ["mylib.cpp"],
856 shared_libs: ["libdl#27"],
857 stl: "none",
858 }
859
860 cc_library_shared {
861 name: "mylib_shared",
862 srcs: ["mylib.cpp"],
863 shared_libs: ["libdl#27"],
864 stl: "none",
865 }
866
867 cc_library {
868 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700869 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900870 nocrt: true,
871 system_shared_libs: [],
872 stl: "none",
873 stubs: {
874 versions: ["27", "28", "29"],
875 },
876 }
877
878 cc_library {
879 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700880 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900881 nocrt: true,
882 system_shared_libs: [],
883 stl: "none",
884 stubs: {
885 versions: ["27", "28", "29"],
886 },
887 }
888
889 cc_library {
890 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700891 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900892 nocrt: true,
893 system_shared_libs: [],
894 stl: "none",
895 stubs: {
896 versions: ["27", "28", "29"],
897 },
898 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900899
900 cc_library {
901 name: "libBootstrap",
902 srcs: ["mylib.cpp"],
903 stl: "none",
904 bootstrap: true,
905 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900906 `)
907
Sundong Ahnabb64432019-10-22 13:58:29 +0900908 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900909 copyCmds := apexRule.Args["copy_commands"]
910
911 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800912 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900913 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
914 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900915
916 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900917 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900918
Jiyong Parkda6eb592018-12-19 17:12:36 +0900919 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
920 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
921 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900922
923 // For dependency to libc
924 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900925 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900926 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900927 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900928 // ... Cflags from stub is correctly exported to mylib
929 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
930 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
931
932 // For dependency to libm
933 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900934 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900935 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900936 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900937 // ... and is not compiling with the stub
938 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
939 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
940
941 // For dependency to libdl
942 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900943 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900944 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900945 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
946 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900947 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900948 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900949 // ... Cflags from stub is correctly exported to mylib
950 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
951 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900952
953 // Ensure that libBootstrap is depending on the platform variant of bionic libs
954 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
955 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
956 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
957 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900958}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900959
960func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700961 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900962 apex {
963 name: "myapex",
964 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900965 native_shared_libs: ["mylib"],
966 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900967 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900968 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900969 }
970
971 apex_key {
972 name: "myapex.key",
973 public_key: "testkey.avbpubkey",
974 private_key: "testkey.pem",
975 }
976
977 prebuilt_etc {
978 name: "myetc",
979 src: "myprebuilt",
980 sub_dir: "foo/bar",
981 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900982
983 cc_library {
984 name: "mylib",
985 srcs: ["mylib.cpp"],
986 relative_install_path: "foo/bar",
987 system_shared_libs: [],
988 stl: "none",
989 }
990
991 cc_binary {
992 name: "mybin",
993 srcs: ["mylib.cpp"],
994 relative_install_path: "foo/bar",
995 system_shared_libs: [],
996 static_executable: true,
997 stl: "none",
998 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900999 `)
1000
Sundong Ahnabb64432019-10-22 13:58:29 +09001001 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001002 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1003
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001004 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001005 ensureListContains(t, dirs, "etc")
1006 ensureListContains(t, dirs, "etc/foo")
1007 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001008 ensureListContains(t, dirs, "lib64")
1009 ensureListContains(t, dirs, "lib64/foo")
1010 ensureListContains(t, dirs, "lib64/foo/bar")
1011 ensureListContains(t, dirs, "lib")
1012 ensureListContains(t, dirs, "lib/foo")
1013 ensureListContains(t, dirs, "lib/foo/bar")
1014
Jiyong Parkbd13e442019-03-15 18:10:35 +09001015 ensureListContains(t, dirs, "bin")
1016 ensureListContains(t, dirs, "bin/foo")
1017 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001018}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001019
1020func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001021 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001022 apex {
1023 name: "myapex",
1024 key: "myapex.key",
1025 native_shared_libs: ["mylib"],
1026 use_vendor: true,
1027 }
1028
1029 apex_key {
1030 name: "myapex.key",
1031 public_key: "testkey.avbpubkey",
1032 private_key: "testkey.pem",
1033 }
1034
1035 cc_library {
1036 name: "mylib",
1037 srcs: ["mylib.cpp"],
1038 shared_libs: ["mylib2"],
1039 system_shared_libs: [],
1040 vendor_available: true,
1041 stl: "none",
1042 }
1043
1044 cc_library {
1045 name: "mylib2",
1046 srcs: ["mylib.cpp"],
1047 system_shared_libs: [],
1048 vendor_available: true,
1049 stl: "none",
1050 }
Jooyung Handc782442019-11-01 03:14:38 +09001051 `, func(fs map[string][]byte, config android.Config) {
1052 setUseVendorWhitelistForTest(config, []string{"myapex"})
1053 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001054
1055 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001056 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001057 for _, implicit := range i.Implicits {
1058 inputsList = append(inputsList, implicit.String())
1059 }
1060 }
1061 inputsString := strings.Join(inputsList, " ")
1062
1063 // ensure that the apex includes vendor variants of the direct and indirect deps
Inseob Kim64c43952019-08-26 16:52:35 +09001064 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib.so")
1065 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001066
1067 // ensure that the apex does not include core variants
1068 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1069 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1070}
Jiyong Park16e91a02018-12-20 18:18:08 +09001071
Jooyung Handc782442019-11-01 03:14:38 +09001072func TestUseVendorRestriction(t *testing.T) {
1073 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1074 apex {
1075 name: "myapex",
1076 key: "myapex.key",
1077 use_vendor: true,
1078 }
1079 apex_key {
1080 name: "myapex.key",
1081 public_key: "testkey.avbpubkey",
1082 private_key: "testkey.pem",
1083 }
1084 `, func(fs map[string][]byte, config android.Config) {
1085 setUseVendorWhitelistForTest(config, []string{""})
1086 })
1087 // no error with whitelist
1088 testApex(t, `
1089 apex {
1090 name: "myapex",
1091 key: "myapex.key",
1092 use_vendor: true,
1093 }
1094 apex_key {
1095 name: "myapex.key",
1096 public_key: "testkey.avbpubkey",
1097 private_key: "testkey.pem",
1098 }
1099 `, func(fs map[string][]byte, config android.Config) {
1100 setUseVendorWhitelistForTest(config, []string{"myapex"})
1101 })
1102}
1103
Jooyung Han5c998b92019-06-27 11:30:33 +09001104func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1105 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1106 apex {
1107 name: "myapex",
1108 key: "myapex.key",
1109 native_shared_libs: ["mylib"],
1110 use_vendor: true,
1111 }
1112
1113 apex_key {
1114 name: "myapex.key",
1115 public_key: "testkey.avbpubkey",
1116 private_key: "testkey.pem",
1117 }
1118
1119 cc_library {
1120 name: "mylib",
1121 srcs: ["mylib.cpp"],
1122 system_shared_libs: [],
1123 stl: "none",
1124 }
1125 `)
1126}
1127
Jiyong Park16e91a02018-12-20 18:18:08 +09001128func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001129 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001130 apex {
1131 name: "myapex",
1132 key: "myapex.key",
1133 native_shared_libs: ["mylib"],
1134 }
1135
1136 apex_key {
1137 name: "myapex.key",
1138 public_key: "testkey.avbpubkey",
1139 private_key: "testkey.pem",
1140 }
1141
1142 cc_library {
1143 name: "mylib",
1144 srcs: ["mylib.cpp"],
1145 system_shared_libs: [],
1146 stl: "none",
1147 stubs: {
1148 versions: ["1", "2", "3"],
1149 },
1150 }
1151
1152 cc_binary {
1153 name: "not_in_apex",
1154 srcs: ["mylib.cpp"],
1155 static_libs: ["mylib"],
1156 static_executable: true,
1157 system_shared_libs: [],
1158 stl: "none",
1159 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001160 `)
1161
1162 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1163
1164 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001165 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001166}
Jiyong Park9335a262018-12-24 11:31:58 +09001167
1168func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001169 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001170 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001171 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001172 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001173 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001174 native_shared_libs: ["mylib"],
1175 }
1176
1177 cc_library {
1178 name: "mylib",
1179 srcs: ["mylib.cpp"],
1180 system_shared_libs: [],
1181 stl: "none",
1182 }
1183
1184 apex_key {
1185 name: "myapex.key",
1186 public_key: "testkey.avbpubkey",
1187 private_key: "testkey.pem",
1188 }
1189
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001190 android_app_certificate {
1191 name: "myapex.certificate",
1192 certificate: "testkey",
1193 }
1194
1195 android_app_certificate {
1196 name: "myapex.certificate.override",
1197 certificate: "testkey.override",
1198 }
1199
Jiyong Park9335a262018-12-24 11:31:58 +09001200 `)
1201
1202 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001203 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001204
1205 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1206 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1207 "vendor/foo/devkeys/testkey.avbpubkey")
1208 }
1209 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1210 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1211 "vendor/foo/devkeys/testkey.pem")
1212 }
1213
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001214 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001215 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001216 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001217 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001218 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001219 }
1220}
Jiyong Park58e364a2019-01-19 19:24:06 +09001221
1222func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001223 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001224 apex {
1225 name: "myapex",
1226 key: "myapex.key",
1227 native_shared_libs: ["mylib"],
1228 }
1229
1230 apex {
1231 name: "otherapex",
1232 key: "myapex.key",
1233 native_shared_libs: ["mylib"],
1234 }
1235
1236 apex_key {
1237 name: "myapex.key",
1238 public_key: "testkey.avbpubkey",
1239 private_key: "testkey.pem",
1240 }
1241
1242 cc_library {
1243 name: "mylib",
1244 srcs: ["mylib.cpp"],
1245 system_shared_libs: [],
1246 stl: "none",
1247 }
1248 `)
1249
Jooyung Han6b8459b2019-10-30 08:29:25 +09001250 // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001251 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001252 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001253 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1254 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001255
Jooyung Han6b8459b2019-10-30 08:29:25 +09001256 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001257 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001258 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001259 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1260 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001261
Jooyung Han6b8459b2019-10-30 08:29:25 +09001262 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001263 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001264 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001265 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1266 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001267}
Jiyong Park7e636d02019-01-28 16:16:54 +09001268
1269func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001270 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001271 apex {
1272 name: "myapex",
1273 key: "myapex.key",
1274 native_shared_libs: ["mylib"],
1275 }
1276
1277 apex_key {
1278 name: "myapex.key",
1279 public_key: "testkey.avbpubkey",
1280 private_key: "testkey.pem",
1281 }
1282
1283 cc_library_headers {
1284 name: "mylib_headers",
1285 export_include_dirs: ["my_include"],
1286 system_shared_libs: [],
1287 stl: "none",
1288 }
1289
1290 cc_library {
1291 name: "mylib",
1292 srcs: ["mylib.cpp"],
1293 system_shared_libs: [],
1294 stl: "none",
1295 header_libs: ["mylib_headers"],
1296 export_header_lib_headers: ["mylib_headers"],
1297 stubs: {
1298 versions: ["1", "2", "3"],
1299 },
1300 }
1301
1302 cc_library {
1303 name: "otherlib",
1304 srcs: ["mylib.cpp"],
1305 system_shared_libs: [],
1306 stl: "none",
1307 shared_libs: ["mylib"],
1308 }
1309 `)
1310
1311 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1312
1313 // Ensure that the include path of the header lib is exported to 'otherlib'
1314 ensureContains(t, cFlags, "-Imy_include")
1315}
Alex Light9670d332019-01-29 18:07:33 -08001316
Jooyung Han31c470b2019-10-18 16:26:59 +09001317func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) {
1318 t.Helper()
Sundong Ahnabb64432019-10-22 13:58:29 +09001319 apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001320 copyCmds := apexRule.Args["copy_commands"]
1321 imageApexDir := "/image.apex/"
1322 dstFiles := []string{}
1323 for _, cmd := range strings.Split(copyCmds, "&&") {
1324 cmd = strings.TrimSpace(cmd)
1325 if cmd == "" {
1326 continue
1327 }
1328 terms := strings.Split(cmd, " ")
1329 switch terms[0] {
1330 case "mkdir":
1331 case "cp":
1332 if len(terms) != 3 {
1333 t.Fatal("copyCmds contains invalid cp command", cmd)
1334 }
1335 dst := terms[2]
1336 index := strings.Index(dst, imageApexDir)
1337 if index == -1 {
1338 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1339 }
1340 dstFile := dst[index+len(imageApexDir):]
1341 dstFiles = append(dstFiles, dstFile)
1342 default:
1343 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1344 }
1345 }
1346 sort.Strings(dstFiles)
1347 sort.Strings(files)
1348 missing := []string{}
1349 surplus := []string{}
1350 i := 0
1351 j := 0
1352 for i < len(dstFiles) && j < len(files) {
1353 if dstFiles[i] == files[j] {
1354 i++
1355 j++
1356 } else if dstFiles[i] < files[j] {
1357 surplus = append(surplus, dstFiles[i])
1358 i++
1359 } else {
1360 missing = append(missing, files[j])
1361 j++
1362 }
1363 }
1364 if i < len(dstFiles) {
1365 surplus = append(surplus, dstFiles[i:]...)
1366 }
1367 if j < len(files) {
1368 missing = append(missing, files[j:]...)
1369 }
1370
1371 failed := false
1372 if len(surplus) > 0 {
1373 t.Log("surplus files", surplus)
1374 failed = true
1375 }
1376 if len(missing) > 0 {
1377 t.Log("missing files", missing)
1378 failed = true
1379 }
1380 if failed {
1381 t.Fail()
1382 }
1383}
1384
Jooyung Han344d5432019-08-23 11:17:39 +09001385func TestVndkApexCurrent(t *testing.T) {
1386 ctx, _ := testApex(t, `
1387 apex_vndk {
1388 name: "myapex",
1389 key: "myapex.key",
1390 file_contexts: "myapex",
1391 }
1392
1393 apex_key {
1394 name: "myapex.key",
1395 public_key: "testkey.avbpubkey",
1396 private_key: "testkey.pem",
1397 }
1398
1399 cc_library {
1400 name: "libvndk",
1401 srcs: ["mylib.cpp"],
1402 vendor_available: true,
1403 vndk: {
1404 enabled: true,
1405 },
1406 system_shared_libs: [],
1407 stl: "none",
1408 }
1409
1410 cc_library {
1411 name: "libvndksp",
1412 srcs: ["mylib.cpp"],
1413 vendor_available: true,
1414 vndk: {
1415 enabled: true,
1416 support_system_process: true,
1417 },
1418 system_shared_libs: [],
1419 stl: "none",
1420 }
1421 `)
1422
Jooyung Han31c470b2019-10-18 16:26:59 +09001423 ensureExactContents(t, ctx, "myapex", []string{
1424 "lib/libvndk.so",
1425 "lib/libvndksp.so",
1426 "lib64/libvndk.so",
1427 "lib64/libvndksp.so",
1428 })
Jooyung Han344d5432019-08-23 11:17:39 +09001429}
1430
1431func TestVndkApexWithPrebuilt(t *testing.T) {
1432 ctx, _ := testApex(t, `
1433 apex_vndk {
1434 name: "myapex",
1435 key: "myapex.key",
1436 file_contexts: "myapex",
1437 }
1438
1439 apex_key {
1440 name: "myapex.key",
1441 public_key: "testkey.avbpubkey",
1442 private_key: "testkey.pem",
1443 }
1444
1445 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001446 name: "libvndk",
1447 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001448 vendor_available: true,
1449 vndk: {
1450 enabled: true,
1451 },
1452 system_shared_libs: [],
1453 stl: "none",
1454 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001455
1456 cc_prebuilt_library_shared {
1457 name: "libvndk.arm",
1458 srcs: ["libvndk.arm.so"],
1459 vendor_available: true,
1460 vndk: {
1461 enabled: true,
1462 },
1463 enabled: false,
1464 arch: {
1465 arm: {
1466 enabled: true,
1467 },
1468 },
1469 system_shared_libs: [],
1470 stl: "none",
1471 }
Jooyung Han344d5432019-08-23 11:17:39 +09001472 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001473 "libvndk.so": nil,
1474 "libvndk.arm.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001475 }))
1476
Jooyung Han31c470b2019-10-18 16:26:59 +09001477 ensureExactContents(t, ctx, "myapex", []string{
1478 "lib/libvndk.so",
1479 "lib/libvndk.arm.so",
1480 "lib64/libvndk.so",
1481 })
Jooyung Han344d5432019-08-23 11:17:39 +09001482}
1483
1484func TestVndkApexVersion(t *testing.T) {
1485 ctx, _ := testApex(t, `
1486 apex_vndk {
1487 name: "myapex_v27",
1488 key: "myapex.key",
1489 file_contexts: "myapex",
1490 vndk_version: "27",
1491 }
1492
1493 apex_key {
1494 name: "myapex.key",
1495 public_key: "testkey.avbpubkey",
1496 private_key: "testkey.pem",
1497 }
1498
Jooyung Han31c470b2019-10-18 16:26:59 +09001499 vndk_prebuilt_shared {
1500 name: "libvndk27",
1501 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001502 vendor_available: true,
1503 vndk: {
1504 enabled: true,
1505 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001506 target_arch: "arm64",
1507 arch: {
1508 arm: {
1509 srcs: ["libvndk27_arm.so"],
1510 },
1511 arm64: {
1512 srcs: ["libvndk27_arm64.so"],
1513 },
1514 },
Jooyung Han344d5432019-08-23 11:17:39 +09001515 }
1516
1517 vndk_prebuilt_shared {
1518 name: "libvndk27",
1519 version: "27",
1520 vendor_available: true,
1521 vndk: {
1522 enabled: true,
1523 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001524 target_arch: "x86_64",
1525 arch: {
1526 x86: {
1527 srcs: ["libvndk27_x86.so"],
1528 },
1529 x86_64: {
1530 srcs: ["libvndk27_x86_64.so"],
1531 },
1532 },
1533 }
Jooyung Han344d5432019-08-23 11:17:39 +09001534 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001535 "libvndk27_arm.so": nil,
1536 "libvndk27_arm64.so": nil,
1537 "libvndk27_x86.so": nil,
1538 "libvndk27_x86_64.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001539 }))
1540
Jooyung Han31c470b2019-10-18 16:26:59 +09001541 ensureExactContents(t, ctx, "myapex_v27", []string{
1542 "lib/libvndk27_arm.so",
1543 "lib64/libvndk27_arm64.so",
1544 })
Jooyung Han344d5432019-08-23 11:17:39 +09001545}
1546
1547func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1548 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1549 apex_vndk {
1550 name: "myapex_v27",
1551 key: "myapex.key",
1552 file_contexts: "myapex",
1553 vndk_version: "27",
1554 }
1555 apex_vndk {
1556 name: "myapex_v27_other",
1557 key: "myapex.key",
1558 file_contexts: "myapex",
1559 vndk_version: "27",
1560 }
1561
1562 apex_key {
1563 name: "myapex.key",
1564 public_key: "testkey.avbpubkey",
1565 private_key: "testkey.pem",
1566 }
1567
1568 cc_library {
1569 name: "libvndk",
1570 srcs: ["mylib.cpp"],
1571 vendor_available: true,
1572 vndk: {
1573 enabled: true,
1574 },
1575 system_shared_libs: [],
1576 stl: "none",
1577 }
1578
1579 vndk_prebuilt_shared {
1580 name: "libvndk",
1581 version: "27",
1582 vendor_available: true,
1583 vndk: {
1584 enabled: true,
1585 },
1586 srcs: ["libvndk.so"],
1587 }
1588 `, withFiles(map[string][]byte{
1589 "libvndk.so": nil,
1590 }))
1591}
1592
Jooyung Han90eee022019-10-01 20:02:42 +09001593func TestVndkApexNameRule(t *testing.T) {
1594 ctx, _ := testApex(t, `
1595 apex_vndk {
1596 name: "myapex",
1597 key: "myapex.key",
1598 file_contexts: "myapex",
1599 }
1600 apex_vndk {
1601 name: "myapex_v28",
1602 key: "myapex.key",
1603 file_contexts: "myapex",
1604 vndk_version: "28",
1605 }
1606 apex_key {
1607 name: "myapex.key",
1608 public_key: "testkey.avbpubkey",
1609 private_key: "testkey.pem",
1610 }`)
1611
1612 assertApexName := func(expected, moduleName string) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001613 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09001614 actual := proptools.String(bundle.properties.Apex_name)
1615 if !reflect.DeepEqual(actual, expected) {
1616 t.Errorf("Got '%v', expected '%v'", actual, expected)
1617 }
1618 }
1619
1620 assertApexName("com.android.vndk.vVER", "myapex")
1621 assertApexName("com.android.vndk.v28", "myapex_v28")
1622}
1623
Jooyung Han344d5432019-08-23 11:17:39 +09001624func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1625 ctx, _ := testApex(t, `
1626 apex_vndk {
1627 name: "myapex",
1628 key: "myapex.key",
1629 file_contexts: "myapex",
1630 }
1631
1632 apex_key {
1633 name: "myapex.key",
1634 public_key: "testkey.avbpubkey",
1635 private_key: "testkey.pem",
1636 }
1637
1638 cc_library {
1639 name: "libvndk",
1640 srcs: ["mylib.cpp"],
1641 vendor_available: true,
1642 native_bridge_supported: true,
1643 host_supported: true,
1644 vndk: {
1645 enabled: true,
1646 },
1647 system_shared_libs: [],
1648 stl: "none",
1649 }
1650 `, withTargets(map[android.OsType][]android.Target{
1651 android.Android: []android.Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -07001652 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1653 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1654 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1655 {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 +09001656 },
1657 }))
1658
Jooyung Han31c470b2019-10-18 16:26:59 +09001659 ensureExactContents(t, ctx, "myapex", []string{
1660 "lib/libvndk.so",
1661 "lib64/libvndk.so",
1662 })
Jooyung Han344d5432019-08-23 11:17:39 +09001663}
1664
1665func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1666 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1667 apex_vndk {
1668 name: "myapex",
1669 key: "myapex.key",
1670 file_contexts: "myapex",
1671 native_bridge_supported: true,
1672 }
1673
1674 apex_key {
1675 name: "myapex.key",
1676 public_key: "testkey.avbpubkey",
1677 private_key: "testkey.pem",
1678 }
1679
1680 cc_library {
1681 name: "libvndk",
1682 srcs: ["mylib.cpp"],
1683 vendor_available: true,
1684 native_bridge_supported: true,
1685 host_supported: true,
1686 vndk: {
1687 enabled: true,
1688 },
1689 system_shared_libs: [],
1690 stl: "none",
1691 }
1692 `)
1693}
1694
Jooyung Han31c470b2019-10-18 16:26:59 +09001695func TestVndkApexWithBinder32(t *testing.T) {
1696 ctx, _ := testApex(t,
1697 `
1698 apex_vndk {
1699 name: "myapex_v27",
1700 key: "myapex.key",
1701 file_contexts: "myapex",
1702 vndk_version: "27",
1703 }
1704
1705 apex_key {
1706 name: "myapex.key",
1707 public_key: "testkey.avbpubkey",
1708 private_key: "testkey.pem",
1709 }
1710
1711 vndk_prebuilt_shared {
1712 name: "libvndk27",
1713 version: "27",
1714 target_arch: "arm",
1715 vendor_available: true,
1716 vndk: {
1717 enabled: true,
1718 },
1719 arch: {
1720 arm: {
1721 srcs: ["libvndk27.so"],
1722 }
1723 },
1724 }
1725
1726 vndk_prebuilt_shared {
1727 name: "libvndk27",
1728 version: "27",
1729 target_arch: "arm",
1730 binder32bit: true,
1731 vendor_available: true,
1732 vndk: {
1733 enabled: true,
1734 },
1735 arch: {
1736 arm: {
1737 srcs: ["libvndk27binder32.so"],
1738 }
1739 },
1740 }
1741 `,
1742 withFiles(map[string][]byte{
1743 "libvndk27.so": nil,
1744 "libvndk27binder32.so": nil,
1745 }),
1746 withBinder32bit,
1747 withTargets(map[android.OsType][]android.Target{
1748 android.Android: []android.Target{
1749 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1750 },
1751 }),
1752 )
1753
1754 ensureExactContents(t, ctx, "myapex_v27", []string{
1755 "lib/libvndk27binder32.so",
1756 })
1757}
1758
Jooyung Hane1633032019-08-01 17:41:43 +09001759func TestDependenciesInApexManifest(t *testing.T) {
1760 ctx, _ := testApex(t, `
1761 apex {
1762 name: "myapex_nodep",
1763 key: "myapex.key",
1764 native_shared_libs: ["lib_nodep"],
1765 compile_multilib: "both",
1766 file_contexts: "myapex",
1767 }
1768
1769 apex {
1770 name: "myapex_dep",
1771 key: "myapex.key",
1772 native_shared_libs: ["lib_dep"],
1773 compile_multilib: "both",
1774 file_contexts: "myapex",
1775 }
1776
1777 apex {
1778 name: "myapex_provider",
1779 key: "myapex.key",
1780 native_shared_libs: ["libfoo"],
1781 compile_multilib: "both",
1782 file_contexts: "myapex",
1783 }
1784
1785 apex {
1786 name: "myapex_selfcontained",
1787 key: "myapex.key",
1788 native_shared_libs: ["lib_dep", "libfoo"],
1789 compile_multilib: "both",
1790 file_contexts: "myapex",
1791 }
1792
1793 apex_key {
1794 name: "myapex.key",
1795 public_key: "testkey.avbpubkey",
1796 private_key: "testkey.pem",
1797 }
1798
1799 cc_library {
1800 name: "lib_nodep",
1801 srcs: ["mylib.cpp"],
1802 system_shared_libs: [],
1803 stl: "none",
1804 }
1805
1806 cc_library {
1807 name: "lib_dep",
1808 srcs: ["mylib.cpp"],
1809 shared_libs: ["libfoo"],
1810 system_shared_libs: [],
1811 stl: "none",
1812 }
1813
1814 cc_library {
1815 name: "libfoo",
1816 srcs: ["mytest.cpp"],
1817 stubs: {
1818 versions: ["1"],
1819 },
1820 system_shared_libs: [],
1821 stl: "none",
1822 }
1823 `)
1824
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001825 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09001826 var provideNativeLibs, requireNativeLibs []string
1827
Sundong Ahnabb64432019-10-22 13:58:29 +09001828 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001829 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1830 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001831 ensureListEmpty(t, provideNativeLibs)
1832 ensureListEmpty(t, requireNativeLibs)
1833
Sundong Ahnabb64432019-10-22 13:58:29 +09001834 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001835 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1836 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001837 ensureListEmpty(t, provideNativeLibs)
1838 ensureListContains(t, requireNativeLibs, "libfoo.so")
1839
Sundong Ahnabb64432019-10-22 13:58:29 +09001840 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001841 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1842 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001843 ensureListContains(t, provideNativeLibs, "libfoo.so")
1844 ensureListEmpty(t, requireNativeLibs)
1845
Sundong Ahnabb64432019-10-22 13:58:29 +09001846 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001847 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1848 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001849 ensureListContains(t, provideNativeLibs, "libfoo.so")
1850 ensureListEmpty(t, requireNativeLibs)
1851}
1852
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001853func TestApexName(t *testing.T) {
1854 ctx, _ := testApex(t, `
1855 apex {
1856 name: "myapex",
1857 key: "myapex.key",
1858 apex_name: "com.android.myapex",
1859 }
1860
1861 apex_key {
1862 name: "myapex.key",
1863 public_key: "testkey.avbpubkey",
1864 private_key: "testkey.pem",
1865 }
1866 `)
1867
Sundong Ahnabb64432019-10-22 13:58:29 +09001868 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001869 apexManifestRule := module.Rule("apexManifestRule")
1870 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
1871 apexRule := module.Rule("apexRule")
1872 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
1873}
1874
Alex Light0851b882019-02-07 13:20:53 -08001875func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001876 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001877 apex {
1878 name: "myapex",
1879 key: "myapex.key",
1880 native_shared_libs: ["mylib_common"],
1881 }
1882
1883 apex_key {
1884 name: "myapex.key",
1885 public_key: "testkey.avbpubkey",
1886 private_key: "testkey.pem",
1887 }
1888
1889 cc_library {
1890 name: "mylib_common",
1891 srcs: ["mylib.cpp"],
1892 system_shared_libs: [],
1893 stl: "none",
1894 }
1895 `)
1896
Sundong Ahnabb64432019-10-22 13:58:29 +09001897 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08001898 apexRule := module.Rule("apexRule")
1899 copyCmds := apexRule.Args["copy_commands"]
1900
1901 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1902 t.Log("Apex was a test apex!")
1903 t.Fail()
1904 }
1905 // Ensure that main rule creates an output
1906 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1907
1908 // Ensure that apex variant is created for the direct dep
1909 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1910
1911 // Ensure that both direct and indirect deps are copied into apex
1912 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1913
1914 // Ensure that the platform variant ends with _core_shared
1915 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1916
1917 if !android.InAnyApex("mylib_common") {
1918 t.Log("Found mylib_common not in any apex!")
1919 t.Fail()
1920 }
1921}
1922
1923func TestTestApex(t *testing.T) {
1924 if android.InAnyApex("mylib_common_test") {
1925 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!")
1926 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001927 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001928 apex_test {
1929 name: "myapex",
1930 key: "myapex.key",
1931 native_shared_libs: ["mylib_common_test"],
1932 }
1933
1934 apex_key {
1935 name: "myapex.key",
1936 public_key: "testkey.avbpubkey",
1937 private_key: "testkey.pem",
1938 }
1939
1940 cc_library {
1941 name: "mylib_common_test",
1942 srcs: ["mylib.cpp"],
1943 system_shared_libs: [],
1944 stl: "none",
1945 }
1946 `)
1947
Sundong Ahnabb64432019-10-22 13:58:29 +09001948 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08001949 apexRule := module.Rule("apexRule")
1950 copyCmds := apexRule.Args["copy_commands"]
1951
1952 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1953 t.Log("Apex was not a test apex!")
1954 t.Fail()
1955 }
1956 // Ensure that main rule creates an output
1957 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1958
1959 // Ensure that apex variant is created for the direct dep
1960 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1961
1962 // Ensure that both direct and indirect deps are copied into apex
1963 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1964
1965 // Ensure that the platform variant ends with _core_shared
1966 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1967
1968 if android.InAnyApex("mylib_common_test") {
1969 t.Log("Found mylib_common_test in some apex!")
1970 t.Fail()
1971 }
1972}
1973
Alex Light9670d332019-01-29 18:07:33 -08001974func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001975 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001976 apex {
1977 name: "myapex",
1978 key: "myapex.key",
1979 multilib: {
1980 first: {
1981 native_shared_libs: ["mylib_common"],
1982 }
1983 },
1984 target: {
1985 android: {
1986 multilib: {
1987 first: {
1988 native_shared_libs: ["mylib"],
1989 }
1990 }
1991 },
1992 host: {
1993 multilib: {
1994 first: {
1995 native_shared_libs: ["mylib2"],
1996 }
1997 }
1998 }
1999 }
2000 }
2001
2002 apex_key {
2003 name: "myapex.key",
2004 public_key: "testkey.avbpubkey",
2005 private_key: "testkey.pem",
2006 }
2007
2008 cc_library {
2009 name: "mylib",
2010 srcs: ["mylib.cpp"],
2011 system_shared_libs: [],
2012 stl: "none",
2013 }
2014
2015 cc_library {
2016 name: "mylib_common",
2017 srcs: ["mylib.cpp"],
2018 system_shared_libs: [],
2019 stl: "none",
2020 compile_multilib: "first",
2021 }
2022
2023 cc_library {
2024 name: "mylib2",
2025 srcs: ["mylib.cpp"],
2026 system_shared_libs: [],
2027 stl: "none",
2028 compile_multilib: "first",
2029 }
2030 `)
2031
Sundong Ahnabb64432019-10-22 13:58:29 +09002032 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002033 copyCmds := apexRule.Args["copy_commands"]
2034
2035 // Ensure that main rule creates an output
2036 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2037
2038 // Ensure that apex variant is created for the direct dep
2039 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2040 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
2041 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
2042
2043 // Ensure that both direct and indirect deps are copied into apex
2044 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2045 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2046 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2047
2048 // Ensure that the platform variant ends with _core_shared
2049 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
2050 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
2051 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
2052}
Jiyong Park04480cf2019-02-06 00:16:29 +09002053
2054func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002055 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002056 apex {
2057 name: "myapex",
2058 key: "myapex.key",
2059 binaries: ["myscript"],
2060 }
2061
2062 apex_key {
2063 name: "myapex.key",
2064 public_key: "testkey.avbpubkey",
2065 private_key: "testkey.pem",
2066 }
2067
2068 sh_binary {
2069 name: "myscript",
2070 src: "mylib.cpp",
2071 filename: "myscript.sh",
2072 sub_dir: "script",
2073 }
2074 `)
2075
Sundong Ahnabb64432019-10-22 13:58:29 +09002076 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002077 copyCmds := apexRule.Args["copy_commands"]
2078
2079 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2080}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002081
2082func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002083 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002084 apex {
2085 name: "myapex",
2086 key: "myapex.key",
2087 native_shared_libs: ["mylib"],
2088 product_specific: true,
2089 }
2090
2091 apex_key {
2092 name: "myapex.key",
2093 public_key: "testkey.avbpubkey",
2094 private_key: "testkey.pem",
2095 product_specific: true,
2096 }
2097
2098 cc_library {
2099 name: "mylib",
2100 srcs: ["mylib.cpp"],
2101 system_shared_libs: [],
2102 stl: "none",
2103 }
2104 `)
2105
Sundong Ahnabb64432019-10-22 13:58:29 +09002106 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossff6c33d2019-10-02 16:01:35 -07002107 expected := buildDir + "/target/product/test_device/product/apex"
2108 actual := apex.installDir.String()
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002109 if actual != expected {
2110 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2111 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002112}
Jiyong Park67882562019-03-21 01:11:21 +09002113
2114func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002115 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002116 apex_key {
2117 name: "myapex.key",
2118 public_key: ":my.avbpubkey",
2119 private_key: ":my.pem",
2120 product_specific: true,
2121 }
2122
2123 filegroup {
2124 name: "my.avbpubkey",
2125 srcs: ["testkey2.avbpubkey"],
2126 }
2127
2128 filegroup {
2129 name: "my.pem",
2130 srcs: ["testkey2.pem"],
2131 }
2132 `)
2133
2134 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2135 expected_pubkey := "testkey2.avbpubkey"
2136 actual_pubkey := apex_key.public_key_file.String()
2137 if actual_pubkey != expected_pubkey {
2138 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2139 }
2140 expected_privkey := "testkey2.pem"
2141 actual_privkey := apex_key.private_key_file.String()
2142 if actual_privkey != expected_privkey {
2143 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2144 }
2145}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002146
2147func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002148 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002149 prebuilt_apex {
2150 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002151 arch: {
2152 arm64: {
2153 src: "myapex-arm64.apex",
2154 },
2155 arm: {
2156 src: "myapex-arm.apex",
2157 },
2158 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002159 }
2160 `)
2161
2162 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2163
Jiyong Parkc95714e2019-03-29 14:23:10 +09002164 expectedInput := "myapex-arm64.apex"
2165 if prebuilt.inputApex.String() != expectedInput {
2166 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2167 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002168}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002169
2170func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002171 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002172 prebuilt_apex {
2173 name: "myapex",
2174 src: "myapex-arm.apex",
2175 filename: "notmyapex.apex",
2176 }
2177 `)
2178
2179 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2180
2181 expected := "notmyapex.apex"
2182 if p.installFilename != expected {
2183 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2184 }
2185}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002186
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002187func TestPrebuiltOverrides(t *testing.T) {
2188 ctx, config := testApex(t, `
2189 prebuilt_apex {
2190 name: "myapex.prebuilt",
2191 src: "myapex-arm.apex",
2192 overrides: [
2193 "myapex",
2194 ],
2195 }
2196 `)
2197
2198 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2199
2200 expected := []string{"myapex"}
2201 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
2202 if !reflect.DeepEqual(actual, expected) {
2203 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
2204 }
2205}
2206
Roland Levillain630846d2019-06-26 12:48:34 +01002207func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002208 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002209 apex_test {
2210 name: "myapex",
2211 key: "myapex.key",
2212 tests: [
2213 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002214 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002215 ],
2216 }
2217
2218 apex_key {
2219 name: "myapex.key",
2220 public_key: "testkey.avbpubkey",
2221 private_key: "testkey.pem",
2222 }
2223
2224 cc_test {
2225 name: "mytest",
2226 gtest: false,
2227 srcs: ["mytest.cpp"],
2228 relative_install_path: "test",
2229 system_shared_libs: [],
2230 static_executable: true,
2231 stl: "none",
2232 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002233
2234 cc_test {
2235 name: "mytests",
2236 gtest: false,
2237 srcs: [
2238 "mytest1.cpp",
2239 "mytest2.cpp",
2240 "mytest3.cpp",
2241 ],
2242 test_per_src: true,
2243 relative_install_path: "test",
2244 system_shared_libs: [],
2245 static_executable: true,
2246 stl: "none",
2247 }
Roland Levillain630846d2019-06-26 12:48:34 +01002248 `)
2249
Sundong Ahnabb64432019-10-22 13:58:29 +09002250 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002251 copyCmds := apexRule.Args["copy_commands"]
2252
2253 // Ensure that test dep is copied into apex.
2254 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002255
2256 // Ensure that test deps built with `test_per_src` are copied into apex.
2257 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2258 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2259 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002260
2261 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002262 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002263 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2264 name := apexBundle.BaseModuleName()
2265 prefix := "TARGET_"
2266 var builder strings.Builder
2267 data.Custom(&builder, name, prefix, "", data)
2268 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002269 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2270 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2271 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2272 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
2273 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.json.myapex\n")
2274 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002275 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002276}
2277
Jooyung Han5c998b92019-06-27 11:30:33 +09002278func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002279 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002280 apex {
2281 name: "myapex",
2282 key: "myapex.key",
2283 native_shared_libs: ["mylib"],
2284 uses: ["commonapex"],
2285 }
2286
2287 apex {
2288 name: "commonapex",
2289 key: "myapex.key",
2290 native_shared_libs: ["libcommon"],
2291 provide_cpp_shared_libs: true,
2292 }
2293
2294 apex_key {
2295 name: "myapex.key",
2296 public_key: "testkey.avbpubkey",
2297 private_key: "testkey.pem",
2298 }
2299
2300 cc_library {
2301 name: "mylib",
2302 srcs: ["mylib.cpp"],
2303 shared_libs: ["libcommon"],
2304 system_shared_libs: [],
2305 stl: "none",
2306 }
2307
2308 cc_library {
2309 name: "libcommon",
2310 srcs: ["mylib_common.cpp"],
2311 system_shared_libs: [],
2312 stl: "none",
2313 }
2314 `)
2315
Sundong Ahnabb64432019-10-22 13:58:29 +09002316 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002317 apexRule1 := module1.Rule("apexRule")
2318 copyCmds1 := apexRule1.Args["copy_commands"]
2319
Sundong Ahnabb64432019-10-22 13:58:29 +09002320 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002321 apexRule2 := module2.Rule("apexRule")
2322 copyCmds2 := apexRule2.Args["copy_commands"]
2323
2324 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2325 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2326 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2327 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2328 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2329}
2330
2331func TestApexUsesFailsIfNotProvided(t *testing.T) {
2332 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2333 apex {
2334 name: "myapex",
2335 key: "myapex.key",
2336 uses: ["commonapex"],
2337 }
2338
2339 apex {
2340 name: "commonapex",
2341 key: "myapex.key",
2342 }
2343
2344 apex_key {
2345 name: "myapex.key",
2346 public_key: "testkey.avbpubkey",
2347 private_key: "testkey.pem",
2348 }
2349 `)
2350 testApexError(t, `uses: "commonapex" is not a provider`, `
2351 apex {
2352 name: "myapex",
2353 key: "myapex.key",
2354 uses: ["commonapex"],
2355 }
2356
2357 cc_library {
2358 name: "commonapex",
2359 system_shared_libs: [],
2360 stl: "none",
2361 }
2362
2363 apex_key {
2364 name: "myapex.key",
2365 public_key: "testkey.avbpubkey",
2366 private_key: "testkey.pem",
2367 }
2368 `)
2369}
2370
2371func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2372 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2373 apex {
2374 name: "myapex",
2375 key: "myapex.key",
2376 use_vendor: true,
2377 uses: ["commonapex"],
2378 }
2379
2380 apex {
2381 name: "commonapex",
2382 key: "myapex.key",
2383 provide_cpp_shared_libs: true,
2384 }
2385
2386 apex_key {
2387 name: "myapex.key",
2388 public_key: "testkey.avbpubkey",
2389 private_key: "testkey.pem",
2390 }
Jooyung Handc782442019-11-01 03:14:38 +09002391 `, func(fs map[string][]byte, config android.Config) {
2392 setUseVendorWhitelistForTest(config, []string{"myapex"})
2393 })
Jooyung Han5c998b92019-06-27 11:30:33 +09002394}
2395
Jooyung Hand48f3c32019-08-23 11:18:57 +09002396func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2397 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2398 apex {
2399 name: "myapex",
2400 key: "myapex.key",
2401 native_shared_libs: ["libfoo"],
2402 }
2403
2404 apex_key {
2405 name: "myapex.key",
2406 public_key: "testkey.avbpubkey",
2407 private_key: "testkey.pem",
2408 }
2409
2410 cc_library {
2411 name: "libfoo",
2412 stl: "none",
2413 system_shared_libs: [],
2414 enabled: false,
2415 }
2416 `)
2417 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2418 apex {
2419 name: "myapex",
2420 key: "myapex.key",
2421 java_libs: ["myjar"],
2422 }
2423
2424 apex_key {
2425 name: "myapex.key",
2426 public_key: "testkey.avbpubkey",
2427 private_key: "testkey.pem",
2428 }
2429
2430 java_library {
2431 name: "myjar",
2432 srcs: ["foo/bar/MyClass.java"],
2433 sdk_version: "none",
2434 system_modules: "none",
2435 compile_dex: true,
2436 enabled: false,
2437 }
2438 `)
2439}
2440
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002441func TestApexWithApps(t *testing.T) {
2442 ctx, _ := testApex(t, `
2443 apex {
2444 name: "myapex",
2445 key: "myapex.key",
2446 apps: [
2447 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09002448 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002449 ],
2450 }
2451
2452 apex_key {
2453 name: "myapex.key",
2454 public_key: "testkey.avbpubkey",
2455 private_key: "testkey.pem",
2456 }
2457
2458 android_app {
2459 name: "AppFoo",
2460 srcs: ["foo/bar/MyClass.java"],
2461 sdk_version: "none",
2462 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09002463 jni_libs: ["libjni"],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002464 }
Jiyong Parkf7487312019-10-17 12:54:30 +09002465
2466 android_app {
2467 name: "AppFooPriv",
2468 srcs: ["foo/bar/MyClass.java"],
2469 sdk_version: "none",
2470 system_modules: "none",
2471 privileged: true,
2472 }
Jiyong Park8be103b2019-11-08 15:53:48 +09002473
2474 cc_library_shared {
2475 name: "libjni",
2476 srcs: ["mylib.cpp"],
2477 stl: "none",
2478 system_shared_libs: [],
2479 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002480 `)
2481
Sundong Ahnabb64432019-10-22 13:58:29 +09002482 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002483 apexRule := module.Rule("apexRule")
2484 copyCmds := apexRule.Args["copy_commands"]
2485
2486 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09002487 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park8be103b2019-11-08 15:53:48 +09002488 ensureContains(t, copyCmds, "image.apex/lib64/libjni.so")
Dario Frenicde2a032019-10-27 00:29:22 +01002489}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002490
Dario Frenicde2a032019-10-27 00:29:22 +01002491func TestApexWithAppImports(t *testing.T) {
2492 ctx, _ := testApex(t, `
2493 apex {
2494 name: "myapex",
2495 key: "myapex.key",
2496 apps: [
2497 "AppFooPrebuilt",
2498 "AppFooPrivPrebuilt",
2499 ],
2500 }
2501
2502 apex_key {
2503 name: "myapex.key",
2504 public_key: "testkey.avbpubkey",
2505 private_key: "testkey.pem",
2506 }
2507
2508 android_app_import {
2509 name: "AppFooPrebuilt",
2510 apk: "PrebuiltAppFoo.apk",
2511 presigned: true,
2512 dex_preopt: {
2513 enabled: false,
2514 },
2515 }
2516
2517 android_app_import {
2518 name: "AppFooPrivPrebuilt",
2519 apk: "PrebuiltAppFooPriv.apk",
2520 privileged: true,
2521 presigned: true,
2522 dex_preopt: {
2523 enabled: false,
2524 },
2525 }
2526 `)
2527
Sundong Ahnabb64432019-10-22 13:58:29 +09002528 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01002529 apexRule := module.Rule("apexRule")
2530 copyCmds := apexRule.Args["copy_commands"]
2531
2532 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
2533 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002534}
2535
Jiyong Park127b40b2019-09-30 16:04:35 +09002536func TestApexAvailable(t *testing.T) {
2537 // libfoo is not available to myapex, but only to otherapex
2538 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
2539 apex {
2540 name: "myapex",
2541 key: "myapex.key",
2542 native_shared_libs: ["libfoo"],
2543 }
2544
2545 apex_key {
2546 name: "myapex.key",
2547 public_key: "testkey.avbpubkey",
2548 private_key: "testkey.pem",
2549 }
2550
2551 apex {
2552 name: "otherapex",
2553 key: "otherapex.key",
2554 native_shared_libs: ["libfoo"],
2555 }
2556
2557 apex_key {
2558 name: "otherapex.key",
2559 public_key: "testkey.avbpubkey",
2560 private_key: "testkey.pem",
2561 }
2562
2563 cc_library {
2564 name: "libfoo",
2565 stl: "none",
2566 system_shared_libs: [],
2567 apex_available: ["otherapex"],
2568 }`)
2569
2570 // libbar is an indirect dep
2571 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
2572 apex {
2573 name: "myapex",
2574 key: "myapex.key",
2575 native_shared_libs: ["libfoo"],
2576 }
2577
2578 apex_key {
2579 name: "myapex.key",
2580 public_key: "testkey.avbpubkey",
2581 private_key: "testkey.pem",
2582 }
2583
2584 apex {
2585 name: "otherapex",
2586 key: "otherapex.key",
2587 native_shared_libs: ["libfoo"],
2588 }
2589
2590 apex_key {
2591 name: "otherapex.key",
2592 public_key: "testkey.avbpubkey",
2593 private_key: "testkey.pem",
2594 }
2595
2596 cc_library {
2597 name: "libfoo",
2598 stl: "none",
2599 shared_libs: ["libbar"],
2600 system_shared_libs: [],
2601 apex_available: ["myapex", "otherapex"],
2602 }
2603
2604 cc_library {
2605 name: "libbar",
2606 stl: "none",
2607 system_shared_libs: [],
2608 apex_available: ["otherapex"],
2609 }`)
2610
2611 testApexError(t, "\"otherapex\" is not a valid module name", `
2612 apex {
2613 name: "myapex",
2614 key: "myapex.key",
2615 native_shared_libs: ["libfoo"],
2616 }
2617
2618 apex_key {
2619 name: "myapex.key",
2620 public_key: "testkey.avbpubkey",
2621 private_key: "testkey.pem",
2622 }
2623
2624 cc_library {
2625 name: "libfoo",
2626 stl: "none",
2627 system_shared_libs: [],
2628 apex_available: ["otherapex"],
2629 }`)
2630
2631 ctx, _ := testApex(t, `
2632 apex {
2633 name: "myapex",
2634 key: "myapex.key",
2635 native_shared_libs: ["libfoo", "libbar"],
2636 }
2637
2638 apex_key {
2639 name: "myapex.key",
2640 public_key: "testkey.avbpubkey",
2641 private_key: "testkey.pem",
2642 }
2643
2644 cc_library {
2645 name: "libfoo",
2646 stl: "none",
2647 system_shared_libs: [],
2648 apex_available: ["myapex"],
2649 }
2650
2651 cc_library {
2652 name: "libbar",
2653 stl: "none",
2654 system_shared_libs: [],
2655 apex_available: ["//apex_available:anyapex"],
2656 }`)
2657
2658 // check that libfoo and libbar are created only for myapex, but not for the platform
2659 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2660 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2661 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared_myapex")
2662 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared")
2663
2664 ctx, _ = testApex(t, `
2665 apex {
2666 name: "myapex",
2667 key: "myapex.key",
2668 }
2669
2670 apex_key {
2671 name: "myapex.key",
2672 public_key: "testkey.avbpubkey",
2673 private_key: "testkey.pem",
2674 }
2675
2676 cc_library {
2677 name: "libfoo",
2678 stl: "none",
2679 system_shared_libs: [],
2680 apex_available: ["//apex_available:platform"],
2681 }`)
2682
2683 // check that libfoo is created only for the platform
2684 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2685 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09002686
2687 ctx, _ = testApex(t, `
2688 apex {
2689 name: "myapex",
2690 key: "myapex.key",
2691 native_shared_libs: ["libfoo"],
2692 }
2693
2694 apex_key {
2695 name: "myapex.key",
2696 public_key: "testkey.avbpubkey",
2697 private_key: "testkey.pem",
2698 }
2699
2700 cc_library {
2701 name: "libfoo",
2702 stl: "none",
2703 system_shared_libs: [],
2704 apex_available: ["myapex"],
2705 static: {
2706 apex_available: ["//apex_available:platform"],
2707 },
2708 }`)
2709
2710 // shared variant of libfoo is only available to myapex
2711 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2712 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2713 // but the static variant is available to both myapex and the platform
2714 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static_myapex")
2715 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09002716}
2717
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002718func TestMain(m *testing.M) {
2719 run := func() int {
2720 setUp()
2721 defer tearDown()
2722
2723 return m.Run()
2724 }
2725
2726 os.Exit(run())
2727}