blob: 071e813c5687adf6b7009f681f5f1d853522f439 [file] [log] [blame]
Colin Crossd00350c2017-11-17 10:55:38 -08001// Copyright 2017 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
Colin Cross74d1ec02015-04-28 13:30:13 -070015package cc
16
17import (
Jeff Gaston294356f2017-09-27 17:05:30 -070018 "fmt"
Jiyong Park6a43f042017-10-12 23:05:00 +090019 "io/ioutil"
20 "os"
Inseob Kim1f086e22019-05-09 13:29:15 +090021 "path/filepath"
Colin Cross74d1ec02015-04-28 13:30:13 -070022 "reflect"
Jeff Gaston294356f2017-09-27 17:05:30 -070023 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070024 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070025
26 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070027)
28
Jiyong Park6a43f042017-10-12 23:05:00 +090029var buildDir string
30
31func setUp() {
32 var err error
33 buildDir, err = ioutil.TempDir("", "soong_cc_test")
34 if err != nil {
35 panic(err)
36 }
37}
38
39func tearDown() {
40 os.RemoveAll(buildDir)
41}
42
43func TestMain(m *testing.M) {
44 run := func() int {
45 setUp()
46 defer tearDown()
47
48 return m.Run()
49 }
50
51 os.Exit(run())
52}
53
Colin Cross98be1bb2019-12-13 20:41:13 -080054func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070055 t.Helper()
Colin Crossae8600b2020-10-29 17:09:13 -070056 ctx := CreateTestContext(config)
57 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080058
Jeff Gastond3e141d2017-08-08 17:46:01 -070059 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +080060 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090061 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +080062 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090063
64 return ctx
65}
66
Logan Chienf3511742017-10-31 18:04:35 +080067func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080068 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080069 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070070 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
71 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080072
Colin Cross98be1bb2019-12-13 20:41:13 -080073 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080074}
75
76func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080077 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080078 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070079 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080080
Colin Cross98be1bb2019-12-13 20:41:13 -080081 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080082}
83
Justin Yun5f7f7e82019-11-18 19:52:14 +090084func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +080085 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080086
Colin Crossae8600b2020-10-29 17:09:13 -070087 ctx := CreateTestContext(config)
88 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080089
90 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
91 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +080092 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +080093 return
94 }
95
96 _, errs = ctx.PrepareBuildActions(config)
97 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +080098 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +080099 return
100 }
101
102 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
103}
104
Justin Yun5f7f7e82019-11-18 19:52:14 +0900105func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900106 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900107 config := TestConfig(buildDir, android.Android, nil, bp, nil)
108 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
109 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
110 testCcErrorWithConfig(t, pattern, config)
111 return
112}
113
114func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900115 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900116 config := TestConfig(buildDir, android.Android, nil, bp, nil)
117 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
118 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
119 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
120 testCcErrorWithConfig(t, pattern, config)
121 return
122}
123
Logan Chienf3511742017-10-31 18:04:35 +0800124const (
Colin Cross7113d202019-11-20 16:39:12 -0800125 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800126 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900127 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800128 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800129)
130
Doug Hornc32c6b02019-01-17 14:44:05 -0800131func TestFuchsiaDeps(t *testing.T) {
132 t.Helper()
133
134 bp := `
135 cc_library {
136 name: "libTest",
137 srcs: ["foo.c"],
138 target: {
139 fuchsia: {
140 srcs: ["bar.c"],
141 },
142 },
143 }`
144
Colin Cross98be1bb2019-12-13 20:41:13 -0800145 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
146 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800147
148 rt := false
149 fb := false
150
151 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
152 implicits := ld.Implicits
153 for _, lib := range implicits {
154 if strings.Contains(lib.Rel(), "libcompiler_rt") {
155 rt = true
156 }
157
158 if strings.Contains(lib.Rel(), "libbioniccompat") {
159 fb = true
160 }
161 }
162
163 if !rt || !fb {
164 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
165 }
166}
167
168func TestFuchsiaTargetDecl(t *testing.T) {
169 t.Helper()
170
171 bp := `
172 cc_library {
173 name: "libTest",
174 srcs: ["foo.c"],
175 target: {
176 fuchsia: {
177 srcs: ["bar.c"],
178 },
179 },
180 }`
181
Colin Cross98be1bb2019-12-13 20:41:13 -0800182 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
183 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800184 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
185 var objs []string
186 for _, o := range ld.Inputs {
187 objs = append(objs, o.Base())
188 }
189 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
190 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
191 }
192}
193
Jiyong Park6a43f042017-10-12 23:05:00 +0900194func TestVendorSrc(t *testing.T) {
195 ctx := testCc(t, `
196 cc_library {
197 name: "libTest",
198 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700199 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800200 nocrt: true,
201 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900202 vendor_available: true,
203 target: {
204 vendor: {
205 srcs: ["bar.c"],
206 },
207 },
208 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900209 `)
210
Logan Chienf3511742017-10-31 18:04:35 +0800211 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900212 var objs []string
213 for _, o := range ld.Inputs {
214 objs = append(objs, o.Base())
215 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800216 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900217 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
218 }
219}
220
Logan Chienf3511742017-10-31 18:04:35 +0800221func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900222 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800223
Logan Chiend3c59a22018-03-29 14:08:15 +0800224 t.Helper()
225
Justin Yun0ecf0b22020-02-28 15:07:59 +0900226 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Ivan Lozano52767be2019-10-18 14:49:46 -0700227 if !mod.HasVendorVariant() {
Justin Yun0ecf0b22020-02-28 15:07:59 +0900228 t.Errorf("%q must have variant %q", name, variant)
Logan Chienf3511742017-10-31 18:04:35 +0800229 }
230
231 // Check library properties.
232 lib, ok := mod.compiler.(*libraryDecorator)
233 if !ok {
234 t.Errorf("%q must have libraryDecorator", name)
235 } else if lib.baseInstaller.subDir != subDir {
236 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
237 lib.baseInstaller.subDir)
238 }
239
240 // Check VNDK properties.
241 if mod.vndkdep == nil {
242 t.Fatalf("%q must have `vndkdep`", name)
243 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700244 if !mod.IsVndk() {
245 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800246 }
247 if mod.isVndkSp() != isVndkSp {
248 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
249 }
250
251 // Check VNDK extension properties.
252 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500253 if mod.IsVndkExt() != isVndkExt {
254 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800255 }
256
257 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
258 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
259 }
260}
261
Bill Peckham945441c2020-08-31 16:07:58 -0700262func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool) {
263 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900264 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
265 if !ok {
266 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900267 return
268 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900269 outputFiles, err := mod.OutputFiles("")
270 if err != nil || len(outputFiles) != 1 {
271 t.Errorf("%q must have single output\n", moduleName)
272 return
273 }
274 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900275
Bill Peckham945441c2020-08-31 16:07:58 -0700276 if include {
277 out := singleton.Output(snapshotPath)
278 if out.Input.String() != outputFiles[0].String() {
279 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
280 }
281 } else {
282 out := singleton.MaybeOutput(snapshotPath)
283 if out.Rule != nil {
284 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
285 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900286 }
287}
288
Bill Peckham945441c2020-08-31 16:07:58 -0700289func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
290 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true)
291}
292
293func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
294 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false)
295}
296
Jooyung Han2216fb12019-11-06 16:46:15 +0900297func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
298 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800299 content := android.ContentFromFileRuleForTests(t, params)
300 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900301 assertArrayString(t, actual, expected)
302}
303
Jooyung Han097087b2019-10-22 19:32:18 +0900304func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
305 t.Helper()
306 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900307 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
308}
309
310func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
311 t.Helper()
312 vndkLibraries := ctx.ModuleForTests(module, "")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900313
314 var output string
315 if module != "vndkcorevariant.libraries.txt" {
316 output = insertVndkVersion(module, "VER")
317 } else {
318 output = module
319 }
320
Jooyung Han2216fb12019-11-06 16:46:15 +0900321 checkWriteFileOutput(t, vndkLibraries.Output(output), expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900322}
323
Logan Chienf3511742017-10-31 18:04:35 +0800324func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800325 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800326 cc_library {
327 name: "libvndk",
328 vendor_available: true,
329 vndk: {
330 enabled: true,
331 },
332 nocrt: true,
333 }
334
335 cc_library {
336 name: "libvndk_private",
337 vendor_available: false,
338 vndk: {
339 enabled: true,
340 },
341 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900342 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800343 }
344
345 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900346 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800347 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900348 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800349 vndk: {
350 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900351 },
352 nocrt: true,
353 target: {
354 vendor: {
355 cflags: ["-DTEST"],
356 },
357 product: {
358 cflags: ["-DTEST"],
359 },
360 },
361 }
362
363 cc_library {
364 name: "libvndk_sp",
365 vendor_available: true,
366 vndk: {
367 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800368 support_system_process: true,
369 },
370 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900371 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800372 }
373
374 cc_library {
375 name: "libvndk_sp_private",
376 vendor_available: false,
377 vndk: {
378 enabled: true,
379 support_system_process: true,
380 },
381 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900382 target: {
383 vendor: {
384 suffix: "-x",
385 },
386 },
Logan Chienf3511742017-10-31 18:04:35 +0800387 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900388
389 cc_library {
390 name: "libvndk_sp_product_private",
391 vendor_available: false,
392 product_available: false,
393 vndk: {
394 enabled: true,
395 support_system_process: true,
396 },
397 nocrt: true,
398 target: {
399 vendor: {
400 suffix: "-x",
401 },
402 product: {
403 suffix: "-x",
404 },
405 },
406 }
407
Jooyung Han2216fb12019-11-06 16:46:15 +0900408 vndk_libraries_txt {
409 name: "llndk.libraries.txt",
410 }
411 vndk_libraries_txt {
412 name: "vndkcore.libraries.txt",
413 }
414 vndk_libraries_txt {
415 name: "vndksp.libraries.txt",
416 }
417 vndk_libraries_txt {
418 name: "vndkprivate.libraries.txt",
419 }
420 vndk_libraries_txt {
421 name: "vndkcorevariant.libraries.txt",
422 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800423 `
424
425 config := TestConfig(buildDir, android.Android, nil, bp, nil)
426 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900427 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800428 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
429
430 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800431
Jooyung Han261e1582020-10-20 18:54:21 +0900432 // subdir == "" because VNDK libs are not supposed to be installed separately.
433 // They are installed as part of VNDK APEX instead.
434 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
435 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900436 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900437 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
438 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900439 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900440
Justin Yun6977e8a2020-10-29 18:24:11 +0900441 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
442 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900443
Inseob Kim1f086e22019-05-09 13:29:15 +0900444 // Check VNDK snapshot output.
445
446 snapshotDir := "vndk-snapshot"
447 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
448
449 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
450 "arm64", "armv8-a"))
451 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
452 "arm", "armv7-a-neon"))
453
454 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
455 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
456 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
457 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
458
Colin Crossfb0c16e2019-11-20 17:12:35 -0800459 variant := "android_vendor.VER_arm64_armv8-a_shared"
460 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900461
Inseob Kim7f283f42020-06-01 21:53:49 +0900462 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
463
464 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
465 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900466 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
467 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900468 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
469 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900470
Jooyung Han39edb6c2019-11-06 16:53:07 +0900471 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900472 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
473 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
474 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
475 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900476
Jooyung Han097087b2019-10-22 19:32:18 +0900477 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
478 "LLNDK: libc.so",
479 "LLNDK: libdl.so",
480 "LLNDK: libft2.so",
481 "LLNDK: libm.so",
482 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900483 "VNDK-SP: libvndk_sp-x.so",
484 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900485 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900486 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900487 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900488 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900489 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900490 "VNDK-private: libvndk-private.so",
491 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900492 "VNDK-private: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900493 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900494 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900495 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
496 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
497 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
Jooyung Han2216fb12019-11-06 16:46:15 +0900498 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
499}
500
Yo Chiangbba545e2020-06-09 16:15:37 +0800501func TestVndkWithHostSupported(t *testing.T) {
502 ctx := testCc(t, `
503 cc_library {
504 name: "libvndk_host_supported",
505 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900506 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800507 vndk: {
508 enabled: true,
509 },
510 host_supported: true,
511 }
512
513 cc_library {
514 name: "libvndk_host_supported_but_disabled_on_device",
515 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900516 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800517 vndk: {
518 enabled: true,
519 },
520 host_supported: true,
521 enabled: false,
522 target: {
523 host: {
524 enabled: true,
525 }
526 }
527 }
528
529 vndk_libraries_txt {
530 name: "vndkcore.libraries.txt",
531 }
532 `)
533
534 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
535}
536
Jooyung Han2216fb12019-11-06 16:46:15 +0900537func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800538 bp := `
Jooyung Han2216fb12019-11-06 16:46:15 +0900539 vndk_libraries_txt {
540 name: "llndk.libraries.txt",
Colin Cross98be1bb2019-12-13 20:41:13 -0800541 }`
542 config := TestConfig(buildDir, android.Android, nil, bp, nil)
543 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
544 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
545 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900546
547 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900548 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900549 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900550}
551
552func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800553 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900554 cc_library {
555 name: "libvndk",
556 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900557 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900558 vndk: {
559 enabled: true,
560 },
561 nocrt: true,
562 }
563
564 cc_library {
565 name: "libvndk_sp",
566 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900567 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900568 vndk: {
569 enabled: true,
570 support_system_process: true,
571 },
572 nocrt: true,
573 }
574
575 cc_library {
576 name: "libvndk2",
577 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900578 product_available: false,
Jooyung Han097087b2019-10-22 19:32:18 +0900579 vndk: {
580 enabled: true,
581 },
582 nocrt: true,
583 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900584
585 vndk_libraries_txt {
586 name: "vndkcorevariant.libraries.txt",
587 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800588 `
589
590 config := TestConfig(buildDir, android.Android, nil, bp, nil)
591 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
592 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
593 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
594
595 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
596
597 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900598
Jooyung Han2216fb12019-11-06 16:46:15 +0900599 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900600}
601
Chris Parsons79d66a52020-06-05 17:26:16 -0400602func TestDataLibs(t *testing.T) {
603 bp := `
604 cc_test_library {
605 name: "test_lib",
606 srcs: ["test_lib.cpp"],
607 gtest: false,
608 }
609
610 cc_test {
611 name: "main_test",
612 data_libs: ["test_lib"],
613 gtest: false,
614 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400615 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400616
617 config := TestConfig(buildDir, android.Android, nil, bp, nil)
618 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
619 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
620 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
621
622 ctx := testCcWithConfig(t, config)
623 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
624 testBinary := module.(*Module).linker.(*testBinary)
625 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
626 if err != nil {
627 t.Errorf("Expected cc_test to produce output files, error: %s", err)
628 return
629 }
630 if len(outputFiles) != 1 {
631 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
632 return
633 }
634 if len(testBinary.dataPaths()) != 1 {
635 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
636 return
637 }
638
639 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400640 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400641
642 if !strings.HasSuffix(outputPath, "/main_test") {
643 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
644 return
645 }
646 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
647 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
648 return
649 }
650}
651
Chris Parsons216e10a2020-07-09 17:12:52 -0400652func TestDataLibsRelativeInstallPath(t *testing.T) {
653 bp := `
654 cc_test_library {
655 name: "test_lib",
656 srcs: ["test_lib.cpp"],
657 relative_install_path: "foo/bar/baz",
658 gtest: false,
659 }
660
661 cc_test {
662 name: "main_test",
663 data_libs: ["test_lib"],
664 gtest: false,
665 }
666 `
667
668 config := TestConfig(buildDir, android.Android, nil, bp, nil)
669 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
670 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
671 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
672
673 ctx := testCcWithConfig(t, config)
674 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
675 testBinary := module.(*Module).linker.(*testBinary)
676 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
677 if err != nil {
678 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
679 }
680 if len(outputFiles) != 1 {
681 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
682 }
683 if len(testBinary.dataPaths()) != 1 {
684 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
685 }
686
687 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400688
689 if !strings.HasSuffix(outputPath, "/main_test") {
690 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
691 }
692 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
693 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
694 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400695 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400696 }
697}
698
Jooyung Han0302a842019-10-30 18:43:49 +0900699func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900700 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900701 cc_library {
702 name: "libvndk",
703 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900704 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900705 vndk: {
706 enabled: true,
707 },
708 nocrt: true,
709 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900710 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900711
712 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
713 "LLNDK: libc.so",
714 "LLNDK: libdl.so",
715 "LLNDK: libft2.so",
716 "LLNDK: libm.so",
717 "VNDK-SP: libc++.so",
718 "VNDK-core: libvndk.so",
719 "VNDK-private: libft2.so",
720 })
Logan Chienf3511742017-10-31 18:04:35 +0800721}
722
Justin Yun63e9ec72020-10-29 16:49:43 +0900723func TestVndkModuleError(t *testing.T) {
724 // Check the error message for vendor_available and product_available properties.
Justin Yun6977e8a2020-10-29 18:24:11 +0900725 testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", `
726 cc_library {
727 name: "libvndk",
728 vndk: {
729 enabled: true,
730 },
731 nocrt: true,
732 }
733 `)
734
735 testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", `
736 cc_library {
737 name: "libvndk",
738 product_available: true,
739 vndk: {
740 enabled: true,
741 },
742 nocrt: true,
743 }
744 `)
745
746 testCcErrorProductVndk(t, "product_available: may not have different value than `vendor_available` for a VNDK", `
Justin Yun63e9ec72020-10-29 16:49:43 +0900747 cc_library {
748 name: "libvndk",
749 vendor_available: true,
750 product_available: false,
751 vndk: {
752 enabled: true,
753 },
754 nocrt: true,
755 }
756 `)
Justin Yun6977e8a2020-10-29 18:24:11 +0900757
758 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
759 cc_library {
760 name: "libvndkprop",
761 vendor_available: true,
762 product_available: true,
763 vndk: {
764 enabled: true,
765 },
766 nocrt: true,
767 target: {
768 vendor: {
769 cflags: ["-DTEST",],
770 },
771 },
772 }
773 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900774}
775
Logan Chiend3c59a22018-03-29 14:08:15 +0800776func TestVndkDepError(t *testing.T) {
777 // Check whether an error is emitted when a VNDK lib depends on a system lib.
778 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
779 cc_library {
780 name: "libvndk",
781 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900782 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800783 vndk: {
784 enabled: true,
785 },
786 shared_libs: ["libfwk"], // Cause error
787 nocrt: true,
788 }
789
790 cc_library {
791 name: "libfwk",
792 nocrt: true,
793 }
794 `)
795
796 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
797 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
798 cc_library {
799 name: "libvndk",
800 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900801 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800802 vndk: {
803 enabled: true,
804 },
805 shared_libs: ["libvendor"], // Cause error
806 nocrt: true,
807 }
808
809 cc_library {
810 name: "libvendor",
811 vendor: true,
812 nocrt: true,
813 }
814 `)
815
816 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
817 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
818 cc_library {
819 name: "libvndk_sp",
820 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900821 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800822 vndk: {
823 enabled: true,
824 support_system_process: true,
825 },
826 shared_libs: ["libfwk"], // Cause error
827 nocrt: true,
828 }
829
830 cc_library {
831 name: "libfwk",
832 nocrt: true,
833 }
834 `)
835
836 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
837 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
838 cc_library {
839 name: "libvndk_sp",
840 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900841 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800842 vndk: {
843 enabled: true,
844 support_system_process: true,
845 },
846 shared_libs: ["libvendor"], // Cause error
847 nocrt: true,
848 }
849
850 cc_library {
851 name: "libvendor",
852 vendor: true,
853 nocrt: true,
854 }
855 `)
856
857 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
858 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
859 cc_library {
860 name: "libvndk_sp",
861 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900862 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800863 vndk: {
864 enabled: true,
865 support_system_process: true,
866 },
867 shared_libs: ["libvndk"], // Cause error
868 nocrt: true,
869 }
870
871 cc_library {
872 name: "libvndk",
873 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900874 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800875 vndk: {
876 enabled: true,
877 },
878 nocrt: true,
879 }
880 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900881
882 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
883 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
884 cc_library {
885 name: "libvndk",
886 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900887 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900888 vndk: {
889 enabled: true,
890 },
891 shared_libs: ["libnonvndk"],
892 nocrt: true,
893 }
894
895 cc_library {
896 name: "libnonvndk",
897 vendor_available: true,
898 nocrt: true,
899 }
900 `)
901
902 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
903 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
904 cc_library {
905 name: "libvndkprivate",
906 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900907 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +0900908 vndk: {
909 enabled: true,
910 },
911 shared_libs: ["libnonvndk"],
912 nocrt: true,
913 }
914
915 cc_library {
916 name: "libnonvndk",
917 vendor_available: true,
918 nocrt: true,
919 }
920 `)
921
922 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
923 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
924 cc_library {
925 name: "libvndksp",
926 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900927 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900928 vndk: {
929 enabled: true,
930 support_system_process: true,
931 },
932 shared_libs: ["libnonvndk"],
933 nocrt: true,
934 }
935
936 cc_library {
937 name: "libnonvndk",
938 vendor_available: true,
939 nocrt: true,
940 }
941 `)
942
943 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
944 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
945 cc_library {
946 name: "libvndkspprivate",
947 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900948 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +0900949 vndk: {
950 enabled: true,
951 support_system_process: true,
952 },
953 shared_libs: ["libnonvndk"],
954 nocrt: true,
955 }
956
957 cc_library {
958 name: "libnonvndk",
959 vendor_available: true,
960 nocrt: true,
961 }
962 `)
963}
964
965func TestDoubleLoadbleDep(t *testing.T) {
966 // okay to link : LLNDK -> double_loadable VNDK
967 testCc(t, `
968 cc_library {
969 name: "libllndk",
970 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -0700971 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900972 }
973
974 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700975 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900976 symbol_file: "",
977 }
978
979 cc_library {
980 name: "libdoubleloadable",
981 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900982 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900983 vndk: {
984 enabled: true,
985 },
986 double_loadable: true,
987 }
988 `)
989 // okay to link : LLNDK -> VNDK-SP
990 testCc(t, `
991 cc_library {
992 name: "libllndk",
993 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -0700994 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900995 }
996
997 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700998 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900999 symbol_file: "",
1000 }
1001
1002 cc_library {
1003 name: "libvndksp",
1004 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001005 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001006 vndk: {
1007 enabled: true,
1008 support_system_process: true,
1009 },
1010 }
1011 `)
1012 // okay to link : double_loadable -> double_loadable
1013 testCc(t, `
1014 cc_library {
1015 name: "libdoubleloadable1",
1016 shared_libs: ["libdoubleloadable2"],
1017 vendor_available: true,
1018 double_loadable: true,
1019 }
1020
1021 cc_library {
1022 name: "libdoubleloadable2",
1023 vendor_available: true,
1024 double_loadable: true,
1025 }
1026 `)
1027 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1028 testCc(t, `
1029 cc_library {
1030 name: "libdoubleloadable",
1031 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001032 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001033 vndk: {
1034 enabled: true,
1035 },
1036 double_loadable: true,
1037 shared_libs: ["libnondoubleloadable"],
1038 }
1039
1040 cc_library {
1041 name: "libnondoubleloadable",
1042 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09001043 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +09001044 vndk: {
1045 enabled: true,
1046 },
1047 double_loadable: true,
1048 }
1049 `)
1050 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1051 testCc(t, `
1052 cc_library {
1053 name: "libllndk",
1054 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001055 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001056 }
1057
1058 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001059 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001060 symbol_file: "",
1061 }
1062
1063 cc_library {
1064 name: "libcoreonly",
1065 shared_libs: ["libvendoravailable"],
1066 }
1067
1068 // indirect dependency of LLNDK
1069 cc_library {
1070 name: "libvendoravailable",
1071 vendor_available: true,
1072 double_loadable: true,
1073 }
1074 `)
1075}
1076
Inseob Kim5f58ff72020-09-07 19:53:31 +09001077func TestVendorSnapshotCapture(t *testing.T) {
Inseob Kim8471cda2019-11-15 09:59:12 +09001078 bp := `
1079 cc_library {
1080 name: "libvndk",
1081 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001082 product_available: true,
Inseob Kim8471cda2019-11-15 09:59:12 +09001083 vndk: {
1084 enabled: true,
1085 },
1086 nocrt: true,
1087 }
1088
1089 cc_library {
1090 name: "libvendor",
1091 vendor: true,
1092 nocrt: true,
1093 }
1094
1095 cc_library {
1096 name: "libvendor_available",
1097 vendor_available: true,
1098 nocrt: true,
1099 }
1100
1101 cc_library_headers {
1102 name: "libvendor_headers",
1103 vendor_available: true,
1104 nocrt: true,
1105 }
1106
1107 cc_binary {
1108 name: "vendor_bin",
1109 vendor: true,
1110 nocrt: true,
1111 }
1112
1113 cc_binary {
1114 name: "vendor_available_bin",
1115 vendor_available: true,
1116 nocrt: true,
1117 }
Inseob Kim7f283f42020-06-01 21:53:49 +09001118
1119 toolchain_library {
1120 name: "libb",
1121 vendor_available: true,
1122 src: "libb.a",
1123 }
Inseob Kim1042d292020-06-01 23:23:05 +09001124
1125 cc_object {
1126 name: "obj",
1127 vendor_available: true,
1128 }
Colin Cross127bb8b2020-12-16 16:46:01 -08001129
1130 cc_library {
1131 name: "libllndk",
1132 llndk_stubs: "libllndk.llndk",
1133 }
1134
1135 llndk_library {
1136 name: "libllndk.llndk",
1137 symbol_file: "",
1138 }
Inseob Kim8471cda2019-11-15 09:59:12 +09001139`
1140 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1141 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1142 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1143 ctx := testCcWithConfig(t, config)
1144
1145 // Check Vendor snapshot output.
1146
1147 snapshotDir := "vendor-snapshot"
1148 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
Inseob Kim7f283f42020-06-01 21:53:49 +09001149 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1150
1151 var jsonFiles []string
Inseob Kim8471cda2019-11-15 09:59:12 +09001152
1153 for _, arch := range [][]string{
1154 []string{"arm64", "armv8-a"},
1155 []string{"arm", "armv7-a-neon"},
1156 } {
1157 archType := arch[0]
1158 archVariant := arch[1]
1159 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1160
1161 // For shared libraries, only non-VNDK vendor_available modules are captured
1162 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1163 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Inseob Kim7f283f42020-06-01 21:53:49 +09001164 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1165 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1166 jsonFiles = append(jsonFiles,
1167 filepath.Join(sharedDir, "libvendor.so.json"),
1168 filepath.Join(sharedDir, "libvendor_available.so.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001169
Colin Cross127bb8b2020-12-16 16:46:01 -08001170 // LLNDK modules are not captured
1171 checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
1172
Inseob Kim8471cda2019-11-15 09:59:12 +09001173 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
Inseob Kimc42f2f22020-07-29 20:32:10 +09001174 // Also cfi variants are captured, except for prebuilts like toolchain_library
Inseob Kim8471cda2019-11-15 09:59:12 +09001175 staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001176 staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant)
Inseob Kim8471cda2019-11-15 09:59:12 +09001177 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Inseob Kim7f283f42020-06-01 21:53:49 +09001178 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1179 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001180 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001181 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001182 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001183 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001184 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001185 jsonFiles = append(jsonFiles,
1186 filepath.Join(staticDir, "libb.a.json"),
1187 filepath.Join(staticDir, "libvndk.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001188 filepath.Join(staticDir, "libvndk.cfi.a.json"),
Inseob Kim7f283f42020-06-01 21:53:49 +09001189 filepath.Join(staticDir, "libvendor.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001190 filepath.Join(staticDir, "libvendor.cfi.a.json"),
1191 filepath.Join(staticDir, "libvendor_available.a.json"),
1192 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001193
Inseob Kim7f283f42020-06-01 21:53:49 +09001194 // For binary executables, all vendor:true and vendor_available modules are captured.
Inseob Kim8471cda2019-11-15 09:59:12 +09001195 if archType == "arm64" {
1196 binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1197 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Inseob Kim7f283f42020-06-01 21:53:49 +09001198 checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
1199 checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
1200 jsonFiles = append(jsonFiles,
1201 filepath.Join(binaryDir, "vendor_bin.json"),
1202 filepath.Join(binaryDir, "vendor_available_bin.json"))
1203 }
1204
1205 // For header libraries, all vendor:true and vendor_available modules are captured.
1206 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1207 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
Inseob Kim1042d292020-06-01 23:23:05 +09001208
1209 // For object modules, all vendor:true and vendor_available modules are captured.
1210 objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1211 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1212 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1213 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
Inseob Kim7f283f42020-06-01 21:53:49 +09001214 }
1215
1216 for _, jsonFile := range jsonFiles {
1217 // verify all json files exist
1218 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1219 t.Errorf("%q expected but not found", jsonFile)
Inseob Kim8471cda2019-11-15 09:59:12 +09001220 }
1221 }
1222}
1223
Inseob Kim5f58ff72020-09-07 19:53:31 +09001224func TestVendorSnapshotUse(t *testing.T) {
1225 frameworkBp := `
1226 cc_library {
1227 name: "libvndk",
1228 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001229 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001230 vndk: {
1231 enabled: true,
1232 },
1233 nocrt: true,
1234 compile_multilib: "64",
1235 }
1236
1237 cc_library {
1238 name: "libvendor",
1239 vendor: true,
1240 nocrt: true,
1241 no_libcrt: true,
1242 stl: "none",
1243 system_shared_libs: [],
1244 compile_multilib: "64",
1245 }
1246
1247 cc_binary {
1248 name: "bin",
1249 vendor: true,
1250 nocrt: true,
1251 no_libcrt: true,
1252 stl: "none",
1253 system_shared_libs: [],
1254 compile_multilib: "64",
1255 }
1256`
1257
1258 vndkBp := `
1259 vndk_prebuilt_shared {
1260 name: "libvndk",
1261 version: "BOARD",
1262 target_arch: "arm64",
1263 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001264 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001265 vndk: {
1266 enabled: true,
1267 },
1268 arch: {
1269 arm64: {
1270 srcs: ["libvndk.so"],
Inseob Kim67be7322020-10-19 10:15:28 +09001271 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001272 },
1273 },
1274 }
1275`
1276
1277 vendorProprietaryBp := `
1278 cc_library {
1279 name: "libvendor_without_snapshot",
1280 vendor: true,
1281 nocrt: true,
1282 no_libcrt: true,
1283 stl: "none",
1284 system_shared_libs: [],
1285 compile_multilib: "64",
1286 }
1287
1288 cc_library_shared {
1289 name: "libclient",
1290 vendor: true,
1291 nocrt: true,
1292 no_libcrt: true,
1293 stl: "none",
1294 system_shared_libs: [],
1295 shared_libs: ["libvndk"],
1296 static_libs: ["libvendor", "libvendor_without_snapshot"],
1297 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001298 srcs: ["client.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001299 }
1300
1301 cc_binary {
1302 name: "bin_without_snapshot",
1303 vendor: true,
1304 nocrt: true,
1305 no_libcrt: true,
1306 stl: "none",
1307 system_shared_libs: [],
1308 static_libs: ["libvndk"],
1309 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001310 srcs: ["bin.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001311 }
1312
1313 vendor_snapshot_static {
1314 name: "libvndk",
1315 version: "BOARD",
1316 target_arch: "arm64",
1317 vendor: true,
1318 arch: {
1319 arm64: {
1320 src: "libvndk.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001321 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001322 },
1323 },
1324 }
1325
1326 vendor_snapshot_shared {
1327 name: "libvendor",
1328 version: "BOARD",
1329 target_arch: "arm64",
1330 vendor: true,
1331 arch: {
1332 arm64: {
1333 src: "libvendor.so",
Inseob Kim67be7322020-10-19 10:15:28 +09001334 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001335 },
1336 },
1337 }
1338
1339 vendor_snapshot_static {
1340 name: "libvendor",
1341 version: "BOARD",
1342 target_arch: "arm64",
1343 vendor: true,
1344 arch: {
1345 arm64: {
1346 src: "libvendor.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001347 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001348 },
1349 },
1350 }
1351
1352 vendor_snapshot_binary {
1353 name: "bin",
1354 version: "BOARD",
1355 target_arch: "arm64",
1356 vendor: true,
1357 arch: {
1358 arm64: {
1359 src: "bin",
1360 },
1361 },
1362 }
1363`
1364 depsBp := GatherRequiredDepsForTest(android.Android)
1365
1366 mockFS := map[string][]byte{
Inseob Kim67be7322020-10-19 10:15:28 +09001367 "deps/Android.bp": []byte(depsBp),
1368 "framework/Android.bp": []byte(frameworkBp),
1369 "vendor/Android.bp": []byte(vendorProprietaryBp),
1370 "vendor/bin": nil,
1371 "vendor/bin.cpp": nil,
1372 "vendor/client.cpp": nil,
1373 "vendor/include/libvndk/a.h": nil,
1374 "vendor/include/libvendor/b.h": nil,
1375 "vendor/libvndk.a": nil,
1376 "vendor/libvendor.a": nil,
1377 "vendor/libvendor.so": nil,
1378 "vndk/Android.bp": []byte(vndkBp),
1379 "vndk/include/libvndk/a.h": nil,
1380 "vndk/libvndk.so": nil,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001381 }
1382
1383 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1384 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1385 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001386 ctx := CreateTestContext(config)
1387 ctx.Register()
Inseob Kim5f58ff72020-09-07 19:53:31 +09001388
1389 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
1390 android.FailIfErrored(t, errs)
1391 _, errs = ctx.PrepareBuildActions(config)
1392 android.FailIfErrored(t, errs)
1393
1394 sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared"
1395 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1396 binaryVariant := "android_vendor.BOARD_arm64_armv8-a"
1397
1398 // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot
Inseob Kim67be7322020-10-19 10:15:28 +09001399 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
1400 for _, includeFlags := range []string{
1401 "-Ivndk/include/libvndk", // libvndk
1402 "-Ivendor/include/libvendor", // libvendor
1403 } {
1404 if !strings.Contains(libclientCcFlags, includeFlags) {
1405 t.Errorf("flags for libclient must contain %#v, but was %#v.",
1406 includeFlags, libclientCcFlags)
1407 }
1408 }
Inseob Kim5f58ff72020-09-07 19:53:31 +09001409
Inseob Kim67be7322020-10-19 10:15:28 +09001410 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001411 for _, input := range [][]string{
1412 []string{sharedVariant, "libvndk.vndk.BOARD.arm64"},
1413 []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"},
1414 []string{staticVariant, "libvendor_without_snapshot"},
1415 } {
1416 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Inseob Kim67be7322020-10-19 10:15:28 +09001417 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
1418 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001419 }
1420 }
1421
1422 // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64
Inseob Kim67be7322020-10-19 10:15:28 +09001423 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
1424 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
1425 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
1426 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
1427 }
1428
1429 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001430 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"})
Inseob Kim67be7322020-10-19 10:15:28 +09001431 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
Inseob Kim5f58ff72020-09-07 19:53:31 +09001432 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
Inseob Kim67be7322020-10-19 10:15:28 +09001433 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001434 }
1435
1436 // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64
1437 ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so")
1438
1439 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
1440 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
1441
1442 // bin is installed by bin.vendor_binary.BOARD.arm64
1443 ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin")
1444
1445 // bin_without_snapshot is installed by bin_without_snapshot
1446 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1447
1448 // libvendor and bin don't have vendor.BOARD variant
1449 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1450 if inList(sharedVariant, libvendorVariants) {
1451 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1452 }
1453
1454 binVariants := ctx.ModuleVariantsForTests("bin")
1455 if inList(binaryVariant, binVariants) {
1456 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1457 }
1458}
1459
Inseob Kimc42f2f22020-07-29 20:32:10 +09001460func TestVendorSnapshotSanitizer(t *testing.T) {
1461 bp := `
1462 vendor_snapshot_static {
1463 name: "libsnapshot",
1464 vendor: true,
1465 target_arch: "arm64",
1466 version: "BOARD",
1467 arch: {
1468 arm64: {
1469 src: "libsnapshot.a",
1470 cfi: {
1471 src: "libsnapshot.cfi.a",
1472 }
1473 },
1474 },
1475 }
1476`
1477 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1478 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1479 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1480 ctx := testCcWithConfig(t, config)
1481
1482 // Check non-cfi and cfi variant.
1483 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1484 staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi"
1485
1486 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module)
1487 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1488
1489 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module)
1490 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1491}
1492
Bill Peckham945441c2020-08-31 16:07:58 -07001493func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) {
1494 t.Helper()
1495 if c.ExcludeFromVendorSnapshot() != expected {
1496 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected)
1497 }
1498}
1499
1500func TestVendorSnapshotExclude(t *testing.T) {
1501
1502 // This test verifies that the exclude_from_vendor_snapshot property
1503 // makes its way from the Android.bp source file into the module data
1504 // structure. It also verifies that modules are correctly included or
1505 // excluded in the vendor snapshot based on their path (framework or
1506 // vendor) and the exclude_from_vendor_snapshot property.
1507
1508 frameworkBp := `
1509 cc_library_shared {
1510 name: "libinclude",
1511 srcs: ["src/include.cpp"],
1512 vendor_available: true,
1513 }
1514 cc_library_shared {
1515 name: "libexclude",
1516 srcs: ["src/exclude.cpp"],
1517 vendor: true,
1518 exclude_from_vendor_snapshot: true,
1519 }
1520 `
1521
1522 vendorProprietaryBp := `
1523 cc_library_shared {
1524 name: "libvendor",
1525 srcs: ["vendor.cpp"],
1526 vendor: true,
1527 }
1528 `
1529
1530 depsBp := GatherRequiredDepsForTest(android.Android)
1531
1532 mockFS := map[string][]byte{
1533 "deps/Android.bp": []byte(depsBp),
1534 "framework/Android.bp": []byte(frameworkBp),
1535 "framework/include.cpp": nil,
1536 "framework/exclude.cpp": nil,
1537 "device/Android.bp": []byte(vendorProprietaryBp),
1538 "device/vendor.cpp": nil,
1539 }
1540
1541 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1542 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1543 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001544 ctx := CreateTestContext(config)
1545 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001546
1547 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1548 android.FailIfErrored(t, errs)
1549 _, errs = ctx.PrepareBuildActions(config)
1550 android.FailIfErrored(t, errs)
1551
1552 // Test an include and exclude framework module.
1553 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
1554 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false)
1555 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true)
1556
1557 // A vendor module is excluded, but by its path, not the
1558 // exclude_from_vendor_snapshot property.
1559 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false)
1560
1561 // Verify the content of the vendor snapshot.
1562
1563 snapshotDir := "vendor-snapshot"
1564 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1565 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1566
1567 var includeJsonFiles []string
1568 var excludeJsonFiles []string
1569
1570 for _, arch := range [][]string{
1571 []string{"arm64", "armv8-a"},
1572 []string{"arm", "armv7-a-neon"},
1573 } {
1574 archType := arch[0]
1575 archVariant := arch[1]
1576 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1577
1578 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1579 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1580
1581 // Included modules
1582 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1583 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1584
1585 // Excluded modules
1586 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1587 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1588 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1589 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1590 }
1591
1592 // Verify that each json file for an included module has a rule.
1593 for _, jsonFile := range includeJsonFiles {
1594 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1595 t.Errorf("include json file %q not found", jsonFile)
1596 }
1597 }
1598
1599 // Verify that each json file for an excluded module has no rule.
1600 for _, jsonFile := range excludeJsonFiles {
1601 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1602 t.Errorf("exclude json file %q found", jsonFile)
1603 }
1604 }
1605}
1606
1607func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1608
1609 // This test verifies that using the exclude_from_vendor_snapshot
1610 // property on a module in a vendor proprietary path generates an
1611 // error. These modules are already excluded, so we prohibit using the
1612 // property in this way, which could add to confusion.
1613
1614 vendorProprietaryBp := `
1615 cc_library_shared {
1616 name: "libvendor",
1617 srcs: ["vendor.cpp"],
1618 vendor: true,
1619 exclude_from_vendor_snapshot: true,
1620 }
1621 `
1622
1623 depsBp := GatherRequiredDepsForTest(android.Android)
1624
1625 mockFS := map[string][]byte{
1626 "deps/Android.bp": []byte(depsBp),
1627 "device/Android.bp": []byte(vendorProprietaryBp),
1628 "device/vendor.cpp": nil,
1629 }
1630
1631 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1632 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1633 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001634 ctx := CreateTestContext(config)
1635 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001636
1637 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1638 android.FailIfErrored(t, errs)
1639
1640 _, errs = ctx.PrepareBuildActions(config)
1641 android.CheckErrorsAgainstExpectations(t, errs, []string{
1642 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1643 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
Jose Galmesf7294582020-11-13 12:07:36 -08001644 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1645 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
Bill Peckham945441c2020-08-31 16:07:58 -07001646 })
1647}
1648
1649func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) {
1650
1651 // This test verifies that using the exclude_from_vendor_snapshot
1652 // property on a module that is vendor available generates an error. A
1653 // vendor available module must be captured in the vendor snapshot and
1654 // must not built from source when building the vendor image against
1655 // the vendor snapshot.
1656
1657 frameworkBp := `
1658 cc_library_shared {
1659 name: "libinclude",
1660 srcs: ["src/include.cpp"],
1661 vendor_available: true,
1662 exclude_from_vendor_snapshot: true,
1663 }
1664 `
1665
1666 depsBp := GatherRequiredDepsForTest(android.Android)
1667
1668 mockFS := map[string][]byte{
1669 "deps/Android.bp": []byte(depsBp),
1670 "framework/Android.bp": []byte(frameworkBp),
1671 "framework/include.cpp": nil,
1672 }
1673
1674 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1675 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1676 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001677 ctx := CreateTestContext(config)
1678 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001679
1680 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"})
1681 android.FailIfErrored(t, errs)
1682
1683 _, errs = ctx.PrepareBuildActions(config)
1684 android.CheckErrorsAgainstExpectations(t, errs, []string{
1685 `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1686 `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1687 `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1688 `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1689 })
1690}
1691
Jose Galmesf7294582020-11-13 12:07:36 -08001692func TestRecoverySnapshotCapture(t *testing.T) {
1693 bp := `
1694 cc_library {
1695 name: "libvndk",
1696 vendor_available: true,
1697 recovery_available: true,
1698 product_available: true,
1699 vndk: {
1700 enabled: true,
1701 },
1702 nocrt: true,
1703 }
1704
1705 cc_library {
1706 name: "librecovery",
1707 recovery: true,
1708 nocrt: true,
1709 }
1710
1711 cc_library {
1712 name: "librecovery_available",
1713 recovery_available: true,
1714 nocrt: true,
1715 }
1716
1717 cc_library_headers {
1718 name: "librecovery_headers",
1719 recovery_available: true,
1720 nocrt: true,
1721 }
1722
1723 cc_binary {
1724 name: "recovery_bin",
1725 recovery: true,
1726 nocrt: true,
1727 }
1728
1729 cc_binary {
1730 name: "recovery_available_bin",
1731 recovery_available: true,
1732 nocrt: true,
1733 }
1734
1735 toolchain_library {
1736 name: "libb",
1737 recovery_available: true,
1738 src: "libb.a",
1739 }
1740
1741 cc_object {
1742 name: "obj",
1743 recovery_available: true,
1744 }
1745`
1746 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1747 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1748 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1749 ctx := testCcWithConfig(t, config)
1750
1751 // Check Recovery snapshot output.
1752
1753 snapshotDir := "recovery-snapshot"
1754 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1755 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1756
1757 var jsonFiles []string
1758
1759 for _, arch := range [][]string{
1760 []string{"arm64", "armv8-a"},
1761 } {
1762 archType := arch[0]
1763 archVariant := arch[1]
1764 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1765
1766 // For shared libraries, only recovery_available modules are captured.
1767 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1768 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1769 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1770 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1771 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1772 jsonFiles = append(jsonFiles,
1773 filepath.Join(sharedDir, "libvndk.so.json"),
1774 filepath.Join(sharedDir, "librecovery.so.json"),
1775 filepath.Join(sharedDir, "librecovery_available.so.json"))
1776
1777 // For static libraries, all recovery:true and recovery_available modules are captured.
1778 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1779 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1780 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1781 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1782 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1783 jsonFiles = append(jsonFiles,
1784 filepath.Join(staticDir, "libb.a.json"),
1785 filepath.Join(staticDir, "librecovery.a.json"),
1786 filepath.Join(staticDir, "librecovery_available.a.json"))
1787
1788 // For binary executables, all recovery:true and recovery_available modules are captured.
1789 if archType == "arm64" {
1790 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1791 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1792 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1793 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1794 jsonFiles = append(jsonFiles,
1795 filepath.Join(binaryDir, "recovery_bin.json"),
1796 filepath.Join(binaryDir, "recovery_available_bin.json"))
1797 }
1798
1799 // For header libraries, all vendor:true and vendor_available modules are captured.
1800 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1801 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1802
1803 // For object modules, all vendor:true and vendor_available modules are captured.
1804 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1805 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1806 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1807 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1808 }
1809
1810 for _, jsonFile := range jsonFiles {
1811 // verify all json files exist
1812 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1813 t.Errorf("%q expected but not found", jsonFile)
1814 }
1815 }
1816}
1817
Jooyung Hana70f0672019-01-18 15:20:43 +09001818func TestDoubleLoadableDepError(t *testing.T) {
1819 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1820 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1821 cc_library {
1822 name: "libllndk",
1823 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001824 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001825 }
1826
1827 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001828 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001829 symbol_file: "",
1830 }
1831
1832 cc_library {
1833 name: "libnondoubleloadable",
1834 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001835 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001836 vndk: {
1837 enabled: true,
1838 },
1839 }
1840 `)
1841
1842 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1843 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1844 cc_library {
1845 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001846 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001847 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001848 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001849 }
1850
1851 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001852 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001853 symbol_file: "",
1854 }
1855
1856 cc_library {
1857 name: "libnondoubleloadable",
1858 vendor_available: true,
1859 }
1860 `)
1861
1862 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
1863 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1864 cc_library {
1865 name: "libdoubleloadable",
1866 vendor_available: true,
1867 double_loadable: true,
1868 shared_libs: ["libnondoubleloadable"],
1869 }
1870
1871 cc_library {
1872 name: "libnondoubleloadable",
1873 vendor_available: true,
1874 }
1875 `)
1876
1877 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
1878 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1879 cc_library {
1880 name: "libdoubleloadable",
1881 vendor_available: true,
1882 double_loadable: true,
1883 shared_libs: ["libnondoubleloadable"],
1884 }
1885
1886 cc_library {
1887 name: "libnondoubleloadable",
1888 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001889 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001890 vndk: {
1891 enabled: true,
1892 },
1893 }
1894 `)
1895
1896 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
1897 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1898 cc_library {
1899 name: "libdoubleloadable",
1900 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001901 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001902 vndk: {
1903 enabled: true,
1904 },
1905 double_loadable: true,
1906 shared_libs: ["libnondoubleloadable"],
1907 }
1908
1909 cc_library {
1910 name: "libnondoubleloadable",
1911 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09001912 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +09001913 vndk: {
1914 enabled: true,
1915 },
1916 }
1917 `)
1918
1919 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1920 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1921 cc_library {
1922 name: "libllndk",
1923 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001924 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001925 }
1926
1927 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001928 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001929 symbol_file: "",
1930 }
1931
1932 cc_library {
1933 name: "libcoreonly",
1934 shared_libs: ["libvendoravailable"],
1935 }
1936
1937 // indirect dependency of LLNDK
1938 cc_library {
1939 name: "libvendoravailable",
1940 vendor_available: true,
1941 }
1942 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001943}
1944
Jooyung Han479ca172020-10-19 18:51:07 +09001945func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1946 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1947 cc_library {
1948 name: "libvndksp",
1949 shared_libs: ["libanothervndksp"],
1950 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001951 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001952 vndk: {
1953 enabled: true,
1954 support_system_process: true,
1955 }
1956 }
1957
1958 cc_library {
1959 name: "libllndk",
1960 shared_libs: ["libanothervndksp"],
1961 }
1962
1963 llndk_library {
1964 name: "libllndk",
1965 symbol_file: "",
1966 }
1967
1968 cc_library {
1969 name: "libanothervndksp",
1970 vendor_available: true,
1971 }
1972 `)
1973}
1974
Logan Chienf3511742017-10-31 18:04:35 +08001975func TestVndkExt(t *testing.T) {
1976 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001977 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001978 cc_library {
1979 name: "libvndk",
1980 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001981 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001982 vndk: {
1983 enabled: true,
1984 },
1985 nocrt: true,
1986 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001987 cc_library {
1988 name: "libvndk2",
1989 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001990 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001991 vndk: {
1992 enabled: true,
1993 },
1994 target: {
1995 vendor: {
1996 suffix: "-suffix",
1997 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001998 product: {
1999 suffix: "-suffix",
2000 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09002001 },
2002 nocrt: true,
2003 }
Logan Chienf3511742017-10-31 18:04:35 +08002004
2005 cc_library {
2006 name: "libvndk_ext",
2007 vendor: true,
2008 vndk: {
2009 enabled: true,
2010 extends: "libvndk",
2011 },
2012 nocrt: true,
2013 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002014
2015 cc_library {
2016 name: "libvndk2_ext",
2017 vendor: true,
2018 vndk: {
2019 enabled: true,
2020 extends: "libvndk2",
2021 },
2022 nocrt: true,
2023 }
Logan Chienf3511742017-10-31 18:04:35 +08002024
Justin Yun0ecf0b22020-02-28 15:07:59 +09002025 cc_library {
2026 name: "libvndk_ext_product",
2027 product_specific: true,
2028 vndk: {
2029 enabled: true,
2030 extends: "libvndk",
2031 },
2032 nocrt: true,
2033 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002034
Justin Yun0ecf0b22020-02-28 15:07:59 +09002035 cc_library {
2036 name: "libvndk2_ext_product",
2037 product_specific: true,
2038 vndk: {
2039 enabled: true,
2040 extends: "libvndk2",
2041 },
2042 nocrt: true,
2043 }
2044 `
2045 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2046 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2047 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2048 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2049
2050 ctx := testCcWithConfig(t, config)
2051
2052 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
2053 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
2054
2055 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
2056 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
2057
2058 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
2059 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08002060}
2061
Logan Chiend3c59a22018-03-29 14:08:15 +08002062func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08002063 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
2064 ctx := testCcNoVndk(t, `
2065 cc_library {
2066 name: "libvndk",
2067 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002068 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002069 vndk: {
2070 enabled: true,
2071 },
2072 nocrt: true,
2073 }
2074
2075 cc_library {
2076 name: "libvndk_ext",
2077 vendor: true,
2078 vndk: {
2079 enabled: true,
2080 extends: "libvndk",
2081 },
2082 nocrt: true,
2083 }
2084 `)
2085
2086 // Ensures that the core variant of "libvndk_ext" can be found.
2087 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
2088 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2089 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
2090 }
2091}
2092
Justin Yun0ecf0b22020-02-28 15:07:59 +09002093func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
2094 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
2095 ctx := testCc(t, `
2096 cc_library {
2097 name: "libvndk",
2098 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002099 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002100 vndk: {
2101 enabled: true,
2102 },
2103 nocrt: true,
2104 }
2105
2106 cc_library {
2107 name: "libvndk_ext_product",
2108 product_specific: true,
2109 vndk: {
2110 enabled: true,
2111 extends: "libvndk",
2112 },
2113 nocrt: true,
2114 }
2115 `)
2116
2117 // Ensures that the core variant of "libvndk_ext_product" can be found.
2118 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
2119 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2120 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
2121 }
2122}
2123
Logan Chienf3511742017-10-31 18:04:35 +08002124func TestVndkExtError(t *testing.T) {
2125 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002126 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08002127 cc_library {
2128 name: "libvndk",
2129 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002130 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002131 vndk: {
2132 enabled: true,
2133 },
2134 nocrt: true,
2135 }
2136
2137 cc_library {
2138 name: "libvndk_ext",
2139 vndk: {
2140 enabled: true,
2141 extends: "libvndk",
2142 },
2143 nocrt: true,
2144 }
2145 `)
2146
2147 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2148 cc_library {
2149 name: "libvndk",
2150 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002151 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002152 vndk: {
2153 enabled: true,
2154 },
2155 nocrt: true,
2156 }
2157
2158 cc_library {
2159 name: "libvndk_ext",
2160 vendor: true,
2161 vndk: {
2162 enabled: true,
2163 },
2164 nocrt: true,
2165 }
2166 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002167
2168 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2169 cc_library {
2170 name: "libvndk",
2171 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002172 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002173 vndk: {
2174 enabled: true,
2175 },
2176 nocrt: true,
2177 }
2178
2179 cc_library {
2180 name: "libvndk_ext_product",
2181 product_specific: true,
2182 vndk: {
2183 enabled: true,
2184 },
2185 nocrt: true,
2186 }
2187 `)
2188
2189 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
2190 cc_library {
2191 name: "libvndk",
2192 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002193 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002194 vndk: {
2195 enabled: true,
2196 },
2197 nocrt: true,
2198 }
2199
2200 cc_library {
2201 name: "libvndk_ext_product",
2202 product_specific: true,
2203 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002204 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002205 vndk: {
2206 enabled: true,
2207 extends: "libvndk",
2208 },
2209 nocrt: true,
2210 }
2211 `)
Logan Chienf3511742017-10-31 18:04:35 +08002212}
2213
2214func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
2215 // This test ensures an error is emitted for inconsistent support_system_process.
2216 testCcError(t, "module \".*\" with mismatched support_system_process", `
2217 cc_library {
2218 name: "libvndk",
2219 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002220 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002221 vndk: {
2222 enabled: true,
2223 },
2224 nocrt: true,
2225 }
2226
2227 cc_library {
2228 name: "libvndk_sp_ext",
2229 vendor: true,
2230 vndk: {
2231 enabled: true,
2232 extends: "libvndk",
2233 support_system_process: true,
2234 },
2235 nocrt: true,
2236 }
2237 `)
2238
2239 testCcError(t, "module \".*\" with mismatched support_system_process", `
2240 cc_library {
2241 name: "libvndk_sp",
2242 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002243 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002244 vndk: {
2245 enabled: true,
2246 support_system_process: true,
2247 },
2248 nocrt: true,
2249 }
2250
2251 cc_library {
2252 name: "libvndk_ext",
2253 vendor: true,
2254 vndk: {
2255 enabled: true,
2256 extends: "libvndk_sp",
2257 },
2258 nocrt: true,
2259 }
2260 `)
2261}
2262
2263func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08002264 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +08002265 // with `vendor_available: false`.
2266 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
2267 cc_library {
2268 name: "libvndk",
2269 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002270 product_available: false,
Logan Chienf3511742017-10-31 18:04:35 +08002271 vndk: {
2272 enabled: true,
2273 },
2274 nocrt: true,
2275 }
2276
2277 cc_library {
2278 name: "libvndk_ext",
2279 vendor: true,
2280 vndk: {
2281 enabled: true,
2282 extends: "libvndk",
2283 },
2284 nocrt: true,
2285 }
2286 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002287
Justin Yun6977e8a2020-10-29 18:24:11 +09002288 testCcErrorProductVndk(t, "`extends` refers module \".*\" which does not have `product_available: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002289 cc_library {
2290 name: "libvndk",
2291 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002292 product_available: false,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002293 vndk: {
2294 enabled: true,
2295 },
2296 nocrt: true,
2297 }
2298
2299 cc_library {
2300 name: "libvndk_ext_product",
2301 product_specific: true,
2302 vndk: {
2303 enabled: true,
2304 extends: "libvndk",
2305 },
2306 nocrt: true,
2307 }
2308 `)
Logan Chienf3511742017-10-31 18:04:35 +08002309}
2310
Logan Chiend3c59a22018-03-29 14:08:15 +08002311func TestVendorModuleUseVndkExt(t *testing.T) {
2312 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002313 testCc(t, `
2314 cc_library {
2315 name: "libvndk",
2316 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002317 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002318 vndk: {
2319 enabled: true,
2320 },
2321 nocrt: true,
2322 }
2323
2324 cc_library {
2325 name: "libvndk_ext",
2326 vendor: true,
2327 vndk: {
2328 enabled: true,
2329 extends: "libvndk",
2330 },
2331 nocrt: true,
2332 }
2333
2334 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08002335 name: "libvndk_sp",
2336 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002337 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002338 vndk: {
2339 enabled: true,
2340 support_system_process: true,
2341 },
2342 nocrt: true,
2343 }
2344
2345 cc_library {
2346 name: "libvndk_sp_ext",
2347 vendor: true,
2348 vndk: {
2349 enabled: true,
2350 extends: "libvndk_sp",
2351 support_system_process: true,
2352 },
2353 nocrt: true,
2354 }
2355
2356 cc_library {
2357 name: "libvendor",
2358 vendor: true,
2359 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
2360 nocrt: true,
2361 }
2362 `)
2363}
2364
Logan Chiend3c59a22018-03-29 14:08:15 +08002365func TestVndkExtUseVendorLib(t *testing.T) {
2366 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08002367 testCc(t, `
2368 cc_library {
2369 name: "libvndk",
2370 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002371 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002372 vndk: {
2373 enabled: true,
2374 },
2375 nocrt: true,
2376 }
2377
2378 cc_library {
2379 name: "libvndk_ext",
2380 vendor: true,
2381 vndk: {
2382 enabled: true,
2383 extends: "libvndk",
2384 },
2385 shared_libs: ["libvendor"],
2386 nocrt: true,
2387 }
2388
2389 cc_library {
2390 name: "libvendor",
2391 vendor: true,
2392 nocrt: true,
2393 }
2394 `)
Logan Chienf3511742017-10-31 18:04:35 +08002395
Logan Chiend3c59a22018-03-29 14:08:15 +08002396 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
2397 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08002398 cc_library {
2399 name: "libvndk_sp",
2400 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002401 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002402 vndk: {
2403 enabled: true,
2404 support_system_process: true,
2405 },
2406 nocrt: true,
2407 }
2408
2409 cc_library {
2410 name: "libvndk_sp_ext",
2411 vendor: true,
2412 vndk: {
2413 enabled: true,
2414 extends: "libvndk_sp",
2415 support_system_process: true,
2416 },
2417 shared_libs: ["libvendor"], // Cause an error
2418 nocrt: true,
2419 }
2420
2421 cc_library {
2422 name: "libvendor",
2423 vendor: true,
2424 nocrt: true,
2425 }
2426 `)
2427}
2428
Justin Yun0ecf0b22020-02-28 15:07:59 +09002429func TestProductVndkExtDependency(t *testing.T) {
2430 bp := `
2431 cc_library {
2432 name: "libvndk",
2433 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002434 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002435 vndk: {
2436 enabled: true,
2437 },
2438 nocrt: true,
2439 }
2440
2441 cc_library {
2442 name: "libvndk_ext_product",
2443 product_specific: true,
2444 vndk: {
2445 enabled: true,
2446 extends: "libvndk",
2447 },
2448 shared_libs: ["libproduct_for_vndklibs"],
2449 nocrt: true,
2450 }
2451
2452 cc_library {
2453 name: "libvndk_sp",
2454 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002455 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002456 vndk: {
2457 enabled: true,
2458 support_system_process: true,
2459 },
2460 nocrt: true,
2461 }
2462
2463 cc_library {
2464 name: "libvndk_sp_ext_product",
2465 product_specific: true,
2466 vndk: {
2467 enabled: true,
2468 extends: "libvndk_sp",
2469 support_system_process: true,
2470 },
2471 shared_libs: ["libproduct_for_vndklibs"],
2472 nocrt: true,
2473 }
2474
2475 cc_library {
2476 name: "libproduct",
2477 product_specific: true,
2478 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
2479 nocrt: true,
2480 }
2481
2482 cc_library {
2483 name: "libproduct_for_vndklibs",
2484 product_specific: true,
2485 nocrt: true,
2486 }
2487 `
2488 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2489 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2490 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2491 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2492
2493 testCcWithConfig(t, config)
2494}
2495
Logan Chiend3c59a22018-03-29 14:08:15 +08002496func TestVndkSpExtUseVndkError(t *testing.T) {
2497 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
2498 // library.
2499 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2500 cc_library {
2501 name: "libvndk",
2502 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002503 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002504 vndk: {
2505 enabled: true,
2506 },
2507 nocrt: true,
2508 }
2509
2510 cc_library {
2511 name: "libvndk_sp",
2512 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002513 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002514 vndk: {
2515 enabled: true,
2516 support_system_process: true,
2517 },
2518 nocrt: true,
2519 }
2520
2521 cc_library {
2522 name: "libvndk_sp_ext",
2523 vendor: true,
2524 vndk: {
2525 enabled: true,
2526 extends: "libvndk_sp",
2527 support_system_process: true,
2528 },
2529 shared_libs: ["libvndk"], // Cause an error
2530 nocrt: true,
2531 }
2532 `)
2533
2534 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
2535 // library.
2536 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2537 cc_library {
2538 name: "libvndk",
2539 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002540 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002541 vndk: {
2542 enabled: true,
2543 },
2544 nocrt: true,
2545 }
2546
2547 cc_library {
2548 name: "libvndk_ext",
2549 vendor: true,
2550 vndk: {
2551 enabled: true,
2552 extends: "libvndk",
2553 },
2554 nocrt: true,
2555 }
2556
2557 cc_library {
2558 name: "libvndk_sp",
2559 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002560 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002561 vndk: {
2562 enabled: true,
2563 support_system_process: true,
2564 },
2565 nocrt: true,
2566 }
2567
2568 cc_library {
2569 name: "libvndk_sp_ext",
2570 vendor: true,
2571 vndk: {
2572 enabled: true,
2573 extends: "libvndk_sp",
2574 support_system_process: true,
2575 },
2576 shared_libs: ["libvndk_ext"], // Cause an error
2577 nocrt: true,
2578 }
2579 `)
2580}
2581
2582func TestVndkUseVndkExtError(t *testing.T) {
2583 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
2584 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002585 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2586 cc_library {
2587 name: "libvndk",
2588 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002589 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002590 vndk: {
2591 enabled: true,
2592 },
2593 nocrt: true,
2594 }
2595
2596 cc_library {
2597 name: "libvndk_ext",
2598 vendor: true,
2599 vndk: {
2600 enabled: true,
2601 extends: "libvndk",
2602 },
2603 nocrt: true,
2604 }
2605
2606 cc_library {
2607 name: "libvndk2",
2608 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002609 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002610 vndk: {
2611 enabled: true,
2612 },
2613 shared_libs: ["libvndk_ext"],
2614 nocrt: true,
2615 }
2616 `)
2617
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002618 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002619 cc_library {
2620 name: "libvndk",
2621 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002622 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002623 vndk: {
2624 enabled: true,
2625 },
2626 nocrt: true,
2627 }
2628
2629 cc_library {
2630 name: "libvndk_ext",
2631 vendor: true,
2632 vndk: {
2633 enabled: true,
2634 extends: "libvndk",
2635 },
2636 nocrt: true,
2637 }
2638
2639 cc_library {
2640 name: "libvndk2",
2641 vendor_available: true,
2642 vndk: {
2643 enabled: true,
2644 },
2645 target: {
2646 vendor: {
2647 shared_libs: ["libvndk_ext"],
2648 },
2649 },
2650 nocrt: true,
2651 }
2652 `)
2653
2654 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2655 cc_library {
2656 name: "libvndk_sp",
2657 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002658 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002659 vndk: {
2660 enabled: true,
2661 support_system_process: true,
2662 },
2663 nocrt: true,
2664 }
2665
2666 cc_library {
2667 name: "libvndk_sp_ext",
2668 vendor: true,
2669 vndk: {
2670 enabled: true,
2671 extends: "libvndk_sp",
2672 support_system_process: true,
2673 },
2674 nocrt: true,
2675 }
2676
2677 cc_library {
2678 name: "libvndk_sp_2",
2679 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002680 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002681 vndk: {
2682 enabled: true,
2683 support_system_process: true,
2684 },
2685 shared_libs: ["libvndk_sp_ext"],
2686 nocrt: true,
2687 }
2688 `)
2689
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002690 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002691 cc_library {
2692 name: "libvndk_sp",
2693 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002694 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002695 vndk: {
2696 enabled: true,
2697 },
2698 nocrt: true,
2699 }
2700
2701 cc_library {
2702 name: "libvndk_sp_ext",
2703 vendor: true,
2704 vndk: {
2705 enabled: true,
2706 extends: "libvndk_sp",
2707 },
2708 nocrt: true,
2709 }
2710
2711 cc_library {
2712 name: "libvndk_sp2",
2713 vendor_available: true,
2714 vndk: {
2715 enabled: true,
2716 },
2717 target: {
2718 vendor: {
2719 shared_libs: ["libvndk_sp_ext"],
2720 },
2721 },
2722 nocrt: true,
2723 }
2724 `)
2725}
2726
Justin Yun5f7f7e82019-11-18 19:52:14 +09002727func TestEnforceProductVndkVersion(t *testing.T) {
2728 bp := `
2729 cc_library {
2730 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002731 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002732 }
2733 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002734 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002735 symbol_file: "",
2736 }
2737 cc_library {
2738 name: "libvndk",
2739 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002740 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002741 vndk: {
2742 enabled: true,
2743 },
2744 nocrt: true,
2745 }
2746 cc_library {
2747 name: "libvndk_sp",
2748 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002749 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002750 vndk: {
2751 enabled: true,
2752 support_system_process: true,
2753 },
2754 nocrt: true,
2755 }
2756 cc_library {
2757 name: "libva",
2758 vendor_available: true,
2759 nocrt: true,
2760 }
2761 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002762 name: "libpa",
2763 product_available: true,
2764 nocrt: true,
2765 }
2766 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002767 name: "libboth_available",
2768 vendor_available: true,
2769 product_available: true,
2770 nocrt: true,
2771 target: {
2772 vendor: {
2773 suffix: "-vendor",
2774 },
2775 product: {
2776 suffix: "-product",
2777 },
2778 }
2779 }
2780 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002781 name: "libproduct_va",
2782 product_specific: true,
2783 vendor_available: true,
2784 nocrt: true,
2785 }
2786 cc_library {
2787 name: "libprod",
2788 product_specific: true,
2789 shared_libs: [
2790 "libllndk",
2791 "libvndk",
2792 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002793 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002794 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002795 "libproduct_va",
2796 ],
2797 nocrt: true,
2798 }
2799 cc_library {
2800 name: "libvendor",
2801 vendor: true,
2802 shared_libs: [
2803 "libllndk",
2804 "libvndk",
2805 "libvndk_sp",
2806 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002807 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002808 "libproduct_va",
2809 ],
2810 nocrt: true,
2811 }
2812 `
2813
2814 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2815 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2816 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2817 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2818
2819 ctx := testCcWithConfig(t, config)
2820
Jooyung Han261e1582020-10-20 18:54:21 +09002821 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2822 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002823
2824 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2825 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2826
2827 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2828 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002829}
2830
2831func TestEnforceProductVndkVersionErrors(t *testing.T) {
2832 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2833 cc_library {
2834 name: "libprod",
2835 product_specific: true,
2836 shared_libs: [
2837 "libvendor",
2838 ],
2839 nocrt: true,
2840 }
2841 cc_library {
2842 name: "libvendor",
2843 vendor: true,
2844 nocrt: true,
2845 }
2846 `)
2847 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2848 cc_library {
2849 name: "libprod",
2850 product_specific: true,
2851 shared_libs: [
2852 "libsystem",
2853 ],
2854 nocrt: true,
2855 }
2856 cc_library {
2857 name: "libsystem",
2858 nocrt: true,
2859 }
2860 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002861 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2862 cc_library {
2863 name: "libprod",
2864 product_specific: true,
2865 shared_libs: [
2866 "libva",
2867 ],
2868 nocrt: true,
2869 }
2870 cc_library {
2871 name: "libva",
2872 vendor_available: true,
2873 nocrt: true,
2874 }
2875 `)
2876 testCcErrorProductVndk(t, "product module that is not VNDK should not link to \".*\" which is marked as `product_available: false`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002877 cc_library {
2878 name: "libprod",
2879 product_specific: true,
2880 shared_libs: [
2881 "libvndk_private",
2882 ],
2883 nocrt: true,
2884 }
2885 cc_library {
2886 name: "libvndk_private",
2887 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002888 product_available: false,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002889 vndk: {
2890 enabled: true,
2891 },
2892 nocrt: true,
2893 }
2894 `)
2895 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2896 cc_library {
2897 name: "libprod",
2898 product_specific: true,
2899 shared_libs: [
2900 "libsystem_ext",
2901 ],
2902 nocrt: true,
2903 }
2904 cc_library {
2905 name: "libsystem_ext",
2906 system_ext_specific: true,
2907 nocrt: true,
2908 }
2909 `)
2910 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2911 cc_library {
2912 name: "libsystem",
2913 shared_libs: [
2914 "libproduct_va",
2915 ],
2916 nocrt: true,
2917 }
2918 cc_library {
2919 name: "libproduct_va",
2920 product_specific: true,
2921 vendor_available: true,
2922 nocrt: true,
2923 }
2924 `)
2925}
2926
Jooyung Han38002912019-05-16 04:01:54 +09002927func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002928 bp := `
2929 cc_library {
2930 name: "libvndk",
2931 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002932 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002933 vndk: {
2934 enabled: true,
2935 },
2936 }
2937 cc_library {
2938 name: "libvndksp",
2939 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002940 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002941 vndk: {
2942 enabled: true,
2943 support_system_process: true,
2944 },
2945 }
2946 cc_library {
2947 name: "libvndkprivate",
2948 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002949 product_available: false,
Colin Cross98be1bb2019-12-13 20:41:13 -08002950 vndk: {
2951 enabled: true,
2952 },
2953 }
2954 cc_library {
2955 name: "libvendor",
2956 vendor: true,
2957 }
2958 cc_library {
2959 name: "libvndkext",
2960 vendor: true,
2961 vndk: {
2962 enabled: true,
2963 extends: "libvndk",
2964 },
2965 }
2966 vndk_prebuilt_shared {
2967 name: "prevndk",
2968 version: "27",
2969 target_arch: "arm",
2970 binder32bit: true,
2971 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002972 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002973 vndk: {
2974 enabled: true,
2975 },
2976 arch: {
2977 arm: {
2978 srcs: ["liba.so"],
2979 },
2980 },
2981 }
2982 cc_library {
2983 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002984 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002985 }
2986 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002987 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002988 symbol_file: "",
2989 }
2990 cc_library {
2991 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002992 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002993 }
2994 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002995 name: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002996 vendor_available: false,
2997 symbol_file: "",
2998 }`
2999
3000 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09003001 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3002 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3003 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08003004 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09003005
Jooyung Han0302a842019-10-30 18:43:49 +09003006 assertMapKeys(t, vndkCoreLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09003007 []string{"libvndk", "libvndkprivate"})
Jooyung Han0302a842019-10-30 18:43:49 +09003008 assertMapKeys(t, vndkSpLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09003009 []string{"libc++", "libvndksp"})
Jooyung Han0302a842019-10-30 18:43:49 +09003010 assertMapKeys(t, llndkLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09003011 []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"})
Jooyung Han0302a842019-10-30 18:43:49 +09003012 assertMapKeys(t, vndkPrivateLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09003013 []string{"libft2", "libllndkprivate", "libvndkprivate"})
Jooyung Han38002912019-05-16 04:01:54 +09003014
Colin Crossfb0c16e2019-11-20 17:12:35 -08003015 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09003016
Jooyung Han38002912019-05-16 04:01:54 +09003017 tests := []struct {
3018 variant string
3019 name string
3020 expected string
3021 }{
3022 {vendorVariant, "libvndk", "native:vndk"},
3023 {vendorVariant, "libvndksp", "native:vndk"},
3024 {vendorVariant, "libvndkprivate", "native:vndk_private"},
3025 {vendorVariant, "libvendor", "native:vendor"},
3026 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08003027 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09003028 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09003029 {coreVariant, "libvndk", "native:platform"},
3030 {coreVariant, "libvndkprivate", "native:platform"},
3031 {coreVariant, "libllndk", "native:platform"},
3032 }
3033 for _, test := range tests {
3034 t.Run(test.name, func(t *testing.T) {
3035 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
3036 assertString(t, module.makeLinkType, test.expected)
3037 })
3038 }
3039}
3040
Jeff Gaston294356f2017-09-27 17:05:30 -07003041var staticLinkDepOrderTestCases = []struct {
3042 // This is a string representation of a map[moduleName][]moduleDependency .
3043 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003044 inStatic string
3045
3046 // This is a string representation of a map[moduleName][]moduleDependency .
3047 // It models the dependencies declared in an Android.bp file.
3048 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07003049
3050 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
3051 // The keys of allOrdered specify which modules we would like to check.
3052 // The values of allOrdered specify the expected result (of the transitive closure of all
3053 // dependencies) for each module to test
3054 allOrdered string
3055
3056 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
3057 // The keys of outOrdered specify which modules we would like to check.
3058 // The values of outOrdered specify the expected result (of the ordered linker command line)
3059 // for each module to test.
3060 outOrdered string
3061}{
3062 // Simple tests
3063 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003064 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07003065 outOrdered: "",
3066 },
3067 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003068 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003069 outOrdered: "a:",
3070 },
3071 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003072 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003073 outOrdered: "a:b; b:",
3074 },
3075 // Tests of reordering
3076 {
3077 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003078 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003079 outOrdered: "a:b,c,d; b:d; c:d; d:",
3080 },
3081 {
3082 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003083 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003084 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
3085 },
3086 {
3087 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003088 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07003089 outOrdered: "a:d,b,e,c; d:b; e:c",
3090 },
3091 {
3092 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003093 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07003094 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
3095 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
3096 },
3097 {
3098 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003099 inStatic: "a:b,c,d,e,f,g,h; f:b,c,d; b:c,d; c:d",
Jeff Gaston294356f2017-09-27 17:05:30 -07003100 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3101 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3102 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003103 // shared dependencies
3104 {
3105 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
3106 // So, we don't actually have to check that a shared dependency of c will change the order
3107 // of a library that depends statically on b and on c. We only need to check that if c has
3108 // a shared dependency on b, that that shows up in allOrdered.
3109 inShared: "c:b",
3110 allOrdered: "c:b",
3111 outOrdered: "c:",
3112 },
3113 {
3114 // This test doesn't actually include any shared dependencies but it's a reminder of what
3115 // the second phase of the above test would look like
3116 inStatic: "a:b,c; c:b",
3117 allOrdered: "a:c,b; c:b",
3118 outOrdered: "a:c,b; c:b",
3119 },
Jeff Gaston294356f2017-09-27 17:05:30 -07003120 // tiebreakers for when two modules specifying different orderings and there is no dependency
3121 // to dictate an order
3122 {
3123 // if the tie is between two modules at the end of a's deps, then a's order wins
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003124 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07003125 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
3126 },
3127 {
3128 // if the tie is between two modules at the start of a's deps, then c's order is used
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003129 inStatic: "a1:d,e,b1,c1; b1:d,e; c1:e,d; a2:d,e,b2,c2; b2:d,e; c2:d,e",
Jeff Gaston294356f2017-09-27 17:05:30 -07003130 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
3131 },
3132 // Tests involving duplicate dependencies
3133 {
3134 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003135 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003136 outOrdered: "a:c,b",
3137 },
3138 {
3139 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003140 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003141 outOrdered: "a:d,c,b",
3142 },
3143 // Tests to confirm the nonexistence of infinite loops.
3144 // These cases should never happen, so as long as the test terminates and the
3145 // result is deterministic then that should be fine.
3146 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003147 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003148 outOrdered: "a:a",
3149 },
3150 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003151 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003152 allOrdered: "a:b,c; b:c,a; c:a,b",
3153 outOrdered: "a:b; b:c; c:a",
3154 },
3155 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003156 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003157 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
3158 outOrdered: "a:c,b; b:a,c; c:b,a",
3159 },
3160}
3161
3162// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
3163func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
3164 // convert from "a:b,c; d:e" to "a:b,c;d:e"
3165 strippedText := strings.Replace(text, " ", "", -1)
3166 if len(strippedText) < 1 {
3167 return []android.Path{}, make(map[android.Path][]android.Path, 0)
3168 }
3169 allDeps = make(map[android.Path][]android.Path, 0)
3170
3171 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
3172 moduleTexts := strings.Split(strippedText, ";")
3173
3174 outputForModuleName := func(moduleName string) android.Path {
3175 return android.PathForTesting(moduleName)
3176 }
3177
3178 for _, moduleText := range moduleTexts {
3179 // convert from "a:b,c" to ["a", "b,c"]
3180 components := strings.Split(moduleText, ":")
3181 if len(components) != 2 {
3182 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
3183 }
3184 moduleName := components[0]
3185 moduleOutput := outputForModuleName(moduleName)
3186 modulesInOrder = append(modulesInOrder, moduleOutput)
3187
3188 depString := components[1]
3189 // convert from "b,c" to ["b", "c"]
3190 depNames := strings.Split(depString, ",")
3191 if len(depString) < 1 {
3192 depNames = []string{}
3193 }
3194 var deps []android.Path
3195 for _, depName := range depNames {
3196 deps = append(deps, outputForModuleName(depName))
3197 }
3198 allDeps[moduleOutput] = deps
3199 }
3200 return modulesInOrder, allDeps
3201}
3202
Jeff Gaston294356f2017-09-27 17:05:30 -07003203func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
3204 for _, moduleName := range moduleNames {
3205 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
3206 output := module.outputFile.Path()
3207 paths = append(paths, output)
3208 }
3209 return paths
3210}
3211
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003212func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07003213 ctx := testCc(t, `
3214 cc_library {
3215 name: "a",
3216 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09003217 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003218 }
3219 cc_library {
3220 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003221 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003222 }
3223 cc_library {
3224 name: "c",
3225 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003226 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003227 }
3228 cc_library {
3229 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09003230 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003231 }
3232
3233 `)
3234
Colin Cross7113d202019-11-20 16:39:12 -08003235 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07003236 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003237 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3238 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07003239
3240 if !reflect.DeepEqual(actual, expected) {
3241 t.Errorf("staticDeps orderings were not propagated correctly"+
3242 "\nactual: %v"+
3243 "\nexpected: %v",
3244 actual,
3245 expected,
3246 )
3247 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09003248}
Jeff Gaston294356f2017-09-27 17:05:30 -07003249
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003250func TestStaticLibDepReorderingWithShared(t *testing.T) {
3251 ctx := testCc(t, `
3252 cc_library {
3253 name: "a",
3254 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09003255 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003256 }
3257 cc_library {
3258 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003259 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003260 }
3261 cc_library {
3262 name: "c",
3263 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003264 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003265 }
3266
3267 `)
3268
Colin Cross7113d202019-11-20 16:39:12 -08003269 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003270 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003271 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3272 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003273
3274 if !reflect.DeepEqual(actual, expected) {
3275 t.Errorf("staticDeps orderings did not account for shared libs"+
3276 "\nactual: %v"+
3277 "\nexpected: %v",
3278 actual,
3279 expected,
3280 )
3281 }
3282}
3283
Jooyung Hanb04a4992020-03-13 18:57:35 +09003284func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07003285 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09003286 if !reflect.DeepEqual(actual, expected) {
3287 t.Errorf(message+
3288 "\nactual: %v"+
3289 "\nexpected: %v",
3290 actual,
3291 expected,
3292 )
3293 }
3294}
3295
Jooyung Han61b66e92020-03-21 14:21:46 +00003296func TestLlndkLibrary(t *testing.T) {
3297 ctx := testCc(t, `
3298 cc_library {
3299 name: "libllndk",
3300 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07003301 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003302 }
3303 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003304 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003305 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003306
3307 cc_prebuilt_library_shared {
3308 name: "libllndkprebuilt",
3309 stubs: { versions: ["1", "2"] },
3310 llndk_stubs: "libllndkprebuilt.llndk",
3311 }
3312 llndk_library {
3313 name: "libllndkprebuilt.llndk",
3314 }
3315
3316 cc_library {
3317 name: "libllndk_with_external_headers",
3318 stubs: { versions: ["1", "2"] },
3319 llndk_stubs: "libllndk_with_external_headers.llndk",
3320 header_libs: ["libexternal_headers"],
3321 export_header_lib_headers: ["libexternal_headers"],
3322 }
3323 llndk_library {
3324 name: "libllndk_with_external_headers.llndk",
3325 }
3326 cc_library_headers {
3327 name: "libexternal_headers",
3328 export_include_dirs: ["include"],
3329 vendor_available: true,
3330 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003331 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08003332 actual := ctx.ModuleVariantsForTests("libllndk")
3333 for i := 0; i < len(actual); i++ {
3334 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
3335 actual = append(actual[:i], actual[i+1:]...)
3336 i--
3337 }
3338 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003339 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00003340 "android_vendor.VER_arm64_armv8-a_shared_1",
3341 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003342 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003343 "android_vendor.VER_arm_armv7-a-neon_shared_1",
3344 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003345 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003346 }
3347 checkEquals(t, "variants for llndk stubs", expected, actual)
3348
Colin Cross127bb8b2020-12-16 16:46:01 -08003349 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003350 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
3351
Colin Cross127bb8b2020-12-16 16:46:01 -08003352 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003353 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
3354}
3355
Jiyong Parka46a4d52017-12-14 19:54:34 +09003356func TestLlndkHeaders(t *testing.T) {
3357 ctx := testCc(t, `
3358 llndk_headers {
3359 name: "libllndk_headers",
3360 export_include_dirs: ["my_include"],
3361 }
3362 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003363 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09003364 export_llndk_headers: ["libllndk_headers"],
3365 }
3366 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07003367 name: "libllndk",
3368 llndk_stubs: "libllndk.llndk",
3369 }
3370
3371 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09003372 name: "libvendor",
3373 shared_libs: ["libllndk"],
3374 vendor: true,
3375 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003376 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08003377 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09003378 }
3379 `)
3380
3381 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08003382 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09003383 cflags := cc.Args["cFlags"]
3384 if !strings.Contains(cflags, "-Imy_include") {
3385 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
3386 }
3387}
3388
Logan Chien43d34c32017-12-20 01:17:32 +08003389func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
3390 actual := module.Properties.AndroidMkRuntimeLibs
3391 if !reflect.DeepEqual(actual, expected) {
3392 t.Errorf("incorrect runtime_libs for shared libs"+
3393 "\nactual: %v"+
3394 "\nexpected: %v",
3395 actual,
3396 expected,
3397 )
3398 }
3399}
3400
3401const runtimeLibAndroidBp = `
3402 cc_library {
3403 name: "libvendor_available1",
3404 vendor_available: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003405 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003406 nocrt : true,
3407 system_shared_libs : [],
3408 }
3409 cc_library {
3410 name: "libvendor_available2",
3411 vendor_available: true,
3412 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003413 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003414 nocrt : true,
3415 system_shared_libs : [],
3416 }
3417 cc_library {
3418 name: "libvendor_available3",
3419 vendor_available: true,
3420 runtime_libs: ["libvendor_available1"],
3421 target: {
3422 vendor: {
3423 exclude_runtime_libs: ["libvendor_available1"],
3424 }
3425 },
Yi Konge7fe9912019-06-02 00:53:50 -07003426 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003427 nocrt : true,
3428 system_shared_libs : [],
3429 }
3430 cc_library {
3431 name: "libcore",
3432 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003433 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003434 nocrt : true,
3435 system_shared_libs : [],
3436 }
3437 cc_library {
3438 name: "libvendor1",
3439 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003440 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003441 nocrt : true,
3442 system_shared_libs : [],
3443 }
3444 cc_library {
3445 name: "libvendor2",
3446 vendor: true,
3447 runtime_libs: ["libvendor_available1", "libvendor1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003448 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003449 nocrt : true,
3450 system_shared_libs : [],
3451 }
3452`
3453
3454func TestRuntimeLibs(t *testing.T) {
3455 ctx := testCc(t, runtimeLibAndroidBp)
3456
3457 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08003458 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003459
3460 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3461 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3462
3463 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
3464 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3465
3466 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
3467 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08003468 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003469
3470 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3471 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
3472
3473 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
3474 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
3475}
3476
3477func TestExcludeRuntimeLibs(t *testing.T) {
3478 ctx := testCc(t, runtimeLibAndroidBp)
3479
Colin Cross7113d202019-11-20 16:39:12 -08003480 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003481 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
3482 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3483
Colin Crossfb0c16e2019-11-20 17:12:35 -08003484 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003485 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
3486 checkRuntimeLibs(t, nil, module)
3487}
3488
3489func TestRuntimeLibsNoVndk(t *testing.T) {
3490 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
3491
3492 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
3493
Colin Cross7113d202019-11-20 16:39:12 -08003494 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003495
3496 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3497 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3498
3499 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
3500 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
3501}
3502
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003503func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09003504 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003505 actual := module.Properties.AndroidMkStaticLibs
3506 if !reflect.DeepEqual(actual, expected) {
3507 t.Errorf("incorrect static_libs"+
3508 "\nactual: %v"+
3509 "\nexpected: %v",
3510 actual,
3511 expected,
3512 )
3513 }
3514}
3515
3516const staticLibAndroidBp = `
3517 cc_library {
3518 name: "lib1",
3519 }
3520 cc_library {
3521 name: "lib2",
3522 static_libs: ["lib1"],
3523 }
3524`
3525
3526func TestStaticLibDepExport(t *testing.T) {
3527 ctx := testCc(t, staticLibAndroidBp)
3528
3529 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003530 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003531 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003532 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003533
3534 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003535 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003536 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
3537 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003538 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003539}
3540
Jiyong Parkd08b6972017-09-26 10:50:54 +09003541var compilerFlagsTestCases = []struct {
3542 in string
3543 out bool
3544}{
3545 {
3546 in: "a",
3547 out: false,
3548 },
3549 {
3550 in: "-a",
3551 out: true,
3552 },
3553 {
3554 in: "-Ipath/to/something",
3555 out: false,
3556 },
3557 {
3558 in: "-isystempath/to/something",
3559 out: false,
3560 },
3561 {
3562 in: "--coverage",
3563 out: false,
3564 },
3565 {
3566 in: "-include a/b",
3567 out: true,
3568 },
3569 {
3570 in: "-include a/b c/d",
3571 out: false,
3572 },
3573 {
3574 in: "-DMACRO",
3575 out: true,
3576 },
3577 {
3578 in: "-DMAC RO",
3579 out: false,
3580 },
3581 {
3582 in: "-a -b",
3583 out: false,
3584 },
3585 {
3586 in: "-DMACRO=definition",
3587 out: true,
3588 },
3589 {
3590 in: "-DMACRO=defi nition",
3591 out: true, // TODO(jiyong): this should be false
3592 },
3593 {
3594 in: "-DMACRO(x)=x + 1",
3595 out: true,
3596 },
3597 {
3598 in: "-DMACRO=\"defi nition\"",
3599 out: true,
3600 },
3601}
3602
3603type mockContext struct {
3604 BaseModuleContext
3605 result bool
3606}
3607
3608func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3609 // CheckBadCompilerFlags calls this function when the flag should be rejected
3610 ctx.result = false
3611}
3612
3613func TestCompilerFlags(t *testing.T) {
3614 for _, testCase := range compilerFlagsTestCases {
3615 ctx := &mockContext{result: true}
3616 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3617 if ctx.result != testCase.out {
3618 t.Errorf("incorrect output:")
3619 t.Errorf(" input: %#v", testCase.in)
3620 t.Errorf(" expected: %#v", testCase.out)
3621 t.Errorf(" got: %#v", ctx.result)
3622 }
3623 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003624}
Jiyong Park374510b2018-03-19 18:23:01 +09003625
3626func TestVendorPublicLibraries(t *testing.T) {
3627 ctx := testCc(t, `
3628 cc_library_headers {
3629 name: "libvendorpublic_headers",
3630 export_include_dirs: ["my_include"],
3631 }
3632 vendor_public_library {
3633 name: "libvendorpublic",
3634 symbol_file: "",
3635 export_public_headers: ["libvendorpublic_headers"],
3636 }
3637 cc_library {
3638 name: "libvendorpublic",
3639 srcs: ["foo.c"],
3640 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003641 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003642 nocrt: true,
3643 }
3644
3645 cc_library {
3646 name: "libsystem",
3647 shared_libs: ["libvendorpublic"],
3648 vendor: false,
3649 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003650 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003651 nocrt: true,
3652 }
3653 cc_library {
3654 name: "libvendor",
3655 shared_libs: ["libvendorpublic"],
3656 vendor: true,
3657 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003658 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003659 nocrt: true,
3660 }
3661 `)
3662
Colin Cross7113d202019-11-20 16:39:12 -08003663 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003664 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003665
3666 // test if header search paths are correctly added
3667 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003668 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003669 cflags := cc.Args["cFlags"]
3670 if !strings.Contains(cflags, "-Imy_include") {
3671 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3672 }
3673
3674 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003675 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003676 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003677 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003678 if !strings.Contains(libflags, stubPaths[0].String()) {
3679 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3680 }
3681
3682 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003683 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003684 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003685 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003686 if !strings.Contains(libflags, stubPaths[0].String()) {
3687 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3688 }
3689
3690}
Jiyong Park37b25202018-07-11 10:49:27 +09003691
3692func TestRecovery(t *testing.T) {
3693 ctx := testCc(t, `
3694 cc_library_shared {
3695 name: "librecovery",
3696 recovery: true,
3697 }
3698 cc_library_shared {
3699 name: "librecovery32",
3700 recovery: true,
3701 compile_multilib:"32",
3702 }
Jiyong Park5baac542018-08-28 09:55:37 +09003703 cc_library_shared {
3704 name: "libHalInRecovery",
3705 recovery_available: true,
3706 vendor: true,
3707 }
Jiyong Park37b25202018-07-11 10:49:27 +09003708 `)
3709
3710 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003711 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003712 if len(variants) != 1 || !android.InList(arm64, variants) {
3713 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3714 }
3715
3716 variants = ctx.ModuleVariantsForTests("librecovery32")
3717 if android.InList(arm64, variants) {
3718 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3719 }
Jiyong Park5baac542018-08-28 09:55:37 +09003720
3721 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3722 if !recoveryModule.Platform() {
3723 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3724 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003725}
Jiyong Park5baac542018-08-28 09:55:37 +09003726
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003727func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3728 bp := `
3729 cc_prebuilt_test_library_shared {
3730 name: "test_lib",
3731 relative_install_path: "foo/bar/baz",
3732 srcs: ["srcpath/dontusethispath/baz.so"],
3733 }
3734
3735 cc_test {
3736 name: "main_test",
3737 data_libs: ["test_lib"],
3738 gtest: false,
3739 }
3740 `
3741
3742 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3743 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3744 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3745 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3746
3747 ctx := testCcWithConfig(t, config)
3748 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3749 testBinary := module.(*Module).linker.(*testBinary)
3750 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3751 if err != nil {
3752 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3753 }
3754 if len(outputFiles) != 1 {
3755 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3756 }
3757 if len(testBinary.dataPaths()) != 1 {
3758 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3759 }
3760
3761 outputPath := outputFiles[0].String()
3762
3763 if !strings.HasSuffix(outputPath, "/main_test") {
3764 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3765 }
3766 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3767 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3768 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3769 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3770 }
3771}
3772
Jiyong Park7ed9de32018-10-15 22:25:07 +09003773func TestVersionedStubs(t *testing.T) {
3774 ctx := testCc(t, `
3775 cc_library_shared {
3776 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003777 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003778 stubs: {
3779 symbol_file: "foo.map.txt",
3780 versions: ["1", "2", "3"],
3781 },
3782 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003783
Jiyong Park7ed9de32018-10-15 22:25:07 +09003784 cc_library_shared {
3785 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003786 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003787 shared_libs: ["libFoo#1"],
3788 }`)
3789
3790 variants := ctx.ModuleVariantsForTests("libFoo")
3791 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003792 "android_arm64_armv8-a_shared",
3793 "android_arm64_armv8-a_shared_1",
3794 "android_arm64_armv8-a_shared_2",
3795 "android_arm64_armv8-a_shared_3",
3796 "android_arm_armv7-a-neon_shared",
3797 "android_arm_armv7-a-neon_shared_1",
3798 "android_arm_armv7-a-neon_shared_2",
3799 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003800 }
3801 variantsMismatch := false
3802 if len(variants) != len(expectedVariants) {
3803 variantsMismatch = true
3804 } else {
3805 for _, v := range expectedVariants {
3806 if !inList(v, variants) {
3807 variantsMismatch = false
3808 }
3809 }
3810 }
3811 if variantsMismatch {
3812 t.Errorf("variants of libFoo expected:\n")
3813 for _, v := range expectedVariants {
3814 t.Errorf("%q\n", v)
3815 }
3816 t.Errorf(", but got:\n")
3817 for _, v := range variants {
3818 t.Errorf("%q\n", v)
3819 }
3820 }
3821
Colin Cross7113d202019-11-20 16:39:12 -08003822 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003823 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003824 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003825 if !strings.Contains(libFlags, libFoo1StubPath) {
3826 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3827 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003828
Colin Cross7113d202019-11-20 16:39:12 -08003829 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003830 cFlags := libBarCompileRule.Args["cFlags"]
3831 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3832 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3833 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3834 }
Jiyong Park37b25202018-07-11 10:49:27 +09003835}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003836
Jooyung Hanb04a4992020-03-13 18:57:35 +09003837func TestVersioningMacro(t *testing.T) {
3838 for _, tc := range []struct{ moduleName, expected string }{
3839 {"libc", "__LIBC_API__"},
3840 {"libfoo", "__LIBFOO_API__"},
3841 {"libfoo@1", "__LIBFOO_1_API__"},
3842 {"libfoo-v1", "__LIBFOO_V1_API__"},
3843 {"libfoo.v1", "__LIBFOO_V1_API__"},
3844 } {
3845 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3846 }
3847}
3848
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003849func TestStaticExecutable(t *testing.T) {
3850 ctx := testCc(t, `
3851 cc_binary {
3852 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003853 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003854 static_executable: true,
3855 }`)
3856
Colin Cross7113d202019-11-20 16:39:12 -08003857 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003858 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3859 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003860 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003861 for _, lib := range systemStaticLibs {
3862 if !strings.Contains(libFlags, lib) {
3863 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3864 }
3865 }
3866 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3867 for _, lib := range systemSharedLibs {
3868 if strings.Contains(libFlags, lib) {
3869 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3870 }
3871 }
3872}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003873
3874func TestStaticDepsOrderWithStubs(t *testing.T) {
3875 ctx := testCc(t, `
3876 cc_binary {
3877 name: "mybin",
3878 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003879 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003880 static_executable: true,
3881 stl: "none",
3882 }
3883
3884 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003885 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003886 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003887 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003888 stl: "none",
3889 }
3890
3891 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003892 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003893 srcs: ["foo.c"],
3894 stl: "none",
3895 stubs: {
3896 versions: ["1"],
3897 },
3898 }`)
3899
Colin Cross0de8a1e2020-09-18 14:15:30 -07003900 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3901 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003902 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003903
3904 if !reflect.DeepEqual(actual, expected) {
3905 t.Errorf("staticDeps orderings were not propagated correctly"+
3906 "\nactual: %v"+
3907 "\nexpected: %v",
3908 actual,
3909 expected,
3910 )
3911 }
3912}
Jooyung Han38002912019-05-16 04:01:54 +09003913
Jooyung Hand48f3c32019-08-23 11:18:57 +09003914func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3915 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3916 cc_library {
3917 name: "libA",
3918 srcs: ["foo.c"],
3919 shared_libs: ["libB"],
3920 stl: "none",
3921 }
3922
3923 cc_library {
3924 name: "libB",
3925 srcs: ["foo.c"],
3926 enabled: false,
3927 stl: "none",
3928 }
3929 `)
3930}
3931
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003932// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3933// correctly.
3934func TestFuzzTarget(t *testing.T) {
3935 ctx := testCc(t, `
3936 cc_fuzz {
3937 name: "fuzz_smoke_test",
3938 srcs: ["foo.c"],
3939 }`)
3940
Paul Duffin075c4172019-12-19 19:06:13 +00003941 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003942 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3943}
3944
Jiyong Park29074592019-07-07 16:27:47 +09003945func TestAidl(t *testing.T) {
3946}
3947
Jooyung Han38002912019-05-16 04:01:54 +09003948func assertString(t *testing.T, got, expected string) {
3949 t.Helper()
3950 if got != expected {
3951 t.Errorf("expected %q got %q", expected, got)
3952 }
3953}
3954
3955func assertArrayString(t *testing.T, got, expected []string) {
3956 t.Helper()
3957 if len(got) != len(expected) {
3958 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3959 return
3960 }
3961 for i := range got {
3962 if got[i] != expected[i] {
3963 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3964 i, expected[i], expected, got[i], got)
3965 return
3966 }
3967 }
3968}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003969
Jooyung Han0302a842019-10-30 18:43:49 +09003970func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3971 t.Helper()
3972 assertArrayString(t, android.SortedStringKeys(m), expected)
3973}
3974
Colin Crosse1bb5d02019-09-24 14:55:04 -07003975func TestDefaults(t *testing.T) {
3976 ctx := testCc(t, `
3977 cc_defaults {
3978 name: "defaults",
3979 srcs: ["foo.c"],
3980 static: {
3981 srcs: ["bar.c"],
3982 },
3983 shared: {
3984 srcs: ["baz.c"],
3985 },
3986 }
3987
3988 cc_library_static {
3989 name: "libstatic",
3990 defaults: ["defaults"],
3991 }
3992
3993 cc_library_shared {
3994 name: "libshared",
3995 defaults: ["defaults"],
3996 }
3997
3998 cc_library {
3999 name: "libboth",
4000 defaults: ["defaults"],
4001 }
4002
4003 cc_binary {
4004 name: "binary",
4005 defaults: ["defaults"],
4006 }`)
4007
4008 pathsToBase := func(paths android.Paths) []string {
4009 var ret []string
4010 for _, p := range paths {
4011 ret = append(ret, p.Base())
4012 }
4013 return ret
4014 }
4015
Colin Cross7113d202019-11-20 16:39:12 -08004016 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004017 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4018 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
4019 }
Colin Cross7113d202019-11-20 16:39:12 -08004020 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004021 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4022 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
4023 }
Colin Cross7113d202019-11-20 16:39:12 -08004024 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004025 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
4026 t.Errorf("binary ld rule wanted %q, got %q", w, g)
4027 }
4028
Colin Cross7113d202019-11-20 16:39:12 -08004029 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004030 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4031 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
4032 }
Colin Cross7113d202019-11-20 16:39:12 -08004033 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004034 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4035 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
4036 }
4037}
Colin Crosseabaedd2020-02-06 17:01:55 -08004038
4039func TestProductVariableDefaults(t *testing.T) {
4040 bp := `
4041 cc_defaults {
4042 name: "libfoo_defaults",
4043 srcs: ["foo.c"],
4044 cppflags: ["-DFOO"],
4045 product_variables: {
4046 debuggable: {
4047 cppflags: ["-DBAR"],
4048 },
4049 },
4050 }
4051
4052 cc_library {
4053 name: "libfoo",
4054 defaults: ["libfoo_defaults"],
4055 }
4056 `
4057
4058 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4059 config.TestProductVariables.Debuggable = BoolPtr(true)
4060
Colin Crossae8600b2020-10-29 17:09:13 -07004061 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08004062 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
4063 ctx.BottomUp("variable", android.VariableMutator).Parallel()
4064 })
Colin Crossae8600b2020-10-29 17:09:13 -07004065 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08004066
4067 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4068 android.FailIfErrored(t, errs)
4069 _, errs = ctx.PrepareBuildActions(config)
4070 android.FailIfErrored(t, errs)
4071
4072 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
4073 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
4074 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
4075 }
4076}
Colin Crosse4f6eba2020-09-22 18:11:25 -07004077
4078func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
4079 t.Parallel()
4080 bp := `
4081 cc_library_static {
4082 name: "libfoo",
4083 srcs: ["foo.c"],
4084 whole_static_libs: ["libbar"],
4085 }
4086
4087 cc_library_static {
4088 name: "libbar",
4089 whole_static_libs: ["libmissing"],
4090 }
4091 `
4092
4093 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4094 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
4095
Colin Crossae8600b2020-10-29 17:09:13 -07004096 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07004097 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07004098 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07004099
4100 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4101 android.FailIfErrored(t, errs)
4102 _, errs = ctx.PrepareBuildActions(config)
4103 android.FailIfErrored(t, errs)
4104
4105 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
4106 if g, w := libbar.Rule, android.ErrorRule; g != w {
4107 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
4108 }
4109
4110 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
4111 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
4112 }
4113
4114 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
4115 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
4116 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
4117 }
4118
4119}
Colin Crosse9fe2942020-11-10 18:12:15 -08004120
4121func TestInstallSharedLibs(t *testing.T) {
4122 bp := `
4123 cc_binary {
4124 name: "bin",
4125 host_supported: true,
4126 shared_libs: ["libshared"],
4127 runtime_libs: ["libruntime"],
4128 srcs: [":gen"],
4129 }
4130
4131 cc_library_shared {
4132 name: "libshared",
4133 host_supported: true,
4134 shared_libs: ["libtransitive"],
4135 }
4136
4137 cc_library_shared {
4138 name: "libtransitive",
4139 host_supported: true,
4140 }
4141
4142 cc_library_shared {
4143 name: "libruntime",
4144 host_supported: true,
4145 }
4146
4147 cc_binary_host {
4148 name: "tool",
4149 srcs: ["foo.cpp"],
4150 }
4151
4152 genrule {
4153 name: "gen",
4154 tools: ["tool"],
4155 out: ["gen.cpp"],
4156 cmd: "$(location tool) $(out)",
4157 }
4158 `
4159
4160 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4161 ctx := testCcWithConfig(t, config)
4162
4163 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
4164 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
4165 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
4166 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
4167 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
4168
4169 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
4170 t.Errorf("expected host bin dependency %q, got %q", w, g)
4171 }
4172
4173 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4174 t.Errorf("expected host bin dependency %q, got %q", w, g)
4175 }
4176
4177 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4178 t.Errorf("expected host bin dependency %q, got %q", w, g)
4179 }
4180
4181 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
4182 t.Errorf("expected host bin dependency %q, got %q", w, g)
4183 }
4184
4185 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
4186 t.Errorf("expected no host bin dependency %q, got %q", w, g)
4187 }
4188
4189 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
4190 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
4191 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
4192 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
4193
4194 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
4195 t.Errorf("expected device bin dependency %q, got %q", w, g)
4196 }
4197
4198 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4199 t.Errorf("expected device bin dependency %q, got %q", w, g)
4200 }
4201
4202 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4203 t.Errorf("expected device bin dependency %q, got %q", w, g)
4204 }
4205
4206 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
4207 t.Errorf("expected device bin dependency %q, got %q", w, g)
4208 }
4209
4210 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
4211 t.Errorf("expected no device bin dependency %q, got %q", w, g)
4212 }
4213
4214}
Jiyong Park1ad8e162020-12-01 23:40:09 +09004215
4216func TestStubsLibReexportsHeaders(t *testing.T) {
4217 ctx := testCc(t, `
4218 cc_library_shared {
4219 name: "libclient",
4220 srcs: ["foo.c"],
4221 shared_libs: ["libfoo#1"],
4222 }
4223
4224 cc_library_shared {
4225 name: "libfoo",
4226 srcs: ["foo.c"],
4227 shared_libs: ["libbar"],
4228 export_shared_lib_headers: ["libbar"],
4229 stubs: {
4230 symbol_file: "foo.map.txt",
4231 versions: ["1", "2", "3"],
4232 },
4233 }
4234
4235 cc_library_shared {
4236 name: "libbar",
4237 export_include_dirs: ["include/libbar"],
4238 srcs: ["foo.c"],
4239 }`)
4240
4241 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
4242
4243 if !strings.Contains(cFlags, "-Iinclude/libbar") {
4244 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
4245 }
4246}