blob: fb85336411f7d0b395d8fe608be9ebab18e0b66f [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",
Justin Yunfd9e8042020-12-23 18:23:14 +0900337 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800338 vndk: {
339 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900340 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800341 },
342 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900343 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800344 }
345
346 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900347 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800348 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900349 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800350 vndk: {
351 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900352 },
353 nocrt: true,
354 target: {
355 vendor: {
356 cflags: ["-DTEST"],
357 },
358 product: {
359 cflags: ["-DTEST"],
360 },
361 },
362 }
363
364 cc_library {
365 name: "libvndk_sp",
366 vendor_available: true,
367 vndk: {
368 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800369 support_system_process: true,
370 },
371 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900372 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800373 }
374
375 cc_library {
376 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900377 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800378 vndk: {
379 enabled: true,
380 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900381 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800382 },
383 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900384 target: {
385 vendor: {
386 suffix: "-x",
387 },
388 },
Logan Chienf3511742017-10-31 18:04:35 +0800389 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900390
391 cc_library {
392 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900393 vendor_available: true,
394 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900395 vndk: {
396 enabled: true,
397 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900398 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900399 },
400 nocrt: true,
401 target: {
402 vendor: {
403 suffix: "-x",
404 },
405 product: {
406 suffix: "-x",
407 },
408 },
409 }
410
Jooyung Han2216fb12019-11-06 16:46:15 +0900411 vndk_libraries_txt {
412 name: "llndk.libraries.txt",
413 }
414 vndk_libraries_txt {
415 name: "vndkcore.libraries.txt",
416 }
417 vndk_libraries_txt {
418 name: "vndksp.libraries.txt",
419 }
420 vndk_libraries_txt {
421 name: "vndkprivate.libraries.txt",
422 }
423 vndk_libraries_txt {
424 name: "vndkcorevariant.libraries.txt",
425 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800426 `
427
428 config := TestConfig(buildDir, android.Android, nil, bp, nil)
429 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900430 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800431 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
432
433 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800434
Jooyung Han261e1582020-10-20 18:54:21 +0900435 // subdir == "" because VNDK libs are not supposed to be installed separately.
436 // They are installed as part of VNDK APEX instead.
437 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
438 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900439 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900440 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
441 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900442 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900443
Justin Yun6977e8a2020-10-29 18:24:11 +0900444 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
445 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900446
Inseob Kim1f086e22019-05-09 13:29:15 +0900447 // Check VNDK snapshot output.
448
449 snapshotDir := "vndk-snapshot"
450 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
451
452 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
453 "arm64", "armv8-a"))
454 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
455 "arm", "armv7-a-neon"))
456
457 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
458 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
459 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
460 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
461
Colin Crossfb0c16e2019-11-20 17:12:35 -0800462 variant := "android_vendor.VER_arm64_armv8-a_shared"
463 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900464
Inseob Kim7f283f42020-06-01 21:53:49 +0900465 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
466
467 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
468 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900469 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
470 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900471 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
472 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900473
Jooyung Han39edb6c2019-11-06 16:53:07 +0900474 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900475 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
476 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
477 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
478 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900479
Jooyung Han097087b2019-10-22 19:32:18 +0900480 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
481 "LLNDK: libc.so",
482 "LLNDK: libdl.so",
483 "LLNDK: libft2.so",
484 "LLNDK: libm.so",
485 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900486 "VNDK-SP: libvndk_sp-x.so",
487 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900488 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900489 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900490 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900491 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900492 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900493 "VNDK-private: libvndk-private.so",
494 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900495 "VNDK-private: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900496 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900497 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900498 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
499 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
500 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 +0900501 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
502}
503
Yo Chiangbba545e2020-06-09 16:15:37 +0800504func TestVndkWithHostSupported(t *testing.T) {
505 ctx := testCc(t, `
506 cc_library {
507 name: "libvndk_host_supported",
508 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900509 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800510 vndk: {
511 enabled: true,
512 },
513 host_supported: true,
514 }
515
516 cc_library {
517 name: "libvndk_host_supported_but_disabled_on_device",
518 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900519 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800520 vndk: {
521 enabled: true,
522 },
523 host_supported: true,
524 enabled: false,
525 target: {
526 host: {
527 enabled: true,
528 }
529 }
530 }
531
532 vndk_libraries_txt {
533 name: "vndkcore.libraries.txt",
534 }
535 `)
536
537 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
538}
539
Jooyung Han2216fb12019-11-06 16:46:15 +0900540func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800541 bp := `
Jooyung Han2216fb12019-11-06 16:46:15 +0900542 vndk_libraries_txt {
543 name: "llndk.libraries.txt",
Colin Cross98be1bb2019-12-13 20:41:13 -0800544 }`
545 config := TestConfig(buildDir, android.Android, nil, bp, nil)
546 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
547 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
548 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900549
550 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900551 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900552 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900553}
554
555func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800556 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900557 cc_library {
558 name: "libvndk",
559 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900560 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900561 vndk: {
562 enabled: true,
563 },
564 nocrt: true,
565 }
566
567 cc_library {
568 name: "libvndk_sp",
569 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900570 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900571 vndk: {
572 enabled: true,
573 support_system_process: true,
574 },
575 nocrt: true,
576 }
577
578 cc_library {
579 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900580 vendor_available: true,
581 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900582 vndk: {
583 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900584 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900585 },
586 nocrt: true,
587 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900588
589 vndk_libraries_txt {
590 name: "vndkcorevariant.libraries.txt",
591 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800592 `
593
594 config := TestConfig(buildDir, android.Android, nil, bp, nil)
595 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
596 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
597 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
598
599 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
600
601 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900602
Jooyung Han2216fb12019-11-06 16:46:15 +0900603 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900604}
605
Chris Parsons79d66a52020-06-05 17:26:16 -0400606func TestDataLibs(t *testing.T) {
607 bp := `
608 cc_test_library {
609 name: "test_lib",
610 srcs: ["test_lib.cpp"],
611 gtest: false,
612 }
613
614 cc_test {
615 name: "main_test",
616 data_libs: ["test_lib"],
617 gtest: false,
618 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400619 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400620
621 config := TestConfig(buildDir, android.Android, nil, bp, nil)
622 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
623 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
624 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
625
626 ctx := testCcWithConfig(t, config)
627 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
628 testBinary := module.(*Module).linker.(*testBinary)
629 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
630 if err != nil {
631 t.Errorf("Expected cc_test to produce output files, error: %s", err)
632 return
633 }
634 if len(outputFiles) != 1 {
635 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
636 return
637 }
638 if len(testBinary.dataPaths()) != 1 {
639 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
640 return
641 }
642
643 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400644 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400645
646 if !strings.HasSuffix(outputPath, "/main_test") {
647 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
648 return
649 }
650 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
651 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
652 return
653 }
654}
655
Chris Parsons216e10a2020-07-09 17:12:52 -0400656func TestDataLibsRelativeInstallPath(t *testing.T) {
657 bp := `
658 cc_test_library {
659 name: "test_lib",
660 srcs: ["test_lib.cpp"],
661 relative_install_path: "foo/bar/baz",
662 gtest: false,
663 }
664
665 cc_test {
666 name: "main_test",
667 data_libs: ["test_lib"],
668 gtest: false,
669 }
670 `
671
672 config := TestConfig(buildDir, android.Android, nil, bp, nil)
673 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
674 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
675 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
676
677 ctx := testCcWithConfig(t, config)
678 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
679 testBinary := module.(*Module).linker.(*testBinary)
680 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
681 if err != nil {
682 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
683 }
684 if len(outputFiles) != 1 {
685 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
686 }
687 if len(testBinary.dataPaths()) != 1 {
688 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
689 }
690
691 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400692
693 if !strings.HasSuffix(outputPath, "/main_test") {
694 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
695 }
696 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
697 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
698 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400699 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400700 }
701}
702
Jooyung Han0302a842019-10-30 18:43:49 +0900703func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900704 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900705 cc_library {
706 name: "libvndk",
707 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900708 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900709 vndk: {
710 enabled: true,
711 },
712 nocrt: true,
713 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900714 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900715
716 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
717 "LLNDK: libc.so",
718 "LLNDK: libdl.so",
719 "LLNDK: libft2.so",
720 "LLNDK: libm.so",
721 "VNDK-SP: libc++.so",
722 "VNDK-core: libvndk.so",
723 "VNDK-private: libft2.so",
724 })
Logan Chienf3511742017-10-31 18:04:35 +0800725}
726
Justin Yun63e9ec72020-10-29 16:49:43 +0900727func TestVndkModuleError(t *testing.T) {
728 // Check the error message for vendor_available and product_available properties.
Justin Yun6977e8a2020-10-29 18:24:11 +0900729 testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", `
730 cc_library {
731 name: "libvndk",
732 vndk: {
733 enabled: true,
734 },
735 nocrt: true,
736 }
737 `)
738
739 testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", `
740 cc_library {
741 name: "libvndk",
742 product_available: true,
743 vndk: {
744 enabled: true,
745 },
746 nocrt: true,
747 }
748 `)
749
Justin Yun6977e8a2020-10-29 18:24:11 +0900750 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
751 cc_library {
752 name: "libvndkprop",
753 vendor_available: true,
754 product_available: true,
755 vndk: {
756 enabled: true,
757 },
758 nocrt: true,
759 target: {
760 vendor: {
761 cflags: ["-DTEST",],
762 },
763 },
764 }
765 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900766}
767
Logan Chiend3c59a22018-03-29 14:08:15 +0800768func TestVndkDepError(t *testing.T) {
769 // Check whether an error is emitted when a VNDK lib depends on a system lib.
770 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
771 cc_library {
772 name: "libvndk",
773 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900774 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800775 vndk: {
776 enabled: true,
777 },
778 shared_libs: ["libfwk"], // Cause error
779 nocrt: true,
780 }
781
782 cc_library {
783 name: "libfwk",
784 nocrt: true,
785 }
786 `)
787
788 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
789 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
790 cc_library {
791 name: "libvndk",
792 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900793 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800794 vndk: {
795 enabled: true,
796 },
797 shared_libs: ["libvendor"], // Cause error
798 nocrt: true,
799 }
800
801 cc_library {
802 name: "libvendor",
803 vendor: true,
804 nocrt: true,
805 }
806 `)
807
808 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
809 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
810 cc_library {
811 name: "libvndk_sp",
812 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900813 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800814 vndk: {
815 enabled: true,
816 support_system_process: true,
817 },
818 shared_libs: ["libfwk"], // Cause error
819 nocrt: true,
820 }
821
822 cc_library {
823 name: "libfwk",
824 nocrt: true,
825 }
826 `)
827
828 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
829 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
830 cc_library {
831 name: "libvndk_sp",
832 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900833 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800834 vndk: {
835 enabled: true,
836 support_system_process: true,
837 },
838 shared_libs: ["libvendor"], // Cause error
839 nocrt: true,
840 }
841
842 cc_library {
843 name: "libvendor",
844 vendor: true,
845 nocrt: true,
846 }
847 `)
848
849 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
850 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
851 cc_library {
852 name: "libvndk_sp",
853 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900854 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800855 vndk: {
856 enabled: true,
857 support_system_process: true,
858 },
859 shared_libs: ["libvndk"], // Cause error
860 nocrt: true,
861 }
862
863 cc_library {
864 name: "libvndk",
865 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900866 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800867 vndk: {
868 enabled: true,
869 },
870 nocrt: true,
871 }
872 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900873
874 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
875 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
876 cc_library {
877 name: "libvndk",
878 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900879 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900880 vndk: {
881 enabled: true,
882 },
883 shared_libs: ["libnonvndk"],
884 nocrt: true,
885 }
886
887 cc_library {
888 name: "libnonvndk",
889 vendor_available: true,
890 nocrt: true,
891 }
892 `)
893
894 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
895 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
896 cc_library {
897 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900898 vendor_available: true,
899 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900900 vndk: {
901 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900902 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900903 },
904 shared_libs: ["libnonvndk"],
905 nocrt: true,
906 }
907
908 cc_library {
909 name: "libnonvndk",
910 vendor_available: true,
911 nocrt: true,
912 }
913 `)
914
915 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
916 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
917 cc_library {
918 name: "libvndksp",
919 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900920 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900921 vndk: {
922 enabled: true,
923 support_system_process: true,
924 },
925 shared_libs: ["libnonvndk"],
926 nocrt: true,
927 }
928
929 cc_library {
930 name: "libnonvndk",
931 vendor_available: true,
932 nocrt: true,
933 }
934 `)
935
936 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
937 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
938 cc_library {
939 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900940 vendor_available: true,
941 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900942 vndk: {
943 enabled: true,
944 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900945 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900946 },
947 shared_libs: ["libnonvndk"],
948 nocrt: true,
949 }
950
951 cc_library {
952 name: "libnonvndk",
953 vendor_available: true,
954 nocrt: true,
955 }
956 `)
957}
958
959func TestDoubleLoadbleDep(t *testing.T) {
960 // okay to link : LLNDK -> double_loadable VNDK
961 testCc(t, `
962 cc_library {
963 name: "libllndk",
964 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -0700965 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900966 }
967
968 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700969 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900970 symbol_file: "",
971 }
972
973 cc_library {
974 name: "libdoubleloadable",
975 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900976 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900977 vndk: {
978 enabled: true,
979 },
980 double_loadable: true,
981 }
982 `)
983 // okay to link : LLNDK -> VNDK-SP
984 testCc(t, `
985 cc_library {
986 name: "libllndk",
987 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -0700988 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900989 }
990
991 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700992 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900993 symbol_file: "",
994 }
995
996 cc_library {
997 name: "libvndksp",
998 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900999 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001000 vndk: {
1001 enabled: true,
1002 support_system_process: true,
1003 },
1004 }
1005 `)
1006 // okay to link : double_loadable -> double_loadable
1007 testCc(t, `
1008 cc_library {
1009 name: "libdoubleloadable1",
1010 shared_libs: ["libdoubleloadable2"],
1011 vendor_available: true,
1012 double_loadable: true,
1013 }
1014
1015 cc_library {
1016 name: "libdoubleloadable2",
1017 vendor_available: true,
1018 double_loadable: true,
1019 }
1020 `)
1021 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1022 testCc(t, `
1023 cc_library {
1024 name: "libdoubleloadable",
1025 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001026 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001027 vndk: {
1028 enabled: true,
1029 },
1030 double_loadable: true,
1031 shared_libs: ["libnondoubleloadable"],
1032 }
1033
1034 cc_library {
1035 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001036 vendor_available: true,
1037 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001038 vndk: {
1039 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001040 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001041 },
1042 double_loadable: true,
1043 }
1044 `)
1045 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1046 testCc(t, `
1047 cc_library {
1048 name: "libllndk",
1049 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001050 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001051 }
1052
1053 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001054 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001055 symbol_file: "",
1056 }
1057
1058 cc_library {
1059 name: "libcoreonly",
1060 shared_libs: ["libvendoravailable"],
1061 }
1062
1063 // indirect dependency of LLNDK
1064 cc_library {
1065 name: "libvendoravailable",
1066 vendor_available: true,
1067 double_loadable: true,
1068 }
1069 `)
1070}
1071
Inseob Kim5f58ff72020-09-07 19:53:31 +09001072func TestVendorSnapshotCapture(t *testing.T) {
Inseob Kim8471cda2019-11-15 09:59:12 +09001073 bp := `
1074 cc_library {
1075 name: "libvndk",
1076 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001077 product_available: true,
Inseob Kim8471cda2019-11-15 09:59:12 +09001078 vndk: {
1079 enabled: true,
1080 },
1081 nocrt: true,
1082 }
1083
1084 cc_library {
1085 name: "libvendor",
1086 vendor: true,
1087 nocrt: true,
1088 }
1089
1090 cc_library {
1091 name: "libvendor_available",
1092 vendor_available: true,
1093 nocrt: true,
1094 }
1095
1096 cc_library_headers {
1097 name: "libvendor_headers",
1098 vendor_available: true,
1099 nocrt: true,
1100 }
1101
1102 cc_binary {
1103 name: "vendor_bin",
1104 vendor: true,
1105 nocrt: true,
1106 }
1107
1108 cc_binary {
1109 name: "vendor_available_bin",
1110 vendor_available: true,
1111 nocrt: true,
1112 }
Inseob Kim7f283f42020-06-01 21:53:49 +09001113
1114 toolchain_library {
1115 name: "libb",
1116 vendor_available: true,
1117 src: "libb.a",
1118 }
Inseob Kim1042d292020-06-01 23:23:05 +09001119
1120 cc_object {
1121 name: "obj",
1122 vendor_available: true,
1123 }
Colin Cross127bb8b2020-12-16 16:46:01 -08001124
1125 cc_library {
1126 name: "libllndk",
1127 llndk_stubs: "libllndk.llndk",
1128 }
1129
1130 llndk_library {
1131 name: "libllndk.llndk",
1132 symbol_file: "",
1133 }
Inseob Kim8471cda2019-11-15 09:59:12 +09001134`
1135 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1136 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1137 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1138 ctx := testCcWithConfig(t, config)
1139
1140 // Check Vendor snapshot output.
1141
1142 snapshotDir := "vendor-snapshot"
1143 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
Inseob Kim7f283f42020-06-01 21:53:49 +09001144 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1145
1146 var jsonFiles []string
Inseob Kim8471cda2019-11-15 09:59:12 +09001147
1148 for _, arch := range [][]string{
1149 []string{"arm64", "armv8-a"},
1150 []string{"arm", "armv7-a-neon"},
1151 } {
1152 archType := arch[0]
1153 archVariant := arch[1]
1154 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1155
1156 // For shared libraries, only non-VNDK vendor_available modules are captured
1157 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1158 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Inseob Kim7f283f42020-06-01 21:53:49 +09001159 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1160 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1161 jsonFiles = append(jsonFiles,
1162 filepath.Join(sharedDir, "libvendor.so.json"),
1163 filepath.Join(sharedDir, "libvendor_available.so.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001164
Colin Cross127bb8b2020-12-16 16:46:01 -08001165 // LLNDK modules are not captured
1166 checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
1167
Inseob Kim8471cda2019-11-15 09:59:12 +09001168 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
Inseob Kimc42f2f22020-07-29 20:32:10 +09001169 // Also cfi variants are captured, except for prebuilts like toolchain_library
Inseob Kim8471cda2019-11-15 09:59:12 +09001170 staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001171 staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant)
Inseob Kim8471cda2019-11-15 09:59:12 +09001172 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Inseob Kim7f283f42020-06-01 21:53:49 +09001173 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1174 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001175 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001176 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001177 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001178 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001179 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001180 jsonFiles = append(jsonFiles,
1181 filepath.Join(staticDir, "libb.a.json"),
1182 filepath.Join(staticDir, "libvndk.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001183 filepath.Join(staticDir, "libvndk.cfi.a.json"),
Inseob Kim7f283f42020-06-01 21:53:49 +09001184 filepath.Join(staticDir, "libvendor.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001185 filepath.Join(staticDir, "libvendor.cfi.a.json"),
1186 filepath.Join(staticDir, "libvendor_available.a.json"),
1187 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001188
Inseob Kim7f283f42020-06-01 21:53:49 +09001189 // For binary executables, all vendor:true and vendor_available modules are captured.
Inseob Kim8471cda2019-11-15 09:59:12 +09001190 if archType == "arm64" {
1191 binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1192 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Inseob Kim7f283f42020-06-01 21:53:49 +09001193 checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
1194 checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
1195 jsonFiles = append(jsonFiles,
1196 filepath.Join(binaryDir, "vendor_bin.json"),
1197 filepath.Join(binaryDir, "vendor_available_bin.json"))
1198 }
1199
1200 // For header libraries, all vendor:true and vendor_available modules are captured.
1201 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1202 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
Inseob Kim1042d292020-06-01 23:23:05 +09001203
1204 // For object modules, all vendor:true and vendor_available modules are captured.
1205 objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1206 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1207 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1208 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
Inseob Kim7f283f42020-06-01 21:53:49 +09001209 }
1210
1211 for _, jsonFile := range jsonFiles {
1212 // verify all json files exist
1213 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1214 t.Errorf("%q expected but not found", jsonFile)
Inseob Kim8471cda2019-11-15 09:59:12 +09001215 }
1216 }
1217}
1218
Inseob Kim5f58ff72020-09-07 19:53:31 +09001219func TestVendorSnapshotUse(t *testing.T) {
1220 frameworkBp := `
1221 cc_library {
1222 name: "libvndk",
1223 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001224 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001225 vndk: {
1226 enabled: true,
1227 },
1228 nocrt: true,
1229 compile_multilib: "64",
1230 }
1231
1232 cc_library {
1233 name: "libvendor",
1234 vendor: true,
1235 nocrt: true,
1236 no_libcrt: true,
1237 stl: "none",
1238 system_shared_libs: [],
1239 compile_multilib: "64",
1240 }
1241
1242 cc_binary {
1243 name: "bin",
1244 vendor: true,
1245 nocrt: true,
1246 no_libcrt: true,
1247 stl: "none",
1248 system_shared_libs: [],
1249 compile_multilib: "64",
1250 }
1251`
1252
1253 vndkBp := `
1254 vndk_prebuilt_shared {
1255 name: "libvndk",
1256 version: "BOARD",
1257 target_arch: "arm64",
1258 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001259 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001260 vndk: {
1261 enabled: true,
1262 },
1263 arch: {
1264 arm64: {
1265 srcs: ["libvndk.so"],
Inseob Kim67be7322020-10-19 10:15:28 +09001266 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001267 },
1268 },
1269 }
1270`
1271
1272 vendorProprietaryBp := `
1273 cc_library {
1274 name: "libvendor_without_snapshot",
1275 vendor: true,
1276 nocrt: true,
1277 no_libcrt: true,
1278 stl: "none",
1279 system_shared_libs: [],
1280 compile_multilib: "64",
1281 }
1282
1283 cc_library_shared {
1284 name: "libclient",
1285 vendor: true,
1286 nocrt: true,
1287 no_libcrt: true,
1288 stl: "none",
1289 system_shared_libs: [],
1290 shared_libs: ["libvndk"],
1291 static_libs: ["libvendor", "libvendor_without_snapshot"],
1292 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001293 srcs: ["client.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001294 }
1295
1296 cc_binary {
1297 name: "bin_without_snapshot",
1298 vendor: true,
1299 nocrt: true,
1300 no_libcrt: true,
1301 stl: "none",
1302 system_shared_libs: [],
1303 static_libs: ["libvndk"],
1304 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001305 srcs: ["bin.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001306 }
1307
1308 vendor_snapshot_static {
1309 name: "libvndk",
1310 version: "BOARD",
1311 target_arch: "arm64",
1312 vendor: true,
1313 arch: {
1314 arm64: {
1315 src: "libvndk.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001316 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001317 },
1318 },
1319 }
1320
1321 vendor_snapshot_shared {
1322 name: "libvendor",
1323 version: "BOARD",
1324 target_arch: "arm64",
1325 vendor: true,
1326 arch: {
1327 arm64: {
1328 src: "libvendor.so",
Inseob Kim67be7322020-10-19 10:15:28 +09001329 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001330 },
1331 },
1332 }
1333
1334 vendor_snapshot_static {
1335 name: "libvendor",
1336 version: "BOARD",
1337 target_arch: "arm64",
1338 vendor: true,
1339 arch: {
1340 arm64: {
1341 src: "libvendor.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001342 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001343 },
1344 },
1345 }
1346
1347 vendor_snapshot_binary {
1348 name: "bin",
1349 version: "BOARD",
1350 target_arch: "arm64",
1351 vendor: true,
1352 arch: {
1353 arm64: {
1354 src: "bin",
1355 },
1356 },
1357 }
1358`
1359 depsBp := GatherRequiredDepsForTest(android.Android)
1360
1361 mockFS := map[string][]byte{
Inseob Kim67be7322020-10-19 10:15:28 +09001362 "deps/Android.bp": []byte(depsBp),
1363 "framework/Android.bp": []byte(frameworkBp),
1364 "vendor/Android.bp": []byte(vendorProprietaryBp),
1365 "vendor/bin": nil,
1366 "vendor/bin.cpp": nil,
1367 "vendor/client.cpp": nil,
1368 "vendor/include/libvndk/a.h": nil,
1369 "vendor/include/libvendor/b.h": nil,
1370 "vendor/libvndk.a": nil,
1371 "vendor/libvendor.a": nil,
1372 "vendor/libvendor.so": nil,
1373 "vndk/Android.bp": []byte(vndkBp),
1374 "vndk/include/libvndk/a.h": nil,
1375 "vndk/libvndk.so": nil,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001376 }
1377
1378 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1379 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1380 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001381 ctx := CreateTestContext(config)
1382 ctx.Register()
Inseob Kim5f58ff72020-09-07 19:53:31 +09001383
1384 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
1385 android.FailIfErrored(t, errs)
1386 _, errs = ctx.PrepareBuildActions(config)
1387 android.FailIfErrored(t, errs)
1388
1389 sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared"
1390 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1391 binaryVariant := "android_vendor.BOARD_arm64_armv8-a"
1392
1393 // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot
Inseob Kim67be7322020-10-19 10:15:28 +09001394 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
1395 for _, includeFlags := range []string{
1396 "-Ivndk/include/libvndk", // libvndk
1397 "-Ivendor/include/libvendor", // libvendor
1398 } {
1399 if !strings.Contains(libclientCcFlags, includeFlags) {
1400 t.Errorf("flags for libclient must contain %#v, but was %#v.",
1401 includeFlags, libclientCcFlags)
1402 }
1403 }
Inseob Kim5f58ff72020-09-07 19:53:31 +09001404
Inseob Kim67be7322020-10-19 10:15:28 +09001405 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001406 for _, input := range [][]string{
1407 []string{sharedVariant, "libvndk.vndk.BOARD.arm64"},
1408 []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"},
1409 []string{staticVariant, "libvendor_without_snapshot"},
1410 } {
1411 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Inseob Kim67be7322020-10-19 10:15:28 +09001412 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
1413 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001414 }
1415 }
1416
1417 // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64
Inseob Kim67be7322020-10-19 10:15:28 +09001418 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
1419 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
1420 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
1421 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
1422 }
1423
1424 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001425 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"})
Inseob Kim67be7322020-10-19 10:15:28 +09001426 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
Inseob Kim5f58ff72020-09-07 19:53:31 +09001427 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
Inseob Kim67be7322020-10-19 10:15:28 +09001428 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001429 }
1430
1431 // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64
1432 ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so")
1433
1434 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
1435 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
1436
1437 // bin is installed by bin.vendor_binary.BOARD.arm64
1438 ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin")
1439
1440 // bin_without_snapshot is installed by bin_without_snapshot
1441 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1442
1443 // libvendor and bin don't have vendor.BOARD variant
1444 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1445 if inList(sharedVariant, libvendorVariants) {
1446 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1447 }
1448
1449 binVariants := ctx.ModuleVariantsForTests("bin")
1450 if inList(binaryVariant, binVariants) {
1451 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1452 }
1453}
1454
Inseob Kimc42f2f22020-07-29 20:32:10 +09001455func TestVendorSnapshotSanitizer(t *testing.T) {
1456 bp := `
1457 vendor_snapshot_static {
1458 name: "libsnapshot",
1459 vendor: true,
1460 target_arch: "arm64",
1461 version: "BOARD",
1462 arch: {
1463 arm64: {
1464 src: "libsnapshot.a",
1465 cfi: {
1466 src: "libsnapshot.cfi.a",
1467 }
1468 },
1469 },
1470 }
1471`
1472 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1473 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1474 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1475 ctx := testCcWithConfig(t, config)
1476
1477 // Check non-cfi and cfi variant.
1478 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1479 staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi"
1480
1481 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module)
1482 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1483
1484 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module)
1485 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1486}
1487
Bill Peckham945441c2020-08-31 16:07:58 -07001488func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) {
1489 t.Helper()
1490 if c.ExcludeFromVendorSnapshot() != expected {
1491 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected)
1492 }
1493}
1494
1495func TestVendorSnapshotExclude(t *testing.T) {
1496
1497 // This test verifies that the exclude_from_vendor_snapshot property
1498 // makes its way from the Android.bp source file into the module data
1499 // structure. It also verifies that modules are correctly included or
1500 // excluded in the vendor snapshot based on their path (framework or
1501 // vendor) and the exclude_from_vendor_snapshot property.
1502
1503 frameworkBp := `
1504 cc_library_shared {
1505 name: "libinclude",
1506 srcs: ["src/include.cpp"],
1507 vendor_available: true,
1508 }
1509 cc_library_shared {
1510 name: "libexclude",
1511 srcs: ["src/exclude.cpp"],
1512 vendor: true,
1513 exclude_from_vendor_snapshot: true,
1514 }
1515 `
1516
1517 vendorProprietaryBp := `
1518 cc_library_shared {
1519 name: "libvendor",
1520 srcs: ["vendor.cpp"],
1521 vendor: true,
1522 }
1523 `
1524
1525 depsBp := GatherRequiredDepsForTest(android.Android)
1526
1527 mockFS := map[string][]byte{
1528 "deps/Android.bp": []byte(depsBp),
1529 "framework/Android.bp": []byte(frameworkBp),
1530 "framework/include.cpp": nil,
1531 "framework/exclude.cpp": nil,
1532 "device/Android.bp": []byte(vendorProprietaryBp),
1533 "device/vendor.cpp": nil,
1534 }
1535
1536 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1537 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1538 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001539 ctx := CreateTestContext(config)
1540 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001541
1542 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1543 android.FailIfErrored(t, errs)
1544 _, errs = ctx.PrepareBuildActions(config)
1545 android.FailIfErrored(t, errs)
1546
1547 // Test an include and exclude framework module.
1548 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
1549 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false)
1550 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true)
1551
1552 // A vendor module is excluded, but by its path, not the
1553 // exclude_from_vendor_snapshot property.
1554 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false)
1555
1556 // Verify the content of the vendor snapshot.
1557
1558 snapshotDir := "vendor-snapshot"
1559 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1560 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1561
1562 var includeJsonFiles []string
1563 var excludeJsonFiles []string
1564
1565 for _, arch := range [][]string{
1566 []string{"arm64", "armv8-a"},
1567 []string{"arm", "armv7-a-neon"},
1568 } {
1569 archType := arch[0]
1570 archVariant := arch[1]
1571 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1572
1573 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1574 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1575
1576 // Included modules
1577 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1578 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1579
1580 // Excluded modules
1581 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1582 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1583 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1584 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1585 }
1586
1587 // Verify that each json file for an included module has a rule.
1588 for _, jsonFile := range includeJsonFiles {
1589 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1590 t.Errorf("include json file %q not found", jsonFile)
1591 }
1592 }
1593
1594 // Verify that each json file for an excluded module has no rule.
1595 for _, jsonFile := range excludeJsonFiles {
1596 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1597 t.Errorf("exclude json file %q found", jsonFile)
1598 }
1599 }
1600}
1601
1602func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1603
1604 // This test verifies that using the exclude_from_vendor_snapshot
1605 // property on a module in a vendor proprietary path generates an
1606 // error. These modules are already excluded, so we prohibit using the
1607 // property in this way, which could add to confusion.
1608
1609 vendorProprietaryBp := `
1610 cc_library_shared {
1611 name: "libvendor",
1612 srcs: ["vendor.cpp"],
1613 vendor: true,
1614 exclude_from_vendor_snapshot: true,
1615 }
1616 `
1617
1618 depsBp := GatherRequiredDepsForTest(android.Android)
1619
1620 mockFS := map[string][]byte{
1621 "deps/Android.bp": []byte(depsBp),
1622 "device/Android.bp": []byte(vendorProprietaryBp),
1623 "device/vendor.cpp": nil,
1624 }
1625
1626 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1627 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1628 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001629 ctx := CreateTestContext(config)
1630 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001631
1632 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1633 android.FailIfErrored(t, errs)
1634
1635 _, errs = ctx.PrepareBuildActions(config)
1636 android.CheckErrorsAgainstExpectations(t, errs, []string{
1637 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1638 `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 -08001639 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1640 `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 -07001641 })
1642}
1643
1644func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) {
1645
1646 // This test verifies that using the exclude_from_vendor_snapshot
1647 // property on a module that is vendor available generates an error. A
1648 // vendor available module must be captured in the vendor snapshot and
1649 // must not built from source when building the vendor image against
1650 // the vendor snapshot.
1651
1652 frameworkBp := `
1653 cc_library_shared {
1654 name: "libinclude",
1655 srcs: ["src/include.cpp"],
1656 vendor_available: true,
1657 exclude_from_vendor_snapshot: true,
1658 }
1659 `
1660
1661 depsBp := GatherRequiredDepsForTest(android.Android)
1662
1663 mockFS := map[string][]byte{
1664 "deps/Android.bp": []byte(depsBp),
1665 "framework/Android.bp": []byte(frameworkBp),
1666 "framework/include.cpp": nil,
1667 }
1668
1669 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1670 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1671 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001672 ctx := CreateTestContext(config)
1673 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001674
1675 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"})
1676 android.FailIfErrored(t, errs)
1677
1678 _, errs = ctx.PrepareBuildActions(config)
1679 android.CheckErrorsAgainstExpectations(t, errs, []string{
1680 `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1681 `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1682 `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1683 `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1684 })
1685}
1686
Jose Galmesf7294582020-11-13 12:07:36 -08001687func TestRecoverySnapshotCapture(t *testing.T) {
1688 bp := `
1689 cc_library {
1690 name: "libvndk",
1691 vendor_available: true,
1692 recovery_available: true,
1693 product_available: true,
1694 vndk: {
1695 enabled: true,
1696 },
1697 nocrt: true,
1698 }
1699
1700 cc_library {
1701 name: "librecovery",
1702 recovery: true,
1703 nocrt: true,
1704 }
1705
1706 cc_library {
1707 name: "librecovery_available",
1708 recovery_available: true,
1709 nocrt: true,
1710 }
1711
1712 cc_library_headers {
1713 name: "librecovery_headers",
1714 recovery_available: true,
1715 nocrt: true,
1716 }
1717
1718 cc_binary {
1719 name: "recovery_bin",
1720 recovery: true,
1721 nocrt: true,
1722 }
1723
1724 cc_binary {
1725 name: "recovery_available_bin",
1726 recovery_available: true,
1727 nocrt: true,
1728 }
1729
1730 toolchain_library {
1731 name: "libb",
1732 recovery_available: true,
1733 src: "libb.a",
1734 }
1735
1736 cc_object {
1737 name: "obj",
1738 recovery_available: true,
1739 }
1740`
1741 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1742 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1743 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1744 ctx := testCcWithConfig(t, config)
1745
1746 // Check Recovery snapshot output.
1747
1748 snapshotDir := "recovery-snapshot"
1749 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1750 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1751
1752 var jsonFiles []string
1753
1754 for _, arch := range [][]string{
1755 []string{"arm64", "armv8-a"},
1756 } {
1757 archType := arch[0]
1758 archVariant := arch[1]
1759 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1760
1761 // For shared libraries, only recovery_available modules are captured.
1762 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1763 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1764 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1765 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1766 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1767 jsonFiles = append(jsonFiles,
1768 filepath.Join(sharedDir, "libvndk.so.json"),
1769 filepath.Join(sharedDir, "librecovery.so.json"),
1770 filepath.Join(sharedDir, "librecovery_available.so.json"))
1771
1772 // For static libraries, all recovery:true and recovery_available modules are captured.
1773 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1774 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1775 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1776 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1777 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1778 jsonFiles = append(jsonFiles,
1779 filepath.Join(staticDir, "libb.a.json"),
1780 filepath.Join(staticDir, "librecovery.a.json"),
1781 filepath.Join(staticDir, "librecovery_available.a.json"))
1782
1783 // For binary executables, all recovery:true and recovery_available modules are captured.
1784 if archType == "arm64" {
1785 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1786 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1787 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1788 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1789 jsonFiles = append(jsonFiles,
1790 filepath.Join(binaryDir, "recovery_bin.json"),
1791 filepath.Join(binaryDir, "recovery_available_bin.json"))
1792 }
1793
1794 // For header libraries, all vendor:true and vendor_available modules are captured.
1795 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1796 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1797
1798 // For object modules, all vendor:true and vendor_available modules are captured.
1799 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1800 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1801 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1802 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1803 }
1804
1805 for _, jsonFile := range jsonFiles {
1806 // verify all json files exist
1807 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1808 t.Errorf("%q expected but not found", jsonFile)
1809 }
1810 }
1811}
1812
Jooyung Hana70f0672019-01-18 15:20:43 +09001813func TestDoubleLoadableDepError(t *testing.T) {
1814 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1815 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1816 cc_library {
1817 name: "libllndk",
1818 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001819 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001820 }
1821
1822 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001823 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001824 symbol_file: "",
1825 }
1826
1827 cc_library {
1828 name: "libnondoubleloadable",
1829 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001830 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001831 vndk: {
1832 enabled: true,
1833 },
1834 }
1835 `)
1836
1837 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1838 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1839 cc_library {
1840 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001841 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001842 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001843 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001844 }
1845
1846 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001847 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001848 symbol_file: "",
1849 }
1850
1851 cc_library {
1852 name: "libnondoubleloadable",
1853 vendor_available: true,
1854 }
1855 `)
1856
1857 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
1858 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1859 cc_library {
1860 name: "libdoubleloadable",
1861 vendor_available: true,
1862 double_loadable: true,
1863 shared_libs: ["libnondoubleloadable"],
1864 }
1865
1866 cc_library {
1867 name: "libnondoubleloadable",
1868 vendor_available: true,
1869 }
1870 `)
1871
1872 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
1873 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1874 cc_library {
1875 name: "libdoubleloadable",
1876 vendor_available: true,
1877 double_loadable: true,
1878 shared_libs: ["libnondoubleloadable"],
1879 }
1880
1881 cc_library {
1882 name: "libnondoubleloadable",
1883 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001884 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001885 vndk: {
1886 enabled: true,
1887 },
1888 }
1889 `)
1890
1891 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
1892 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1893 cc_library {
1894 name: "libdoubleloadable",
1895 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001896 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001897 vndk: {
1898 enabled: true,
1899 },
1900 double_loadable: true,
1901 shared_libs: ["libnondoubleloadable"],
1902 }
1903
1904 cc_library {
1905 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001906 vendor_available: true,
1907 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001908 vndk: {
1909 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001910 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001911 },
1912 }
1913 `)
1914
1915 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1916 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1917 cc_library {
1918 name: "libllndk",
1919 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001920 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001921 }
1922
1923 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001924 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001925 symbol_file: "",
1926 }
1927
1928 cc_library {
1929 name: "libcoreonly",
1930 shared_libs: ["libvendoravailable"],
1931 }
1932
1933 // indirect dependency of LLNDK
1934 cc_library {
1935 name: "libvendoravailable",
1936 vendor_available: true,
1937 }
1938 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001939}
1940
Jooyung Han479ca172020-10-19 18:51:07 +09001941func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1942 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1943 cc_library {
1944 name: "libvndksp",
1945 shared_libs: ["libanothervndksp"],
1946 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001947 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001948 vndk: {
1949 enabled: true,
1950 support_system_process: true,
1951 }
1952 }
1953
1954 cc_library {
1955 name: "libllndk",
1956 shared_libs: ["libanothervndksp"],
1957 }
1958
1959 llndk_library {
1960 name: "libllndk",
1961 symbol_file: "",
1962 }
1963
1964 cc_library {
1965 name: "libanothervndksp",
1966 vendor_available: true,
1967 }
1968 `)
1969}
1970
Logan Chienf3511742017-10-31 18:04:35 +08001971func TestVndkExt(t *testing.T) {
1972 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001973 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001974 cc_library {
1975 name: "libvndk",
1976 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001977 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001978 vndk: {
1979 enabled: true,
1980 },
1981 nocrt: true,
1982 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001983 cc_library {
1984 name: "libvndk2",
1985 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001986 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001987 vndk: {
1988 enabled: true,
1989 },
1990 target: {
1991 vendor: {
1992 suffix: "-suffix",
1993 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001994 product: {
1995 suffix: "-suffix",
1996 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001997 },
1998 nocrt: true,
1999 }
Logan Chienf3511742017-10-31 18:04:35 +08002000
2001 cc_library {
2002 name: "libvndk_ext",
2003 vendor: true,
2004 vndk: {
2005 enabled: true,
2006 extends: "libvndk",
2007 },
2008 nocrt: true,
2009 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002010
2011 cc_library {
2012 name: "libvndk2_ext",
2013 vendor: true,
2014 vndk: {
2015 enabled: true,
2016 extends: "libvndk2",
2017 },
2018 nocrt: true,
2019 }
Logan Chienf3511742017-10-31 18:04:35 +08002020
Justin Yun0ecf0b22020-02-28 15:07:59 +09002021 cc_library {
2022 name: "libvndk_ext_product",
2023 product_specific: true,
2024 vndk: {
2025 enabled: true,
2026 extends: "libvndk",
2027 },
2028 nocrt: true,
2029 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002030
Justin Yun0ecf0b22020-02-28 15:07:59 +09002031 cc_library {
2032 name: "libvndk2_ext_product",
2033 product_specific: true,
2034 vndk: {
2035 enabled: true,
2036 extends: "libvndk2",
2037 },
2038 nocrt: true,
2039 }
2040 `
2041 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2042 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2043 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2044 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2045
2046 ctx := testCcWithConfig(t, config)
2047
2048 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
2049 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
2050
2051 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
2052 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
2053
2054 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
2055 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08002056}
2057
Logan Chiend3c59a22018-03-29 14:08:15 +08002058func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08002059 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
2060 ctx := testCcNoVndk(t, `
2061 cc_library {
2062 name: "libvndk",
2063 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002064 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002065 vndk: {
2066 enabled: true,
2067 },
2068 nocrt: true,
2069 }
2070
2071 cc_library {
2072 name: "libvndk_ext",
2073 vendor: true,
2074 vndk: {
2075 enabled: true,
2076 extends: "libvndk",
2077 },
2078 nocrt: true,
2079 }
2080 `)
2081
2082 // Ensures that the core variant of "libvndk_ext" can be found.
2083 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
2084 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2085 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
2086 }
2087}
2088
Justin Yun0ecf0b22020-02-28 15:07:59 +09002089func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
2090 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
2091 ctx := testCc(t, `
2092 cc_library {
2093 name: "libvndk",
2094 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002095 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002096 vndk: {
2097 enabled: true,
2098 },
2099 nocrt: true,
2100 }
2101
2102 cc_library {
2103 name: "libvndk_ext_product",
2104 product_specific: true,
2105 vndk: {
2106 enabled: true,
2107 extends: "libvndk",
2108 },
2109 nocrt: true,
2110 }
2111 `)
2112
2113 // Ensures that the core variant of "libvndk_ext_product" can be found.
2114 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
2115 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2116 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
2117 }
2118}
2119
Logan Chienf3511742017-10-31 18:04:35 +08002120func TestVndkExtError(t *testing.T) {
2121 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002122 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08002123 cc_library {
2124 name: "libvndk",
2125 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002126 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002127 vndk: {
2128 enabled: true,
2129 },
2130 nocrt: true,
2131 }
2132
2133 cc_library {
2134 name: "libvndk_ext",
2135 vndk: {
2136 enabled: true,
2137 extends: "libvndk",
2138 },
2139 nocrt: true,
2140 }
2141 `)
2142
2143 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2144 cc_library {
2145 name: "libvndk",
2146 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002147 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002148 vndk: {
2149 enabled: true,
2150 },
2151 nocrt: true,
2152 }
2153
2154 cc_library {
2155 name: "libvndk_ext",
2156 vendor: true,
2157 vndk: {
2158 enabled: true,
2159 },
2160 nocrt: true,
2161 }
2162 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002163
2164 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2165 cc_library {
2166 name: "libvndk",
2167 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002168 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002169 vndk: {
2170 enabled: true,
2171 },
2172 nocrt: true,
2173 }
2174
2175 cc_library {
2176 name: "libvndk_ext_product",
2177 product_specific: true,
2178 vndk: {
2179 enabled: true,
2180 },
2181 nocrt: true,
2182 }
2183 `)
2184
2185 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
2186 cc_library {
2187 name: "libvndk",
2188 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002189 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002190 vndk: {
2191 enabled: true,
2192 },
2193 nocrt: true,
2194 }
2195
2196 cc_library {
2197 name: "libvndk_ext_product",
2198 product_specific: true,
2199 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002200 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002201 vndk: {
2202 enabled: true,
2203 extends: "libvndk",
2204 },
2205 nocrt: true,
2206 }
2207 `)
Logan Chienf3511742017-10-31 18:04:35 +08002208}
2209
2210func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
2211 // This test ensures an error is emitted for inconsistent support_system_process.
2212 testCcError(t, "module \".*\" with mismatched support_system_process", `
2213 cc_library {
2214 name: "libvndk",
2215 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002216 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002217 vndk: {
2218 enabled: true,
2219 },
2220 nocrt: true,
2221 }
2222
2223 cc_library {
2224 name: "libvndk_sp_ext",
2225 vendor: true,
2226 vndk: {
2227 enabled: true,
2228 extends: "libvndk",
2229 support_system_process: true,
2230 },
2231 nocrt: true,
2232 }
2233 `)
2234
2235 testCcError(t, "module \".*\" with mismatched support_system_process", `
2236 cc_library {
2237 name: "libvndk_sp",
2238 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002239 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002240 vndk: {
2241 enabled: true,
2242 support_system_process: true,
2243 },
2244 nocrt: true,
2245 }
2246
2247 cc_library {
2248 name: "libvndk_ext",
2249 vendor: true,
2250 vndk: {
2251 enabled: true,
2252 extends: "libvndk_sp",
2253 },
2254 nocrt: true,
2255 }
2256 `)
2257}
2258
2259func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08002260 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09002261 // with `private: true`.
2262 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08002263 cc_library {
2264 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002265 vendor_available: true,
2266 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002267 vndk: {
2268 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002269 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08002270 },
2271 nocrt: true,
2272 }
2273
2274 cc_library {
2275 name: "libvndk_ext",
2276 vendor: true,
2277 vndk: {
2278 enabled: true,
2279 extends: "libvndk",
2280 },
2281 nocrt: true,
2282 }
2283 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002284
Justin Yunfd9e8042020-12-23 18:23:14 +09002285 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002286 cc_library {
2287 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002288 vendor_available: true,
2289 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002290 vndk: {
2291 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002292 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002293 },
2294 nocrt: true,
2295 }
2296
2297 cc_library {
2298 name: "libvndk_ext_product",
2299 product_specific: true,
2300 vndk: {
2301 enabled: true,
2302 extends: "libvndk",
2303 },
2304 nocrt: true,
2305 }
2306 `)
Logan Chienf3511742017-10-31 18:04:35 +08002307}
2308
Logan Chiend3c59a22018-03-29 14:08:15 +08002309func TestVendorModuleUseVndkExt(t *testing.T) {
2310 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002311 testCc(t, `
2312 cc_library {
2313 name: "libvndk",
2314 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002315 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002316 vndk: {
2317 enabled: true,
2318 },
2319 nocrt: true,
2320 }
2321
2322 cc_library {
2323 name: "libvndk_ext",
2324 vendor: true,
2325 vndk: {
2326 enabled: true,
2327 extends: "libvndk",
2328 },
2329 nocrt: true,
2330 }
2331
2332 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08002333 name: "libvndk_sp",
2334 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002335 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002336 vndk: {
2337 enabled: true,
2338 support_system_process: true,
2339 },
2340 nocrt: true,
2341 }
2342
2343 cc_library {
2344 name: "libvndk_sp_ext",
2345 vendor: true,
2346 vndk: {
2347 enabled: true,
2348 extends: "libvndk_sp",
2349 support_system_process: true,
2350 },
2351 nocrt: true,
2352 }
2353
2354 cc_library {
2355 name: "libvendor",
2356 vendor: true,
2357 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
2358 nocrt: true,
2359 }
2360 `)
2361}
2362
Logan Chiend3c59a22018-03-29 14:08:15 +08002363func TestVndkExtUseVendorLib(t *testing.T) {
2364 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08002365 testCc(t, `
2366 cc_library {
2367 name: "libvndk",
2368 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002369 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002370 vndk: {
2371 enabled: true,
2372 },
2373 nocrt: true,
2374 }
2375
2376 cc_library {
2377 name: "libvndk_ext",
2378 vendor: true,
2379 vndk: {
2380 enabled: true,
2381 extends: "libvndk",
2382 },
2383 shared_libs: ["libvendor"],
2384 nocrt: true,
2385 }
2386
2387 cc_library {
2388 name: "libvendor",
2389 vendor: true,
2390 nocrt: true,
2391 }
2392 `)
Logan Chienf3511742017-10-31 18:04:35 +08002393
Logan Chiend3c59a22018-03-29 14:08:15 +08002394 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
2395 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08002396 cc_library {
2397 name: "libvndk_sp",
2398 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002399 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002400 vndk: {
2401 enabled: true,
2402 support_system_process: true,
2403 },
2404 nocrt: true,
2405 }
2406
2407 cc_library {
2408 name: "libvndk_sp_ext",
2409 vendor: true,
2410 vndk: {
2411 enabled: true,
2412 extends: "libvndk_sp",
2413 support_system_process: true,
2414 },
2415 shared_libs: ["libvendor"], // Cause an error
2416 nocrt: true,
2417 }
2418
2419 cc_library {
2420 name: "libvendor",
2421 vendor: true,
2422 nocrt: true,
2423 }
2424 `)
2425}
2426
Justin Yun0ecf0b22020-02-28 15:07:59 +09002427func TestProductVndkExtDependency(t *testing.T) {
2428 bp := `
2429 cc_library {
2430 name: "libvndk",
2431 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002432 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002433 vndk: {
2434 enabled: true,
2435 },
2436 nocrt: true,
2437 }
2438
2439 cc_library {
2440 name: "libvndk_ext_product",
2441 product_specific: true,
2442 vndk: {
2443 enabled: true,
2444 extends: "libvndk",
2445 },
2446 shared_libs: ["libproduct_for_vndklibs"],
2447 nocrt: true,
2448 }
2449
2450 cc_library {
2451 name: "libvndk_sp",
2452 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002453 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002454 vndk: {
2455 enabled: true,
2456 support_system_process: true,
2457 },
2458 nocrt: true,
2459 }
2460
2461 cc_library {
2462 name: "libvndk_sp_ext_product",
2463 product_specific: true,
2464 vndk: {
2465 enabled: true,
2466 extends: "libvndk_sp",
2467 support_system_process: true,
2468 },
2469 shared_libs: ["libproduct_for_vndklibs"],
2470 nocrt: true,
2471 }
2472
2473 cc_library {
2474 name: "libproduct",
2475 product_specific: true,
2476 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
2477 nocrt: true,
2478 }
2479
2480 cc_library {
2481 name: "libproduct_for_vndklibs",
2482 product_specific: true,
2483 nocrt: true,
2484 }
2485 `
2486 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2487 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2488 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2489 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2490
2491 testCcWithConfig(t, config)
2492}
2493
Logan Chiend3c59a22018-03-29 14:08:15 +08002494func TestVndkSpExtUseVndkError(t *testing.T) {
2495 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
2496 // library.
2497 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2498 cc_library {
2499 name: "libvndk",
2500 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002501 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002502 vndk: {
2503 enabled: true,
2504 },
2505 nocrt: true,
2506 }
2507
2508 cc_library {
2509 name: "libvndk_sp",
2510 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002511 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002512 vndk: {
2513 enabled: true,
2514 support_system_process: true,
2515 },
2516 nocrt: true,
2517 }
2518
2519 cc_library {
2520 name: "libvndk_sp_ext",
2521 vendor: true,
2522 vndk: {
2523 enabled: true,
2524 extends: "libvndk_sp",
2525 support_system_process: true,
2526 },
2527 shared_libs: ["libvndk"], // Cause an error
2528 nocrt: true,
2529 }
2530 `)
2531
2532 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
2533 // library.
2534 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2535 cc_library {
2536 name: "libvndk",
2537 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002538 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002539 vndk: {
2540 enabled: true,
2541 },
2542 nocrt: true,
2543 }
2544
2545 cc_library {
2546 name: "libvndk_ext",
2547 vendor: true,
2548 vndk: {
2549 enabled: true,
2550 extends: "libvndk",
2551 },
2552 nocrt: true,
2553 }
2554
2555 cc_library {
2556 name: "libvndk_sp",
2557 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002558 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002559 vndk: {
2560 enabled: true,
2561 support_system_process: true,
2562 },
2563 nocrt: true,
2564 }
2565
2566 cc_library {
2567 name: "libvndk_sp_ext",
2568 vendor: true,
2569 vndk: {
2570 enabled: true,
2571 extends: "libvndk_sp",
2572 support_system_process: true,
2573 },
2574 shared_libs: ["libvndk_ext"], // Cause an error
2575 nocrt: true,
2576 }
2577 `)
2578}
2579
2580func TestVndkUseVndkExtError(t *testing.T) {
2581 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
2582 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002583 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2584 cc_library {
2585 name: "libvndk",
2586 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002587 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002588 vndk: {
2589 enabled: true,
2590 },
2591 nocrt: true,
2592 }
2593
2594 cc_library {
2595 name: "libvndk_ext",
2596 vendor: true,
2597 vndk: {
2598 enabled: true,
2599 extends: "libvndk",
2600 },
2601 nocrt: true,
2602 }
2603
2604 cc_library {
2605 name: "libvndk2",
2606 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002607 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002608 vndk: {
2609 enabled: true,
2610 },
2611 shared_libs: ["libvndk_ext"],
2612 nocrt: true,
2613 }
2614 `)
2615
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002616 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002617 cc_library {
2618 name: "libvndk",
2619 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002620 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002621 vndk: {
2622 enabled: true,
2623 },
2624 nocrt: true,
2625 }
2626
2627 cc_library {
2628 name: "libvndk_ext",
2629 vendor: true,
2630 vndk: {
2631 enabled: true,
2632 extends: "libvndk",
2633 },
2634 nocrt: true,
2635 }
2636
2637 cc_library {
2638 name: "libvndk2",
2639 vendor_available: true,
2640 vndk: {
2641 enabled: true,
2642 },
2643 target: {
2644 vendor: {
2645 shared_libs: ["libvndk_ext"],
2646 },
2647 },
2648 nocrt: true,
2649 }
2650 `)
2651
2652 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2653 cc_library {
2654 name: "libvndk_sp",
2655 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002656 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002657 vndk: {
2658 enabled: true,
2659 support_system_process: true,
2660 },
2661 nocrt: true,
2662 }
2663
2664 cc_library {
2665 name: "libvndk_sp_ext",
2666 vendor: true,
2667 vndk: {
2668 enabled: true,
2669 extends: "libvndk_sp",
2670 support_system_process: true,
2671 },
2672 nocrt: true,
2673 }
2674
2675 cc_library {
2676 name: "libvndk_sp_2",
2677 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002678 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002679 vndk: {
2680 enabled: true,
2681 support_system_process: true,
2682 },
2683 shared_libs: ["libvndk_sp_ext"],
2684 nocrt: true,
2685 }
2686 `)
2687
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002688 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002689 cc_library {
2690 name: "libvndk_sp",
2691 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002692 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002693 vndk: {
2694 enabled: true,
2695 },
2696 nocrt: true,
2697 }
2698
2699 cc_library {
2700 name: "libvndk_sp_ext",
2701 vendor: true,
2702 vndk: {
2703 enabled: true,
2704 extends: "libvndk_sp",
2705 },
2706 nocrt: true,
2707 }
2708
2709 cc_library {
2710 name: "libvndk_sp2",
2711 vendor_available: true,
2712 vndk: {
2713 enabled: true,
2714 },
2715 target: {
2716 vendor: {
2717 shared_libs: ["libvndk_sp_ext"],
2718 },
2719 },
2720 nocrt: true,
2721 }
2722 `)
2723}
2724
Justin Yun5f7f7e82019-11-18 19:52:14 +09002725func TestEnforceProductVndkVersion(t *testing.T) {
2726 bp := `
2727 cc_library {
2728 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002729 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002730 }
2731 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002732 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002733 symbol_file: "",
2734 }
2735 cc_library {
2736 name: "libvndk",
2737 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002738 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002739 vndk: {
2740 enabled: true,
2741 },
2742 nocrt: true,
2743 }
2744 cc_library {
2745 name: "libvndk_sp",
2746 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002747 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002748 vndk: {
2749 enabled: true,
2750 support_system_process: true,
2751 },
2752 nocrt: true,
2753 }
2754 cc_library {
2755 name: "libva",
2756 vendor_available: true,
2757 nocrt: true,
2758 }
2759 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002760 name: "libpa",
2761 product_available: true,
2762 nocrt: true,
2763 }
2764 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002765 name: "libboth_available",
2766 vendor_available: true,
2767 product_available: true,
2768 nocrt: true,
2769 target: {
2770 vendor: {
2771 suffix: "-vendor",
2772 },
2773 product: {
2774 suffix: "-product",
2775 },
2776 }
2777 }
2778 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002779 name: "libproduct_va",
2780 product_specific: true,
2781 vendor_available: true,
2782 nocrt: true,
2783 }
2784 cc_library {
2785 name: "libprod",
2786 product_specific: true,
2787 shared_libs: [
2788 "libllndk",
2789 "libvndk",
2790 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002791 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002792 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002793 "libproduct_va",
2794 ],
2795 nocrt: true,
2796 }
2797 cc_library {
2798 name: "libvendor",
2799 vendor: true,
2800 shared_libs: [
2801 "libllndk",
2802 "libvndk",
2803 "libvndk_sp",
2804 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002805 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002806 "libproduct_va",
2807 ],
2808 nocrt: true,
2809 }
2810 `
2811
2812 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2813 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2814 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2815 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2816
2817 ctx := testCcWithConfig(t, config)
2818
Jooyung Han261e1582020-10-20 18:54:21 +09002819 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2820 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002821
2822 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2823 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2824
2825 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2826 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002827}
2828
2829func TestEnforceProductVndkVersionErrors(t *testing.T) {
2830 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2831 cc_library {
2832 name: "libprod",
2833 product_specific: true,
2834 shared_libs: [
2835 "libvendor",
2836 ],
2837 nocrt: true,
2838 }
2839 cc_library {
2840 name: "libvendor",
2841 vendor: true,
2842 nocrt: true,
2843 }
2844 `)
2845 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2846 cc_library {
2847 name: "libprod",
2848 product_specific: true,
2849 shared_libs: [
2850 "libsystem",
2851 ],
2852 nocrt: true,
2853 }
2854 cc_library {
2855 name: "libsystem",
2856 nocrt: true,
2857 }
2858 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002859 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2860 cc_library {
2861 name: "libprod",
2862 product_specific: true,
2863 shared_libs: [
2864 "libva",
2865 ],
2866 nocrt: true,
2867 }
2868 cc_library {
2869 name: "libva",
2870 vendor_available: true,
2871 nocrt: true,
2872 }
2873 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002874 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002875 cc_library {
2876 name: "libprod",
2877 product_specific: true,
2878 shared_libs: [
2879 "libvndk_private",
2880 ],
2881 nocrt: true,
2882 }
2883 cc_library {
2884 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002885 vendor_available: true,
2886 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002887 vndk: {
2888 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002889 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002890 },
2891 nocrt: true,
2892 }
2893 `)
2894 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2895 cc_library {
2896 name: "libprod",
2897 product_specific: true,
2898 shared_libs: [
2899 "libsystem_ext",
2900 ],
2901 nocrt: true,
2902 }
2903 cc_library {
2904 name: "libsystem_ext",
2905 system_ext_specific: true,
2906 nocrt: true,
2907 }
2908 `)
2909 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2910 cc_library {
2911 name: "libsystem",
2912 shared_libs: [
2913 "libproduct_va",
2914 ],
2915 nocrt: true,
2916 }
2917 cc_library {
2918 name: "libproduct_va",
2919 product_specific: true,
2920 vendor_available: true,
2921 nocrt: true,
2922 }
2923 `)
2924}
2925
Jooyung Han38002912019-05-16 04:01:54 +09002926func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002927 bp := `
2928 cc_library {
2929 name: "libvndk",
2930 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002931 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002932 vndk: {
2933 enabled: true,
2934 },
2935 }
2936 cc_library {
2937 name: "libvndksp",
2938 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002939 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002940 vndk: {
2941 enabled: true,
2942 support_system_process: true,
2943 },
2944 }
2945 cc_library {
2946 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002947 vendor_available: true,
2948 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002949 vndk: {
2950 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002951 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002952 },
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}