blob: 16ae7ee308ca0d2cddc13ac7ce7f505ecc8879c4 [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,
Paul Duffin02a3d652021-02-24 18:51:54 +000058 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
59 variables.DeviceVndkVersion = StringPtr("current")
60 variables.ProductVndkVersion = StringPtr("current")
61 variables.Platform_vndk_version = StringPtr("VER")
62 }),
63)
64
65// testCcWithConfig runs tests using the ccFixtureFactory
66//
67// See testCc for an explanation as to how to stop using this deprecated method.
68//
69// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -080070func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070071 t.Helper()
Paul Duffin02a3d652021-02-24 18:51:54 +000072 result := ccFixtureFactory.RunTestWithConfig(t, config)
73 return result.TestContext
Jiyong Park6a43f042017-10-12 23:05:00 +090074}
75
Paul Duffin02a3d652021-02-24 18:51:54 +000076// testCc runs tests using the ccFixtureFactory
77//
78// Do not add any new usages of this, instead use the ccFixtureFactory directly as it makes it much
79// easier to customize the test behavior.
80//
81// If it is necessary to customize the behavior of an existing test that uses this then please first
82// convert the test to using ccFixtureFactory first and then in a following change add the
83// appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
84// that it did not change the test behavior unexpectedly.
85//
86// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080087func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080088 t.Helper()
Paul Duffin02a3d652021-02-24 18:51:54 +000089 result := ccFixtureFactory.RunTestWithBp(t, bp)
90 return result.TestContext
Logan Chienf3511742017-10-31 18:04:35 +080091}
92
Paul Duffin02a3d652021-02-24 18:51:54 +000093// testCcNoVndk runs tests using the ccFixtureFactory
94//
95// See testCc for an explanation as to how to stop using this deprecated method.
96//
97// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080098func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080099 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800100 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700101 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800102
Colin Cross98be1bb2019-12-13 20:41:13 -0800103 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800104}
105
Paul Duffin02a3d652021-02-24 18:51:54 +0000106// testCcNoProductVndk runs tests using the ccFixtureFactory
107//
108// See testCc for an explanation as to how to stop using this deprecated method.
109//
110// deprecated
Justin Yun8a2600c2020-12-07 12:44:03 +0900111func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
112 t.Helper()
113 config := TestConfig(buildDir, android.Android, nil, bp, nil)
114 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
115 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
116
117 return testCcWithConfig(t, config)
118}
119
Paul Duffin02a3d652021-02-24 18:51:54 +0000120// testCcErrorWithConfig runs tests using the ccFixtureFactory
121//
122// See testCc for an explanation as to how to stop using this deprecated method.
123//
124// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900125func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800126 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800127
Paul Duffin02a3d652021-02-24 18:51:54 +0000128 ccFixtureFactory.Extend().
129 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
130 RunTestWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800131}
132
Paul Duffin02a3d652021-02-24 18:51:54 +0000133// testCcError runs tests using the ccFixtureFactory
134//
135// See testCc for an explanation as to how to stop using this deprecated method.
136//
137// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900138func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900139 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900140 config := TestConfig(buildDir, android.Android, nil, bp, nil)
141 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
142 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
143 testCcErrorWithConfig(t, pattern, config)
144 return
145}
146
Paul Duffin02a3d652021-02-24 18:51:54 +0000147// testCcErrorProductVndk runs tests using the ccFixtureFactory
148//
149// See testCc for an explanation as to how to stop using this deprecated method.
150//
151// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900152func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900153 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900154 config := TestConfig(buildDir, android.Android, nil, bp, nil)
155 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
156 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
157 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
158 testCcErrorWithConfig(t, pattern, config)
159 return
160}
161
Logan Chienf3511742017-10-31 18:04:35 +0800162const (
Colin Cross7113d202019-11-20 16:39:12 -0800163 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800164 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900165 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800166 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800167)
168
Doug Hornc32c6b02019-01-17 14:44:05 -0800169func TestFuchsiaDeps(t *testing.T) {
170 t.Helper()
171
172 bp := `
173 cc_library {
174 name: "libTest",
175 srcs: ["foo.c"],
176 target: {
177 fuchsia: {
178 srcs: ["bar.c"],
179 },
180 },
181 }`
182
Paul Duffinecdac8a2021-02-24 19:18:42 +0000183 result := ccFixtureFactory.Extend(PrepareForTestOnFuchsia).RunTestWithBp(t, bp)
Doug Hornc32c6b02019-01-17 14:44:05 -0800184
185 rt := false
186 fb := false
187
Paul Duffinecdac8a2021-02-24 19:18:42 +0000188 ld := result.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
Doug Hornc32c6b02019-01-17 14:44:05 -0800189 implicits := ld.Implicits
190 for _, lib := range implicits {
191 if strings.Contains(lib.Rel(), "libcompiler_rt") {
192 rt = true
193 }
194
195 if strings.Contains(lib.Rel(), "libbioniccompat") {
196 fb = true
197 }
198 }
199
200 if !rt || !fb {
201 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
202 }
203}
204
205func TestFuchsiaTargetDecl(t *testing.T) {
206 t.Helper()
207
208 bp := `
209 cc_library {
210 name: "libTest",
211 srcs: ["foo.c"],
212 target: {
213 fuchsia: {
214 srcs: ["bar.c"],
215 },
216 },
217 }`
218
Paul Duffinecdac8a2021-02-24 19:18:42 +0000219 result := ccFixtureFactory.Extend(PrepareForTestOnFuchsia).RunTestWithBp(t, bp)
220 ld := result.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
Doug Hornc32c6b02019-01-17 14:44:05 -0800221 var objs []string
222 for _, o := range ld.Inputs {
223 objs = append(objs, o.Base())
224 }
Paul Duffine84b1332021-03-12 11:59:43 +0000225 android.AssertArrayString(t, "libTest inputs", []string{"foo.o", "bar.o"}, objs)
Doug Hornc32c6b02019-01-17 14:44:05 -0800226}
227
Jiyong Park6a43f042017-10-12 23:05:00 +0900228func TestVendorSrc(t *testing.T) {
229 ctx := testCc(t, `
230 cc_library {
231 name: "libTest",
232 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700233 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800234 nocrt: true,
235 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900236 vendor_available: true,
237 target: {
238 vendor: {
239 srcs: ["bar.c"],
240 },
241 },
242 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900243 `)
244
Logan Chienf3511742017-10-31 18:04:35 +0800245 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900246 var objs []string
247 for _, o := range ld.Inputs {
248 objs = append(objs, o.Base())
249 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800250 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900251 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
252 }
253}
254
Logan Chienf3511742017-10-31 18:04:35 +0800255func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900256 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800257
Logan Chiend3c59a22018-03-29 14:08:15 +0800258 t.Helper()
259
Justin Yun0ecf0b22020-02-28 15:07:59 +0900260 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Logan Chienf3511742017-10-31 18:04:35 +0800261
262 // Check library properties.
263 lib, ok := mod.compiler.(*libraryDecorator)
264 if !ok {
265 t.Errorf("%q must have libraryDecorator", name)
266 } else if lib.baseInstaller.subDir != subDir {
267 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
268 lib.baseInstaller.subDir)
269 }
270
271 // Check VNDK properties.
272 if mod.vndkdep == nil {
273 t.Fatalf("%q must have `vndkdep`", name)
274 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700275 if !mod.IsVndk() {
276 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800277 }
278 if mod.isVndkSp() != isVndkSp {
279 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
280 }
281
282 // Check VNDK extension properties.
283 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500284 if mod.IsVndkExt() != isVndkExt {
285 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800286 }
287
288 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
289 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
290 }
291}
292
Jose Galmes0a942a02021-02-03 14:23:15 -0800293func 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 -0700294 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900295 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
296 if !ok {
297 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900298 return
299 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900300 outputFiles, err := mod.OutputFiles("")
301 if err != nil || len(outputFiles) != 1 {
302 t.Errorf("%q must have single output\n", moduleName)
303 return
304 }
305 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900306
Bill Peckham945441c2020-08-31 16:07:58 -0700307 if include {
308 out := singleton.Output(snapshotPath)
Jose Galmes0a942a02021-02-03 14:23:15 -0800309 if fake {
310 if out.Rule == nil {
311 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
312 }
313 } else {
314 if out.Input.String() != outputFiles[0].String() {
315 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
316 }
Bill Peckham945441c2020-08-31 16:07:58 -0700317 }
318 } else {
319 out := singleton.MaybeOutput(snapshotPath)
320 if out.Rule != nil {
321 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
322 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900323 }
324}
325
Bill Peckham945441c2020-08-31 16:07:58 -0700326func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800327 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
Bill Peckham945441c2020-08-31 16:07:58 -0700328}
329
330func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800331 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
332}
333
334func checkSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
335 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
Bill Peckham945441c2020-08-31 16:07:58 -0700336}
337
Jooyung Han2216fb12019-11-06 16:46:15 +0900338func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
339 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800340 content := android.ContentFromFileRuleForTests(t, params)
341 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900342 assertArrayString(t, actual, expected)
343}
344
Jooyung Han097087b2019-10-22 19:32:18 +0900345func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
346 t.Helper()
347 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900348 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
349}
350
351func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
352 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800353 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
354 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900355}
356
Logan Chienf3511742017-10-31 18:04:35 +0800357func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800358 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800359 cc_library {
360 name: "libvndk",
361 vendor_available: true,
362 vndk: {
363 enabled: true,
364 },
365 nocrt: true,
366 }
367
368 cc_library {
369 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900370 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800371 vndk: {
372 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900373 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800374 },
375 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900376 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800377 }
378
379 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900380 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800381 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900382 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800383 vndk: {
384 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900385 },
386 nocrt: true,
387 target: {
388 vendor: {
389 cflags: ["-DTEST"],
390 },
391 product: {
392 cflags: ["-DTEST"],
393 },
394 },
395 }
396
397 cc_library {
398 name: "libvndk_sp",
399 vendor_available: true,
400 vndk: {
401 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800402 support_system_process: true,
403 },
404 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900405 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800406 }
407
408 cc_library {
409 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900410 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800411 vndk: {
412 enabled: true,
413 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900414 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800415 },
416 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900417 target: {
418 vendor: {
419 suffix: "-x",
420 },
421 },
Logan Chienf3511742017-10-31 18:04:35 +0800422 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900423
424 cc_library {
425 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900426 vendor_available: true,
427 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900428 vndk: {
429 enabled: true,
430 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900431 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900432 },
433 nocrt: true,
434 target: {
435 vendor: {
436 suffix: "-x",
437 },
438 product: {
439 suffix: "-x",
440 },
441 },
442 }
443
Colin Crosse4e44bc2020-12-28 13:50:21 -0800444 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900445 name: "llndk.libraries.txt",
446 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800447 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900448 name: "vndkcore.libraries.txt",
449 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800450 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900451 name: "vndksp.libraries.txt",
452 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800453 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900454 name: "vndkprivate.libraries.txt",
455 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800456 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900457 name: "vndkproduct.libraries.txt",
458 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800459 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900460 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800461 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900462 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800463 `
464
465 config := TestConfig(buildDir, android.Android, nil, bp, nil)
466 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900467 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800468 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
469
470 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800471
Jooyung Han261e1582020-10-20 18:54:21 +0900472 // subdir == "" because VNDK libs are not supposed to be installed separately.
473 // They are installed as part of VNDK APEX instead.
474 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
475 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900476 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900477 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
478 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900479 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900480
Justin Yun6977e8a2020-10-29 18:24:11 +0900481 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
482 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900483
Inseob Kim1f086e22019-05-09 13:29:15 +0900484 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900485 snapshotDir := "vndk-snapshot"
486 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
487
488 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
489 "arm64", "armv8-a"))
490 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
491 "arm", "armv7-a-neon"))
492
493 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
494 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
495 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
496 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
497
Colin Crossfb0c16e2019-11-20 17:12:35 -0800498 variant := "android_vendor.VER_arm64_armv8-a_shared"
499 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900500
Inseob Kim7f283f42020-06-01 21:53:49 +0900501 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
502
503 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
504 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900505 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
506 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900507 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
508 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900509
Jooyung Han39edb6c2019-11-06 16:53:07 +0900510 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900511 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
512 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
513 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
514 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900515 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900516
Jooyung Han097087b2019-10-22 19:32:18 +0900517 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
518 "LLNDK: libc.so",
519 "LLNDK: libdl.so",
520 "LLNDK: libft2.so",
521 "LLNDK: libm.so",
522 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900523 "VNDK-SP: libvndk_sp-x.so",
524 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900525 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900526 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900527 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900528 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900529 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900530 "VNDK-private: libvndk-private.so",
531 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900532 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900533 "VNDK-product: libc++.so",
534 "VNDK-product: libvndk_product.so",
535 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900536 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900537 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900538 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
539 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
540 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 +0900541 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 +0900542 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
543}
544
Yo Chiangbba545e2020-06-09 16:15:37 +0800545func TestVndkWithHostSupported(t *testing.T) {
546 ctx := testCc(t, `
547 cc_library {
548 name: "libvndk_host_supported",
549 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900550 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800551 vndk: {
552 enabled: true,
553 },
554 host_supported: true,
555 }
556
557 cc_library {
558 name: "libvndk_host_supported_but_disabled_on_device",
559 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900560 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800561 vndk: {
562 enabled: true,
563 },
564 host_supported: true,
565 enabled: false,
566 target: {
567 host: {
568 enabled: true,
569 }
570 }
571 }
572
Colin Crosse4e44bc2020-12-28 13:50:21 -0800573 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800574 name: "vndkcore.libraries.txt",
575 }
576 `)
577
578 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
579}
580
Jooyung Han2216fb12019-11-06 16:46:15 +0900581func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800582 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800583 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900584 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800585 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800586 }`
587 config := TestConfig(buildDir, android.Android, nil, bp, nil)
588 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
589 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
590 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900591
592 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Colin Crossaa255532020-07-03 13:18:24 -0700593 entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900594 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900595}
596
597func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800598 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900599 cc_library {
600 name: "libvndk",
601 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900602 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900603 vndk: {
604 enabled: true,
605 },
606 nocrt: true,
607 }
608
609 cc_library {
610 name: "libvndk_sp",
611 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900612 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900613 vndk: {
614 enabled: true,
615 support_system_process: true,
616 },
617 nocrt: true,
618 }
619
620 cc_library {
621 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900622 vendor_available: true,
623 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900624 vndk: {
625 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900626 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900627 },
628 nocrt: true,
629 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900630
Colin Crosse4e44bc2020-12-28 13:50:21 -0800631 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900632 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800633 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900634 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800635 `
636
637 config := TestConfig(buildDir, android.Android, nil, bp, nil)
638 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
639 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
640 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
641
642 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
643
644 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900645
Jooyung Han2216fb12019-11-06 16:46:15 +0900646 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900647}
648
Chris Parsons79d66a52020-06-05 17:26:16 -0400649func TestDataLibs(t *testing.T) {
650 bp := `
651 cc_test_library {
652 name: "test_lib",
653 srcs: ["test_lib.cpp"],
654 gtest: false,
655 }
656
657 cc_test {
658 name: "main_test",
659 data_libs: ["test_lib"],
660 gtest: false,
661 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400662 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400663
664 config := TestConfig(buildDir, android.Android, nil, bp, nil)
665 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
666 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
667 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
668
669 ctx := testCcWithConfig(t, config)
670 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
671 testBinary := module.(*Module).linker.(*testBinary)
672 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
673 if err != nil {
674 t.Errorf("Expected cc_test to produce output files, error: %s", err)
675 return
676 }
677 if len(outputFiles) != 1 {
678 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
679 return
680 }
681 if len(testBinary.dataPaths()) != 1 {
682 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
683 return
684 }
685
686 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400687 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400688
689 if !strings.HasSuffix(outputPath, "/main_test") {
690 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
691 return
692 }
693 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
694 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
695 return
696 }
697}
698
Chris Parsons216e10a2020-07-09 17:12:52 -0400699func TestDataLibsRelativeInstallPath(t *testing.T) {
700 bp := `
701 cc_test_library {
702 name: "test_lib",
703 srcs: ["test_lib.cpp"],
704 relative_install_path: "foo/bar/baz",
705 gtest: false,
706 }
707
708 cc_test {
709 name: "main_test",
710 data_libs: ["test_lib"],
711 gtest: false,
712 }
713 `
714
715 config := TestConfig(buildDir, android.Android, nil, bp, nil)
716 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
717 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
718 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
719
720 ctx := testCcWithConfig(t, config)
721 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
722 testBinary := module.(*Module).linker.(*testBinary)
723 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
724 if err != nil {
725 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
726 }
727 if len(outputFiles) != 1 {
728 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
729 }
730 if len(testBinary.dataPaths()) != 1 {
731 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
732 }
733
734 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400735
736 if !strings.HasSuffix(outputPath, "/main_test") {
737 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
738 }
Colin Crossaa255532020-07-03 13:18:24 -0700739 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons216e10a2020-07-09 17:12:52 -0400740 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
741 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400742 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400743 }
744}
745
Jooyung Han0302a842019-10-30 18:43:49 +0900746func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900747 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900748 cc_library {
749 name: "libvndk",
750 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900751 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900752 vndk: {
753 enabled: true,
754 },
755 nocrt: true,
756 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900757 cc_library {
758 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900759 vendor_available: true,
760 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900761 vndk: {
762 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900763 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900764 },
765 nocrt: true,
766 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800767
768 cc_library {
769 name: "libllndk",
770 llndk_stubs: "libllndk.llndk",
771 }
772
773 llndk_library {
774 name: "libllndk.llndk",
775 symbol_file: "",
776 export_llndk_headers: ["libllndk_headers"],
777 }
778
779 llndk_headers {
780 name: "libllndk_headers",
781 export_include_dirs: ["include"],
782 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900783 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900784
785 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
786 "LLNDK: libc.so",
787 "LLNDK: libdl.so",
788 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800789 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900790 "LLNDK: libm.so",
791 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900792 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900793 "VNDK-core: libvndk.so",
794 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900795 "VNDK-private: libvndk-private.so",
796 "VNDK-product: libc++.so",
797 "VNDK-product: libvndk-private.so",
798 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900799 })
Logan Chienf3511742017-10-31 18:04:35 +0800800}
801
Justin Yun63e9ec72020-10-29 16:49:43 +0900802func TestVndkModuleError(t *testing.T) {
803 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900804 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900805 cc_library {
806 name: "libvndk",
807 vndk: {
808 enabled: true,
809 },
810 nocrt: true,
811 }
812 `)
813
Justin Yunc0d8c492021-01-07 17:45:31 +0900814 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900815 cc_library {
816 name: "libvndk",
817 product_available: true,
818 vndk: {
819 enabled: true,
820 },
821 nocrt: true,
822 }
823 `)
824
Justin Yun6977e8a2020-10-29 18:24:11 +0900825 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
826 cc_library {
827 name: "libvndkprop",
828 vendor_available: true,
829 product_available: true,
830 vndk: {
831 enabled: true,
832 },
833 nocrt: true,
834 target: {
835 vendor: {
836 cflags: ["-DTEST",],
837 },
838 },
839 }
840 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900841}
842
Logan Chiend3c59a22018-03-29 14:08:15 +0800843func TestVndkDepError(t *testing.T) {
844 // Check whether an error is emitted when a VNDK lib depends on a system lib.
845 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
846 cc_library {
847 name: "libvndk",
848 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900849 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800850 vndk: {
851 enabled: true,
852 },
853 shared_libs: ["libfwk"], // Cause error
854 nocrt: true,
855 }
856
857 cc_library {
858 name: "libfwk",
859 nocrt: true,
860 }
861 `)
862
863 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
864 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
865 cc_library {
866 name: "libvndk",
867 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900868 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800869 vndk: {
870 enabled: true,
871 },
872 shared_libs: ["libvendor"], // Cause error
873 nocrt: true,
874 }
875
876 cc_library {
877 name: "libvendor",
878 vendor: true,
879 nocrt: true,
880 }
881 `)
882
883 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
884 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
885 cc_library {
886 name: "libvndk_sp",
887 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900888 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800889 vndk: {
890 enabled: true,
891 support_system_process: true,
892 },
893 shared_libs: ["libfwk"], // Cause error
894 nocrt: true,
895 }
896
897 cc_library {
898 name: "libfwk",
899 nocrt: true,
900 }
901 `)
902
903 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
904 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
905 cc_library {
906 name: "libvndk_sp",
907 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900908 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800909 vndk: {
910 enabled: true,
911 support_system_process: true,
912 },
913 shared_libs: ["libvendor"], // Cause error
914 nocrt: true,
915 }
916
917 cc_library {
918 name: "libvendor",
919 vendor: true,
920 nocrt: true,
921 }
922 `)
923
924 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
925 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
926 cc_library {
927 name: "libvndk_sp",
928 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900929 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800930 vndk: {
931 enabled: true,
932 support_system_process: true,
933 },
934 shared_libs: ["libvndk"], // Cause error
935 nocrt: true,
936 }
937
938 cc_library {
939 name: "libvndk",
940 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900941 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800942 vndk: {
943 enabled: true,
944 },
945 nocrt: true,
946 }
947 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900948
949 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
950 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
951 cc_library {
952 name: "libvndk",
953 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900954 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900955 vndk: {
956 enabled: true,
957 },
958 shared_libs: ["libnonvndk"],
959 nocrt: true,
960 }
961
962 cc_library {
963 name: "libnonvndk",
964 vendor_available: true,
965 nocrt: true,
966 }
967 `)
968
969 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
970 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
971 cc_library {
972 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900973 vendor_available: true,
974 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900975 vndk: {
976 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900977 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900978 },
979 shared_libs: ["libnonvndk"],
980 nocrt: true,
981 }
982
983 cc_library {
984 name: "libnonvndk",
985 vendor_available: true,
986 nocrt: true,
987 }
988 `)
989
990 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
991 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
992 cc_library {
993 name: "libvndksp",
994 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900995 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900996 vndk: {
997 enabled: true,
998 support_system_process: true,
999 },
1000 shared_libs: ["libnonvndk"],
1001 nocrt: true,
1002 }
1003
1004 cc_library {
1005 name: "libnonvndk",
1006 vendor_available: true,
1007 nocrt: true,
1008 }
1009 `)
1010
1011 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
1012 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1013 cc_library {
1014 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001015 vendor_available: true,
1016 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001017 vndk: {
1018 enabled: true,
1019 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001020 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001021 },
1022 shared_libs: ["libnonvndk"],
1023 nocrt: true,
1024 }
1025
1026 cc_library {
1027 name: "libnonvndk",
1028 vendor_available: true,
1029 nocrt: true,
1030 }
1031 `)
1032}
1033
1034func TestDoubleLoadbleDep(t *testing.T) {
1035 // okay to link : LLNDK -> double_loadable VNDK
1036 testCc(t, `
1037 cc_library {
1038 name: "libllndk",
1039 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001040 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001041 }
1042
1043 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001044 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001045 symbol_file: "",
1046 }
1047
1048 cc_library {
1049 name: "libdoubleloadable",
1050 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001051 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001052 vndk: {
1053 enabled: true,
1054 },
1055 double_loadable: true,
1056 }
1057 `)
1058 // okay to link : LLNDK -> VNDK-SP
1059 testCc(t, `
1060 cc_library {
1061 name: "libllndk",
1062 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -07001063 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001064 }
1065
1066 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001067 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001068 symbol_file: "",
1069 }
1070
1071 cc_library {
1072 name: "libvndksp",
1073 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001074 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001075 vndk: {
1076 enabled: true,
1077 support_system_process: true,
1078 },
1079 }
1080 `)
1081 // okay to link : double_loadable -> double_loadable
1082 testCc(t, `
1083 cc_library {
1084 name: "libdoubleloadable1",
1085 shared_libs: ["libdoubleloadable2"],
1086 vendor_available: true,
1087 double_loadable: true,
1088 }
1089
1090 cc_library {
1091 name: "libdoubleloadable2",
1092 vendor_available: true,
1093 double_loadable: true,
1094 }
1095 `)
1096 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1097 testCc(t, `
1098 cc_library {
1099 name: "libdoubleloadable",
1100 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001101 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001102 vndk: {
1103 enabled: true,
1104 },
1105 double_loadable: true,
1106 shared_libs: ["libnondoubleloadable"],
1107 }
1108
1109 cc_library {
1110 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001111 vendor_available: true,
1112 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001113 vndk: {
1114 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001115 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001116 },
1117 double_loadable: true,
1118 }
1119 `)
1120 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1121 testCc(t, `
1122 cc_library {
1123 name: "libllndk",
1124 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001125 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001126 }
1127
1128 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001129 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001130 symbol_file: "",
1131 }
1132
1133 cc_library {
1134 name: "libcoreonly",
1135 shared_libs: ["libvendoravailable"],
1136 }
1137
1138 // indirect dependency of LLNDK
1139 cc_library {
1140 name: "libvendoravailable",
1141 vendor_available: true,
1142 double_loadable: true,
1143 }
1144 `)
1145}
1146
1147func TestDoubleLoadableDepError(t *testing.T) {
1148 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1149 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1150 cc_library {
1151 name: "libllndk",
1152 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001153 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001154 }
1155
1156 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001157 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001158 symbol_file: "",
1159 }
1160
1161 cc_library {
1162 name: "libnondoubleloadable",
1163 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001164 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001165 vndk: {
1166 enabled: true,
1167 },
1168 }
1169 `)
1170
1171 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1172 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1173 cc_library {
1174 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001175 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001176 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001177 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001178 }
1179
1180 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001181 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001182 symbol_file: "",
1183 }
1184
1185 cc_library {
1186 name: "libnondoubleloadable",
1187 vendor_available: true,
1188 }
1189 `)
1190
Jooyung Hana70f0672019-01-18 15:20:43 +09001191 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1192 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1193 cc_library {
1194 name: "libllndk",
1195 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001196 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001197 }
1198
1199 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001200 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001201 symbol_file: "",
1202 }
1203
1204 cc_library {
1205 name: "libcoreonly",
1206 shared_libs: ["libvendoravailable"],
1207 }
1208
1209 // indirect dependency of LLNDK
1210 cc_library {
1211 name: "libvendoravailable",
1212 vendor_available: true,
1213 }
1214 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001215
1216 // The error is not from 'client' but from 'libllndk'
1217 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1218 cc_library {
1219 name: "client",
1220 vendor_available: true,
1221 double_loadable: true,
1222 shared_libs: ["libllndk"],
1223 }
1224 cc_library {
1225 name: "libllndk",
1226 shared_libs: ["libnondoubleloadable"],
1227 llndk_stubs: "libllndk.llndk",
1228 }
1229 llndk_library {
1230 name: "libllndk.llndk",
1231 symbol_file: "",
1232 }
1233 cc_library {
1234 name: "libnondoubleloadable",
1235 vendor_available: true,
1236 }
1237 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001238}
1239
Jooyung Han479ca172020-10-19 18:51:07 +09001240func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1241 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1242 cc_library {
1243 name: "libvndksp",
1244 shared_libs: ["libanothervndksp"],
1245 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001246 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001247 vndk: {
1248 enabled: true,
1249 support_system_process: true,
1250 }
1251 }
1252
1253 cc_library {
1254 name: "libllndk",
1255 shared_libs: ["libanothervndksp"],
1256 }
1257
1258 llndk_library {
1259 name: "libllndk",
1260 symbol_file: "",
1261 }
1262
1263 cc_library {
1264 name: "libanothervndksp",
1265 vendor_available: true,
1266 }
1267 `)
1268}
1269
Logan Chienf3511742017-10-31 18:04:35 +08001270func TestVndkExt(t *testing.T) {
1271 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001272 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001273 cc_library {
1274 name: "libvndk",
1275 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001276 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001277 vndk: {
1278 enabled: true,
1279 },
1280 nocrt: true,
1281 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001282 cc_library {
1283 name: "libvndk2",
1284 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001285 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001286 vndk: {
1287 enabled: true,
1288 },
1289 target: {
1290 vendor: {
1291 suffix: "-suffix",
1292 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001293 product: {
1294 suffix: "-suffix",
1295 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001296 },
1297 nocrt: true,
1298 }
Logan Chienf3511742017-10-31 18:04:35 +08001299
1300 cc_library {
1301 name: "libvndk_ext",
1302 vendor: true,
1303 vndk: {
1304 enabled: true,
1305 extends: "libvndk",
1306 },
1307 nocrt: true,
1308 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001309
1310 cc_library {
1311 name: "libvndk2_ext",
1312 vendor: true,
1313 vndk: {
1314 enabled: true,
1315 extends: "libvndk2",
1316 },
1317 nocrt: true,
1318 }
Logan Chienf3511742017-10-31 18:04:35 +08001319
Justin Yun0ecf0b22020-02-28 15:07:59 +09001320 cc_library {
1321 name: "libvndk_ext_product",
1322 product_specific: true,
1323 vndk: {
1324 enabled: true,
1325 extends: "libvndk",
1326 },
1327 nocrt: true,
1328 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001329
Justin Yun0ecf0b22020-02-28 15:07:59 +09001330 cc_library {
1331 name: "libvndk2_ext_product",
1332 product_specific: true,
1333 vndk: {
1334 enabled: true,
1335 extends: "libvndk2",
1336 },
1337 nocrt: true,
1338 }
1339 `
1340 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1341 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1342 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1343 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1344
1345 ctx := testCcWithConfig(t, config)
1346
1347 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1348 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1349
1350 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1351 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1352
1353 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1354 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001355}
1356
Logan Chiend3c59a22018-03-29 14:08:15 +08001357func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001358 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1359 ctx := testCcNoVndk(t, `
1360 cc_library {
1361 name: "libvndk",
1362 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001363 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001364 vndk: {
1365 enabled: true,
1366 },
1367 nocrt: true,
1368 }
1369
1370 cc_library {
1371 name: "libvndk_ext",
1372 vendor: true,
1373 vndk: {
1374 enabled: true,
1375 extends: "libvndk",
1376 },
1377 nocrt: true,
1378 }
1379 `)
1380
1381 // Ensures that the core variant of "libvndk_ext" can be found.
1382 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1383 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1384 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1385 }
1386}
1387
Justin Yun0ecf0b22020-02-28 15:07:59 +09001388func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1389 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001390 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001391 cc_library {
1392 name: "libvndk",
1393 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001394 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001395 vndk: {
1396 enabled: true,
1397 },
1398 nocrt: true,
1399 }
1400
1401 cc_library {
1402 name: "libvndk_ext_product",
1403 product_specific: true,
1404 vndk: {
1405 enabled: true,
1406 extends: "libvndk",
1407 },
1408 nocrt: true,
1409 }
1410 `)
1411
1412 // Ensures that the core variant of "libvndk_ext_product" can be found.
1413 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1414 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1415 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1416 }
1417}
1418
Logan Chienf3511742017-10-31 18:04:35 +08001419func TestVndkExtError(t *testing.T) {
1420 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001421 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001422 cc_library {
1423 name: "libvndk",
1424 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001425 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001426 vndk: {
1427 enabled: true,
1428 },
1429 nocrt: true,
1430 }
1431
1432 cc_library {
1433 name: "libvndk_ext",
1434 vndk: {
1435 enabled: true,
1436 extends: "libvndk",
1437 },
1438 nocrt: true,
1439 }
1440 `)
1441
1442 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1443 cc_library {
1444 name: "libvndk",
1445 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001446 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001447 vndk: {
1448 enabled: true,
1449 },
1450 nocrt: true,
1451 }
1452
1453 cc_library {
1454 name: "libvndk_ext",
1455 vendor: true,
1456 vndk: {
1457 enabled: true,
1458 },
1459 nocrt: true,
1460 }
1461 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001462
1463 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1464 cc_library {
1465 name: "libvndk",
1466 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001467 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001468 vndk: {
1469 enabled: true,
1470 },
1471 nocrt: true,
1472 }
1473
1474 cc_library {
1475 name: "libvndk_ext_product",
1476 product_specific: true,
1477 vndk: {
1478 enabled: true,
1479 },
1480 nocrt: true,
1481 }
1482 `)
1483
1484 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1485 cc_library {
1486 name: "libvndk",
1487 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001488 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001489 vndk: {
1490 enabled: true,
1491 },
1492 nocrt: true,
1493 }
1494
1495 cc_library {
1496 name: "libvndk_ext_product",
1497 product_specific: true,
1498 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001499 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001500 vndk: {
1501 enabled: true,
1502 extends: "libvndk",
1503 },
1504 nocrt: true,
1505 }
1506 `)
Logan Chienf3511742017-10-31 18:04:35 +08001507}
1508
1509func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1510 // This test ensures an error is emitted for inconsistent support_system_process.
1511 testCcError(t, "module \".*\" with mismatched support_system_process", `
1512 cc_library {
1513 name: "libvndk",
1514 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001515 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001516 vndk: {
1517 enabled: true,
1518 },
1519 nocrt: true,
1520 }
1521
1522 cc_library {
1523 name: "libvndk_sp_ext",
1524 vendor: true,
1525 vndk: {
1526 enabled: true,
1527 extends: "libvndk",
1528 support_system_process: true,
1529 },
1530 nocrt: true,
1531 }
1532 `)
1533
1534 testCcError(t, "module \".*\" with mismatched support_system_process", `
1535 cc_library {
1536 name: "libvndk_sp",
1537 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001538 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001539 vndk: {
1540 enabled: true,
1541 support_system_process: true,
1542 },
1543 nocrt: true,
1544 }
1545
1546 cc_library {
1547 name: "libvndk_ext",
1548 vendor: true,
1549 vndk: {
1550 enabled: true,
1551 extends: "libvndk_sp",
1552 },
1553 nocrt: true,
1554 }
1555 `)
1556}
1557
1558func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001559 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001560 // with `private: true`.
1561 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001562 cc_library {
1563 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001564 vendor_available: true,
1565 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001566 vndk: {
1567 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001568 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001569 },
1570 nocrt: true,
1571 }
1572
1573 cc_library {
1574 name: "libvndk_ext",
1575 vendor: true,
1576 vndk: {
1577 enabled: true,
1578 extends: "libvndk",
1579 },
1580 nocrt: true,
1581 }
1582 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001583
Justin Yunfd9e8042020-12-23 18:23:14 +09001584 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001585 cc_library {
1586 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001587 vendor_available: true,
1588 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001589 vndk: {
1590 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001591 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001592 },
1593 nocrt: true,
1594 }
1595
1596 cc_library {
1597 name: "libvndk_ext_product",
1598 product_specific: true,
1599 vndk: {
1600 enabled: true,
1601 extends: "libvndk",
1602 },
1603 nocrt: true,
1604 }
1605 `)
Logan Chienf3511742017-10-31 18:04:35 +08001606}
1607
Logan Chiend3c59a22018-03-29 14:08:15 +08001608func TestVendorModuleUseVndkExt(t *testing.T) {
1609 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001610 testCc(t, `
1611 cc_library {
1612 name: "libvndk",
1613 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001614 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001615 vndk: {
1616 enabled: true,
1617 },
1618 nocrt: true,
1619 }
1620
1621 cc_library {
1622 name: "libvndk_ext",
1623 vendor: true,
1624 vndk: {
1625 enabled: true,
1626 extends: "libvndk",
1627 },
1628 nocrt: true,
1629 }
1630
1631 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001632 name: "libvndk_sp",
1633 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001634 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001635 vndk: {
1636 enabled: true,
1637 support_system_process: true,
1638 },
1639 nocrt: true,
1640 }
1641
1642 cc_library {
1643 name: "libvndk_sp_ext",
1644 vendor: true,
1645 vndk: {
1646 enabled: true,
1647 extends: "libvndk_sp",
1648 support_system_process: true,
1649 },
1650 nocrt: true,
1651 }
1652
1653 cc_library {
1654 name: "libvendor",
1655 vendor: true,
1656 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1657 nocrt: true,
1658 }
1659 `)
1660}
1661
Logan Chiend3c59a22018-03-29 14:08:15 +08001662func TestVndkExtUseVendorLib(t *testing.T) {
1663 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001664 testCc(t, `
1665 cc_library {
1666 name: "libvndk",
1667 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001668 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001669 vndk: {
1670 enabled: true,
1671 },
1672 nocrt: true,
1673 }
1674
1675 cc_library {
1676 name: "libvndk_ext",
1677 vendor: true,
1678 vndk: {
1679 enabled: true,
1680 extends: "libvndk",
1681 },
1682 shared_libs: ["libvendor"],
1683 nocrt: true,
1684 }
1685
1686 cc_library {
1687 name: "libvendor",
1688 vendor: true,
1689 nocrt: true,
1690 }
1691 `)
Logan Chienf3511742017-10-31 18:04:35 +08001692
Logan Chiend3c59a22018-03-29 14:08:15 +08001693 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1694 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001695 cc_library {
1696 name: "libvndk_sp",
1697 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001698 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001699 vndk: {
1700 enabled: true,
1701 support_system_process: true,
1702 },
1703 nocrt: true,
1704 }
1705
1706 cc_library {
1707 name: "libvndk_sp_ext",
1708 vendor: true,
1709 vndk: {
1710 enabled: true,
1711 extends: "libvndk_sp",
1712 support_system_process: true,
1713 },
1714 shared_libs: ["libvendor"], // Cause an error
1715 nocrt: true,
1716 }
1717
1718 cc_library {
1719 name: "libvendor",
1720 vendor: true,
1721 nocrt: true,
1722 }
1723 `)
1724}
1725
Justin Yun0ecf0b22020-02-28 15:07:59 +09001726func TestProductVndkExtDependency(t *testing.T) {
1727 bp := `
1728 cc_library {
1729 name: "libvndk",
1730 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001731 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001732 vndk: {
1733 enabled: true,
1734 },
1735 nocrt: true,
1736 }
1737
1738 cc_library {
1739 name: "libvndk_ext_product",
1740 product_specific: true,
1741 vndk: {
1742 enabled: true,
1743 extends: "libvndk",
1744 },
1745 shared_libs: ["libproduct_for_vndklibs"],
1746 nocrt: true,
1747 }
1748
1749 cc_library {
1750 name: "libvndk_sp",
1751 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001752 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001753 vndk: {
1754 enabled: true,
1755 support_system_process: true,
1756 },
1757 nocrt: true,
1758 }
1759
1760 cc_library {
1761 name: "libvndk_sp_ext_product",
1762 product_specific: true,
1763 vndk: {
1764 enabled: true,
1765 extends: "libvndk_sp",
1766 support_system_process: true,
1767 },
1768 shared_libs: ["libproduct_for_vndklibs"],
1769 nocrt: true,
1770 }
1771
1772 cc_library {
1773 name: "libproduct",
1774 product_specific: true,
1775 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1776 nocrt: true,
1777 }
1778
1779 cc_library {
1780 name: "libproduct_for_vndklibs",
1781 product_specific: true,
1782 nocrt: true,
1783 }
1784 `
1785 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1786 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1787 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1788 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1789
1790 testCcWithConfig(t, config)
1791}
1792
Logan Chiend3c59a22018-03-29 14:08:15 +08001793func TestVndkSpExtUseVndkError(t *testing.T) {
1794 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1795 // library.
1796 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1797 cc_library {
1798 name: "libvndk",
1799 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001800 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001801 vndk: {
1802 enabled: true,
1803 },
1804 nocrt: true,
1805 }
1806
1807 cc_library {
1808 name: "libvndk_sp",
1809 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001810 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001811 vndk: {
1812 enabled: true,
1813 support_system_process: true,
1814 },
1815 nocrt: true,
1816 }
1817
1818 cc_library {
1819 name: "libvndk_sp_ext",
1820 vendor: true,
1821 vndk: {
1822 enabled: true,
1823 extends: "libvndk_sp",
1824 support_system_process: true,
1825 },
1826 shared_libs: ["libvndk"], // Cause an error
1827 nocrt: true,
1828 }
1829 `)
1830
1831 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1832 // library.
1833 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1834 cc_library {
1835 name: "libvndk",
1836 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001837 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001838 vndk: {
1839 enabled: true,
1840 },
1841 nocrt: true,
1842 }
1843
1844 cc_library {
1845 name: "libvndk_ext",
1846 vendor: true,
1847 vndk: {
1848 enabled: true,
1849 extends: "libvndk",
1850 },
1851 nocrt: true,
1852 }
1853
1854 cc_library {
1855 name: "libvndk_sp",
1856 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001857 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001858 vndk: {
1859 enabled: true,
1860 support_system_process: true,
1861 },
1862 nocrt: true,
1863 }
1864
1865 cc_library {
1866 name: "libvndk_sp_ext",
1867 vendor: true,
1868 vndk: {
1869 enabled: true,
1870 extends: "libvndk_sp",
1871 support_system_process: true,
1872 },
1873 shared_libs: ["libvndk_ext"], // Cause an error
1874 nocrt: true,
1875 }
1876 `)
1877}
1878
1879func TestVndkUseVndkExtError(t *testing.T) {
1880 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1881 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001882 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1883 cc_library {
1884 name: "libvndk",
1885 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001886 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001887 vndk: {
1888 enabled: true,
1889 },
1890 nocrt: true,
1891 }
1892
1893 cc_library {
1894 name: "libvndk_ext",
1895 vendor: true,
1896 vndk: {
1897 enabled: true,
1898 extends: "libvndk",
1899 },
1900 nocrt: true,
1901 }
1902
1903 cc_library {
1904 name: "libvndk2",
1905 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001906 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001907 vndk: {
1908 enabled: true,
1909 },
1910 shared_libs: ["libvndk_ext"],
1911 nocrt: true,
1912 }
1913 `)
1914
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001915 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001916 cc_library {
1917 name: "libvndk",
1918 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001919 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001920 vndk: {
1921 enabled: true,
1922 },
1923 nocrt: true,
1924 }
1925
1926 cc_library {
1927 name: "libvndk_ext",
1928 vendor: true,
1929 vndk: {
1930 enabled: true,
1931 extends: "libvndk",
1932 },
1933 nocrt: true,
1934 }
1935
1936 cc_library {
1937 name: "libvndk2",
1938 vendor_available: true,
1939 vndk: {
1940 enabled: true,
1941 },
1942 target: {
1943 vendor: {
1944 shared_libs: ["libvndk_ext"],
1945 },
1946 },
1947 nocrt: true,
1948 }
1949 `)
1950
1951 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1952 cc_library {
1953 name: "libvndk_sp",
1954 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001955 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001956 vndk: {
1957 enabled: true,
1958 support_system_process: true,
1959 },
1960 nocrt: true,
1961 }
1962
1963 cc_library {
1964 name: "libvndk_sp_ext",
1965 vendor: true,
1966 vndk: {
1967 enabled: true,
1968 extends: "libvndk_sp",
1969 support_system_process: true,
1970 },
1971 nocrt: true,
1972 }
1973
1974 cc_library {
1975 name: "libvndk_sp_2",
1976 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001977 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001978 vndk: {
1979 enabled: true,
1980 support_system_process: true,
1981 },
1982 shared_libs: ["libvndk_sp_ext"],
1983 nocrt: true,
1984 }
1985 `)
1986
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001987 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001988 cc_library {
1989 name: "libvndk_sp",
1990 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001991 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001992 vndk: {
1993 enabled: true,
1994 },
1995 nocrt: true,
1996 }
1997
1998 cc_library {
1999 name: "libvndk_sp_ext",
2000 vendor: true,
2001 vndk: {
2002 enabled: true,
2003 extends: "libvndk_sp",
2004 },
2005 nocrt: true,
2006 }
2007
2008 cc_library {
2009 name: "libvndk_sp2",
2010 vendor_available: true,
2011 vndk: {
2012 enabled: true,
2013 },
2014 target: {
2015 vendor: {
2016 shared_libs: ["libvndk_sp_ext"],
2017 },
2018 },
2019 nocrt: true,
2020 }
2021 `)
2022}
2023
Justin Yun5f7f7e82019-11-18 19:52:14 +09002024func TestEnforceProductVndkVersion(t *testing.T) {
2025 bp := `
2026 cc_library {
2027 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002028 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002029 }
2030 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002031 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002032 symbol_file: "",
2033 }
2034 cc_library {
2035 name: "libvndk",
2036 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002037 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002038 vndk: {
2039 enabled: true,
2040 },
2041 nocrt: true,
2042 }
2043 cc_library {
2044 name: "libvndk_sp",
2045 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002046 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002047 vndk: {
2048 enabled: true,
2049 support_system_process: true,
2050 },
2051 nocrt: true,
2052 }
2053 cc_library {
2054 name: "libva",
2055 vendor_available: true,
2056 nocrt: true,
2057 }
2058 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002059 name: "libpa",
2060 product_available: true,
2061 nocrt: true,
2062 }
2063 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002064 name: "libboth_available",
2065 vendor_available: true,
2066 product_available: true,
2067 nocrt: true,
2068 target: {
2069 vendor: {
2070 suffix: "-vendor",
2071 },
2072 product: {
2073 suffix: "-product",
2074 },
2075 }
2076 }
2077 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002078 name: "libproduct_va",
2079 product_specific: true,
2080 vendor_available: true,
2081 nocrt: true,
2082 }
2083 cc_library {
2084 name: "libprod",
2085 product_specific: true,
2086 shared_libs: [
2087 "libllndk",
2088 "libvndk",
2089 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002090 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002091 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002092 "libproduct_va",
2093 ],
2094 nocrt: true,
2095 }
2096 cc_library {
2097 name: "libvendor",
2098 vendor: true,
2099 shared_libs: [
2100 "libllndk",
2101 "libvndk",
2102 "libvndk_sp",
2103 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002104 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002105 "libproduct_va",
2106 ],
2107 nocrt: true,
2108 }
2109 `
2110
2111 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2112 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2113 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2114 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2115
2116 ctx := testCcWithConfig(t, config)
2117
Jooyung Han261e1582020-10-20 18:54:21 +09002118 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2119 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002120
2121 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2122 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2123
2124 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2125 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002126}
2127
2128func TestEnforceProductVndkVersionErrors(t *testing.T) {
2129 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2130 cc_library {
2131 name: "libprod",
2132 product_specific: true,
2133 shared_libs: [
2134 "libvendor",
2135 ],
2136 nocrt: true,
2137 }
2138 cc_library {
2139 name: "libvendor",
2140 vendor: true,
2141 nocrt: true,
2142 }
2143 `)
2144 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2145 cc_library {
2146 name: "libprod",
2147 product_specific: true,
2148 shared_libs: [
2149 "libsystem",
2150 ],
2151 nocrt: true,
2152 }
2153 cc_library {
2154 name: "libsystem",
2155 nocrt: true,
2156 }
2157 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002158 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2159 cc_library {
2160 name: "libprod",
2161 product_specific: true,
2162 shared_libs: [
2163 "libva",
2164 ],
2165 nocrt: true,
2166 }
2167 cc_library {
2168 name: "libva",
2169 vendor_available: true,
2170 nocrt: true,
2171 }
2172 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002173 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002174 cc_library {
2175 name: "libprod",
2176 product_specific: true,
2177 shared_libs: [
2178 "libvndk_private",
2179 ],
2180 nocrt: true,
2181 }
2182 cc_library {
2183 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002184 vendor_available: true,
2185 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002186 vndk: {
2187 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002188 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002189 },
2190 nocrt: true,
2191 }
2192 `)
2193 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2194 cc_library {
2195 name: "libprod",
2196 product_specific: true,
2197 shared_libs: [
2198 "libsystem_ext",
2199 ],
2200 nocrt: true,
2201 }
2202 cc_library {
2203 name: "libsystem_ext",
2204 system_ext_specific: true,
2205 nocrt: true,
2206 }
2207 `)
2208 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2209 cc_library {
2210 name: "libsystem",
2211 shared_libs: [
2212 "libproduct_va",
2213 ],
2214 nocrt: true,
2215 }
2216 cc_library {
2217 name: "libproduct_va",
2218 product_specific: true,
2219 vendor_available: true,
2220 nocrt: true,
2221 }
2222 `)
2223}
2224
Jooyung Han38002912019-05-16 04:01:54 +09002225func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002226 bp := `
2227 cc_library {
2228 name: "libvndk",
2229 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002230 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002231 vndk: {
2232 enabled: true,
2233 },
2234 }
2235 cc_library {
2236 name: "libvndksp",
2237 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002238 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002239 vndk: {
2240 enabled: true,
2241 support_system_process: true,
2242 },
2243 }
2244 cc_library {
2245 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002246 vendor_available: true,
2247 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002248 vndk: {
2249 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002250 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002251 },
2252 }
2253 cc_library {
2254 name: "libvendor",
2255 vendor: true,
2256 }
2257 cc_library {
2258 name: "libvndkext",
2259 vendor: true,
2260 vndk: {
2261 enabled: true,
2262 extends: "libvndk",
2263 },
2264 }
2265 vndk_prebuilt_shared {
2266 name: "prevndk",
2267 version: "27",
2268 target_arch: "arm",
2269 binder32bit: true,
2270 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002271 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002272 vndk: {
2273 enabled: true,
2274 },
2275 arch: {
2276 arm: {
2277 srcs: ["liba.so"],
2278 },
2279 },
2280 }
2281 cc_library {
2282 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002283 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002284 }
2285 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002286 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002287 symbol_file: "",
2288 }
2289 cc_library {
2290 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002291 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002292 }
2293 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002294 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002295 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002296 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002297 }
2298
2299 llndk_libraries_txt {
2300 name: "llndk.libraries.txt",
2301 }
2302 vndkcore_libraries_txt {
2303 name: "vndkcore.libraries.txt",
2304 }
2305 vndksp_libraries_txt {
2306 name: "vndksp.libraries.txt",
2307 }
2308 vndkprivate_libraries_txt {
2309 name: "vndkprivate.libraries.txt",
2310 }
2311 vndkcorevariant_libraries_txt {
2312 name: "vndkcorevariant.libraries.txt",
2313 insert_vndk_version: false,
2314 }
2315 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002316
2317 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002318 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2319 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2320 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002321 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002322
Colin Cross78212242021-01-06 14:51:30 -08002323 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2324 []string{"libvndk.so", "libvndkprivate.so"})
2325 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2326 []string{"libc++.so", "libvndksp.so"})
2327 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2328 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2329 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2330 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002331
Colin Crossfb0c16e2019-11-20 17:12:35 -08002332 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002333
Jooyung Han38002912019-05-16 04:01:54 +09002334 tests := []struct {
2335 variant string
2336 name string
2337 expected string
2338 }{
2339 {vendorVariant, "libvndk", "native:vndk"},
2340 {vendorVariant, "libvndksp", "native:vndk"},
2341 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2342 {vendorVariant, "libvendor", "native:vendor"},
2343 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002344 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002345 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002346 {coreVariant, "libvndk", "native:platform"},
2347 {coreVariant, "libvndkprivate", "native:platform"},
2348 {coreVariant, "libllndk", "native:platform"},
2349 }
2350 for _, test := range tests {
2351 t.Run(test.name, func(t *testing.T) {
2352 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2353 assertString(t, module.makeLinkType, test.expected)
2354 })
2355 }
2356}
2357
Jeff Gaston294356f2017-09-27 17:05:30 -07002358var staticLinkDepOrderTestCases = []struct {
2359 // This is a string representation of a map[moduleName][]moduleDependency .
2360 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002361 inStatic string
2362
2363 // This is a string representation of a map[moduleName][]moduleDependency .
2364 // It models the dependencies declared in an Android.bp file.
2365 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002366
2367 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2368 // The keys of allOrdered specify which modules we would like to check.
2369 // The values of allOrdered specify the expected result (of the transitive closure of all
2370 // dependencies) for each module to test
2371 allOrdered string
2372
2373 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2374 // The keys of outOrdered specify which modules we would like to check.
2375 // The values of outOrdered specify the expected result (of the ordered linker command line)
2376 // for each module to test.
2377 outOrdered string
2378}{
2379 // Simple tests
2380 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002381 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002382 outOrdered: "",
2383 },
2384 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002385 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002386 outOrdered: "a:",
2387 },
2388 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002389 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002390 outOrdered: "a:b; b:",
2391 },
2392 // Tests of reordering
2393 {
2394 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002395 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002396 outOrdered: "a:b,c,d; b:d; c:d; d:",
2397 },
2398 {
2399 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002400 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002401 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2402 },
2403 {
2404 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002405 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002406 outOrdered: "a:d,b,e,c; d:b; e:c",
2407 },
2408 {
2409 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002410 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002411 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2412 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2413 },
2414 {
2415 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002416 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 -07002417 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2418 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2419 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002420 // shared dependencies
2421 {
2422 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2423 // So, we don't actually have to check that a shared dependency of c will change the order
2424 // of a library that depends statically on b and on c. We only need to check that if c has
2425 // a shared dependency on b, that that shows up in allOrdered.
2426 inShared: "c:b",
2427 allOrdered: "c:b",
2428 outOrdered: "c:",
2429 },
2430 {
2431 // This test doesn't actually include any shared dependencies but it's a reminder of what
2432 // the second phase of the above test would look like
2433 inStatic: "a:b,c; c:b",
2434 allOrdered: "a:c,b; c:b",
2435 outOrdered: "a:c,b; c:b",
2436 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002437 // tiebreakers for when two modules specifying different orderings and there is no dependency
2438 // to dictate an order
2439 {
2440 // 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 -08002441 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002442 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2443 },
2444 {
2445 // 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 -08002446 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 -07002447 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2448 },
2449 // Tests involving duplicate dependencies
2450 {
2451 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002452 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002453 outOrdered: "a:c,b",
2454 },
2455 {
2456 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002457 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002458 outOrdered: "a:d,c,b",
2459 },
2460 // Tests to confirm the nonexistence of infinite loops.
2461 // These cases should never happen, so as long as the test terminates and the
2462 // result is deterministic then that should be fine.
2463 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002464 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002465 outOrdered: "a:a",
2466 },
2467 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002468 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002469 allOrdered: "a:b,c; b:c,a; c:a,b",
2470 outOrdered: "a:b; b:c; c:a",
2471 },
2472 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002473 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002474 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2475 outOrdered: "a:c,b; b:a,c; c:b,a",
2476 },
2477}
2478
2479// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2480func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2481 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2482 strippedText := strings.Replace(text, " ", "", -1)
2483 if len(strippedText) < 1 {
2484 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2485 }
2486 allDeps = make(map[android.Path][]android.Path, 0)
2487
2488 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2489 moduleTexts := strings.Split(strippedText, ";")
2490
2491 outputForModuleName := func(moduleName string) android.Path {
2492 return android.PathForTesting(moduleName)
2493 }
2494
2495 for _, moduleText := range moduleTexts {
2496 // convert from "a:b,c" to ["a", "b,c"]
2497 components := strings.Split(moduleText, ":")
2498 if len(components) != 2 {
2499 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2500 }
2501 moduleName := components[0]
2502 moduleOutput := outputForModuleName(moduleName)
2503 modulesInOrder = append(modulesInOrder, moduleOutput)
2504
2505 depString := components[1]
2506 // convert from "b,c" to ["b", "c"]
2507 depNames := strings.Split(depString, ",")
2508 if len(depString) < 1 {
2509 depNames = []string{}
2510 }
2511 var deps []android.Path
2512 for _, depName := range depNames {
2513 deps = append(deps, outputForModuleName(depName))
2514 }
2515 allDeps[moduleOutput] = deps
2516 }
2517 return modulesInOrder, allDeps
2518}
2519
Jeff Gaston294356f2017-09-27 17:05:30 -07002520func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2521 for _, moduleName := range moduleNames {
2522 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2523 output := module.outputFile.Path()
2524 paths = append(paths, output)
2525 }
2526 return paths
2527}
2528
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002529func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002530 ctx := testCc(t, `
2531 cc_library {
2532 name: "a",
2533 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002534 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002535 }
2536 cc_library {
2537 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002538 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002539 }
2540 cc_library {
2541 name: "c",
2542 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002543 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002544 }
2545 cc_library {
2546 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002547 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002548 }
2549
2550 `)
2551
Colin Cross7113d202019-11-20 16:39:12 -08002552 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002553 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002554 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2555 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002556
2557 if !reflect.DeepEqual(actual, expected) {
2558 t.Errorf("staticDeps orderings were not propagated correctly"+
2559 "\nactual: %v"+
2560 "\nexpected: %v",
2561 actual,
2562 expected,
2563 )
2564 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002565}
Jeff Gaston294356f2017-09-27 17:05:30 -07002566
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002567func TestStaticLibDepReorderingWithShared(t *testing.T) {
2568 ctx := testCc(t, `
2569 cc_library {
2570 name: "a",
2571 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002572 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002573 }
2574 cc_library {
2575 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002576 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002577 }
2578 cc_library {
2579 name: "c",
2580 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002581 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002582 }
2583
2584 `)
2585
Colin Cross7113d202019-11-20 16:39:12 -08002586 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002587 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002588 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2589 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002590
2591 if !reflect.DeepEqual(actual, expected) {
2592 t.Errorf("staticDeps orderings did not account for shared libs"+
2593 "\nactual: %v"+
2594 "\nexpected: %v",
2595 actual,
2596 expected,
2597 )
2598 }
2599}
2600
Jooyung Hanb04a4992020-03-13 18:57:35 +09002601func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002602 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002603 if !reflect.DeepEqual(actual, expected) {
2604 t.Errorf(message+
2605 "\nactual: %v"+
2606 "\nexpected: %v",
2607 actual,
2608 expected,
2609 )
2610 }
2611}
2612
Jooyung Han61b66e92020-03-21 14:21:46 +00002613func TestLlndkLibrary(t *testing.T) {
2614 ctx := testCc(t, `
2615 cc_library {
2616 name: "libllndk",
2617 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002618 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002619 }
2620 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002621 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002622 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002623
2624 cc_prebuilt_library_shared {
2625 name: "libllndkprebuilt",
2626 stubs: { versions: ["1", "2"] },
2627 llndk_stubs: "libllndkprebuilt.llndk",
2628 }
2629 llndk_library {
2630 name: "libllndkprebuilt.llndk",
2631 }
2632
2633 cc_library {
2634 name: "libllndk_with_external_headers",
2635 stubs: { versions: ["1", "2"] },
2636 llndk_stubs: "libllndk_with_external_headers.llndk",
2637 header_libs: ["libexternal_headers"],
2638 export_header_lib_headers: ["libexternal_headers"],
2639 }
2640 llndk_library {
2641 name: "libllndk_with_external_headers.llndk",
2642 }
2643 cc_library_headers {
2644 name: "libexternal_headers",
2645 export_include_dirs: ["include"],
2646 vendor_available: true,
2647 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002648 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002649 actual := ctx.ModuleVariantsForTests("libllndk")
2650 for i := 0; i < len(actual); i++ {
2651 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
2652 actual = append(actual[:i], actual[i+1:]...)
2653 i--
2654 }
2655 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002656 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00002657 "android_vendor.VER_arm64_armv8-a_shared_1",
2658 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002659 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002660 "android_vendor.VER_arm_armv7-a-neon_shared_1",
2661 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002662 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002663 }
2664 checkEquals(t, "variants for llndk stubs", expected, actual)
2665
Colin Cross127bb8b2020-12-16 16:46:01 -08002666 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002667 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2668
Colin Cross127bb8b2020-12-16 16:46:01 -08002669 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002670 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2671}
2672
Jiyong Parka46a4d52017-12-14 19:54:34 +09002673func TestLlndkHeaders(t *testing.T) {
2674 ctx := testCc(t, `
2675 llndk_headers {
2676 name: "libllndk_headers",
2677 export_include_dirs: ["my_include"],
2678 }
2679 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002680 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002681 export_llndk_headers: ["libllndk_headers"],
2682 }
2683 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002684 name: "libllndk",
2685 llndk_stubs: "libllndk.llndk",
2686 }
2687
2688 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002689 name: "libvendor",
2690 shared_libs: ["libllndk"],
2691 vendor: true,
2692 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002693 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002694 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002695 }
2696 `)
2697
2698 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002699 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002700 cflags := cc.Args["cFlags"]
2701 if !strings.Contains(cflags, "-Imy_include") {
2702 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2703 }
2704}
2705
Logan Chien43d34c32017-12-20 01:17:32 +08002706func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2707 actual := module.Properties.AndroidMkRuntimeLibs
2708 if !reflect.DeepEqual(actual, expected) {
2709 t.Errorf("incorrect runtime_libs for shared libs"+
2710 "\nactual: %v"+
2711 "\nexpected: %v",
2712 actual,
2713 expected,
2714 )
2715 }
2716}
2717
2718const runtimeLibAndroidBp = `
2719 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002720 name: "liball_available",
2721 vendor_available: true,
2722 product_available: true,
2723 no_libcrt : true,
2724 nocrt : true,
2725 system_shared_libs : [],
2726 }
2727 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002728 name: "libvendor_available1",
2729 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002730 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002731 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002732 nocrt : true,
2733 system_shared_libs : [],
2734 }
2735 cc_library {
2736 name: "libvendor_available2",
2737 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002738 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002739 target: {
2740 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002741 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002742 }
2743 },
Yi Konge7fe9912019-06-02 00:53:50 -07002744 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002745 nocrt : true,
2746 system_shared_libs : [],
2747 }
2748 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002749 name: "libproduct_vendor",
2750 product_specific: true,
2751 vendor_available: true,
2752 no_libcrt : true,
2753 nocrt : true,
2754 system_shared_libs : [],
2755 }
2756 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002757 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002758 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002759 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002760 nocrt : true,
2761 system_shared_libs : [],
2762 }
2763 cc_library {
2764 name: "libvendor1",
2765 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002766 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002767 nocrt : true,
2768 system_shared_libs : [],
2769 }
2770 cc_library {
2771 name: "libvendor2",
2772 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002773 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002774 no_libcrt : true,
2775 nocrt : true,
2776 system_shared_libs : [],
2777 }
2778 cc_library {
2779 name: "libproduct_available1",
2780 product_available: true,
2781 runtime_libs: ["liball_available"],
2782 no_libcrt : true,
2783 nocrt : true,
2784 system_shared_libs : [],
2785 }
2786 cc_library {
2787 name: "libproduct1",
2788 product_specific: true,
2789 no_libcrt : true,
2790 nocrt : true,
2791 system_shared_libs : [],
2792 }
2793 cc_library {
2794 name: "libproduct2",
2795 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002796 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002797 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002798 nocrt : true,
2799 system_shared_libs : [],
2800 }
2801`
2802
2803func TestRuntimeLibs(t *testing.T) {
2804 ctx := testCc(t, runtimeLibAndroidBp)
2805
2806 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002807 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002808
Justin Yun8a2600c2020-12-07 12:44:03 +09002809 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2810 checkRuntimeLibs(t, []string{"liball_available"}, module)
2811
2812 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2813 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002814
2815 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002816 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002817
2818 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2819 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002820 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002821
Justin Yun8a2600c2020-12-07 12:44:03 +09002822 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2823 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002824
2825 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002826 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002827
2828 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2829 // and product variants.
2830 variant = "android_product.VER_arm64_armv8-a_shared"
2831
2832 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2833 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2834
2835 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002836 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002837}
2838
2839func TestExcludeRuntimeLibs(t *testing.T) {
2840 ctx := testCc(t, runtimeLibAndroidBp)
2841
Colin Cross7113d202019-11-20 16:39:12 -08002842 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002843 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2844 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002845
Colin Crossfb0c16e2019-11-20 17:12:35 -08002846 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002847 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002848 checkRuntimeLibs(t, nil, module)
2849}
2850
2851func TestRuntimeLibsNoVndk(t *testing.T) {
2852 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2853
2854 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2855
Colin Cross7113d202019-11-20 16:39:12 -08002856 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002857
Justin Yun8a2600c2020-12-07 12:44:03 +09002858 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2859 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002860
2861 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002862 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002863
2864 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002865 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002866}
2867
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002868func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002869 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002870 actual := module.Properties.AndroidMkStaticLibs
2871 if !reflect.DeepEqual(actual, expected) {
2872 t.Errorf("incorrect static_libs"+
2873 "\nactual: %v"+
2874 "\nexpected: %v",
2875 actual,
2876 expected,
2877 )
2878 }
2879}
2880
2881const staticLibAndroidBp = `
2882 cc_library {
2883 name: "lib1",
2884 }
2885 cc_library {
2886 name: "lib2",
2887 static_libs: ["lib1"],
2888 }
2889`
2890
2891func TestStaticLibDepExport(t *testing.T) {
2892 ctx := testCc(t, staticLibAndroidBp)
2893
2894 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002895 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002896 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002897 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002898
2899 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002900 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002901 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2902 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002903 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002904}
2905
Jiyong Parkd08b6972017-09-26 10:50:54 +09002906var compilerFlagsTestCases = []struct {
2907 in string
2908 out bool
2909}{
2910 {
2911 in: "a",
2912 out: false,
2913 },
2914 {
2915 in: "-a",
2916 out: true,
2917 },
2918 {
2919 in: "-Ipath/to/something",
2920 out: false,
2921 },
2922 {
2923 in: "-isystempath/to/something",
2924 out: false,
2925 },
2926 {
2927 in: "--coverage",
2928 out: false,
2929 },
2930 {
2931 in: "-include a/b",
2932 out: true,
2933 },
2934 {
2935 in: "-include a/b c/d",
2936 out: false,
2937 },
2938 {
2939 in: "-DMACRO",
2940 out: true,
2941 },
2942 {
2943 in: "-DMAC RO",
2944 out: false,
2945 },
2946 {
2947 in: "-a -b",
2948 out: false,
2949 },
2950 {
2951 in: "-DMACRO=definition",
2952 out: true,
2953 },
2954 {
2955 in: "-DMACRO=defi nition",
2956 out: true, // TODO(jiyong): this should be false
2957 },
2958 {
2959 in: "-DMACRO(x)=x + 1",
2960 out: true,
2961 },
2962 {
2963 in: "-DMACRO=\"defi nition\"",
2964 out: true,
2965 },
2966}
2967
2968type mockContext struct {
2969 BaseModuleContext
2970 result bool
2971}
2972
2973func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2974 // CheckBadCompilerFlags calls this function when the flag should be rejected
2975 ctx.result = false
2976}
2977
2978func TestCompilerFlags(t *testing.T) {
2979 for _, testCase := range compilerFlagsTestCases {
2980 ctx := &mockContext{result: true}
2981 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2982 if ctx.result != testCase.out {
2983 t.Errorf("incorrect output:")
2984 t.Errorf(" input: %#v", testCase.in)
2985 t.Errorf(" expected: %#v", testCase.out)
2986 t.Errorf(" got: %#v", ctx.result)
2987 }
2988 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002989}
Jiyong Park374510b2018-03-19 18:23:01 +09002990
2991func TestVendorPublicLibraries(t *testing.T) {
2992 ctx := testCc(t, `
2993 cc_library_headers {
2994 name: "libvendorpublic_headers",
2995 export_include_dirs: ["my_include"],
2996 }
2997 vendor_public_library {
2998 name: "libvendorpublic",
2999 symbol_file: "",
3000 export_public_headers: ["libvendorpublic_headers"],
3001 }
3002 cc_library {
3003 name: "libvendorpublic",
3004 srcs: ["foo.c"],
3005 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003006 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003007 nocrt: true,
3008 }
3009
3010 cc_library {
3011 name: "libsystem",
3012 shared_libs: ["libvendorpublic"],
3013 vendor: false,
3014 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003015 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003016 nocrt: true,
3017 }
3018 cc_library {
3019 name: "libvendor",
3020 shared_libs: ["libvendorpublic"],
3021 vendor: true,
3022 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003023 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003024 nocrt: true,
3025 }
3026 `)
3027
Colin Cross7113d202019-11-20 16:39:12 -08003028 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003029 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003030
3031 // test if header search paths are correctly added
3032 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003033 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003034 cflags := cc.Args["cFlags"]
3035 if !strings.Contains(cflags, "-Imy_include") {
3036 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3037 }
3038
3039 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003040 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003041 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003042 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003043 if !strings.Contains(libflags, stubPaths[0].String()) {
3044 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3045 }
3046
3047 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003048 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003049 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003050 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003051 if !strings.Contains(libflags, stubPaths[0].String()) {
3052 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3053 }
3054
3055}
Jiyong Park37b25202018-07-11 10:49:27 +09003056
3057func TestRecovery(t *testing.T) {
3058 ctx := testCc(t, `
3059 cc_library_shared {
3060 name: "librecovery",
3061 recovery: true,
3062 }
3063 cc_library_shared {
3064 name: "librecovery32",
3065 recovery: true,
3066 compile_multilib:"32",
3067 }
Jiyong Park5baac542018-08-28 09:55:37 +09003068 cc_library_shared {
3069 name: "libHalInRecovery",
3070 recovery_available: true,
3071 vendor: true,
3072 }
Jiyong Park37b25202018-07-11 10:49:27 +09003073 `)
3074
3075 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003076 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003077 if len(variants) != 1 || !android.InList(arm64, variants) {
3078 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3079 }
3080
3081 variants = ctx.ModuleVariantsForTests("librecovery32")
3082 if android.InList(arm64, variants) {
3083 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3084 }
Jiyong Park5baac542018-08-28 09:55:37 +09003085
3086 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3087 if !recoveryModule.Platform() {
3088 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3089 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003090}
Jiyong Park5baac542018-08-28 09:55:37 +09003091
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003092func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3093 bp := `
3094 cc_prebuilt_test_library_shared {
3095 name: "test_lib",
3096 relative_install_path: "foo/bar/baz",
3097 srcs: ["srcpath/dontusethispath/baz.so"],
3098 }
3099
3100 cc_test {
3101 name: "main_test",
3102 data_libs: ["test_lib"],
3103 gtest: false,
3104 }
3105 `
3106
3107 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3108 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3109 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3110 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3111
3112 ctx := testCcWithConfig(t, config)
3113 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3114 testBinary := module.(*Module).linker.(*testBinary)
3115 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3116 if err != nil {
3117 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3118 }
3119 if len(outputFiles) != 1 {
3120 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3121 }
3122 if len(testBinary.dataPaths()) != 1 {
3123 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3124 }
3125
3126 outputPath := outputFiles[0].String()
3127
3128 if !strings.HasSuffix(outputPath, "/main_test") {
3129 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3130 }
Colin Crossaa255532020-07-03 13:18:24 -07003131 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003132 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3133 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3134 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3135 }
3136}
3137
Jiyong Park7ed9de32018-10-15 22:25:07 +09003138func TestVersionedStubs(t *testing.T) {
3139 ctx := testCc(t, `
3140 cc_library_shared {
3141 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003142 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003143 stubs: {
3144 symbol_file: "foo.map.txt",
3145 versions: ["1", "2", "3"],
3146 },
3147 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003148
Jiyong Park7ed9de32018-10-15 22:25:07 +09003149 cc_library_shared {
3150 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003151 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003152 shared_libs: ["libFoo#1"],
3153 }`)
3154
3155 variants := ctx.ModuleVariantsForTests("libFoo")
3156 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003157 "android_arm64_armv8-a_shared",
3158 "android_arm64_armv8-a_shared_1",
3159 "android_arm64_armv8-a_shared_2",
3160 "android_arm64_armv8-a_shared_3",
3161 "android_arm_armv7-a-neon_shared",
3162 "android_arm_armv7-a-neon_shared_1",
3163 "android_arm_armv7-a-neon_shared_2",
3164 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003165 }
3166 variantsMismatch := false
3167 if len(variants) != len(expectedVariants) {
3168 variantsMismatch = true
3169 } else {
3170 for _, v := range expectedVariants {
3171 if !inList(v, variants) {
3172 variantsMismatch = false
3173 }
3174 }
3175 }
3176 if variantsMismatch {
3177 t.Errorf("variants of libFoo expected:\n")
3178 for _, v := range expectedVariants {
3179 t.Errorf("%q\n", v)
3180 }
3181 t.Errorf(", but got:\n")
3182 for _, v := range variants {
3183 t.Errorf("%q\n", v)
3184 }
3185 }
3186
Colin Cross7113d202019-11-20 16:39:12 -08003187 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003188 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003189 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003190 if !strings.Contains(libFlags, libFoo1StubPath) {
3191 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3192 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003193
Colin Cross7113d202019-11-20 16:39:12 -08003194 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003195 cFlags := libBarCompileRule.Args["cFlags"]
3196 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3197 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3198 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3199 }
Jiyong Park37b25202018-07-11 10:49:27 +09003200}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003201
Jooyung Hanb04a4992020-03-13 18:57:35 +09003202func TestVersioningMacro(t *testing.T) {
3203 for _, tc := range []struct{ moduleName, expected string }{
3204 {"libc", "__LIBC_API__"},
3205 {"libfoo", "__LIBFOO_API__"},
3206 {"libfoo@1", "__LIBFOO_1_API__"},
3207 {"libfoo-v1", "__LIBFOO_V1_API__"},
3208 {"libfoo.v1", "__LIBFOO_V1_API__"},
3209 } {
3210 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3211 }
3212}
3213
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003214func TestStaticExecutable(t *testing.T) {
3215 ctx := testCc(t, `
3216 cc_binary {
3217 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003218 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003219 static_executable: true,
3220 }`)
3221
Colin Cross7113d202019-11-20 16:39:12 -08003222 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003223 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3224 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003225 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003226 for _, lib := range systemStaticLibs {
3227 if !strings.Contains(libFlags, lib) {
3228 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3229 }
3230 }
3231 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3232 for _, lib := range systemSharedLibs {
3233 if strings.Contains(libFlags, lib) {
3234 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3235 }
3236 }
3237}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003238
3239func TestStaticDepsOrderWithStubs(t *testing.T) {
3240 ctx := testCc(t, `
3241 cc_binary {
3242 name: "mybin",
3243 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003244 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003245 static_executable: true,
3246 stl: "none",
3247 }
3248
3249 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003250 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003251 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003252 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003253 stl: "none",
3254 }
3255
3256 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003257 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003258 srcs: ["foo.c"],
3259 stl: "none",
3260 stubs: {
3261 versions: ["1"],
3262 },
3263 }`)
3264
Colin Cross0de8a1e2020-09-18 14:15:30 -07003265 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3266 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003267 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003268
3269 if !reflect.DeepEqual(actual, expected) {
3270 t.Errorf("staticDeps orderings were not propagated correctly"+
3271 "\nactual: %v"+
3272 "\nexpected: %v",
3273 actual,
3274 expected,
3275 )
3276 }
3277}
Jooyung Han38002912019-05-16 04:01:54 +09003278
Jooyung Hand48f3c32019-08-23 11:18:57 +09003279func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3280 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3281 cc_library {
3282 name: "libA",
3283 srcs: ["foo.c"],
3284 shared_libs: ["libB"],
3285 stl: "none",
3286 }
3287
3288 cc_library {
3289 name: "libB",
3290 srcs: ["foo.c"],
3291 enabled: false,
3292 stl: "none",
3293 }
3294 `)
3295}
3296
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003297// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3298// correctly.
3299func TestFuzzTarget(t *testing.T) {
3300 ctx := testCc(t, `
3301 cc_fuzz {
3302 name: "fuzz_smoke_test",
3303 srcs: ["foo.c"],
3304 }`)
3305
Paul Duffin075c4172019-12-19 19:06:13 +00003306 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003307 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3308}
3309
Jiyong Park29074592019-07-07 16:27:47 +09003310func TestAidl(t *testing.T) {
3311}
3312
Jooyung Han38002912019-05-16 04:01:54 +09003313func assertString(t *testing.T, got, expected string) {
3314 t.Helper()
3315 if got != expected {
3316 t.Errorf("expected %q got %q", expected, got)
3317 }
3318}
3319
3320func assertArrayString(t *testing.T, got, expected []string) {
3321 t.Helper()
3322 if len(got) != len(expected) {
3323 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3324 return
3325 }
3326 for i := range got {
3327 if got[i] != expected[i] {
3328 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3329 i, expected[i], expected, got[i], got)
3330 return
3331 }
3332 }
3333}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003334
Jooyung Han0302a842019-10-30 18:43:49 +09003335func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3336 t.Helper()
3337 assertArrayString(t, android.SortedStringKeys(m), expected)
3338}
3339
Colin Crosse1bb5d02019-09-24 14:55:04 -07003340func TestDefaults(t *testing.T) {
3341 ctx := testCc(t, `
3342 cc_defaults {
3343 name: "defaults",
3344 srcs: ["foo.c"],
3345 static: {
3346 srcs: ["bar.c"],
3347 },
3348 shared: {
3349 srcs: ["baz.c"],
3350 },
3351 }
3352
3353 cc_library_static {
3354 name: "libstatic",
3355 defaults: ["defaults"],
3356 }
3357
3358 cc_library_shared {
3359 name: "libshared",
3360 defaults: ["defaults"],
3361 }
3362
3363 cc_library {
3364 name: "libboth",
3365 defaults: ["defaults"],
3366 }
3367
3368 cc_binary {
3369 name: "binary",
3370 defaults: ["defaults"],
3371 }`)
3372
3373 pathsToBase := func(paths android.Paths) []string {
3374 var ret []string
3375 for _, p := range paths {
3376 ret = append(ret, p.Base())
3377 }
3378 return ret
3379 }
3380
Colin Cross7113d202019-11-20 16:39:12 -08003381 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003382 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3383 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3384 }
Colin Cross7113d202019-11-20 16:39:12 -08003385 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003386 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3387 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3388 }
Colin Cross7113d202019-11-20 16:39:12 -08003389 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003390 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3391 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3392 }
3393
Colin Cross7113d202019-11-20 16:39:12 -08003394 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003395 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3396 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3397 }
Colin Cross7113d202019-11-20 16:39:12 -08003398 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003399 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3400 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3401 }
3402}
Colin Crosseabaedd2020-02-06 17:01:55 -08003403
3404func TestProductVariableDefaults(t *testing.T) {
3405 bp := `
3406 cc_defaults {
3407 name: "libfoo_defaults",
3408 srcs: ["foo.c"],
3409 cppflags: ["-DFOO"],
3410 product_variables: {
3411 debuggable: {
3412 cppflags: ["-DBAR"],
3413 },
3414 },
3415 }
3416
3417 cc_library {
3418 name: "libfoo",
3419 defaults: ["libfoo_defaults"],
3420 }
3421 `
3422
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003423 result := ccFixtureFactory.Extend(
3424 android.PrepareForTestWithVariables,
Colin Crosseabaedd2020-02-06 17:01:55 -08003425
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003426 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3427 variables.Debuggable = BoolPtr(true)
3428 }),
3429 ).RunTestWithBp(t, bp)
Colin Crosseabaedd2020-02-06 17:01:55 -08003430
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003431 libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
Paul Duffine84b1332021-03-12 11:59:43 +00003432 android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
Colin Crosseabaedd2020-02-06 17:01:55 -08003433}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003434
3435func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3436 t.Parallel()
3437 bp := `
3438 cc_library_static {
3439 name: "libfoo",
3440 srcs: ["foo.c"],
3441 whole_static_libs: ["libbar"],
3442 }
3443
3444 cc_library_static {
3445 name: "libbar",
3446 whole_static_libs: ["libmissing"],
3447 }
3448 `
3449
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003450 result := ccFixtureFactory.Extend(
3451 android.PrepareForTestWithAllowMissingDependencies,
3452 ).RunTestWithBp(t, bp)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003453
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003454 libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003455 android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003456
Paul Duffine84b1332021-03-12 11:59:43 +00003457 android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
Colin Crosse4f6eba2020-09-22 18:11:25 -07003458
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003459 libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003460 android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
Colin Crosse4f6eba2020-09-22 18:11:25 -07003461}
Colin Crosse9fe2942020-11-10 18:12:15 -08003462
3463func TestInstallSharedLibs(t *testing.T) {
3464 bp := `
3465 cc_binary {
3466 name: "bin",
3467 host_supported: true,
3468 shared_libs: ["libshared"],
3469 runtime_libs: ["libruntime"],
3470 srcs: [":gen"],
3471 }
3472
3473 cc_library_shared {
3474 name: "libshared",
3475 host_supported: true,
3476 shared_libs: ["libtransitive"],
3477 }
3478
3479 cc_library_shared {
3480 name: "libtransitive",
3481 host_supported: true,
3482 }
3483
3484 cc_library_shared {
3485 name: "libruntime",
3486 host_supported: true,
3487 }
3488
3489 cc_binary_host {
3490 name: "tool",
3491 srcs: ["foo.cpp"],
3492 }
3493
3494 genrule {
3495 name: "gen",
3496 tools: ["tool"],
3497 out: ["gen.cpp"],
3498 cmd: "$(location tool) $(out)",
3499 }
3500 `
3501
3502 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3503 ctx := testCcWithConfig(t, config)
3504
3505 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3506 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3507 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3508 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3509 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3510
3511 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3512 t.Errorf("expected host bin dependency %q, got %q", w, g)
3513 }
3514
3515 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3516 t.Errorf("expected host bin dependency %q, got %q", w, g)
3517 }
3518
3519 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3520 t.Errorf("expected host bin dependency %q, got %q", w, g)
3521 }
3522
3523 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3524 t.Errorf("expected host bin dependency %q, got %q", w, g)
3525 }
3526
3527 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3528 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3529 }
3530
3531 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3532 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3533 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3534 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3535
3536 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3537 t.Errorf("expected device bin dependency %q, got %q", w, g)
3538 }
3539
3540 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3541 t.Errorf("expected device bin dependency %q, got %q", w, g)
3542 }
3543
3544 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3545 t.Errorf("expected device bin dependency %q, got %q", w, g)
3546 }
3547
3548 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3549 t.Errorf("expected device bin dependency %q, got %q", w, g)
3550 }
3551
3552 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3553 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3554 }
3555
3556}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003557
3558func TestStubsLibReexportsHeaders(t *testing.T) {
3559 ctx := testCc(t, `
3560 cc_library_shared {
3561 name: "libclient",
3562 srcs: ["foo.c"],
3563 shared_libs: ["libfoo#1"],
3564 }
3565
3566 cc_library_shared {
3567 name: "libfoo",
3568 srcs: ["foo.c"],
3569 shared_libs: ["libbar"],
3570 export_shared_lib_headers: ["libbar"],
3571 stubs: {
3572 symbol_file: "foo.map.txt",
3573 versions: ["1", "2", "3"],
3574 },
3575 }
3576
3577 cc_library_shared {
3578 name: "libbar",
3579 export_include_dirs: ["include/libbar"],
3580 srcs: ["foo.c"],
3581 }`)
3582
3583 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3584
3585 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3586 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3587 }
3588}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003589
3590func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3591 ctx := testCc(t, `
3592 cc_library {
3593 name: "libfoo",
3594 srcs: ["a/Foo.aidl"],
3595 aidl: { flags: ["-Werror"], },
3596 }
3597 `)
3598
3599 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3600 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3601 aidlCommand := manifest.Commands[0].GetCommand()
3602 expectedAidlFlag := "-Werror"
3603 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3604 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3605 }
3606}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003607
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003608type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003609
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003610const (
3611 None MemtagNoteType = iota + 1
3612 Sync
3613 Async
3614)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003615
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003616func (t MemtagNoteType) str() string {
3617 switch t {
3618 case None:
3619 return "none"
3620 case Sync:
3621 return "sync"
3622 case Async:
3623 return "async"
3624 default:
3625 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003626 }
3627}
3628
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003629func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3630 note_async := "note_memtag_heap_async"
3631 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003632
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003633 found := None
3634 implicits := m.Rule("ld").Implicits
3635 for _, lib := range implicits {
3636 if strings.Contains(lib.Rel(), note_async) {
3637 found = Async
3638 break
3639 } else if strings.Contains(lib.Rel(), note_sync) {
3640 found = Sync
3641 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003642 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003643 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003644
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003645 if found != expected {
3646 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3647 }
3648}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003649
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003650var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
3651 android.FixtureModifyMockFS(func(fs android.MockFS) {
3652 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003653 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003654 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003655 gtest: false,
3656 }
3657
3658 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003659 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003660 gtest: false,
3661 sanitize: { memtag_heap: false },
3662 }
3663
3664 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003665 name: "%[1]s_test_true",
3666 gtest: false,
3667 sanitize: { memtag_heap: true },
3668 }
3669
3670 cc_test {
3671 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003672 gtest: false,
3673 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3674 }
3675
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003676 cc_test {
3677 name: "%[1]s_test_true_diag",
3678 gtest: false,
3679 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3680 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003681
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003682 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003683 name: "%[1]s_binary",
3684 }
3685
3686 cc_binary {
3687 name: "%[1]s_binary_false",
3688 sanitize: { memtag_heap: false },
3689 }
3690
3691 cc_binary {
3692 name: "%[1]s_binary_true",
3693 sanitize: { memtag_heap: true },
3694 }
3695
3696 cc_binary {
3697 name: "%[1]s_binary_true_nodiag",
3698 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3699 }
3700
3701 cc_binary {
3702 name: "%[1]s_binary_true_diag",
3703 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003704 }
3705 `
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003706 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3707 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3708 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3709 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003710
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003711 fs.Merge(android.MockFS{
3712 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3713 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3714 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3715 "subdir_async/Android.bp": []byte(subdirAsyncBp),
3716 })
3717 }),
3718 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3719 variables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3720 variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3721 variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3722 }),
3723)
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003724
3725func TestSanitizeMemtagHeap(t *testing.T) {
3726 variant := "android_arm64_armv8-a"
3727
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003728 result := ccFixtureFactory.Extend(prepareForTestWithMemtagHeap).RunTest(t)
3729 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003730
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003731 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3732 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3733 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3734 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3735 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3736
3737 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3738 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3739 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3740 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3741 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3742
3743 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3744 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3745 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3746 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3747 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3748
3749 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3750 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3751 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3752 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3753 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3754
3755 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3756 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3757 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3758 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3759 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3760
3761 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3762 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3763 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3764 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3765 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3766
3767 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3768 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3769 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3770 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3771 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3772
3773 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3774 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3775 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3776 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3777 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3778}
3779
3780func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003781 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003782
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003783 result := ccFixtureFactory.Extend(
3784 prepareForTestWithMemtagHeap,
3785 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3786 variables.SanitizeDevice = []string{"memtag_heap"}
3787 }),
3788 ).RunTest(t)
3789 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003790
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003791 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3792 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3793 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3794 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3795 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003796
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003797 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3798 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3799 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3800 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3801 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3802
3803 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3804 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3805 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3806 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3807 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3808
3809 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3810 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3811 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3812 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3813 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3814
3815 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3816 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3817 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3818 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3819 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3820
3821 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3822 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3823 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3824 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3825 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3826
3827 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3828 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3829 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3830 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3831 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3832
3833 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3834 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3835 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3836 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3837 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3838}
3839
3840func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3841 variant := "android_arm64_armv8-a"
3842
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003843 result := ccFixtureFactory.Extend(
3844 prepareForTestWithMemtagHeap,
3845 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3846 variables.SanitizeDevice = []string{"memtag_heap"}
3847 variables.SanitizeDeviceDiag = []string{"memtag_heap"}
3848 }),
3849 ).RunTest(t)
3850 ctx := result.TestContext
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003851
3852 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3853 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3854 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3855 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3856 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3857
3858 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3859 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3860 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3861 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3862 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3863
3864 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3865 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3866 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3869
3870 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3871 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3872 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3873 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3874 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3875
3876 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3877 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3878 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3879 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3880 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3881
3882 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3883 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3884 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3885 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3886 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3887
3888 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3889 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3890 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3892 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3893
3894 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3895 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3896 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3898 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003899}
Paul Duffin3cb603e2021-02-19 13:57:10 +00003900
3901func TestIncludeDirsExporting(t *testing.T) {
3902
3903 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
3904 // embedded newline characters alone.
3905 trimIndentingSpaces := func(s string) string {
3906 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
3907 }
3908
3909 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
3910 t.Helper()
3911 expected = trimIndentingSpaces(expected)
3912 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
3913 if expected != actual {
3914 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
3915 }
3916 }
3917
3918 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
3919
3920 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
3921 t.Helper()
3922 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
3923 name := module.Name()
3924
3925 for _, checker := range checkers {
3926 checker(t, name, exported)
3927 }
3928 }
3929
3930 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
3931 return func(t *testing.T, name string, exported FlagExporterInfo) {
3932 t.Helper()
3933 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
3934 }
3935 }
3936
3937 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
3938 return func(t *testing.T, name string, exported FlagExporterInfo) {
3939 t.Helper()
3940 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
3941 }
3942 }
3943
3944 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
3945 return func(t *testing.T, name string, exported FlagExporterInfo) {
3946 t.Helper()
3947 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
3948 }
3949 }
3950
3951 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
3952 return func(t *testing.T, name string, exported FlagExporterInfo) {
3953 t.Helper()
3954 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
3955 }
3956 }
3957
3958 genRuleModules := `
3959 genrule {
3960 name: "genrule_foo",
3961 cmd: "generate-foo",
3962 out: [
3963 "generated_headers/foo/generated_header.h",
3964 ],
3965 export_include_dirs: [
3966 "generated_headers",
3967 ],
3968 }
3969
3970 genrule {
3971 name: "genrule_bar",
3972 cmd: "generate-bar",
3973 out: [
3974 "generated_headers/bar/generated_header.h",
3975 ],
3976 export_include_dirs: [
3977 "generated_headers",
3978 ],
3979 }
3980 `
3981
3982 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
3983 ctx := testCc(t, genRuleModules+`
3984 cc_library {
3985 name: "libfoo",
3986 srcs: ["foo.c"],
3987 export_include_dirs: ["foo/standard"],
3988 export_system_include_dirs: ["foo/system"],
3989 generated_headers: ["genrule_foo"],
3990 export_generated_headers: ["genrule_foo"],
3991 }
3992
3993 cc_library {
3994 name: "libbar",
3995 srcs: ["bar.c"],
3996 shared_libs: ["libfoo"],
3997 export_include_dirs: ["bar/standard"],
3998 export_system_include_dirs: ["bar/system"],
3999 generated_headers: ["genrule_bar"],
4000 export_generated_headers: ["genrule_bar"],
4001 }
4002 `)
4003 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4004 checkIncludeDirs(t, ctx, foo,
4005 expectedIncludeDirs(`
4006 foo/standard
4007 .intermediates/genrule_foo/gen/generated_headers
4008 `),
4009 expectedSystemIncludeDirs(`foo/system`),
4010 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4011 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4012 )
4013
4014 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4015 checkIncludeDirs(t, ctx, bar,
4016 expectedIncludeDirs(`
4017 bar/standard
4018 .intermediates/genrule_bar/gen/generated_headers
4019 `),
4020 expectedSystemIncludeDirs(`bar/system`),
4021 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4022 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4023 )
4024 })
4025
4026 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
4027 ctx := testCc(t, genRuleModules+`
4028 cc_library {
4029 name: "libfoo",
4030 srcs: ["foo.c"],
4031 export_include_dirs: ["foo/standard"],
4032 export_system_include_dirs: ["foo/system"],
4033 generated_headers: ["genrule_foo"],
4034 export_generated_headers: ["genrule_foo"],
4035 }
4036
4037 cc_library {
4038 name: "libbar",
4039 srcs: ["bar.c"],
4040 whole_static_libs: ["libfoo"],
4041 export_include_dirs: ["bar/standard"],
4042 export_system_include_dirs: ["bar/system"],
4043 generated_headers: ["genrule_bar"],
4044 export_generated_headers: ["genrule_bar"],
4045 }
4046 `)
4047 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4048 checkIncludeDirs(t, ctx, foo,
4049 expectedIncludeDirs(`
4050 foo/standard
4051 .intermediates/genrule_foo/gen/generated_headers
4052 `),
4053 expectedSystemIncludeDirs(`foo/system`),
4054 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4055 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4056 )
4057
4058 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4059 checkIncludeDirs(t, ctx, bar,
4060 expectedIncludeDirs(`
4061 bar/standard
4062 foo/standard
4063 .intermediates/genrule_foo/gen/generated_headers
4064 .intermediates/genrule_bar/gen/generated_headers
4065 `),
4066 expectedSystemIncludeDirs(`
4067 bar/system
4068 foo/system
4069 `),
4070 expectedGeneratedHeaders(`
4071 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4072 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4073 `),
4074 expectedOrderOnlyDeps(`
4075 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4076 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4077 `),
4078 )
4079 })
4080
Paul Duffin3cb603e2021-02-19 13:57:10 +00004081 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
4082 ctx := testCc(t, genRuleModules+`
4083 cc_library_shared {
4084 name: "libfoo",
4085 srcs: [
4086 "foo.c",
4087 "b.aidl",
4088 "a.proto",
4089 ],
4090 aidl: {
4091 export_aidl_headers: true,
4092 }
4093 }
4094 `)
4095 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4096 checkIncludeDirs(t, ctx, foo,
4097 expectedIncludeDirs(`
4098 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
4099 `),
4100 expectedSystemIncludeDirs(``),
4101 expectedGeneratedHeaders(`
4102 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4103 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4104 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004105 `),
4106 expectedOrderOnlyDeps(`
4107 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4108 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4109 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004110 `),
4111 )
4112 })
4113
Paul Duffin3cb603e2021-02-19 13:57:10 +00004114 t.Run("ensure only proto headers are exported", func(t *testing.T) {
4115 ctx := testCc(t, genRuleModules+`
4116 cc_library_shared {
4117 name: "libfoo",
4118 srcs: [
4119 "foo.c",
4120 "b.aidl",
4121 "a.proto",
4122 ],
4123 proto: {
4124 export_proto_headers: true,
4125 }
4126 }
4127 `)
4128 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4129 checkIncludeDirs(t, ctx, foo,
4130 expectedIncludeDirs(`
4131 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
4132 `),
4133 expectedSystemIncludeDirs(``),
4134 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004135 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4136 `),
4137 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004138 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4139 `),
4140 )
4141 })
4142
Paul Duffin33056e82021-02-19 13:49:08 +00004143 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00004144 ctx := testCc(t, genRuleModules+`
4145 cc_library_shared {
4146 name: "libfoo",
4147 srcs: [
4148 "foo.c",
4149 "a.sysprop",
4150 "b.aidl",
4151 "a.proto",
4152 ],
4153 }
4154 `)
4155 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4156 checkIncludeDirs(t, ctx, foo,
4157 expectedIncludeDirs(`
4158 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
4159 `),
4160 expectedSystemIncludeDirs(``),
4161 expectedGeneratedHeaders(`
4162 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004163 `),
4164 expectedOrderOnlyDeps(`
4165 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4166 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004167 `),
4168 )
4169 })
4170}