blob: 2e44db7c72c4a8759bab5b5f8769902608ecfc10 [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"
20 "strings"
21 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090022
23 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
26 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090027 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090028)
29
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070030var buildDir string
31
Jiyong Park25fc6a92018-11-18 18:02:45 +090032func testApex(t *testing.T, bp string) *android.TestContext {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -070033 config := android.TestArchConfig(buildDir, nil)
34 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
35 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
36 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
37 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
38 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
Jiyong Park25fc6a92018-11-18 18:02:45 +090039
40 ctx := android.NewTestArchContext()
Alex Light0851b882019-02-07 13:20:53 -080041 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory))
42 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090043 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +090044 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -070045 ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +090046 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jiyong Park25fc6a92018-11-18 18:02:45 +090047
48 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
49 ctx.TopDown("apex_deps", apexDepsMutator)
50 ctx.BottomUp("apex", apexMutator)
Jaewoong Jung939ebd52019-03-26 15:07:36 -070051 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
52 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090053 })
54
55 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
56 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +090057 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +090058 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090059 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +090060 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090061 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +090062 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +090063 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +090064 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +090065 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -070066 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
67 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
68 })
Jiyong Park25fc6a92018-11-18 18:02:45 +090069 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090070 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090071 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090072 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090073 ctx.BottomUp("version", cc.VersionMutator).Parallel()
74 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
75 })
76
77 ctx.Register()
78
79 bp = bp + `
80 toolchain_library {
81 name: "libcompiler_rt-extras",
82 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090083 vendor_available: true,
84 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090085 }
86
87 toolchain_library {
88 name: "libatomic",
89 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090090 vendor_available: true,
91 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090092 }
93
94 toolchain_library {
95 name: "libgcc",
96 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090097 vendor_available: true,
98 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090099 }
100
101 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700102 name: "libgcc_stripped",
103 src: "",
104 vendor_available: true,
105 recovery_available: true,
106 }
107
108 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900109 name: "libclang_rt.builtins-aarch64-android",
110 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900111 vendor_available: true,
112 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900113 }
114
115 toolchain_library {
116 name: "libclang_rt.builtins-arm-android",
117 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900118 vendor_available: true,
119 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900120 }
121
122 cc_object {
123 name: "crtbegin_so",
124 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900125 vendor_available: true,
126 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900127 }
128
129 cc_object {
130 name: "crtend_so",
131 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900132 vendor_available: true,
133 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900134 }
135
Alex Light3d673592019-01-18 14:37:31 -0800136 cc_object {
137 name: "crtbegin_static",
138 stl: "none",
139 }
140
141 cc_object {
142 name: "crtend_android",
143 stl: "none",
144 }
145
Jiyong Parkda6eb592018-12-19 17:12:36 +0900146 llndk_library {
147 name: "libc",
148 symbol_file: "",
149 }
150
151 llndk_library {
152 name: "libm",
153 symbol_file: "",
154 }
155
156 llndk_library {
157 name: "libdl",
158 symbol_file: "",
159 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900160 `
161
162 ctx.MockFileSystem(map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900163 "Android.bp": []byte(bp),
Dan Willemsen412160e2019-04-09 21:36:26 -0700164 "build/make/target/product/security": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900165 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900166 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900167 "system/sepolicy/apex/myapex-file_contexts": nil,
168 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
169 "system/sepolicy/apex/otherapex-file_contexts": nil,
170 "mylib.cpp": nil,
171 "myprebuilt": nil,
172 "my_include": nil,
173 "vendor/foo/devkeys/test.x509.pem": nil,
174 "vendor/foo/devkeys/test.pk8": nil,
175 "testkey.x509.pem": nil,
176 "testkey.pk8": nil,
177 "testkey.override.x509.pem": nil,
178 "testkey.override.pk8": nil,
179 "vendor/foo/devkeys/testkey.avbpubkey": nil,
180 "vendor/foo/devkeys/testkey.pem": nil,
Jiyong Park52818fc2019-03-18 12:01:38 +0900181 "NOTICE": nil,
182 "custom_notice": nil,
Jiyong Park67882562019-03-21 01:11:21 +0900183 "testkey2.avbpubkey": nil,
184 "testkey2.pem": nil,
Jiyong Parkc95714e2019-03-29 14:23:10 +0900185 "myapex-arm64.apex": nil,
186 "myapex-arm.apex": nil,
Jiyong Park71b519d2019-04-18 17:25:49 +0900187 "frameworks/base/api/current.txt": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900188 })
189 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
190 android.FailIfErrored(t, errs)
191 _, errs = ctx.PrepareBuildActions(config)
192 android.FailIfErrored(t, errs)
193
194 return ctx
195}
196
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700197func setUp() {
198 var err error
199 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900200 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700201 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900202 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900203}
204
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700205func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900206 os.RemoveAll(buildDir)
207}
208
209// ensure that 'result' contains 'expected'
210func ensureContains(t *testing.T, result string, expected string) {
211 if !strings.Contains(result, expected) {
212 t.Errorf("%q is not found in %q", expected, result)
213 }
214}
215
216// ensures that 'result' does not contain 'notExpected'
217func ensureNotContains(t *testing.T, result string, notExpected string) {
218 if strings.Contains(result, notExpected) {
219 t.Errorf("%q is found in %q", notExpected, result)
220 }
221}
222
223func ensureListContains(t *testing.T, result []string, expected string) {
224 if !android.InList(expected, result) {
225 t.Errorf("%q is not found in %v", expected, result)
226 }
227}
228
229func ensureListNotContains(t *testing.T, result []string, notExpected string) {
230 if android.InList(notExpected, result) {
231 t.Errorf("%q is found in %v", notExpected, result)
232 }
233}
234
235// Minimal test
236func TestBasicApex(t *testing.T) {
237 ctx := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900238 apex_defaults {
239 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900240 manifest: ":myapex.manifest",
241 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900242 key: "myapex.key",
243 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800244 multilib: {
245 both: {
246 binaries: ["foo",],
247 }
248 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900249 }
250
Jiyong Park30ca9372019-02-07 16:27:23 +0900251 apex {
252 name: "myapex",
253 defaults: ["myapex-defaults"],
254 }
255
Jiyong Park25fc6a92018-11-18 18:02:45 +0900256 apex_key {
257 name: "myapex.key",
258 public_key: "testkey.avbpubkey",
259 private_key: "testkey.pem",
260 }
261
Jiyong Park809bb722019-02-13 21:33:49 +0900262 filegroup {
263 name: "myapex.manifest",
264 srcs: ["apex_manifest.json"],
265 }
266
267 filegroup {
268 name: "myapex.androidmanifest",
269 srcs: ["AndroidManifest.xml"],
270 }
271
Jiyong Park25fc6a92018-11-18 18:02:45 +0900272 cc_library {
273 name: "mylib",
274 srcs: ["mylib.cpp"],
275 shared_libs: ["mylib2"],
276 system_shared_libs: [],
277 stl: "none",
278 }
279
Alex Light3d673592019-01-18 14:37:31 -0800280 cc_binary {
281 name: "foo",
282 srcs: ["mylib.cpp"],
283 compile_multilib: "both",
284 multilib: {
285 lib32: {
286 suffix: "32",
287 },
288 lib64: {
289 suffix: "64",
290 },
291 },
292 symlinks: ["foo_link_"],
293 symlink_preferred_arch: true,
294 system_shared_libs: [],
295 static_executable: true,
296 stl: "none",
297 }
298
Jiyong Park25fc6a92018-11-18 18:02:45 +0900299 cc_library {
300 name: "mylib2",
301 srcs: ["mylib.cpp"],
302 system_shared_libs: [],
303 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900304 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900305 }
306 `)
307
308 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900309
310 optFlags := apexRule.Args["opt_flags"]
311 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700312 // Ensure that the NOTICE output is being packaged as an asset.
313 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900314
Jiyong Park25fc6a92018-11-18 18:02:45 +0900315 copyCmds := apexRule.Args["copy_commands"]
316
317 // Ensure that main rule creates an output
318 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
319
320 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900321 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900322
323 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900324 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900325
326 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800327 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
328 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Logan Chien3aeedc92018-12-26 15:32:21 +0800329
330 // Ensure that the platform variant ends with _core_shared
331 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
332 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Alex Light3d673592019-01-18 14:37:31 -0800333
334 // Ensure that all symlinks are present.
335 found_foo_link_64 := false
336 found_foo := false
337 for _, cmd := range strings.Split(copyCmds, " && ") {
338 if strings.HasPrefix(cmd, "ln -s foo64") {
339 if strings.HasSuffix(cmd, "bin/foo") {
340 found_foo = true
341 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
342 found_foo_link_64 = true
343 }
344 }
345 }
346 good := found_foo && found_foo_link_64
347 if !good {
348 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
349 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900350
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700351 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
352 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700353 if len(noticeInputs) != 2 {
354 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900355 }
356 ensureListContains(t, noticeInputs, "NOTICE")
357 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800358}
359
360func TestBasicZipApex(t *testing.T) {
361 ctx := testApex(t, `
362 apex {
363 name: "myapex",
364 key: "myapex.key",
365 payload_type: "zip",
366 native_shared_libs: ["mylib"],
367 }
368
369 apex_key {
370 name: "myapex.key",
371 public_key: "testkey.avbpubkey",
372 private_key: "testkey.pem",
373 }
374
375 cc_library {
376 name: "mylib",
377 srcs: ["mylib.cpp"],
378 shared_libs: ["mylib2"],
379 system_shared_libs: [],
380 stl: "none",
381 }
382
383 cc_library {
384 name: "mylib2",
385 srcs: ["mylib.cpp"],
386 system_shared_libs: [],
387 stl: "none",
388 }
389 `)
390
391 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
392 copyCmds := zipApexRule.Args["copy_commands"]
393
394 // Ensure that main rule creates an output
395 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
396
397 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900398 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800399
400 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900401 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800402
403 // Ensure that both direct and indirect deps are copied into apex
404 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
405 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900406}
407
408func TestApexWithStubs(t *testing.T) {
409 ctx := testApex(t, `
410 apex {
411 name: "myapex",
412 key: "myapex.key",
413 native_shared_libs: ["mylib", "mylib3"],
414 }
415
416 apex_key {
417 name: "myapex.key",
418 public_key: "testkey.avbpubkey",
419 private_key: "testkey.pem",
420 }
421
422 cc_library {
423 name: "mylib",
424 srcs: ["mylib.cpp"],
425 shared_libs: ["mylib2", "mylib3"],
426 system_shared_libs: [],
427 stl: "none",
428 }
429
430 cc_library {
431 name: "mylib2",
432 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900433 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900434 system_shared_libs: [],
435 stl: "none",
436 stubs: {
437 versions: ["1", "2", "3"],
438 },
439 }
440
441 cc_library {
442 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900443 srcs: ["mylib.cpp"],
444 shared_libs: ["mylib4"],
445 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900446 stl: "none",
447 stubs: {
448 versions: ["10", "11", "12"],
449 },
450 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900451
452 cc_library {
453 name: "mylib4",
454 srcs: ["mylib.cpp"],
455 system_shared_libs: [],
456 stl: "none",
457 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900458 `)
459
460 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
461 copyCmds := apexRule.Args["copy_commands"]
462
463 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800464 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900465
466 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800467 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900468
469 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800470 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900471
Jiyong Parkda6eb592018-12-19 17:12:36 +0900472 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900473
474 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900475 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900476 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900477 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900478
479 // 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 +0900480 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900481 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900482 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900483
484 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900485 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900486 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900487
488 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900489 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 +0900490}
491
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900492func TestApexWithExplicitStubsDependency(t *testing.T) {
493 ctx := testApex(t, `
494 apex {
495 name: "myapex",
496 key: "myapex.key",
497 native_shared_libs: ["mylib"],
498 }
499
500 apex_key {
501 name: "myapex.key",
502 public_key: "testkey.avbpubkey",
503 private_key: "testkey.pem",
504 }
505
506 cc_library {
507 name: "mylib",
508 srcs: ["mylib.cpp"],
509 shared_libs: ["libfoo#10"],
510 system_shared_libs: [],
511 stl: "none",
512 }
513
514 cc_library {
515 name: "libfoo",
516 srcs: ["mylib.cpp"],
517 shared_libs: ["libbar"],
518 system_shared_libs: [],
519 stl: "none",
520 stubs: {
521 versions: ["10", "20", "30"],
522 },
523 }
524
525 cc_library {
526 name: "libbar",
527 srcs: ["mylib.cpp"],
528 system_shared_libs: [],
529 stl: "none",
530 }
531
532 `)
533
534 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
535 copyCmds := apexRule.Args["copy_commands"]
536
537 // Ensure that direct non-stubs dep is always included
538 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
539
540 // Ensure that indirect stubs dep is not included
541 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
542
543 // Ensure that dependency of stubs is not included
544 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
545
Jiyong Parkda6eb592018-12-19 17:12:36 +0900546 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900547
548 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900549 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900550 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900551 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900552
Jiyong Parkda6eb592018-12-19 17:12:36 +0900553 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900554
555 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
556 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
557}
558
Jiyong Park25fc6a92018-11-18 18:02:45 +0900559func TestApexWithSystemLibsStubs(t *testing.T) {
560 ctx := testApex(t, `
561 apex {
562 name: "myapex",
563 key: "myapex.key",
564 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
565 }
566
567 apex_key {
568 name: "myapex.key",
569 public_key: "testkey.avbpubkey",
570 private_key: "testkey.pem",
571 }
572
573 cc_library {
574 name: "mylib",
575 srcs: ["mylib.cpp"],
576 shared_libs: ["libdl#27"],
577 stl: "none",
578 }
579
580 cc_library_shared {
581 name: "mylib_shared",
582 srcs: ["mylib.cpp"],
583 shared_libs: ["libdl#27"],
584 stl: "none",
585 }
586
587 cc_library {
588 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700589 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900590 nocrt: true,
591 system_shared_libs: [],
592 stl: "none",
593 stubs: {
594 versions: ["27", "28", "29"],
595 },
596 }
597
598 cc_library {
599 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700600 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900601 nocrt: true,
602 system_shared_libs: [],
603 stl: "none",
604 stubs: {
605 versions: ["27", "28", "29"],
606 },
607 }
608
609 cc_library {
610 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700611 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900612 nocrt: true,
613 system_shared_libs: [],
614 stl: "none",
615 stubs: {
616 versions: ["27", "28", "29"],
617 },
618 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900619
620 cc_library {
621 name: "libBootstrap",
622 srcs: ["mylib.cpp"],
623 stl: "none",
624 bootstrap: true,
625 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900626 `)
627
628 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
629 copyCmds := apexRule.Args["copy_commands"]
630
631 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800632 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900633 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
634 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900635
636 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900637 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900638
Jiyong Parkda6eb592018-12-19 17:12:36 +0900639 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
640 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
641 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900642
643 // For dependency to libc
644 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900645 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900646 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900647 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900648 // ... Cflags from stub is correctly exported to mylib
649 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
650 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
651
652 // For dependency to libm
653 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900654 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900655 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900656 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900657 // ... and is not compiling with the stub
658 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
659 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
660
661 // For dependency to libdl
662 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900663 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900664 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900665 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
666 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900667 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900668 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900669 // ... Cflags from stub is correctly exported to mylib
670 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
671 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900672
673 // Ensure that libBootstrap is depending on the platform variant of bionic libs
674 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
675 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
676 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
677 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900678}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900679
680func TestFilesInSubDir(t *testing.T) {
681 ctx := testApex(t, `
682 apex {
683 name: "myapex",
684 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900685 native_shared_libs: ["mylib"],
686 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900687 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900688 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900689 }
690
691 apex_key {
692 name: "myapex.key",
693 public_key: "testkey.avbpubkey",
694 private_key: "testkey.pem",
695 }
696
697 prebuilt_etc {
698 name: "myetc",
699 src: "myprebuilt",
700 sub_dir: "foo/bar",
701 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900702
703 cc_library {
704 name: "mylib",
705 srcs: ["mylib.cpp"],
706 relative_install_path: "foo/bar",
707 system_shared_libs: [],
708 stl: "none",
709 }
710
711 cc_binary {
712 name: "mybin",
713 srcs: ["mylib.cpp"],
714 relative_install_path: "foo/bar",
715 system_shared_libs: [],
716 static_executable: true,
717 stl: "none",
718 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900719 `)
720
721 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
722 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
723
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900724 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900725 ensureListContains(t, dirs, "etc")
726 ensureListContains(t, dirs, "etc/foo")
727 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900728 ensureListContains(t, dirs, "lib64")
729 ensureListContains(t, dirs, "lib64/foo")
730 ensureListContains(t, dirs, "lib64/foo/bar")
731 ensureListContains(t, dirs, "lib")
732 ensureListContains(t, dirs, "lib/foo")
733 ensureListContains(t, dirs, "lib/foo/bar")
734
Jiyong Parkbd13e442019-03-15 18:10:35 +0900735 ensureListContains(t, dirs, "bin")
736 ensureListContains(t, dirs, "bin/foo")
737 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +0900738}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900739
740func TestUseVendor(t *testing.T) {
741 ctx := testApex(t, `
742 apex {
743 name: "myapex",
744 key: "myapex.key",
745 native_shared_libs: ["mylib"],
746 use_vendor: true,
747 }
748
749 apex_key {
750 name: "myapex.key",
751 public_key: "testkey.avbpubkey",
752 private_key: "testkey.pem",
753 }
754
755 cc_library {
756 name: "mylib",
757 srcs: ["mylib.cpp"],
758 shared_libs: ["mylib2"],
759 system_shared_libs: [],
760 vendor_available: true,
761 stl: "none",
762 }
763
764 cc_library {
765 name: "mylib2",
766 srcs: ["mylib.cpp"],
767 system_shared_libs: [],
768 vendor_available: true,
769 stl: "none",
770 }
771 `)
772
773 inputsList := []string{}
774 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
775 for _, implicit := range i.Implicits {
776 inputsList = append(inputsList, implicit.String())
777 }
778 }
779 inputsString := strings.Join(inputsList, " ")
780
781 // ensure that the apex includes vendor variants of the direct and indirect deps
782 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
783 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
784
785 // ensure that the apex does not include core variants
786 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
787 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
788}
Jiyong Park16e91a02018-12-20 18:18:08 +0900789
790func TestStaticLinking(t *testing.T) {
791 ctx := testApex(t, `
792 apex {
793 name: "myapex",
794 key: "myapex.key",
795 native_shared_libs: ["mylib"],
796 }
797
798 apex_key {
799 name: "myapex.key",
800 public_key: "testkey.avbpubkey",
801 private_key: "testkey.pem",
802 }
803
804 cc_library {
805 name: "mylib",
806 srcs: ["mylib.cpp"],
807 system_shared_libs: [],
808 stl: "none",
809 stubs: {
810 versions: ["1", "2", "3"],
811 },
812 }
813
814 cc_binary {
815 name: "not_in_apex",
816 srcs: ["mylib.cpp"],
817 static_libs: ["mylib"],
818 static_executable: true,
819 system_shared_libs: [],
820 stl: "none",
821 }
Jiyong Park16e91a02018-12-20 18:18:08 +0900822 `)
823
824 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
825
826 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +0800827 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +0900828}
Jiyong Park9335a262018-12-24 11:31:58 +0900829
830func TestKeys(t *testing.T) {
831 ctx := testApex(t, `
832 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900833 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +0900834 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900835 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +0900836 native_shared_libs: ["mylib"],
837 }
838
839 cc_library {
840 name: "mylib",
841 srcs: ["mylib.cpp"],
842 system_shared_libs: [],
843 stl: "none",
844 }
845
846 apex_key {
847 name: "myapex.key",
848 public_key: "testkey.avbpubkey",
849 private_key: "testkey.pem",
850 }
851
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900852 android_app_certificate {
853 name: "myapex.certificate",
854 certificate: "testkey",
855 }
856
857 android_app_certificate {
858 name: "myapex.certificate.override",
859 certificate: "testkey.override",
860 }
861
Jiyong Park9335a262018-12-24 11:31:58 +0900862 `)
863
864 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +0900865 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +0900866
867 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
868 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
869 "vendor/foo/devkeys/testkey.avbpubkey")
870 }
871 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
872 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
873 "vendor/foo/devkeys/testkey.pem")
874 }
875
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900876 // check the APK certs. It should be overridden to myapex.certificate.override
877 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
878 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +0900879 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900880 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +0900881 }
882}
Jiyong Park58e364a2019-01-19 19:24:06 +0900883
884func TestMacro(t *testing.T) {
885 ctx := testApex(t, `
886 apex {
887 name: "myapex",
888 key: "myapex.key",
889 native_shared_libs: ["mylib"],
890 }
891
892 apex {
893 name: "otherapex",
894 key: "myapex.key",
895 native_shared_libs: ["mylib"],
896 }
897
898 apex_key {
899 name: "myapex.key",
900 public_key: "testkey.avbpubkey",
901 private_key: "testkey.pem",
902 }
903
904 cc_library {
905 name: "mylib",
906 srcs: ["mylib.cpp"],
907 system_shared_libs: [],
908 stl: "none",
909 }
910 `)
911
912 // non-APEX variant does not have __ANDROID__APEX__ defined
913 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
914 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
915 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
916
917 // APEX variant has __ANDROID_APEX__=<apexname> defined
918 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
919 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
920 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
921
922 // APEX variant has __ANDROID_APEX__=<apexname> defined
923 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
924 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
925 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
926}
Jiyong Park7e636d02019-01-28 16:16:54 +0900927
928func TestHeaderLibsDependency(t *testing.T) {
929 ctx := testApex(t, `
930 apex {
931 name: "myapex",
932 key: "myapex.key",
933 native_shared_libs: ["mylib"],
934 }
935
936 apex_key {
937 name: "myapex.key",
938 public_key: "testkey.avbpubkey",
939 private_key: "testkey.pem",
940 }
941
942 cc_library_headers {
943 name: "mylib_headers",
944 export_include_dirs: ["my_include"],
945 system_shared_libs: [],
946 stl: "none",
947 }
948
949 cc_library {
950 name: "mylib",
951 srcs: ["mylib.cpp"],
952 system_shared_libs: [],
953 stl: "none",
954 header_libs: ["mylib_headers"],
955 export_header_lib_headers: ["mylib_headers"],
956 stubs: {
957 versions: ["1", "2", "3"],
958 },
959 }
960
961 cc_library {
962 name: "otherlib",
963 srcs: ["mylib.cpp"],
964 system_shared_libs: [],
965 stl: "none",
966 shared_libs: ["mylib"],
967 }
968 `)
969
970 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
971
972 // Ensure that the include path of the header lib is exported to 'otherlib'
973 ensureContains(t, cFlags, "-Imy_include")
974}
Alex Light9670d332019-01-29 18:07:33 -0800975
Alex Light0851b882019-02-07 13:20:53 -0800976func TestNonTestApex(t *testing.T) {
977 ctx := testApex(t, `
978 apex {
979 name: "myapex",
980 key: "myapex.key",
981 native_shared_libs: ["mylib_common"],
982 }
983
984 apex_key {
985 name: "myapex.key",
986 public_key: "testkey.avbpubkey",
987 private_key: "testkey.pem",
988 }
989
990 cc_library {
991 name: "mylib_common",
992 srcs: ["mylib.cpp"],
993 system_shared_libs: [],
994 stl: "none",
995 }
996 `)
997
998 module := ctx.ModuleForTests("myapex", "android_common_myapex")
999 apexRule := module.Rule("apexRule")
1000 copyCmds := apexRule.Args["copy_commands"]
1001
1002 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1003 t.Log("Apex was a test apex!")
1004 t.Fail()
1005 }
1006 // Ensure that main rule creates an output
1007 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1008
1009 // Ensure that apex variant is created for the direct dep
1010 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1011
1012 // Ensure that both direct and indirect deps are copied into apex
1013 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1014
1015 // Ensure that the platform variant ends with _core_shared
1016 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1017
1018 if !android.InAnyApex("mylib_common") {
1019 t.Log("Found mylib_common not in any apex!")
1020 t.Fail()
1021 }
1022}
1023
1024func TestTestApex(t *testing.T) {
1025 if android.InAnyApex("mylib_common_test") {
1026 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!")
1027 }
1028 ctx := testApex(t, `
1029 apex_test {
1030 name: "myapex",
1031 key: "myapex.key",
1032 native_shared_libs: ["mylib_common_test"],
1033 }
1034
1035 apex_key {
1036 name: "myapex.key",
1037 public_key: "testkey.avbpubkey",
1038 private_key: "testkey.pem",
1039 }
1040
1041 cc_library {
1042 name: "mylib_common_test",
1043 srcs: ["mylib.cpp"],
1044 system_shared_libs: [],
1045 stl: "none",
1046 }
1047 `)
1048
1049 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1050 apexRule := module.Rule("apexRule")
1051 copyCmds := apexRule.Args["copy_commands"]
1052
1053 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1054 t.Log("Apex was not a test apex!")
1055 t.Fail()
1056 }
1057 // Ensure that main rule creates an output
1058 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1059
1060 // Ensure that apex variant is created for the direct dep
1061 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1062
1063 // Ensure that both direct and indirect deps are copied into apex
1064 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1065
1066 // Ensure that the platform variant ends with _core_shared
1067 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1068
1069 if android.InAnyApex("mylib_common_test") {
1070 t.Log("Found mylib_common_test in some apex!")
1071 t.Fail()
1072 }
1073}
1074
Alex Light9670d332019-01-29 18:07:33 -08001075func TestApexWithTarget(t *testing.T) {
1076 ctx := testApex(t, `
1077 apex {
1078 name: "myapex",
1079 key: "myapex.key",
1080 multilib: {
1081 first: {
1082 native_shared_libs: ["mylib_common"],
1083 }
1084 },
1085 target: {
1086 android: {
1087 multilib: {
1088 first: {
1089 native_shared_libs: ["mylib"],
1090 }
1091 }
1092 },
1093 host: {
1094 multilib: {
1095 first: {
1096 native_shared_libs: ["mylib2"],
1097 }
1098 }
1099 }
1100 }
1101 }
1102
1103 apex_key {
1104 name: "myapex.key",
1105 public_key: "testkey.avbpubkey",
1106 private_key: "testkey.pem",
1107 }
1108
1109 cc_library {
1110 name: "mylib",
1111 srcs: ["mylib.cpp"],
1112 system_shared_libs: [],
1113 stl: "none",
1114 }
1115
1116 cc_library {
1117 name: "mylib_common",
1118 srcs: ["mylib.cpp"],
1119 system_shared_libs: [],
1120 stl: "none",
1121 compile_multilib: "first",
1122 }
1123
1124 cc_library {
1125 name: "mylib2",
1126 srcs: ["mylib.cpp"],
1127 system_shared_libs: [],
1128 stl: "none",
1129 compile_multilib: "first",
1130 }
1131 `)
1132
1133 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1134 copyCmds := apexRule.Args["copy_commands"]
1135
1136 // Ensure that main rule creates an output
1137 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1138
1139 // Ensure that apex variant is created for the direct dep
1140 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1141 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1142 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1143
1144 // Ensure that both direct and indirect deps are copied into apex
1145 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1146 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1147 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1148
1149 // Ensure that the platform variant ends with _core_shared
1150 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1151 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1152 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1153}
Jiyong Park04480cf2019-02-06 00:16:29 +09001154
1155func TestApexWithShBinary(t *testing.T) {
1156 ctx := testApex(t, `
1157 apex {
1158 name: "myapex",
1159 key: "myapex.key",
1160 binaries: ["myscript"],
1161 }
1162
1163 apex_key {
1164 name: "myapex.key",
1165 public_key: "testkey.avbpubkey",
1166 private_key: "testkey.pem",
1167 }
1168
1169 sh_binary {
1170 name: "myscript",
1171 src: "mylib.cpp",
1172 filename: "myscript.sh",
1173 sub_dir: "script",
1174 }
1175 `)
1176
1177 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1178 copyCmds := apexRule.Args["copy_commands"]
1179
1180 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1181}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001182
1183func TestApexInProductPartition(t *testing.T) {
1184 ctx := testApex(t, `
1185 apex {
1186 name: "myapex",
1187 key: "myapex.key",
1188 native_shared_libs: ["mylib"],
1189 product_specific: true,
1190 }
1191
1192 apex_key {
1193 name: "myapex.key",
1194 public_key: "testkey.avbpubkey",
1195 private_key: "testkey.pem",
1196 product_specific: true,
1197 }
1198
1199 cc_library {
1200 name: "mylib",
1201 srcs: ["mylib.cpp"],
1202 system_shared_libs: [],
1203 stl: "none",
1204 }
1205 `)
1206
1207 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1208 expected := "target/product/test_device/product/apex"
1209 actual := apex.installDir.RelPathString()
1210 if actual != expected {
1211 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1212 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001213}
Jiyong Park67882562019-03-21 01:11:21 +09001214
1215func TestApexKeyFromOtherModule(t *testing.T) {
1216 ctx := testApex(t, `
1217 apex_key {
1218 name: "myapex.key",
1219 public_key: ":my.avbpubkey",
1220 private_key: ":my.pem",
1221 product_specific: true,
1222 }
1223
1224 filegroup {
1225 name: "my.avbpubkey",
1226 srcs: ["testkey2.avbpubkey"],
1227 }
1228
1229 filegroup {
1230 name: "my.pem",
1231 srcs: ["testkey2.pem"],
1232 }
1233 `)
1234
1235 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1236 expected_pubkey := "testkey2.avbpubkey"
1237 actual_pubkey := apex_key.public_key_file.String()
1238 if actual_pubkey != expected_pubkey {
1239 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
1240 }
1241 expected_privkey := "testkey2.pem"
1242 actual_privkey := apex_key.private_key_file.String()
1243 if actual_privkey != expected_privkey {
1244 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
1245 }
1246}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001247
1248func TestPrebuilt(t *testing.T) {
1249 ctx := testApex(t, `
1250 prebuilt_apex {
1251 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09001252 arch: {
1253 arm64: {
1254 src: "myapex-arm64.apex",
1255 },
1256 arm: {
1257 src: "myapex-arm.apex",
1258 },
1259 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001260 }
1261 `)
1262
1263 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1264
Jiyong Parkc95714e2019-03-29 14:23:10 +09001265 expectedInput := "myapex-arm64.apex"
1266 if prebuilt.inputApex.String() != expectedInput {
1267 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
1268 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001269}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001270
1271func TestPrebuiltFilenameOverride(t *testing.T) {
1272 ctx := testApex(t, `
1273 prebuilt_apex {
1274 name: "myapex",
1275 src: "myapex-arm.apex",
1276 filename: "notmyapex.apex",
1277 }
1278 `)
1279
1280 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1281
1282 expected := "notmyapex.apex"
1283 if p.installFilename != expected {
1284 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
1285 }
1286}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001287
1288func TestMain(m *testing.M) {
1289 run := func() int {
1290 setUp()
1291 defer tearDown()
1292
1293 return m.Run()
1294 }
1295
1296 os.Exit(run())
1297}