blob: cc1f7d08222e8da92e17fc4189b1684ace525880 [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"
Paul Duffin3cb603e2021-02-19 13:57:10 +000023 "regexp"
Jeff Gaston294356f2017-09-27 17:05:30 -070024 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070025 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070026
27 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070028)
29
Jiyong Park6a43f042017-10-12 23:05:00 +090030var buildDir string
31
32func setUp() {
33 var err error
34 buildDir, err = ioutil.TempDir("", "soong_cc_test")
35 if err != nil {
36 panic(err)
37 }
38}
39
40func tearDown() {
41 os.RemoveAll(buildDir)
42}
43
44func TestMain(m *testing.M) {
45 run := func() int {
46 setUp()
47 defer tearDown()
48
49 return m.Run()
50 }
51
52 os.Exit(run())
53}
54
Paul Duffin02a3d652021-02-24 18:51:54 +000055var ccFixtureFactory = android.NewFixtureFactory(
56 &buildDir,
57 PrepareForTestWithCcIncludeVndk,
58
59 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
60 variables.DeviceVndkVersion = StringPtr("current")
61 variables.ProductVndkVersion = StringPtr("current")
62 variables.Platform_vndk_version = StringPtr("VER")
63 }),
64)
65
66// testCcWithConfig runs tests using the ccFixtureFactory
67//
68// See testCc for an explanation as to how to stop using this deprecated method.
69//
70// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -080071func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070072 t.Helper()
Paul Duffin02a3d652021-02-24 18:51:54 +000073 result := ccFixtureFactory.RunTestWithConfig(t, config)
74 return result.TestContext
Jiyong Park6a43f042017-10-12 23:05:00 +090075}
76
Paul Duffin02a3d652021-02-24 18:51:54 +000077// testCc runs tests using the ccFixtureFactory
78//
79// Do not add any new usages of this, instead use the ccFixtureFactory directly as it makes it much
80// easier to customize the test behavior.
81//
82// If it is necessary to customize the behavior of an existing test that uses this then please first
83// convert the test to using ccFixtureFactory first and then in a following change add the
84// appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
85// that it did not change the test behavior unexpectedly.
86//
87// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080088func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080089 t.Helper()
Paul Duffin02a3d652021-02-24 18:51:54 +000090 result := ccFixtureFactory.RunTestWithBp(t, bp)
91 return result.TestContext
Logan Chienf3511742017-10-31 18:04:35 +080092}
93
Paul Duffin02a3d652021-02-24 18:51:54 +000094// testCcNoVndk runs tests using the ccFixtureFactory
95//
96// See testCc for an explanation as to how to stop using this deprecated method.
97//
98// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080099func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800100 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800101 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700102 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800103
Colin Cross98be1bb2019-12-13 20:41:13 -0800104 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800105}
106
Paul Duffin02a3d652021-02-24 18:51:54 +0000107// testCcNoProductVndk runs tests using the ccFixtureFactory
108//
109// See testCc for an explanation as to how to stop using this deprecated method.
110//
111// deprecated
Justin Yun8a2600c2020-12-07 12:44:03 +0900112func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
113 t.Helper()
114 config := TestConfig(buildDir, android.Android, nil, bp, nil)
115 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
116 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
117
118 return testCcWithConfig(t, config)
119}
120
Paul Duffin02a3d652021-02-24 18:51:54 +0000121// testCcErrorWithConfig runs tests using the ccFixtureFactory
122//
123// See testCc for an explanation as to how to stop using this deprecated method.
124//
125// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900126func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800127 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800128
Paul Duffin02a3d652021-02-24 18:51:54 +0000129 ccFixtureFactory.Extend().
130 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
131 RunTestWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800132}
133
Paul Duffin02a3d652021-02-24 18:51:54 +0000134// testCcError runs tests using the ccFixtureFactory
135//
136// See testCc for an explanation as to how to stop using this deprecated method.
137//
138// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900139func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900140 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900141 config := TestConfig(buildDir, android.Android, nil, bp, nil)
142 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
143 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
144 testCcErrorWithConfig(t, pattern, config)
145 return
146}
147
Paul Duffin02a3d652021-02-24 18:51:54 +0000148// testCcErrorProductVndk runs tests using the ccFixtureFactory
149//
150// See testCc for an explanation as to how to stop using this deprecated method.
151//
152// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900153func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900154 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900155 config := TestConfig(buildDir, android.Android, nil, bp, nil)
156 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
157 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
158 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
159 testCcErrorWithConfig(t, pattern, config)
160 return
161}
162
Logan Chienf3511742017-10-31 18:04:35 +0800163const (
Colin Cross7113d202019-11-20 16:39:12 -0800164 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800165 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900166 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800167 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800168)
169
Doug Hornc32c6b02019-01-17 14:44:05 -0800170func TestFuchsiaDeps(t *testing.T) {
171 t.Helper()
172
173 bp := `
174 cc_library {
175 name: "libTest",
176 srcs: ["foo.c"],
177 target: {
178 fuchsia: {
179 srcs: ["bar.c"],
180 },
181 },
182 }`
183
Paul Duffinecdac8a2021-02-24 19:18:42 +0000184 result := ccFixtureFactory.Extend(PrepareForTestOnFuchsia).RunTestWithBp(t, bp)
Doug Hornc32c6b02019-01-17 14:44:05 -0800185
186 rt := false
187 fb := false
188
Paul Duffinecdac8a2021-02-24 19:18:42 +0000189 ld := result.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
Doug Hornc32c6b02019-01-17 14:44:05 -0800190 implicits := ld.Implicits
191 for _, lib := range implicits {
192 if strings.Contains(lib.Rel(), "libcompiler_rt") {
193 rt = true
194 }
195
196 if strings.Contains(lib.Rel(), "libbioniccompat") {
197 fb = true
198 }
199 }
200
201 if !rt || !fb {
202 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
203 }
204}
205
206func TestFuchsiaTargetDecl(t *testing.T) {
207 t.Helper()
208
209 bp := `
210 cc_library {
211 name: "libTest",
212 srcs: ["foo.c"],
213 target: {
214 fuchsia: {
215 srcs: ["bar.c"],
216 },
217 },
218 }`
219
Paul Duffinecdac8a2021-02-24 19:18:42 +0000220 result := ccFixtureFactory.Extend(PrepareForTestOnFuchsia).RunTestWithBp(t, bp)
221 ld := result.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
Doug Hornc32c6b02019-01-17 14:44:05 -0800222 var objs []string
223 for _, o := range ld.Inputs {
224 objs = append(objs, o.Base())
225 }
Paul Duffinecdac8a2021-02-24 19:18:42 +0000226 result.AssertArrayString("libTest inputs", []string{"foo.o", "bar.o"}, objs)
Doug Hornc32c6b02019-01-17 14:44:05 -0800227}
228
Jiyong Park6a43f042017-10-12 23:05:00 +0900229func TestVendorSrc(t *testing.T) {
230 ctx := testCc(t, `
231 cc_library {
232 name: "libTest",
233 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700234 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800235 nocrt: true,
236 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900237 vendor_available: true,
238 target: {
239 vendor: {
240 srcs: ["bar.c"],
241 },
242 },
243 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900244 `)
245
Logan Chienf3511742017-10-31 18:04:35 +0800246 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900247 var objs []string
248 for _, o := range ld.Inputs {
249 objs = append(objs, o.Base())
250 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800251 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900252 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
253 }
254}
255
Logan Chienf3511742017-10-31 18:04:35 +0800256func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900257 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800258
Logan Chiend3c59a22018-03-29 14:08:15 +0800259 t.Helper()
260
Justin Yun0ecf0b22020-02-28 15:07:59 +0900261 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Logan Chienf3511742017-10-31 18:04:35 +0800262
263 // Check library properties.
264 lib, ok := mod.compiler.(*libraryDecorator)
265 if !ok {
266 t.Errorf("%q must have libraryDecorator", name)
267 } else if lib.baseInstaller.subDir != subDir {
268 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
269 lib.baseInstaller.subDir)
270 }
271
272 // Check VNDK properties.
273 if mod.vndkdep == nil {
274 t.Fatalf("%q must have `vndkdep`", name)
275 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700276 if !mod.IsVndk() {
277 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800278 }
279 if mod.isVndkSp() != isVndkSp {
280 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
281 }
282
283 // Check VNDK extension properties.
284 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500285 if mod.IsVndkExt() != isVndkExt {
286 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800287 }
288
289 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
290 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
291 }
292}
293
Jose Galmes0a942a02021-02-03 14:23:15 -0800294func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
Bill Peckham945441c2020-08-31 16:07:58 -0700295 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900296 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
297 if !ok {
298 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900299 return
300 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900301 outputFiles, err := mod.OutputFiles("")
302 if err != nil || len(outputFiles) != 1 {
303 t.Errorf("%q must have single output\n", moduleName)
304 return
305 }
306 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900307
Bill Peckham945441c2020-08-31 16:07:58 -0700308 if include {
309 out := singleton.Output(snapshotPath)
Jose Galmes0a942a02021-02-03 14:23:15 -0800310 if fake {
311 if out.Rule == nil {
312 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
313 }
314 } else {
315 if out.Input.String() != outputFiles[0].String() {
316 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
317 }
Bill Peckham945441c2020-08-31 16:07:58 -0700318 }
319 } else {
320 out := singleton.MaybeOutput(snapshotPath)
321 if out.Rule != nil {
322 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
323 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900324 }
325}
326
Bill Peckham945441c2020-08-31 16:07:58 -0700327func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800328 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
Bill Peckham945441c2020-08-31 16:07:58 -0700329}
330
331func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800332 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
333}
334
335func checkSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
336 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
Bill Peckham945441c2020-08-31 16:07:58 -0700337}
338
Jooyung Han2216fb12019-11-06 16:46:15 +0900339func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
340 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800341 content := android.ContentFromFileRuleForTests(t, params)
342 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900343 assertArrayString(t, actual, expected)
344}
345
Jooyung Han097087b2019-10-22 19:32:18 +0900346func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
347 t.Helper()
348 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900349 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
350}
351
352func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
353 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800354 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
355 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900356}
357
Logan Chienf3511742017-10-31 18:04:35 +0800358func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800359 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800360 cc_library {
361 name: "libvndk",
362 vendor_available: true,
363 vndk: {
364 enabled: true,
365 },
366 nocrt: true,
367 }
368
369 cc_library {
370 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900371 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800372 vndk: {
373 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900374 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800375 },
376 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900377 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800378 }
379
380 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900381 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800382 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900383 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800384 vndk: {
385 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900386 },
387 nocrt: true,
388 target: {
389 vendor: {
390 cflags: ["-DTEST"],
391 },
392 product: {
393 cflags: ["-DTEST"],
394 },
395 },
396 }
397
398 cc_library {
399 name: "libvndk_sp",
400 vendor_available: true,
401 vndk: {
402 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800403 support_system_process: true,
404 },
405 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900406 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800407 }
408
409 cc_library {
410 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900411 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800412 vndk: {
413 enabled: true,
414 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900415 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800416 },
417 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900418 target: {
419 vendor: {
420 suffix: "-x",
421 },
422 },
Logan Chienf3511742017-10-31 18:04:35 +0800423 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900424
425 cc_library {
426 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900427 vendor_available: true,
428 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900429 vndk: {
430 enabled: true,
431 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900432 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900433 },
434 nocrt: true,
435 target: {
436 vendor: {
437 suffix: "-x",
438 },
439 product: {
440 suffix: "-x",
441 },
442 },
443 }
444
Colin Crosse4e44bc2020-12-28 13:50:21 -0800445 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900446 name: "llndk.libraries.txt",
447 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800448 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900449 name: "vndkcore.libraries.txt",
450 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800451 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900452 name: "vndksp.libraries.txt",
453 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800454 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900455 name: "vndkprivate.libraries.txt",
456 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800457 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900458 name: "vndkproduct.libraries.txt",
459 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800460 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900461 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800462 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900463 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800464 `
465
466 config := TestConfig(buildDir, android.Android, nil, bp, nil)
467 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900468 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800469 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
470
471 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800472
Jooyung Han261e1582020-10-20 18:54:21 +0900473 // subdir == "" because VNDK libs are not supposed to be installed separately.
474 // They are installed as part of VNDK APEX instead.
475 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
476 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900477 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900478 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
479 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900480 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900481
Justin Yun6977e8a2020-10-29 18:24:11 +0900482 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
483 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900484
Inseob Kim1f086e22019-05-09 13:29:15 +0900485 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900486 snapshotDir := "vndk-snapshot"
487 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
488
489 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
490 "arm64", "armv8-a"))
491 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
492 "arm", "armv7-a-neon"))
493
494 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
495 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
496 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
497 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
498
Colin Crossfb0c16e2019-11-20 17:12:35 -0800499 variant := "android_vendor.VER_arm64_armv8-a_shared"
500 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900501
Inseob Kim7f283f42020-06-01 21:53:49 +0900502 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
503
504 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
505 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900506 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
507 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900508 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
509 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900510
Jooyung Han39edb6c2019-11-06 16:53:07 +0900511 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900512 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
513 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
514 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
515 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900516 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900517
Jooyung Han097087b2019-10-22 19:32:18 +0900518 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
519 "LLNDK: libc.so",
520 "LLNDK: libdl.so",
521 "LLNDK: libft2.so",
522 "LLNDK: libm.so",
523 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900524 "VNDK-SP: libvndk_sp-x.so",
525 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900526 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900527 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900528 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900529 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900530 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900531 "VNDK-private: libvndk-private.so",
532 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900533 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900534 "VNDK-product: libc++.so",
535 "VNDK-product: libvndk_product.so",
536 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900537 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900538 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900539 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
540 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
541 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
Justin Yun8a2600c2020-12-07 12:44:03 +0900542 checkVndkLibrariesOutput(t, ctx, "vndkproduct.libraries.txt", []string{"libc++.so", "libvndk_product.so", "libvndk_sp_product_private-x.so"})
Jooyung Han2216fb12019-11-06 16:46:15 +0900543 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
544}
545
Yo Chiangbba545e2020-06-09 16:15:37 +0800546func TestVndkWithHostSupported(t *testing.T) {
547 ctx := testCc(t, `
548 cc_library {
549 name: "libvndk_host_supported",
550 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900551 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800552 vndk: {
553 enabled: true,
554 },
555 host_supported: true,
556 }
557
558 cc_library {
559 name: "libvndk_host_supported_but_disabled_on_device",
560 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900561 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800562 vndk: {
563 enabled: true,
564 },
565 host_supported: true,
566 enabled: false,
567 target: {
568 host: {
569 enabled: true,
570 }
571 }
572 }
573
Colin Crosse4e44bc2020-12-28 13:50:21 -0800574 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800575 name: "vndkcore.libraries.txt",
576 }
577 `)
578
579 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
580}
581
Jooyung Han2216fb12019-11-06 16:46:15 +0900582func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800583 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800584 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900585 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800586 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800587 }`
588 config := TestConfig(buildDir, android.Android, nil, bp, nil)
589 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
590 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
591 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900592
593 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Colin Crossaa255532020-07-03 13:18:24 -0700594 entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900595 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900596}
597
598func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800599 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900600 cc_library {
601 name: "libvndk",
602 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900603 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900604 vndk: {
605 enabled: true,
606 },
607 nocrt: true,
608 }
609
610 cc_library {
611 name: "libvndk_sp",
612 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900613 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900614 vndk: {
615 enabled: true,
616 support_system_process: true,
617 },
618 nocrt: true,
619 }
620
621 cc_library {
622 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900623 vendor_available: true,
624 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900625 vndk: {
626 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900627 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900628 },
629 nocrt: true,
630 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900631
Colin Crosse4e44bc2020-12-28 13:50:21 -0800632 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900633 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800634 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900635 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800636 `
637
638 config := TestConfig(buildDir, android.Android, nil, bp, nil)
639 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
640 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
641 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
642
643 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
644
645 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900646
Jooyung Han2216fb12019-11-06 16:46:15 +0900647 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900648}
649
Chris Parsons79d66a52020-06-05 17:26:16 -0400650func TestDataLibs(t *testing.T) {
651 bp := `
652 cc_test_library {
653 name: "test_lib",
654 srcs: ["test_lib.cpp"],
655 gtest: false,
656 }
657
658 cc_test {
659 name: "main_test",
660 data_libs: ["test_lib"],
661 gtest: false,
662 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400663 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400664
665 config := TestConfig(buildDir, android.Android, nil, bp, nil)
666 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
667 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
668 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
669
670 ctx := testCcWithConfig(t, config)
671 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
672 testBinary := module.(*Module).linker.(*testBinary)
673 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
674 if err != nil {
675 t.Errorf("Expected cc_test to produce output files, error: %s", err)
676 return
677 }
678 if len(outputFiles) != 1 {
679 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
680 return
681 }
682 if len(testBinary.dataPaths()) != 1 {
683 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
684 return
685 }
686
687 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400688 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400689
690 if !strings.HasSuffix(outputPath, "/main_test") {
691 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
692 return
693 }
694 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
695 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
696 return
697 }
698}
699
Chris Parsons216e10a2020-07-09 17:12:52 -0400700func TestDataLibsRelativeInstallPath(t *testing.T) {
701 bp := `
702 cc_test_library {
703 name: "test_lib",
704 srcs: ["test_lib.cpp"],
705 relative_install_path: "foo/bar/baz",
706 gtest: false,
707 }
708
709 cc_test {
710 name: "main_test",
711 data_libs: ["test_lib"],
712 gtest: false,
713 }
714 `
715
716 config := TestConfig(buildDir, android.Android, nil, bp, nil)
717 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
718 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
719 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
720
721 ctx := testCcWithConfig(t, config)
722 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
723 testBinary := module.(*Module).linker.(*testBinary)
724 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
725 if err != nil {
726 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
727 }
728 if len(outputFiles) != 1 {
729 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
730 }
731 if len(testBinary.dataPaths()) != 1 {
732 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
733 }
734
735 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400736
737 if !strings.HasSuffix(outputPath, "/main_test") {
738 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
739 }
Colin Crossaa255532020-07-03 13:18:24 -0700740 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons216e10a2020-07-09 17:12:52 -0400741 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
742 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400743 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400744 }
745}
746
Jooyung Han0302a842019-10-30 18:43:49 +0900747func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900748 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900749 cc_library {
750 name: "libvndk",
751 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900752 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900753 vndk: {
754 enabled: true,
755 },
756 nocrt: true,
757 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900758 cc_library {
759 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900760 vendor_available: true,
761 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900762 vndk: {
763 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900764 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900765 },
766 nocrt: true,
767 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800768
769 cc_library {
770 name: "libllndk",
771 llndk_stubs: "libllndk.llndk",
772 }
773
774 llndk_library {
775 name: "libllndk.llndk",
776 symbol_file: "",
777 export_llndk_headers: ["libllndk_headers"],
778 }
779
780 llndk_headers {
781 name: "libllndk_headers",
782 export_include_dirs: ["include"],
783 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900784 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900785
786 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
787 "LLNDK: libc.so",
788 "LLNDK: libdl.so",
789 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800790 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900791 "LLNDK: libm.so",
792 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900793 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900794 "VNDK-core: libvndk.so",
795 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900796 "VNDK-private: libvndk-private.so",
797 "VNDK-product: libc++.so",
798 "VNDK-product: libvndk-private.so",
799 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900800 })
Logan Chienf3511742017-10-31 18:04:35 +0800801}
802
Justin Yun63e9ec72020-10-29 16:49:43 +0900803func TestVndkModuleError(t *testing.T) {
804 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900805 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900806 cc_library {
807 name: "libvndk",
808 vndk: {
809 enabled: true,
810 },
811 nocrt: true,
812 }
813 `)
814
Justin Yunc0d8c492021-01-07 17:45:31 +0900815 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900816 cc_library {
817 name: "libvndk",
818 product_available: true,
819 vndk: {
820 enabled: true,
821 },
822 nocrt: true,
823 }
824 `)
825
Justin Yun6977e8a2020-10-29 18:24:11 +0900826 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
827 cc_library {
828 name: "libvndkprop",
829 vendor_available: true,
830 product_available: true,
831 vndk: {
832 enabled: true,
833 },
834 nocrt: true,
835 target: {
836 vendor: {
837 cflags: ["-DTEST",],
838 },
839 },
840 }
841 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900842}
843
Logan Chiend3c59a22018-03-29 14:08:15 +0800844func TestVndkDepError(t *testing.T) {
845 // Check whether an error is emitted when a VNDK lib depends on a system lib.
846 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
847 cc_library {
848 name: "libvndk",
849 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900850 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800851 vndk: {
852 enabled: true,
853 },
854 shared_libs: ["libfwk"], // Cause error
855 nocrt: true,
856 }
857
858 cc_library {
859 name: "libfwk",
860 nocrt: true,
861 }
862 `)
863
864 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
865 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
866 cc_library {
867 name: "libvndk",
868 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900869 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800870 vndk: {
871 enabled: true,
872 },
873 shared_libs: ["libvendor"], // Cause error
874 nocrt: true,
875 }
876
877 cc_library {
878 name: "libvendor",
879 vendor: true,
880 nocrt: true,
881 }
882 `)
883
884 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
885 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
886 cc_library {
887 name: "libvndk_sp",
888 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900889 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800890 vndk: {
891 enabled: true,
892 support_system_process: true,
893 },
894 shared_libs: ["libfwk"], // Cause error
895 nocrt: true,
896 }
897
898 cc_library {
899 name: "libfwk",
900 nocrt: true,
901 }
902 `)
903
904 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
905 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
906 cc_library {
907 name: "libvndk_sp",
908 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900909 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800910 vndk: {
911 enabled: true,
912 support_system_process: true,
913 },
914 shared_libs: ["libvendor"], // Cause error
915 nocrt: true,
916 }
917
918 cc_library {
919 name: "libvendor",
920 vendor: true,
921 nocrt: true,
922 }
923 `)
924
925 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
926 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
927 cc_library {
928 name: "libvndk_sp",
929 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900930 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800931 vndk: {
932 enabled: true,
933 support_system_process: true,
934 },
935 shared_libs: ["libvndk"], // Cause error
936 nocrt: true,
937 }
938
939 cc_library {
940 name: "libvndk",
941 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900942 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800943 vndk: {
944 enabled: true,
945 },
946 nocrt: true,
947 }
948 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900949
950 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
951 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
952 cc_library {
953 name: "libvndk",
954 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900955 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900956 vndk: {
957 enabled: true,
958 },
959 shared_libs: ["libnonvndk"],
960 nocrt: true,
961 }
962
963 cc_library {
964 name: "libnonvndk",
965 vendor_available: true,
966 nocrt: true,
967 }
968 `)
969
970 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
971 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
972 cc_library {
973 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900974 vendor_available: true,
975 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900976 vndk: {
977 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900978 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900979 },
980 shared_libs: ["libnonvndk"],
981 nocrt: true,
982 }
983
984 cc_library {
985 name: "libnonvndk",
986 vendor_available: true,
987 nocrt: true,
988 }
989 `)
990
991 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
992 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
993 cc_library {
994 name: "libvndksp",
995 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900996 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900997 vndk: {
998 enabled: true,
999 support_system_process: true,
1000 },
1001 shared_libs: ["libnonvndk"],
1002 nocrt: true,
1003 }
1004
1005 cc_library {
1006 name: "libnonvndk",
1007 vendor_available: true,
1008 nocrt: true,
1009 }
1010 `)
1011
1012 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
1013 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1014 cc_library {
1015 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001016 vendor_available: true,
1017 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001018 vndk: {
1019 enabled: true,
1020 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001021 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001022 },
1023 shared_libs: ["libnonvndk"],
1024 nocrt: true,
1025 }
1026
1027 cc_library {
1028 name: "libnonvndk",
1029 vendor_available: true,
1030 nocrt: true,
1031 }
1032 `)
1033}
1034
1035func TestDoubleLoadbleDep(t *testing.T) {
1036 // okay to link : LLNDK -> double_loadable VNDK
1037 testCc(t, `
1038 cc_library {
1039 name: "libllndk",
1040 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001041 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001042 }
1043
1044 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001045 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001046 symbol_file: "",
1047 }
1048
1049 cc_library {
1050 name: "libdoubleloadable",
1051 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001052 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001053 vndk: {
1054 enabled: true,
1055 },
1056 double_loadable: true,
1057 }
1058 `)
1059 // okay to link : LLNDK -> VNDK-SP
1060 testCc(t, `
1061 cc_library {
1062 name: "libllndk",
1063 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -07001064 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001065 }
1066
1067 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001068 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001069 symbol_file: "",
1070 }
1071
1072 cc_library {
1073 name: "libvndksp",
1074 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001075 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001076 vndk: {
1077 enabled: true,
1078 support_system_process: true,
1079 },
1080 }
1081 `)
1082 // okay to link : double_loadable -> double_loadable
1083 testCc(t, `
1084 cc_library {
1085 name: "libdoubleloadable1",
1086 shared_libs: ["libdoubleloadable2"],
1087 vendor_available: true,
1088 double_loadable: true,
1089 }
1090
1091 cc_library {
1092 name: "libdoubleloadable2",
1093 vendor_available: true,
1094 double_loadable: true,
1095 }
1096 `)
1097 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1098 testCc(t, `
1099 cc_library {
1100 name: "libdoubleloadable",
1101 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001102 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001103 vndk: {
1104 enabled: true,
1105 },
1106 double_loadable: true,
1107 shared_libs: ["libnondoubleloadable"],
1108 }
1109
1110 cc_library {
1111 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001112 vendor_available: true,
1113 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001114 vndk: {
1115 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001116 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001117 },
1118 double_loadable: true,
1119 }
1120 `)
1121 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1122 testCc(t, `
1123 cc_library {
1124 name: "libllndk",
1125 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001126 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001127 }
1128
1129 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001130 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001131 symbol_file: "",
1132 }
1133
1134 cc_library {
1135 name: "libcoreonly",
1136 shared_libs: ["libvendoravailable"],
1137 }
1138
1139 // indirect dependency of LLNDK
1140 cc_library {
1141 name: "libvendoravailable",
1142 vendor_available: true,
1143 double_loadable: true,
1144 }
1145 `)
1146}
1147
1148func TestDoubleLoadableDepError(t *testing.T) {
1149 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1150 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1151 cc_library {
1152 name: "libllndk",
1153 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001154 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001155 }
1156
1157 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001158 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001159 symbol_file: "",
1160 }
1161
1162 cc_library {
1163 name: "libnondoubleloadable",
1164 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001165 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001166 vndk: {
1167 enabled: true,
1168 },
1169 }
1170 `)
1171
1172 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1173 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1174 cc_library {
1175 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001176 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001177 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001178 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001179 }
1180
1181 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001182 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001183 symbol_file: "",
1184 }
1185
1186 cc_library {
1187 name: "libnondoubleloadable",
1188 vendor_available: true,
1189 }
1190 `)
1191
Jooyung Hana70f0672019-01-18 15:20:43 +09001192 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1193 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1194 cc_library {
1195 name: "libllndk",
1196 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001197 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001198 }
1199
1200 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001201 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001202 symbol_file: "",
1203 }
1204
1205 cc_library {
1206 name: "libcoreonly",
1207 shared_libs: ["libvendoravailable"],
1208 }
1209
1210 // indirect dependency of LLNDK
1211 cc_library {
1212 name: "libvendoravailable",
1213 vendor_available: true,
1214 }
1215 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001216
1217 // The error is not from 'client' but from 'libllndk'
1218 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1219 cc_library {
1220 name: "client",
1221 vendor_available: true,
1222 double_loadable: true,
1223 shared_libs: ["libllndk"],
1224 }
1225 cc_library {
1226 name: "libllndk",
1227 shared_libs: ["libnondoubleloadable"],
1228 llndk_stubs: "libllndk.llndk",
1229 }
1230 llndk_library {
1231 name: "libllndk.llndk",
1232 symbol_file: "",
1233 }
1234 cc_library {
1235 name: "libnondoubleloadable",
1236 vendor_available: true,
1237 }
1238 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001239}
1240
Jooyung Han479ca172020-10-19 18:51:07 +09001241func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1242 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1243 cc_library {
1244 name: "libvndksp",
1245 shared_libs: ["libanothervndksp"],
1246 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001247 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001248 vndk: {
1249 enabled: true,
1250 support_system_process: true,
1251 }
1252 }
1253
1254 cc_library {
1255 name: "libllndk",
1256 shared_libs: ["libanothervndksp"],
1257 }
1258
1259 llndk_library {
1260 name: "libllndk",
1261 symbol_file: "",
1262 }
1263
1264 cc_library {
1265 name: "libanothervndksp",
1266 vendor_available: true,
1267 }
1268 `)
1269}
1270
Logan Chienf3511742017-10-31 18:04:35 +08001271func TestVndkExt(t *testing.T) {
1272 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001273 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001274 cc_library {
1275 name: "libvndk",
1276 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001277 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001278 vndk: {
1279 enabled: true,
1280 },
1281 nocrt: true,
1282 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001283 cc_library {
1284 name: "libvndk2",
1285 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001286 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001287 vndk: {
1288 enabled: true,
1289 },
1290 target: {
1291 vendor: {
1292 suffix: "-suffix",
1293 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001294 product: {
1295 suffix: "-suffix",
1296 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001297 },
1298 nocrt: true,
1299 }
Logan Chienf3511742017-10-31 18:04:35 +08001300
1301 cc_library {
1302 name: "libvndk_ext",
1303 vendor: true,
1304 vndk: {
1305 enabled: true,
1306 extends: "libvndk",
1307 },
1308 nocrt: true,
1309 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001310
1311 cc_library {
1312 name: "libvndk2_ext",
1313 vendor: true,
1314 vndk: {
1315 enabled: true,
1316 extends: "libvndk2",
1317 },
1318 nocrt: true,
1319 }
Logan Chienf3511742017-10-31 18:04:35 +08001320
Justin Yun0ecf0b22020-02-28 15:07:59 +09001321 cc_library {
1322 name: "libvndk_ext_product",
1323 product_specific: true,
1324 vndk: {
1325 enabled: true,
1326 extends: "libvndk",
1327 },
1328 nocrt: true,
1329 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001330
Justin Yun0ecf0b22020-02-28 15:07:59 +09001331 cc_library {
1332 name: "libvndk2_ext_product",
1333 product_specific: true,
1334 vndk: {
1335 enabled: true,
1336 extends: "libvndk2",
1337 },
1338 nocrt: true,
1339 }
1340 `
1341 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1342 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1343 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1344 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1345
1346 ctx := testCcWithConfig(t, config)
1347
1348 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1349 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1350
1351 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1352 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1353
1354 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1355 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001356}
1357
Logan Chiend3c59a22018-03-29 14:08:15 +08001358func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001359 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1360 ctx := testCcNoVndk(t, `
1361 cc_library {
1362 name: "libvndk",
1363 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001364 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001365 vndk: {
1366 enabled: true,
1367 },
1368 nocrt: true,
1369 }
1370
1371 cc_library {
1372 name: "libvndk_ext",
1373 vendor: true,
1374 vndk: {
1375 enabled: true,
1376 extends: "libvndk",
1377 },
1378 nocrt: true,
1379 }
1380 `)
1381
1382 // Ensures that the core variant of "libvndk_ext" can be found.
1383 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1384 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1385 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1386 }
1387}
1388
Justin Yun0ecf0b22020-02-28 15:07:59 +09001389func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1390 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001391 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001392 cc_library {
1393 name: "libvndk",
1394 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001395 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001396 vndk: {
1397 enabled: true,
1398 },
1399 nocrt: true,
1400 }
1401
1402 cc_library {
1403 name: "libvndk_ext_product",
1404 product_specific: true,
1405 vndk: {
1406 enabled: true,
1407 extends: "libvndk",
1408 },
1409 nocrt: true,
1410 }
1411 `)
1412
1413 // Ensures that the core variant of "libvndk_ext_product" can be found.
1414 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1415 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1416 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1417 }
1418}
1419
Logan Chienf3511742017-10-31 18:04:35 +08001420func TestVndkExtError(t *testing.T) {
1421 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001422 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001423 cc_library {
1424 name: "libvndk",
1425 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001426 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001427 vndk: {
1428 enabled: true,
1429 },
1430 nocrt: true,
1431 }
1432
1433 cc_library {
1434 name: "libvndk_ext",
1435 vndk: {
1436 enabled: true,
1437 extends: "libvndk",
1438 },
1439 nocrt: true,
1440 }
1441 `)
1442
1443 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1444 cc_library {
1445 name: "libvndk",
1446 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001447 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001448 vndk: {
1449 enabled: true,
1450 },
1451 nocrt: true,
1452 }
1453
1454 cc_library {
1455 name: "libvndk_ext",
1456 vendor: true,
1457 vndk: {
1458 enabled: true,
1459 },
1460 nocrt: true,
1461 }
1462 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001463
1464 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1465 cc_library {
1466 name: "libvndk",
1467 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001468 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001469 vndk: {
1470 enabled: true,
1471 },
1472 nocrt: true,
1473 }
1474
1475 cc_library {
1476 name: "libvndk_ext_product",
1477 product_specific: true,
1478 vndk: {
1479 enabled: true,
1480 },
1481 nocrt: true,
1482 }
1483 `)
1484
1485 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1486 cc_library {
1487 name: "libvndk",
1488 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001489 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001490 vndk: {
1491 enabled: true,
1492 },
1493 nocrt: true,
1494 }
1495
1496 cc_library {
1497 name: "libvndk_ext_product",
1498 product_specific: true,
1499 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001500 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001501 vndk: {
1502 enabled: true,
1503 extends: "libvndk",
1504 },
1505 nocrt: true,
1506 }
1507 `)
Logan Chienf3511742017-10-31 18:04:35 +08001508}
1509
1510func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1511 // This test ensures an error is emitted for inconsistent support_system_process.
1512 testCcError(t, "module \".*\" with mismatched support_system_process", `
1513 cc_library {
1514 name: "libvndk",
1515 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001516 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001517 vndk: {
1518 enabled: true,
1519 },
1520 nocrt: true,
1521 }
1522
1523 cc_library {
1524 name: "libvndk_sp_ext",
1525 vendor: true,
1526 vndk: {
1527 enabled: true,
1528 extends: "libvndk",
1529 support_system_process: true,
1530 },
1531 nocrt: true,
1532 }
1533 `)
1534
1535 testCcError(t, "module \".*\" with mismatched support_system_process", `
1536 cc_library {
1537 name: "libvndk_sp",
1538 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001539 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001540 vndk: {
1541 enabled: true,
1542 support_system_process: true,
1543 },
1544 nocrt: true,
1545 }
1546
1547 cc_library {
1548 name: "libvndk_ext",
1549 vendor: true,
1550 vndk: {
1551 enabled: true,
1552 extends: "libvndk_sp",
1553 },
1554 nocrt: true,
1555 }
1556 `)
1557}
1558
1559func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001560 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001561 // with `private: true`.
1562 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001563 cc_library {
1564 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001565 vendor_available: true,
1566 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001567 vndk: {
1568 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001569 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001570 },
1571 nocrt: true,
1572 }
1573
1574 cc_library {
1575 name: "libvndk_ext",
1576 vendor: true,
1577 vndk: {
1578 enabled: true,
1579 extends: "libvndk",
1580 },
1581 nocrt: true,
1582 }
1583 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001584
Justin Yunfd9e8042020-12-23 18:23:14 +09001585 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001586 cc_library {
1587 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001588 vendor_available: true,
1589 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001590 vndk: {
1591 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001592 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001593 },
1594 nocrt: true,
1595 }
1596
1597 cc_library {
1598 name: "libvndk_ext_product",
1599 product_specific: true,
1600 vndk: {
1601 enabled: true,
1602 extends: "libvndk",
1603 },
1604 nocrt: true,
1605 }
1606 `)
Logan Chienf3511742017-10-31 18:04:35 +08001607}
1608
Logan Chiend3c59a22018-03-29 14:08:15 +08001609func TestVendorModuleUseVndkExt(t *testing.T) {
1610 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001611 testCc(t, `
1612 cc_library {
1613 name: "libvndk",
1614 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001615 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001616 vndk: {
1617 enabled: true,
1618 },
1619 nocrt: true,
1620 }
1621
1622 cc_library {
1623 name: "libvndk_ext",
1624 vendor: true,
1625 vndk: {
1626 enabled: true,
1627 extends: "libvndk",
1628 },
1629 nocrt: true,
1630 }
1631
1632 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001633 name: "libvndk_sp",
1634 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001635 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001636 vndk: {
1637 enabled: true,
1638 support_system_process: true,
1639 },
1640 nocrt: true,
1641 }
1642
1643 cc_library {
1644 name: "libvndk_sp_ext",
1645 vendor: true,
1646 vndk: {
1647 enabled: true,
1648 extends: "libvndk_sp",
1649 support_system_process: true,
1650 },
1651 nocrt: true,
1652 }
1653
1654 cc_library {
1655 name: "libvendor",
1656 vendor: true,
1657 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1658 nocrt: true,
1659 }
1660 `)
1661}
1662
Logan Chiend3c59a22018-03-29 14:08:15 +08001663func TestVndkExtUseVendorLib(t *testing.T) {
1664 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001665 testCc(t, `
1666 cc_library {
1667 name: "libvndk",
1668 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001669 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001670 vndk: {
1671 enabled: true,
1672 },
1673 nocrt: true,
1674 }
1675
1676 cc_library {
1677 name: "libvndk_ext",
1678 vendor: true,
1679 vndk: {
1680 enabled: true,
1681 extends: "libvndk",
1682 },
1683 shared_libs: ["libvendor"],
1684 nocrt: true,
1685 }
1686
1687 cc_library {
1688 name: "libvendor",
1689 vendor: true,
1690 nocrt: true,
1691 }
1692 `)
Logan Chienf3511742017-10-31 18:04:35 +08001693
Logan Chiend3c59a22018-03-29 14:08:15 +08001694 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1695 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001696 cc_library {
1697 name: "libvndk_sp",
1698 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001699 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001700 vndk: {
1701 enabled: true,
1702 support_system_process: true,
1703 },
1704 nocrt: true,
1705 }
1706
1707 cc_library {
1708 name: "libvndk_sp_ext",
1709 vendor: true,
1710 vndk: {
1711 enabled: true,
1712 extends: "libvndk_sp",
1713 support_system_process: true,
1714 },
1715 shared_libs: ["libvendor"], // Cause an error
1716 nocrt: true,
1717 }
1718
1719 cc_library {
1720 name: "libvendor",
1721 vendor: true,
1722 nocrt: true,
1723 }
1724 `)
1725}
1726
Justin Yun0ecf0b22020-02-28 15:07:59 +09001727func TestProductVndkExtDependency(t *testing.T) {
1728 bp := `
1729 cc_library {
1730 name: "libvndk",
1731 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001732 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001733 vndk: {
1734 enabled: true,
1735 },
1736 nocrt: true,
1737 }
1738
1739 cc_library {
1740 name: "libvndk_ext_product",
1741 product_specific: true,
1742 vndk: {
1743 enabled: true,
1744 extends: "libvndk",
1745 },
1746 shared_libs: ["libproduct_for_vndklibs"],
1747 nocrt: true,
1748 }
1749
1750 cc_library {
1751 name: "libvndk_sp",
1752 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001753 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001754 vndk: {
1755 enabled: true,
1756 support_system_process: true,
1757 },
1758 nocrt: true,
1759 }
1760
1761 cc_library {
1762 name: "libvndk_sp_ext_product",
1763 product_specific: true,
1764 vndk: {
1765 enabled: true,
1766 extends: "libvndk_sp",
1767 support_system_process: true,
1768 },
1769 shared_libs: ["libproduct_for_vndklibs"],
1770 nocrt: true,
1771 }
1772
1773 cc_library {
1774 name: "libproduct",
1775 product_specific: true,
1776 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1777 nocrt: true,
1778 }
1779
1780 cc_library {
1781 name: "libproduct_for_vndklibs",
1782 product_specific: true,
1783 nocrt: true,
1784 }
1785 `
1786 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1787 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1788 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1789 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1790
1791 testCcWithConfig(t, config)
1792}
1793
Logan Chiend3c59a22018-03-29 14:08:15 +08001794func TestVndkSpExtUseVndkError(t *testing.T) {
1795 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1796 // library.
1797 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1798 cc_library {
1799 name: "libvndk",
1800 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001801 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001802 vndk: {
1803 enabled: true,
1804 },
1805 nocrt: true,
1806 }
1807
1808 cc_library {
1809 name: "libvndk_sp",
1810 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001811 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001812 vndk: {
1813 enabled: true,
1814 support_system_process: true,
1815 },
1816 nocrt: true,
1817 }
1818
1819 cc_library {
1820 name: "libvndk_sp_ext",
1821 vendor: true,
1822 vndk: {
1823 enabled: true,
1824 extends: "libvndk_sp",
1825 support_system_process: true,
1826 },
1827 shared_libs: ["libvndk"], // Cause an error
1828 nocrt: true,
1829 }
1830 `)
1831
1832 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1833 // library.
1834 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1835 cc_library {
1836 name: "libvndk",
1837 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001838 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001839 vndk: {
1840 enabled: true,
1841 },
1842 nocrt: true,
1843 }
1844
1845 cc_library {
1846 name: "libvndk_ext",
1847 vendor: true,
1848 vndk: {
1849 enabled: true,
1850 extends: "libvndk",
1851 },
1852 nocrt: true,
1853 }
1854
1855 cc_library {
1856 name: "libvndk_sp",
1857 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001858 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001859 vndk: {
1860 enabled: true,
1861 support_system_process: true,
1862 },
1863 nocrt: true,
1864 }
1865
1866 cc_library {
1867 name: "libvndk_sp_ext",
1868 vendor: true,
1869 vndk: {
1870 enabled: true,
1871 extends: "libvndk_sp",
1872 support_system_process: true,
1873 },
1874 shared_libs: ["libvndk_ext"], // Cause an error
1875 nocrt: true,
1876 }
1877 `)
1878}
1879
1880func TestVndkUseVndkExtError(t *testing.T) {
1881 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1882 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001883 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1884 cc_library {
1885 name: "libvndk",
1886 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001887 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001888 vndk: {
1889 enabled: true,
1890 },
1891 nocrt: true,
1892 }
1893
1894 cc_library {
1895 name: "libvndk_ext",
1896 vendor: true,
1897 vndk: {
1898 enabled: true,
1899 extends: "libvndk",
1900 },
1901 nocrt: true,
1902 }
1903
1904 cc_library {
1905 name: "libvndk2",
1906 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001907 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001908 vndk: {
1909 enabled: true,
1910 },
1911 shared_libs: ["libvndk_ext"],
1912 nocrt: true,
1913 }
1914 `)
1915
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001916 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001917 cc_library {
1918 name: "libvndk",
1919 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001920 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001921 vndk: {
1922 enabled: true,
1923 },
1924 nocrt: true,
1925 }
1926
1927 cc_library {
1928 name: "libvndk_ext",
1929 vendor: true,
1930 vndk: {
1931 enabled: true,
1932 extends: "libvndk",
1933 },
1934 nocrt: true,
1935 }
1936
1937 cc_library {
1938 name: "libvndk2",
1939 vendor_available: true,
1940 vndk: {
1941 enabled: true,
1942 },
1943 target: {
1944 vendor: {
1945 shared_libs: ["libvndk_ext"],
1946 },
1947 },
1948 nocrt: true,
1949 }
1950 `)
1951
1952 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1953 cc_library {
1954 name: "libvndk_sp",
1955 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001956 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001957 vndk: {
1958 enabled: true,
1959 support_system_process: true,
1960 },
1961 nocrt: true,
1962 }
1963
1964 cc_library {
1965 name: "libvndk_sp_ext",
1966 vendor: true,
1967 vndk: {
1968 enabled: true,
1969 extends: "libvndk_sp",
1970 support_system_process: true,
1971 },
1972 nocrt: true,
1973 }
1974
1975 cc_library {
1976 name: "libvndk_sp_2",
1977 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001978 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001979 vndk: {
1980 enabled: true,
1981 support_system_process: true,
1982 },
1983 shared_libs: ["libvndk_sp_ext"],
1984 nocrt: true,
1985 }
1986 `)
1987
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001988 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001989 cc_library {
1990 name: "libvndk_sp",
1991 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001992 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001993 vndk: {
1994 enabled: true,
1995 },
1996 nocrt: true,
1997 }
1998
1999 cc_library {
2000 name: "libvndk_sp_ext",
2001 vendor: true,
2002 vndk: {
2003 enabled: true,
2004 extends: "libvndk_sp",
2005 },
2006 nocrt: true,
2007 }
2008
2009 cc_library {
2010 name: "libvndk_sp2",
2011 vendor_available: true,
2012 vndk: {
2013 enabled: true,
2014 },
2015 target: {
2016 vendor: {
2017 shared_libs: ["libvndk_sp_ext"],
2018 },
2019 },
2020 nocrt: true,
2021 }
2022 `)
2023}
2024
Justin Yun5f7f7e82019-11-18 19:52:14 +09002025func TestEnforceProductVndkVersion(t *testing.T) {
2026 bp := `
2027 cc_library {
2028 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002029 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002030 }
2031 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002032 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002033 symbol_file: "",
2034 }
2035 cc_library {
2036 name: "libvndk",
2037 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002038 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002039 vndk: {
2040 enabled: true,
2041 },
2042 nocrt: true,
2043 }
2044 cc_library {
2045 name: "libvndk_sp",
2046 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002047 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002048 vndk: {
2049 enabled: true,
2050 support_system_process: true,
2051 },
2052 nocrt: true,
2053 }
2054 cc_library {
2055 name: "libva",
2056 vendor_available: true,
2057 nocrt: true,
2058 }
2059 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002060 name: "libpa",
2061 product_available: true,
2062 nocrt: true,
2063 }
2064 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002065 name: "libboth_available",
2066 vendor_available: true,
2067 product_available: true,
2068 nocrt: true,
2069 target: {
2070 vendor: {
2071 suffix: "-vendor",
2072 },
2073 product: {
2074 suffix: "-product",
2075 },
2076 }
2077 }
2078 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002079 name: "libproduct_va",
2080 product_specific: true,
2081 vendor_available: true,
2082 nocrt: true,
2083 }
2084 cc_library {
2085 name: "libprod",
2086 product_specific: true,
2087 shared_libs: [
2088 "libllndk",
2089 "libvndk",
2090 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002091 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002092 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002093 "libproduct_va",
2094 ],
2095 nocrt: true,
2096 }
2097 cc_library {
2098 name: "libvendor",
2099 vendor: true,
2100 shared_libs: [
2101 "libllndk",
2102 "libvndk",
2103 "libvndk_sp",
2104 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002105 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002106 "libproduct_va",
2107 ],
2108 nocrt: true,
2109 }
2110 `
2111
2112 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2113 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2114 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2115 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2116
2117 ctx := testCcWithConfig(t, config)
2118
Jooyung Han261e1582020-10-20 18:54:21 +09002119 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2120 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002121
2122 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2123 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2124
2125 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2126 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002127}
2128
2129func TestEnforceProductVndkVersionErrors(t *testing.T) {
2130 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2131 cc_library {
2132 name: "libprod",
2133 product_specific: true,
2134 shared_libs: [
2135 "libvendor",
2136 ],
2137 nocrt: true,
2138 }
2139 cc_library {
2140 name: "libvendor",
2141 vendor: true,
2142 nocrt: true,
2143 }
2144 `)
2145 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2146 cc_library {
2147 name: "libprod",
2148 product_specific: true,
2149 shared_libs: [
2150 "libsystem",
2151 ],
2152 nocrt: true,
2153 }
2154 cc_library {
2155 name: "libsystem",
2156 nocrt: true,
2157 }
2158 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002159 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2160 cc_library {
2161 name: "libprod",
2162 product_specific: true,
2163 shared_libs: [
2164 "libva",
2165 ],
2166 nocrt: true,
2167 }
2168 cc_library {
2169 name: "libva",
2170 vendor_available: true,
2171 nocrt: true,
2172 }
2173 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002174 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002175 cc_library {
2176 name: "libprod",
2177 product_specific: true,
2178 shared_libs: [
2179 "libvndk_private",
2180 ],
2181 nocrt: true,
2182 }
2183 cc_library {
2184 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002185 vendor_available: true,
2186 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002187 vndk: {
2188 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002189 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002190 },
2191 nocrt: true,
2192 }
2193 `)
2194 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2195 cc_library {
2196 name: "libprod",
2197 product_specific: true,
2198 shared_libs: [
2199 "libsystem_ext",
2200 ],
2201 nocrt: true,
2202 }
2203 cc_library {
2204 name: "libsystem_ext",
2205 system_ext_specific: true,
2206 nocrt: true,
2207 }
2208 `)
2209 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2210 cc_library {
2211 name: "libsystem",
2212 shared_libs: [
2213 "libproduct_va",
2214 ],
2215 nocrt: true,
2216 }
2217 cc_library {
2218 name: "libproduct_va",
2219 product_specific: true,
2220 vendor_available: true,
2221 nocrt: true,
2222 }
2223 `)
2224}
2225
Jooyung Han38002912019-05-16 04:01:54 +09002226func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002227 bp := `
2228 cc_library {
2229 name: "libvndk",
2230 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002231 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002232 vndk: {
2233 enabled: true,
2234 },
2235 }
2236 cc_library {
2237 name: "libvndksp",
2238 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002239 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002240 vndk: {
2241 enabled: true,
2242 support_system_process: true,
2243 },
2244 }
2245 cc_library {
2246 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002247 vendor_available: true,
2248 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002249 vndk: {
2250 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002251 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002252 },
2253 }
2254 cc_library {
2255 name: "libvendor",
2256 vendor: true,
2257 }
2258 cc_library {
2259 name: "libvndkext",
2260 vendor: true,
2261 vndk: {
2262 enabled: true,
2263 extends: "libvndk",
2264 },
2265 }
2266 vndk_prebuilt_shared {
2267 name: "prevndk",
2268 version: "27",
2269 target_arch: "arm",
2270 binder32bit: true,
2271 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002272 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002273 vndk: {
2274 enabled: true,
2275 },
2276 arch: {
2277 arm: {
2278 srcs: ["liba.so"],
2279 },
2280 },
2281 }
2282 cc_library {
2283 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002284 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002285 }
2286 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002287 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002288 symbol_file: "",
2289 }
2290 cc_library {
2291 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002292 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002293 }
2294 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002295 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002296 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002297 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002298 }
2299
2300 llndk_libraries_txt {
2301 name: "llndk.libraries.txt",
2302 }
2303 vndkcore_libraries_txt {
2304 name: "vndkcore.libraries.txt",
2305 }
2306 vndksp_libraries_txt {
2307 name: "vndksp.libraries.txt",
2308 }
2309 vndkprivate_libraries_txt {
2310 name: "vndkprivate.libraries.txt",
2311 }
2312 vndkcorevariant_libraries_txt {
2313 name: "vndkcorevariant.libraries.txt",
2314 insert_vndk_version: false,
2315 }
2316 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002317
2318 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002319 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2320 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2321 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002322 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002323
Colin Cross78212242021-01-06 14:51:30 -08002324 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2325 []string{"libvndk.so", "libvndkprivate.so"})
2326 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2327 []string{"libc++.so", "libvndksp.so"})
2328 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2329 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2330 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2331 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002332
Colin Crossfb0c16e2019-11-20 17:12:35 -08002333 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002334
Jooyung Han38002912019-05-16 04:01:54 +09002335 tests := []struct {
2336 variant string
2337 name string
2338 expected string
2339 }{
2340 {vendorVariant, "libvndk", "native:vndk"},
2341 {vendorVariant, "libvndksp", "native:vndk"},
2342 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2343 {vendorVariant, "libvendor", "native:vendor"},
2344 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002345 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002346 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002347 {coreVariant, "libvndk", "native:platform"},
2348 {coreVariant, "libvndkprivate", "native:platform"},
2349 {coreVariant, "libllndk", "native:platform"},
2350 }
2351 for _, test := range tests {
2352 t.Run(test.name, func(t *testing.T) {
2353 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2354 assertString(t, module.makeLinkType, test.expected)
2355 })
2356 }
2357}
2358
Jeff Gaston294356f2017-09-27 17:05:30 -07002359var staticLinkDepOrderTestCases = []struct {
2360 // This is a string representation of a map[moduleName][]moduleDependency .
2361 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002362 inStatic string
2363
2364 // This is a string representation of a map[moduleName][]moduleDependency .
2365 // It models the dependencies declared in an Android.bp file.
2366 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002367
2368 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2369 // The keys of allOrdered specify which modules we would like to check.
2370 // The values of allOrdered specify the expected result (of the transitive closure of all
2371 // dependencies) for each module to test
2372 allOrdered string
2373
2374 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2375 // The keys of outOrdered specify which modules we would like to check.
2376 // The values of outOrdered specify the expected result (of the ordered linker command line)
2377 // for each module to test.
2378 outOrdered string
2379}{
2380 // Simple tests
2381 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002382 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002383 outOrdered: "",
2384 },
2385 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002386 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002387 outOrdered: "a:",
2388 },
2389 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002390 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002391 outOrdered: "a:b; b:",
2392 },
2393 // Tests of reordering
2394 {
2395 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002396 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002397 outOrdered: "a:b,c,d; b:d; c:d; d:",
2398 },
2399 {
2400 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002401 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002402 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2403 },
2404 {
2405 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002406 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002407 outOrdered: "a:d,b,e,c; d:b; e:c",
2408 },
2409 {
2410 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002411 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002412 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2413 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2414 },
2415 {
2416 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002417 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 -07002418 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2419 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2420 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002421 // shared dependencies
2422 {
2423 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2424 // So, we don't actually have to check that a shared dependency of c will change the order
2425 // of a library that depends statically on b and on c. We only need to check that if c has
2426 // a shared dependency on b, that that shows up in allOrdered.
2427 inShared: "c:b",
2428 allOrdered: "c:b",
2429 outOrdered: "c:",
2430 },
2431 {
2432 // This test doesn't actually include any shared dependencies but it's a reminder of what
2433 // the second phase of the above test would look like
2434 inStatic: "a:b,c; c:b",
2435 allOrdered: "a:c,b; c:b",
2436 outOrdered: "a:c,b; c:b",
2437 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002438 // tiebreakers for when two modules specifying different orderings and there is no dependency
2439 // to dictate an order
2440 {
2441 // 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 -08002442 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002443 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2444 },
2445 {
2446 // 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 -08002447 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 -07002448 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2449 },
2450 // Tests involving duplicate dependencies
2451 {
2452 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002453 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002454 outOrdered: "a:c,b",
2455 },
2456 {
2457 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002458 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002459 outOrdered: "a:d,c,b",
2460 },
2461 // Tests to confirm the nonexistence of infinite loops.
2462 // These cases should never happen, so as long as the test terminates and the
2463 // result is deterministic then that should be fine.
2464 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002465 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002466 outOrdered: "a:a",
2467 },
2468 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002469 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002470 allOrdered: "a:b,c; b:c,a; c:a,b",
2471 outOrdered: "a:b; b:c; c:a",
2472 },
2473 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002474 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002475 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2476 outOrdered: "a:c,b; b:a,c; c:b,a",
2477 },
2478}
2479
2480// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2481func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2482 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2483 strippedText := strings.Replace(text, " ", "", -1)
2484 if len(strippedText) < 1 {
2485 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2486 }
2487 allDeps = make(map[android.Path][]android.Path, 0)
2488
2489 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2490 moduleTexts := strings.Split(strippedText, ";")
2491
2492 outputForModuleName := func(moduleName string) android.Path {
2493 return android.PathForTesting(moduleName)
2494 }
2495
2496 for _, moduleText := range moduleTexts {
2497 // convert from "a:b,c" to ["a", "b,c"]
2498 components := strings.Split(moduleText, ":")
2499 if len(components) != 2 {
2500 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2501 }
2502 moduleName := components[0]
2503 moduleOutput := outputForModuleName(moduleName)
2504 modulesInOrder = append(modulesInOrder, moduleOutput)
2505
2506 depString := components[1]
2507 // convert from "b,c" to ["b", "c"]
2508 depNames := strings.Split(depString, ",")
2509 if len(depString) < 1 {
2510 depNames = []string{}
2511 }
2512 var deps []android.Path
2513 for _, depName := range depNames {
2514 deps = append(deps, outputForModuleName(depName))
2515 }
2516 allDeps[moduleOutput] = deps
2517 }
2518 return modulesInOrder, allDeps
2519}
2520
Jeff Gaston294356f2017-09-27 17:05:30 -07002521func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2522 for _, moduleName := range moduleNames {
2523 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2524 output := module.outputFile.Path()
2525 paths = append(paths, output)
2526 }
2527 return paths
2528}
2529
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002530func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002531 ctx := testCc(t, `
2532 cc_library {
2533 name: "a",
2534 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002535 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002536 }
2537 cc_library {
2538 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002539 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002540 }
2541 cc_library {
2542 name: "c",
2543 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002544 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002545 }
2546 cc_library {
2547 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002548 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002549 }
2550
2551 `)
2552
Colin Cross7113d202019-11-20 16:39:12 -08002553 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002554 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002555 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2556 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002557
2558 if !reflect.DeepEqual(actual, expected) {
2559 t.Errorf("staticDeps orderings were not propagated correctly"+
2560 "\nactual: %v"+
2561 "\nexpected: %v",
2562 actual,
2563 expected,
2564 )
2565 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002566}
Jeff Gaston294356f2017-09-27 17:05:30 -07002567
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002568func TestStaticLibDepReorderingWithShared(t *testing.T) {
2569 ctx := testCc(t, `
2570 cc_library {
2571 name: "a",
2572 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002573 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002574 }
2575 cc_library {
2576 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002577 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002578 }
2579 cc_library {
2580 name: "c",
2581 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002582 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002583 }
2584
2585 `)
2586
Colin Cross7113d202019-11-20 16:39:12 -08002587 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002588 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002589 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2590 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002591
2592 if !reflect.DeepEqual(actual, expected) {
2593 t.Errorf("staticDeps orderings did not account for shared libs"+
2594 "\nactual: %v"+
2595 "\nexpected: %v",
2596 actual,
2597 expected,
2598 )
2599 }
2600}
2601
Jooyung Hanb04a4992020-03-13 18:57:35 +09002602func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002603 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002604 if !reflect.DeepEqual(actual, expected) {
2605 t.Errorf(message+
2606 "\nactual: %v"+
2607 "\nexpected: %v",
2608 actual,
2609 expected,
2610 )
2611 }
2612}
2613
Jooyung Han61b66e92020-03-21 14:21:46 +00002614func TestLlndkLibrary(t *testing.T) {
2615 ctx := testCc(t, `
2616 cc_library {
2617 name: "libllndk",
2618 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002619 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002620 }
2621 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002622 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002623 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002624
2625 cc_prebuilt_library_shared {
2626 name: "libllndkprebuilt",
2627 stubs: { versions: ["1", "2"] },
2628 llndk_stubs: "libllndkprebuilt.llndk",
2629 }
2630 llndk_library {
2631 name: "libllndkprebuilt.llndk",
2632 }
2633
2634 cc_library {
2635 name: "libllndk_with_external_headers",
2636 stubs: { versions: ["1", "2"] },
2637 llndk_stubs: "libllndk_with_external_headers.llndk",
2638 header_libs: ["libexternal_headers"],
2639 export_header_lib_headers: ["libexternal_headers"],
2640 }
2641 llndk_library {
2642 name: "libllndk_with_external_headers.llndk",
2643 }
2644 cc_library_headers {
2645 name: "libexternal_headers",
2646 export_include_dirs: ["include"],
2647 vendor_available: true,
2648 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002649 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002650 actual := ctx.ModuleVariantsForTests("libllndk")
2651 for i := 0; i < len(actual); i++ {
2652 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
2653 actual = append(actual[:i], actual[i+1:]...)
2654 i--
2655 }
2656 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002657 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00002658 "android_vendor.VER_arm64_armv8-a_shared_1",
2659 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002660 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002661 "android_vendor.VER_arm_armv7-a-neon_shared_1",
2662 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002663 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002664 }
2665 checkEquals(t, "variants for llndk stubs", expected, actual)
2666
Colin Cross127bb8b2020-12-16 16:46:01 -08002667 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002668 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2669
Colin Cross127bb8b2020-12-16 16:46:01 -08002670 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002671 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2672}
2673
Jiyong Parka46a4d52017-12-14 19:54:34 +09002674func TestLlndkHeaders(t *testing.T) {
2675 ctx := testCc(t, `
2676 llndk_headers {
2677 name: "libllndk_headers",
2678 export_include_dirs: ["my_include"],
2679 }
2680 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002681 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002682 export_llndk_headers: ["libllndk_headers"],
2683 }
2684 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002685 name: "libllndk",
2686 llndk_stubs: "libllndk.llndk",
2687 }
2688
2689 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002690 name: "libvendor",
2691 shared_libs: ["libllndk"],
2692 vendor: true,
2693 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002694 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002695 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002696 }
2697 `)
2698
2699 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002700 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002701 cflags := cc.Args["cFlags"]
2702 if !strings.Contains(cflags, "-Imy_include") {
2703 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2704 }
2705}
2706
Logan Chien43d34c32017-12-20 01:17:32 +08002707func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2708 actual := module.Properties.AndroidMkRuntimeLibs
2709 if !reflect.DeepEqual(actual, expected) {
2710 t.Errorf("incorrect runtime_libs for shared libs"+
2711 "\nactual: %v"+
2712 "\nexpected: %v",
2713 actual,
2714 expected,
2715 )
2716 }
2717}
2718
2719const runtimeLibAndroidBp = `
2720 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002721 name: "liball_available",
2722 vendor_available: true,
2723 product_available: true,
2724 no_libcrt : true,
2725 nocrt : true,
2726 system_shared_libs : [],
2727 }
2728 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002729 name: "libvendor_available1",
2730 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002731 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002732 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002733 nocrt : true,
2734 system_shared_libs : [],
2735 }
2736 cc_library {
2737 name: "libvendor_available2",
2738 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002739 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002740 target: {
2741 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002742 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002743 }
2744 },
Yi Konge7fe9912019-06-02 00:53:50 -07002745 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002746 nocrt : true,
2747 system_shared_libs : [],
2748 }
2749 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002750 name: "libproduct_vendor",
2751 product_specific: true,
2752 vendor_available: true,
2753 no_libcrt : true,
2754 nocrt : true,
2755 system_shared_libs : [],
2756 }
2757 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002758 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002759 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002760 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002761 nocrt : true,
2762 system_shared_libs : [],
2763 }
2764 cc_library {
2765 name: "libvendor1",
2766 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002767 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002768 nocrt : true,
2769 system_shared_libs : [],
2770 }
2771 cc_library {
2772 name: "libvendor2",
2773 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002774 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002775 no_libcrt : true,
2776 nocrt : true,
2777 system_shared_libs : [],
2778 }
2779 cc_library {
2780 name: "libproduct_available1",
2781 product_available: true,
2782 runtime_libs: ["liball_available"],
2783 no_libcrt : true,
2784 nocrt : true,
2785 system_shared_libs : [],
2786 }
2787 cc_library {
2788 name: "libproduct1",
2789 product_specific: true,
2790 no_libcrt : true,
2791 nocrt : true,
2792 system_shared_libs : [],
2793 }
2794 cc_library {
2795 name: "libproduct2",
2796 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002797 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002798 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002799 nocrt : true,
2800 system_shared_libs : [],
2801 }
2802`
2803
2804func TestRuntimeLibs(t *testing.T) {
2805 ctx := testCc(t, runtimeLibAndroidBp)
2806
2807 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002808 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002809
Justin Yun8a2600c2020-12-07 12:44:03 +09002810 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2811 checkRuntimeLibs(t, []string{"liball_available"}, module)
2812
2813 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2814 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002815
2816 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002817 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002818
2819 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2820 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002821 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002822
Justin Yun8a2600c2020-12-07 12:44:03 +09002823 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2824 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002825
2826 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002827 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002828
2829 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2830 // and product variants.
2831 variant = "android_product.VER_arm64_armv8-a_shared"
2832
2833 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2834 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2835
2836 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002837 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002838}
2839
2840func TestExcludeRuntimeLibs(t *testing.T) {
2841 ctx := testCc(t, runtimeLibAndroidBp)
2842
Colin Cross7113d202019-11-20 16:39:12 -08002843 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002844 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2845 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002846
Colin Crossfb0c16e2019-11-20 17:12:35 -08002847 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002848 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002849 checkRuntimeLibs(t, nil, module)
2850}
2851
2852func TestRuntimeLibsNoVndk(t *testing.T) {
2853 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2854
2855 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2856
Colin Cross7113d202019-11-20 16:39:12 -08002857 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002858
Justin Yun8a2600c2020-12-07 12:44:03 +09002859 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2860 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002861
2862 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002863 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002864
2865 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002866 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002867}
2868
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002869func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002870 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002871 actual := module.Properties.AndroidMkStaticLibs
2872 if !reflect.DeepEqual(actual, expected) {
2873 t.Errorf("incorrect static_libs"+
2874 "\nactual: %v"+
2875 "\nexpected: %v",
2876 actual,
2877 expected,
2878 )
2879 }
2880}
2881
2882const staticLibAndroidBp = `
2883 cc_library {
2884 name: "lib1",
2885 }
2886 cc_library {
2887 name: "lib2",
2888 static_libs: ["lib1"],
2889 }
2890`
2891
2892func TestStaticLibDepExport(t *testing.T) {
2893 ctx := testCc(t, staticLibAndroidBp)
2894
2895 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002896 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002897 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002898 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002899
2900 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002901 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002902 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2903 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002904 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002905}
2906
Jiyong Parkd08b6972017-09-26 10:50:54 +09002907var compilerFlagsTestCases = []struct {
2908 in string
2909 out bool
2910}{
2911 {
2912 in: "a",
2913 out: false,
2914 },
2915 {
2916 in: "-a",
2917 out: true,
2918 },
2919 {
2920 in: "-Ipath/to/something",
2921 out: false,
2922 },
2923 {
2924 in: "-isystempath/to/something",
2925 out: false,
2926 },
2927 {
2928 in: "--coverage",
2929 out: false,
2930 },
2931 {
2932 in: "-include a/b",
2933 out: true,
2934 },
2935 {
2936 in: "-include a/b c/d",
2937 out: false,
2938 },
2939 {
2940 in: "-DMACRO",
2941 out: true,
2942 },
2943 {
2944 in: "-DMAC RO",
2945 out: false,
2946 },
2947 {
2948 in: "-a -b",
2949 out: false,
2950 },
2951 {
2952 in: "-DMACRO=definition",
2953 out: true,
2954 },
2955 {
2956 in: "-DMACRO=defi nition",
2957 out: true, // TODO(jiyong): this should be false
2958 },
2959 {
2960 in: "-DMACRO(x)=x + 1",
2961 out: true,
2962 },
2963 {
2964 in: "-DMACRO=\"defi nition\"",
2965 out: true,
2966 },
2967}
2968
2969type mockContext struct {
2970 BaseModuleContext
2971 result bool
2972}
2973
2974func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2975 // CheckBadCompilerFlags calls this function when the flag should be rejected
2976 ctx.result = false
2977}
2978
2979func TestCompilerFlags(t *testing.T) {
2980 for _, testCase := range compilerFlagsTestCases {
2981 ctx := &mockContext{result: true}
2982 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2983 if ctx.result != testCase.out {
2984 t.Errorf("incorrect output:")
2985 t.Errorf(" input: %#v", testCase.in)
2986 t.Errorf(" expected: %#v", testCase.out)
2987 t.Errorf(" got: %#v", ctx.result)
2988 }
2989 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002990}
Jiyong Park374510b2018-03-19 18:23:01 +09002991
2992func TestVendorPublicLibraries(t *testing.T) {
2993 ctx := testCc(t, `
2994 cc_library_headers {
2995 name: "libvendorpublic_headers",
2996 export_include_dirs: ["my_include"],
2997 }
2998 vendor_public_library {
2999 name: "libvendorpublic",
3000 symbol_file: "",
3001 export_public_headers: ["libvendorpublic_headers"],
3002 }
3003 cc_library {
3004 name: "libvendorpublic",
3005 srcs: ["foo.c"],
3006 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003007 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003008 nocrt: true,
3009 }
3010
3011 cc_library {
3012 name: "libsystem",
3013 shared_libs: ["libvendorpublic"],
3014 vendor: false,
3015 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003016 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003017 nocrt: true,
3018 }
3019 cc_library {
3020 name: "libvendor",
3021 shared_libs: ["libvendorpublic"],
3022 vendor: true,
3023 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003024 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003025 nocrt: true,
3026 }
3027 `)
3028
Colin Cross7113d202019-11-20 16:39:12 -08003029 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003030 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003031
3032 // test if header search paths are correctly added
3033 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003034 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003035 cflags := cc.Args["cFlags"]
3036 if !strings.Contains(cflags, "-Imy_include") {
3037 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3038 }
3039
3040 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003041 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003042 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003043 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003044 if !strings.Contains(libflags, stubPaths[0].String()) {
3045 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3046 }
3047
3048 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003049 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003050 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003051 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003052 if !strings.Contains(libflags, stubPaths[0].String()) {
3053 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3054 }
3055
3056}
Jiyong Park37b25202018-07-11 10:49:27 +09003057
3058func TestRecovery(t *testing.T) {
3059 ctx := testCc(t, `
3060 cc_library_shared {
3061 name: "librecovery",
3062 recovery: true,
3063 }
3064 cc_library_shared {
3065 name: "librecovery32",
3066 recovery: true,
3067 compile_multilib:"32",
3068 }
Jiyong Park5baac542018-08-28 09:55:37 +09003069 cc_library_shared {
3070 name: "libHalInRecovery",
3071 recovery_available: true,
3072 vendor: true,
3073 }
Jiyong Park37b25202018-07-11 10:49:27 +09003074 `)
3075
3076 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003077 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003078 if len(variants) != 1 || !android.InList(arm64, variants) {
3079 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3080 }
3081
3082 variants = ctx.ModuleVariantsForTests("librecovery32")
3083 if android.InList(arm64, variants) {
3084 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3085 }
Jiyong Park5baac542018-08-28 09:55:37 +09003086
3087 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3088 if !recoveryModule.Platform() {
3089 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3090 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003091}
Jiyong Park5baac542018-08-28 09:55:37 +09003092
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003093func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3094 bp := `
3095 cc_prebuilt_test_library_shared {
3096 name: "test_lib",
3097 relative_install_path: "foo/bar/baz",
3098 srcs: ["srcpath/dontusethispath/baz.so"],
3099 }
3100
3101 cc_test {
3102 name: "main_test",
3103 data_libs: ["test_lib"],
3104 gtest: false,
3105 }
3106 `
3107
3108 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3109 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3110 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3111 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3112
3113 ctx := testCcWithConfig(t, config)
3114 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3115 testBinary := module.(*Module).linker.(*testBinary)
3116 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3117 if err != nil {
3118 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3119 }
3120 if len(outputFiles) != 1 {
3121 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3122 }
3123 if len(testBinary.dataPaths()) != 1 {
3124 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3125 }
3126
3127 outputPath := outputFiles[0].String()
3128
3129 if !strings.HasSuffix(outputPath, "/main_test") {
3130 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3131 }
Colin Crossaa255532020-07-03 13:18:24 -07003132 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003133 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3134 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3135 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3136 }
3137}
3138
Jiyong Park7ed9de32018-10-15 22:25:07 +09003139func TestVersionedStubs(t *testing.T) {
3140 ctx := testCc(t, `
3141 cc_library_shared {
3142 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003143 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003144 stubs: {
3145 symbol_file: "foo.map.txt",
3146 versions: ["1", "2", "3"],
3147 },
3148 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003149
Jiyong Park7ed9de32018-10-15 22:25:07 +09003150 cc_library_shared {
3151 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003152 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003153 shared_libs: ["libFoo#1"],
3154 }`)
3155
3156 variants := ctx.ModuleVariantsForTests("libFoo")
3157 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003158 "android_arm64_armv8-a_shared",
3159 "android_arm64_armv8-a_shared_1",
3160 "android_arm64_armv8-a_shared_2",
3161 "android_arm64_armv8-a_shared_3",
3162 "android_arm_armv7-a-neon_shared",
3163 "android_arm_armv7-a-neon_shared_1",
3164 "android_arm_armv7-a-neon_shared_2",
3165 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003166 }
3167 variantsMismatch := false
3168 if len(variants) != len(expectedVariants) {
3169 variantsMismatch = true
3170 } else {
3171 for _, v := range expectedVariants {
3172 if !inList(v, variants) {
3173 variantsMismatch = false
3174 }
3175 }
3176 }
3177 if variantsMismatch {
3178 t.Errorf("variants of libFoo expected:\n")
3179 for _, v := range expectedVariants {
3180 t.Errorf("%q\n", v)
3181 }
3182 t.Errorf(", but got:\n")
3183 for _, v := range variants {
3184 t.Errorf("%q\n", v)
3185 }
3186 }
3187
Colin Cross7113d202019-11-20 16:39:12 -08003188 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003189 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003190 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003191 if !strings.Contains(libFlags, libFoo1StubPath) {
3192 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3193 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003194
Colin Cross7113d202019-11-20 16:39:12 -08003195 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003196 cFlags := libBarCompileRule.Args["cFlags"]
3197 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3198 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3199 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3200 }
Jiyong Park37b25202018-07-11 10:49:27 +09003201}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003202
Jooyung Hanb04a4992020-03-13 18:57:35 +09003203func TestVersioningMacro(t *testing.T) {
3204 for _, tc := range []struct{ moduleName, expected string }{
3205 {"libc", "__LIBC_API__"},
3206 {"libfoo", "__LIBFOO_API__"},
3207 {"libfoo@1", "__LIBFOO_1_API__"},
3208 {"libfoo-v1", "__LIBFOO_V1_API__"},
3209 {"libfoo.v1", "__LIBFOO_V1_API__"},
3210 } {
3211 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3212 }
3213}
3214
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003215func TestStaticExecutable(t *testing.T) {
3216 ctx := testCc(t, `
3217 cc_binary {
3218 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003219 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003220 static_executable: true,
3221 }`)
3222
Colin Cross7113d202019-11-20 16:39:12 -08003223 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003224 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3225 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003226 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003227 for _, lib := range systemStaticLibs {
3228 if !strings.Contains(libFlags, lib) {
3229 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3230 }
3231 }
3232 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3233 for _, lib := range systemSharedLibs {
3234 if strings.Contains(libFlags, lib) {
3235 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3236 }
3237 }
3238}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003239
3240func TestStaticDepsOrderWithStubs(t *testing.T) {
3241 ctx := testCc(t, `
3242 cc_binary {
3243 name: "mybin",
3244 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003245 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003246 static_executable: true,
3247 stl: "none",
3248 }
3249
3250 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003251 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003252 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003253 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003254 stl: "none",
3255 }
3256
3257 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003258 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003259 srcs: ["foo.c"],
3260 stl: "none",
3261 stubs: {
3262 versions: ["1"],
3263 },
3264 }`)
3265
Colin Cross0de8a1e2020-09-18 14:15:30 -07003266 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3267 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003268 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003269
3270 if !reflect.DeepEqual(actual, expected) {
3271 t.Errorf("staticDeps orderings were not propagated correctly"+
3272 "\nactual: %v"+
3273 "\nexpected: %v",
3274 actual,
3275 expected,
3276 )
3277 }
3278}
Jooyung Han38002912019-05-16 04:01:54 +09003279
Jooyung Hand48f3c32019-08-23 11:18:57 +09003280func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3281 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3282 cc_library {
3283 name: "libA",
3284 srcs: ["foo.c"],
3285 shared_libs: ["libB"],
3286 stl: "none",
3287 }
3288
3289 cc_library {
3290 name: "libB",
3291 srcs: ["foo.c"],
3292 enabled: false,
3293 stl: "none",
3294 }
3295 `)
3296}
3297
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003298// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3299// correctly.
3300func TestFuzzTarget(t *testing.T) {
3301 ctx := testCc(t, `
3302 cc_fuzz {
3303 name: "fuzz_smoke_test",
3304 srcs: ["foo.c"],
3305 }`)
3306
Paul Duffin075c4172019-12-19 19:06:13 +00003307 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003308 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3309}
3310
Jiyong Park29074592019-07-07 16:27:47 +09003311func TestAidl(t *testing.T) {
3312}
3313
Jooyung Han38002912019-05-16 04:01:54 +09003314func assertString(t *testing.T, got, expected string) {
3315 t.Helper()
3316 if got != expected {
3317 t.Errorf("expected %q got %q", expected, got)
3318 }
3319}
3320
3321func assertArrayString(t *testing.T, got, expected []string) {
3322 t.Helper()
3323 if len(got) != len(expected) {
3324 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3325 return
3326 }
3327 for i := range got {
3328 if got[i] != expected[i] {
3329 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3330 i, expected[i], expected, got[i], got)
3331 return
3332 }
3333 }
3334}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003335
Jooyung Han0302a842019-10-30 18:43:49 +09003336func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3337 t.Helper()
3338 assertArrayString(t, android.SortedStringKeys(m), expected)
3339}
3340
Colin Crosse1bb5d02019-09-24 14:55:04 -07003341func TestDefaults(t *testing.T) {
3342 ctx := testCc(t, `
3343 cc_defaults {
3344 name: "defaults",
3345 srcs: ["foo.c"],
3346 static: {
3347 srcs: ["bar.c"],
3348 },
3349 shared: {
3350 srcs: ["baz.c"],
3351 },
3352 }
3353
3354 cc_library_static {
3355 name: "libstatic",
3356 defaults: ["defaults"],
3357 }
3358
3359 cc_library_shared {
3360 name: "libshared",
3361 defaults: ["defaults"],
3362 }
3363
3364 cc_library {
3365 name: "libboth",
3366 defaults: ["defaults"],
3367 }
3368
3369 cc_binary {
3370 name: "binary",
3371 defaults: ["defaults"],
3372 }`)
3373
3374 pathsToBase := func(paths android.Paths) []string {
3375 var ret []string
3376 for _, p := range paths {
3377 ret = append(ret, p.Base())
3378 }
3379 return ret
3380 }
3381
Colin Cross7113d202019-11-20 16:39:12 -08003382 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003383 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3384 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3385 }
Colin Cross7113d202019-11-20 16:39:12 -08003386 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003387 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3388 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3389 }
Colin Cross7113d202019-11-20 16:39:12 -08003390 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003391 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3392 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3393 }
3394
Colin Cross7113d202019-11-20 16:39:12 -08003395 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003396 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3397 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3398 }
Colin Cross7113d202019-11-20 16:39:12 -08003399 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003400 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3401 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3402 }
3403}
Colin Crosseabaedd2020-02-06 17:01:55 -08003404
3405func TestProductVariableDefaults(t *testing.T) {
3406 bp := `
3407 cc_defaults {
3408 name: "libfoo_defaults",
3409 srcs: ["foo.c"],
3410 cppflags: ["-DFOO"],
3411 product_variables: {
3412 debuggable: {
3413 cppflags: ["-DBAR"],
3414 },
3415 },
3416 }
3417
3418 cc_library {
3419 name: "libfoo",
3420 defaults: ["libfoo_defaults"],
3421 }
3422 `
3423
3424 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3425 config.TestProductVariables.Debuggable = BoolPtr(true)
3426
Colin Crossae8600b2020-10-29 17:09:13 -07003427 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003428 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3429 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3430 })
Colin Crossae8600b2020-10-29 17:09:13 -07003431 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003432
3433 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3434 android.FailIfErrored(t, errs)
3435 _, errs = ctx.PrepareBuildActions(config)
3436 android.FailIfErrored(t, errs)
3437
3438 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3439 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3440 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3441 }
3442}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003443
3444func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3445 t.Parallel()
3446 bp := `
3447 cc_library_static {
3448 name: "libfoo",
3449 srcs: ["foo.c"],
3450 whole_static_libs: ["libbar"],
3451 }
3452
3453 cc_library_static {
3454 name: "libbar",
3455 whole_static_libs: ["libmissing"],
3456 }
3457 `
3458
3459 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3460 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3461
Colin Crossae8600b2020-10-29 17:09:13 -07003462 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003463 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003464 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003465
3466 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3467 android.FailIfErrored(t, errs)
3468 _, errs = ctx.PrepareBuildActions(config)
3469 android.FailIfErrored(t, errs)
3470
3471 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3472 if g, w := libbar.Rule, android.ErrorRule; g != w {
3473 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3474 }
3475
3476 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3477 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
3478 }
3479
3480 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
3481 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
3482 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
3483 }
3484
3485}
Colin Crosse9fe2942020-11-10 18:12:15 -08003486
3487func TestInstallSharedLibs(t *testing.T) {
3488 bp := `
3489 cc_binary {
3490 name: "bin",
3491 host_supported: true,
3492 shared_libs: ["libshared"],
3493 runtime_libs: ["libruntime"],
3494 srcs: [":gen"],
3495 }
3496
3497 cc_library_shared {
3498 name: "libshared",
3499 host_supported: true,
3500 shared_libs: ["libtransitive"],
3501 }
3502
3503 cc_library_shared {
3504 name: "libtransitive",
3505 host_supported: true,
3506 }
3507
3508 cc_library_shared {
3509 name: "libruntime",
3510 host_supported: true,
3511 }
3512
3513 cc_binary_host {
3514 name: "tool",
3515 srcs: ["foo.cpp"],
3516 }
3517
3518 genrule {
3519 name: "gen",
3520 tools: ["tool"],
3521 out: ["gen.cpp"],
3522 cmd: "$(location tool) $(out)",
3523 }
3524 `
3525
3526 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3527 ctx := testCcWithConfig(t, config)
3528
3529 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3530 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3531 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3532 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3533 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3534
3535 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3536 t.Errorf("expected host bin dependency %q, got %q", w, g)
3537 }
3538
3539 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3540 t.Errorf("expected host bin dependency %q, got %q", w, g)
3541 }
3542
3543 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3544 t.Errorf("expected host bin dependency %q, got %q", w, g)
3545 }
3546
3547 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3548 t.Errorf("expected host bin dependency %q, got %q", w, g)
3549 }
3550
3551 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3552 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3553 }
3554
3555 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3556 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3557 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3558 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3559
3560 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3561 t.Errorf("expected device bin dependency %q, got %q", w, g)
3562 }
3563
3564 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3565 t.Errorf("expected device bin dependency %q, got %q", w, g)
3566 }
3567
3568 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3569 t.Errorf("expected device bin dependency %q, got %q", w, g)
3570 }
3571
3572 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3573 t.Errorf("expected device bin dependency %q, got %q", w, g)
3574 }
3575
3576 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3577 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3578 }
3579
3580}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003581
3582func TestStubsLibReexportsHeaders(t *testing.T) {
3583 ctx := testCc(t, `
3584 cc_library_shared {
3585 name: "libclient",
3586 srcs: ["foo.c"],
3587 shared_libs: ["libfoo#1"],
3588 }
3589
3590 cc_library_shared {
3591 name: "libfoo",
3592 srcs: ["foo.c"],
3593 shared_libs: ["libbar"],
3594 export_shared_lib_headers: ["libbar"],
3595 stubs: {
3596 symbol_file: "foo.map.txt",
3597 versions: ["1", "2", "3"],
3598 },
3599 }
3600
3601 cc_library_shared {
3602 name: "libbar",
3603 export_include_dirs: ["include/libbar"],
3604 srcs: ["foo.c"],
3605 }`)
3606
3607 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3608
3609 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3610 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3611 }
3612}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003613
3614func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3615 ctx := testCc(t, `
3616 cc_library {
3617 name: "libfoo",
3618 srcs: ["a/Foo.aidl"],
3619 aidl: { flags: ["-Werror"], },
3620 }
3621 `)
3622
3623 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3624 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3625 aidlCommand := manifest.Commands[0].GetCommand()
3626 expectedAidlFlag := "-Werror"
3627 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3628 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3629 }
3630}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003631
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003632type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003633
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003634const (
3635 None MemtagNoteType = iota + 1
3636 Sync
3637 Async
3638)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003639
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003640func (t MemtagNoteType) str() string {
3641 switch t {
3642 case None:
3643 return "none"
3644 case Sync:
3645 return "sync"
3646 case Async:
3647 return "async"
3648 default:
3649 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003650 }
3651}
3652
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003653func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3654 note_async := "note_memtag_heap_async"
3655 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003656
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003657 found := None
3658 implicits := m.Rule("ld").Implicits
3659 for _, lib := range implicits {
3660 if strings.Contains(lib.Rel(), note_async) {
3661 found = Async
3662 break
3663 } else if strings.Contains(lib.Rel(), note_sync) {
3664 found = Sync
3665 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003666 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003667 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003668
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003669 if found != expected {
3670 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3671 }
3672}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003673
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003674func makeMemtagTestConfig(t *testing.T) android.Config {
3675 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003676 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003677 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003678 gtest: false,
3679 }
3680
3681 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003682 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003683 gtest: false,
3684 sanitize: { memtag_heap: false },
3685 }
3686
3687 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003688 name: "%[1]s_test_true",
3689 gtest: false,
3690 sanitize: { memtag_heap: true },
3691 }
3692
3693 cc_test {
3694 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003695 gtest: false,
3696 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3697 }
3698
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003699 cc_test {
3700 name: "%[1]s_test_true_diag",
3701 gtest: false,
3702 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3703 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003704
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003705 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003706 name: "%[1]s_binary",
3707 }
3708
3709 cc_binary {
3710 name: "%[1]s_binary_false",
3711 sanitize: { memtag_heap: false },
3712 }
3713
3714 cc_binary {
3715 name: "%[1]s_binary_true",
3716 sanitize: { memtag_heap: true },
3717 }
3718
3719 cc_binary {
3720 name: "%[1]s_binary_true_nodiag",
3721 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3722 }
3723
3724 cc_binary {
3725 name: "%[1]s_binary_true_diag",
3726 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003727 }
3728 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003729 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3730 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3731 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3732 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003733
3734 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003735 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3736 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3737 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3738 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003739 }
3740
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003741 return TestConfig(buildDir, android.Android, nil, "", mockFS)
3742}
3743
3744func TestSanitizeMemtagHeap(t *testing.T) {
3745 variant := "android_arm64_armv8-a"
3746
3747 config := makeMemtagTestConfig(t)
3748 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003749 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003750 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003751 ctx := CreateTestContext(config)
3752 ctx.Register()
3753
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003754 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003755 android.FailIfErrored(t, errs)
3756 _, errs = ctx.PrepareBuildActions(config)
3757 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003758
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003759 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3760 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3761 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3762 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3763 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3764
3765 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3766 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3767 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3768 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3769 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3770
3771 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3772 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3773 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3774 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3775 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3776
3777 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3778 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3779 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3780 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3781 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3782
3783 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3784 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3785 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3786 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3787 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3788
3789 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3790 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3791 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3792 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3793 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3794
3795 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3796 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3797 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3798 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3799 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3800
3801 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3802 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3803 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3804 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3805 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3806}
3807
3808func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003809 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003810
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003811 config := makeMemtagTestConfig(t)
3812 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3813 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3814 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3815 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3816 ctx := CreateTestContext(config)
3817 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003818
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003819 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3820 android.FailIfErrored(t, errs)
3821 _, errs = ctx.PrepareBuildActions(config)
3822 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003823
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003824 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3825 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3826 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3827 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3828 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003829
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003830 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3831 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3832 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3833 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3834 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3835
3836 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3837 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3838 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3839 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3840 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3841
3842 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3843 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3844 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3845 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3846 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3847
3848 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3849 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3850 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3851 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3852 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3853
3854 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3855 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3856 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3857 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3858 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3859
3860 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3861 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3862 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3863 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3864 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3865
3866 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3869 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3870 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3871}
3872
3873func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3874 variant := "android_arm64_armv8-a"
3875
3876 config := makeMemtagTestConfig(t)
3877 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3878 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3879 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3880 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3881 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
3882 ctx := CreateTestContext(config)
3883 ctx.Register()
3884
3885 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3886 android.FailIfErrored(t, errs)
3887 _, errs = ctx.PrepareBuildActions(config)
3888 android.FailIfErrored(t, errs)
3889
3890 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3892 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3893 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3894 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3895
3896 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3898 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3899 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3900 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3901
3902 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3903 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3904 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3905 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3906 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3907
3908 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3909 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3910 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3911 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3912 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3913
3914 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3915 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3916 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3917 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3918 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3919
3920 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3921 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3922 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3923 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3924 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3925
3926 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3927 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3928 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3929 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3930 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3931
3932 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3933 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3934 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3935 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3936 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003937}
Paul Duffin3cb603e2021-02-19 13:57:10 +00003938
3939func TestIncludeDirsExporting(t *testing.T) {
3940
3941 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
3942 // embedded newline characters alone.
3943 trimIndentingSpaces := func(s string) string {
3944 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
3945 }
3946
3947 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
3948 t.Helper()
3949 expected = trimIndentingSpaces(expected)
3950 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
3951 if expected != actual {
3952 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
3953 }
3954 }
3955
3956 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
3957
3958 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
3959 t.Helper()
3960 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
3961 name := module.Name()
3962
3963 for _, checker := range checkers {
3964 checker(t, name, exported)
3965 }
3966 }
3967
3968 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
3969 return func(t *testing.T, name string, exported FlagExporterInfo) {
3970 t.Helper()
3971 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
3972 }
3973 }
3974
3975 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
3976 return func(t *testing.T, name string, exported FlagExporterInfo) {
3977 t.Helper()
3978 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
3979 }
3980 }
3981
3982 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
3983 return func(t *testing.T, name string, exported FlagExporterInfo) {
3984 t.Helper()
3985 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
3986 }
3987 }
3988
3989 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
3990 return func(t *testing.T, name string, exported FlagExporterInfo) {
3991 t.Helper()
3992 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
3993 }
3994 }
3995
3996 genRuleModules := `
3997 genrule {
3998 name: "genrule_foo",
3999 cmd: "generate-foo",
4000 out: [
4001 "generated_headers/foo/generated_header.h",
4002 ],
4003 export_include_dirs: [
4004 "generated_headers",
4005 ],
4006 }
4007
4008 genrule {
4009 name: "genrule_bar",
4010 cmd: "generate-bar",
4011 out: [
4012 "generated_headers/bar/generated_header.h",
4013 ],
4014 export_include_dirs: [
4015 "generated_headers",
4016 ],
4017 }
4018 `
4019
4020 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
4021 ctx := testCc(t, genRuleModules+`
4022 cc_library {
4023 name: "libfoo",
4024 srcs: ["foo.c"],
4025 export_include_dirs: ["foo/standard"],
4026 export_system_include_dirs: ["foo/system"],
4027 generated_headers: ["genrule_foo"],
4028 export_generated_headers: ["genrule_foo"],
4029 }
4030
4031 cc_library {
4032 name: "libbar",
4033 srcs: ["bar.c"],
4034 shared_libs: ["libfoo"],
4035 export_include_dirs: ["bar/standard"],
4036 export_system_include_dirs: ["bar/system"],
4037 generated_headers: ["genrule_bar"],
4038 export_generated_headers: ["genrule_bar"],
4039 }
4040 `)
4041 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4042 checkIncludeDirs(t, ctx, foo,
4043 expectedIncludeDirs(`
4044 foo/standard
4045 .intermediates/genrule_foo/gen/generated_headers
4046 `),
4047 expectedSystemIncludeDirs(`foo/system`),
4048 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4049 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4050 )
4051
4052 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4053 checkIncludeDirs(t, ctx, bar,
4054 expectedIncludeDirs(`
4055 bar/standard
4056 .intermediates/genrule_bar/gen/generated_headers
4057 `),
4058 expectedSystemIncludeDirs(`bar/system`),
4059 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4060 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4061 )
4062 })
4063
4064 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
4065 ctx := testCc(t, genRuleModules+`
4066 cc_library {
4067 name: "libfoo",
4068 srcs: ["foo.c"],
4069 export_include_dirs: ["foo/standard"],
4070 export_system_include_dirs: ["foo/system"],
4071 generated_headers: ["genrule_foo"],
4072 export_generated_headers: ["genrule_foo"],
4073 }
4074
4075 cc_library {
4076 name: "libbar",
4077 srcs: ["bar.c"],
4078 whole_static_libs: ["libfoo"],
4079 export_include_dirs: ["bar/standard"],
4080 export_system_include_dirs: ["bar/system"],
4081 generated_headers: ["genrule_bar"],
4082 export_generated_headers: ["genrule_bar"],
4083 }
4084 `)
4085 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4086 checkIncludeDirs(t, ctx, foo,
4087 expectedIncludeDirs(`
4088 foo/standard
4089 .intermediates/genrule_foo/gen/generated_headers
4090 `),
4091 expectedSystemIncludeDirs(`foo/system`),
4092 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4093 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4094 )
4095
4096 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4097 checkIncludeDirs(t, ctx, bar,
4098 expectedIncludeDirs(`
4099 bar/standard
4100 foo/standard
4101 .intermediates/genrule_foo/gen/generated_headers
4102 .intermediates/genrule_bar/gen/generated_headers
4103 `),
4104 expectedSystemIncludeDirs(`
4105 bar/system
4106 foo/system
4107 `),
4108 expectedGeneratedHeaders(`
4109 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4110 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4111 `),
4112 expectedOrderOnlyDeps(`
4113 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4114 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4115 `),
4116 )
4117 })
4118
Paul Duffin3cb603e2021-02-19 13:57:10 +00004119 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
4120 ctx := testCc(t, genRuleModules+`
4121 cc_library_shared {
4122 name: "libfoo",
4123 srcs: [
4124 "foo.c",
4125 "b.aidl",
4126 "a.proto",
4127 ],
4128 aidl: {
4129 export_aidl_headers: true,
4130 }
4131 }
4132 `)
4133 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4134 checkIncludeDirs(t, ctx, foo,
4135 expectedIncludeDirs(`
4136 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
4137 `),
4138 expectedSystemIncludeDirs(``),
4139 expectedGeneratedHeaders(`
4140 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4141 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4142 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004143 `),
4144 expectedOrderOnlyDeps(`
4145 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4146 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4147 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004148 `),
4149 )
4150 })
4151
Paul Duffin3cb603e2021-02-19 13:57:10 +00004152 t.Run("ensure only proto headers are exported", func(t *testing.T) {
4153 ctx := testCc(t, genRuleModules+`
4154 cc_library_shared {
4155 name: "libfoo",
4156 srcs: [
4157 "foo.c",
4158 "b.aidl",
4159 "a.proto",
4160 ],
4161 proto: {
4162 export_proto_headers: true,
4163 }
4164 }
4165 `)
4166 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4167 checkIncludeDirs(t, ctx, foo,
4168 expectedIncludeDirs(`
4169 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
4170 `),
4171 expectedSystemIncludeDirs(``),
4172 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004173 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4174 `),
4175 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004176 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4177 `),
4178 )
4179 })
4180
Paul Duffin33056e82021-02-19 13:49:08 +00004181 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00004182 ctx := testCc(t, genRuleModules+`
4183 cc_library_shared {
4184 name: "libfoo",
4185 srcs: [
4186 "foo.c",
4187 "a.sysprop",
4188 "b.aidl",
4189 "a.proto",
4190 ],
4191 }
4192 `)
4193 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4194 checkIncludeDirs(t, ctx, foo,
4195 expectedIncludeDirs(`
4196 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
4197 `),
4198 expectedSystemIncludeDirs(``),
4199 expectedGeneratedHeaders(`
4200 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004201 `),
4202 expectedOrderOnlyDeps(`
4203 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4204 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004205 `),
4206 )
4207 })
4208}