blob: 719661598a7d3c2bd9778ed5788a19da5080bd2a [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,
Justin Yun13decfb2021-03-08 19:25:55 +09002068 srcs: ["foo.c"],
Justin Yun6977e8a2020-10-29 18:24:11 +09002069 target: {
2070 vendor: {
2071 suffix: "-vendor",
2072 },
2073 product: {
2074 suffix: "-product",
2075 },
2076 }
2077 }
2078 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002079 name: "libproduct_va",
2080 product_specific: true,
2081 vendor_available: true,
2082 nocrt: true,
2083 }
2084 cc_library {
2085 name: "libprod",
2086 product_specific: true,
2087 shared_libs: [
2088 "libllndk",
2089 "libvndk",
2090 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002091 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002092 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002093 "libproduct_va",
2094 ],
2095 nocrt: true,
2096 }
2097 cc_library {
2098 name: "libvendor",
2099 vendor: true,
2100 shared_libs: [
2101 "libllndk",
2102 "libvndk",
2103 "libvndk_sp",
2104 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002105 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002106 "libproduct_va",
2107 ],
2108 nocrt: true,
2109 }
2110 `
2111
Justin Yun13decfb2021-03-08 19:25:55 +09002112 ctx := ccFixtureFactory.RunTestWithBp(t, bp).TestContext
Justin Yun5f7f7e82019-11-18 19:52:14 +09002113
Jooyung Han261e1582020-10-20 18:54:21 +09002114 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2115 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002116
2117 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2118 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2119
2120 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2121 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun13decfb2021-03-08 19:25:55 +09002122
2123 ensureStringContains := func(t *testing.T, str string, substr string) {
2124 t.Helper()
2125 if !strings.Contains(str, substr) {
2126 t.Errorf("%q is not found in %v", substr, str)
2127 }
2128 }
2129 ensureStringNotContains := func(t *testing.T, str string, substr string) {
2130 t.Helper()
2131 if strings.Contains(str, substr) {
2132 t.Errorf("%q is found in %v", substr, str)
2133 }
2134 }
2135
2136 // _static variant is used since _shared reuses *.o from the static variant
2137 vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1))
2138 product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1))
2139
2140 vendor_cflags := vendor_static.Rule("cc").Args["cFlags"]
2141 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__")
2142 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__")
2143 ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__")
2144
2145 product_cflags := product_static.Rule("cc").Args["cFlags"]
2146 ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__")
2147 ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__")
2148 ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002149}
2150
2151func TestEnforceProductVndkVersionErrors(t *testing.T) {
2152 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2153 cc_library {
2154 name: "libprod",
2155 product_specific: true,
2156 shared_libs: [
2157 "libvendor",
2158 ],
2159 nocrt: true,
2160 }
2161 cc_library {
2162 name: "libvendor",
2163 vendor: true,
2164 nocrt: true,
2165 }
2166 `)
2167 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2168 cc_library {
2169 name: "libprod",
2170 product_specific: true,
2171 shared_libs: [
2172 "libsystem",
2173 ],
2174 nocrt: true,
2175 }
2176 cc_library {
2177 name: "libsystem",
2178 nocrt: true,
2179 }
2180 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002181 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2182 cc_library {
2183 name: "libprod",
2184 product_specific: true,
2185 shared_libs: [
2186 "libva",
2187 ],
2188 nocrt: true,
2189 }
2190 cc_library {
2191 name: "libva",
2192 vendor_available: true,
2193 nocrt: true,
2194 }
2195 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002196 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002197 cc_library {
2198 name: "libprod",
2199 product_specific: true,
2200 shared_libs: [
2201 "libvndk_private",
2202 ],
2203 nocrt: true,
2204 }
2205 cc_library {
2206 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002207 vendor_available: true,
2208 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002209 vndk: {
2210 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002211 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002212 },
2213 nocrt: true,
2214 }
2215 `)
2216 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2217 cc_library {
2218 name: "libprod",
2219 product_specific: true,
2220 shared_libs: [
2221 "libsystem_ext",
2222 ],
2223 nocrt: true,
2224 }
2225 cc_library {
2226 name: "libsystem_ext",
2227 system_ext_specific: true,
2228 nocrt: true,
2229 }
2230 `)
2231 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2232 cc_library {
2233 name: "libsystem",
2234 shared_libs: [
2235 "libproduct_va",
2236 ],
2237 nocrt: true,
2238 }
2239 cc_library {
2240 name: "libproduct_va",
2241 product_specific: true,
2242 vendor_available: true,
2243 nocrt: true,
2244 }
2245 `)
2246}
2247
Jooyung Han38002912019-05-16 04:01:54 +09002248func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002249 bp := `
2250 cc_library {
2251 name: "libvndk",
2252 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002253 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002254 vndk: {
2255 enabled: true,
2256 },
2257 }
2258 cc_library {
2259 name: "libvndksp",
2260 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002261 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002262 vndk: {
2263 enabled: true,
2264 support_system_process: true,
2265 },
2266 }
2267 cc_library {
2268 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002269 vendor_available: true,
2270 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002271 vndk: {
2272 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002273 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002274 },
2275 }
2276 cc_library {
2277 name: "libvendor",
2278 vendor: true,
2279 }
2280 cc_library {
2281 name: "libvndkext",
2282 vendor: true,
2283 vndk: {
2284 enabled: true,
2285 extends: "libvndk",
2286 },
2287 }
2288 vndk_prebuilt_shared {
2289 name: "prevndk",
2290 version: "27",
2291 target_arch: "arm",
2292 binder32bit: true,
2293 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002294 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002295 vndk: {
2296 enabled: true,
2297 },
2298 arch: {
2299 arm: {
2300 srcs: ["liba.so"],
2301 },
2302 },
2303 }
2304 cc_library {
2305 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002306 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002307 }
2308 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002309 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002310 symbol_file: "",
2311 }
2312 cc_library {
2313 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002314 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002315 }
2316 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002317 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002318 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002319 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002320 }
2321
2322 llndk_libraries_txt {
2323 name: "llndk.libraries.txt",
2324 }
2325 vndkcore_libraries_txt {
2326 name: "vndkcore.libraries.txt",
2327 }
2328 vndksp_libraries_txt {
2329 name: "vndksp.libraries.txt",
2330 }
2331 vndkprivate_libraries_txt {
2332 name: "vndkprivate.libraries.txt",
2333 }
2334 vndkcorevariant_libraries_txt {
2335 name: "vndkcorevariant.libraries.txt",
2336 insert_vndk_version: false,
2337 }
2338 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002339
2340 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002341 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2342 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2343 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002344 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002345
Colin Cross78212242021-01-06 14:51:30 -08002346 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2347 []string{"libvndk.so", "libvndkprivate.so"})
2348 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2349 []string{"libc++.so", "libvndksp.so"})
2350 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2351 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2352 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2353 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002354
Colin Crossfb0c16e2019-11-20 17:12:35 -08002355 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002356
Jooyung Han38002912019-05-16 04:01:54 +09002357 tests := []struct {
2358 variant string
2359 name string
2360 expected string
2361 }{
2362 {vendorVariant, "libvndk", "native:vndk"},
2363 {vendorVariant, "libvndksp", "native:vndk"},
2364 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2365 {vendorVariant, "libvendor", "native:vendor"},
2366 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002367 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002368 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002369 {coreVariant, "libvndk", "native:platform"},
2370 {coreVariant, "libvndkprivate", "native:platform"},
2371 {coreVariant, "libllndk", "native:platform"},
2372 }
2373 for _, test := range tests {
2374 t.Run(test.name, func(t *testing.T) {
2375 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2376 assertString(t, module.makeLinkType, test.expected)
2377 })
2378 }
2379}
2380
Jeff Gaston294356f2017-09-27 17:05:30 -07002381var staticLinkDepOrderTestCases = []struct {
2382 // This is a string representation of a map[moduleName][]moduleDependency .
2383 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002384 inStatic string
2385
2386 // This is a string representation of a map[moduleName][]moduleDependency .
2387 // It models the dependencies declared in an Android.bp file.
2388 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002389
2390 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2391 // The keys of allOrdered specify which modules we would like to check.
2392 // The values of allOrdered specify the expected result (of the transitive closure of all
2393 // dependencies) for each module to test
2394 allOrdered string
2395
2396 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2397 // The keys of outOrdered specify which modules we would like to check.
2398 // The values of outOrdered specify the expected result (of the ordered linker command line)
2399 // for each module to test.
2400 outOrdered string
2401}{
2402 // Simple tests
2403 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002404 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002405 outOrdered: "",
2406 },
2407 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002408 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002409 outOrdered: "a:",
2410 },
2411 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002412 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002413 outOrdered: "a:b; b:",
2414 },
2415 // Tests of reordering
2416 {
2417 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002418 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002419 outOrdered: "a:b,c,d; b:d; c:d; d:",
2420 },
2421 {
2422 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002423 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002424 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2425 },
2426 {
2427 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002428 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002429 outOrdered: "a:d,b,e,c; d:b; e:c",
2430 },
2431 {
2432 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002433 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002434 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2435 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2436 },
2437 {
2438 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002439 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 -07002440 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2441 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2442 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002443 // shared dependencies
2444 {
2445 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2446 // So, we don't actually have to check that a shared dependency of c will change the order
2447 // of a library that depends statically on b and on c. We only need to check that if c has
2448 // a shared dependency on b, that that shows up in allOrdered.
2449 inShared: "c:b",
2450 allOrdered: "c:b",
2451 outOrdered: "c:",
2452 },
2453 {
2454 // This test doesn't actually include any shared dependencies but it's a reminder of what
2455 // the second phase of the above test would look like
2456 inStatic: "a:b,c; c:b",
2457 allOrdered: "a:c,b; c:b",
2458 outOrdered: "a:c,b; c:b",
2459 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002460 // tiebreakers for when two modules specifying different orderings and there is no dependency
2461 // to dictate an order
2462 {
2463 // 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 -08002464 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002465 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2466 },
2467 {
2468 // 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 -08002469 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 -07002470 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2471 },
2472 // Tests involving duplicate dependencies
2473 {
2474 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002475 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002476 outOrdered: "a:c,b",
2477 },
2478 {
2479 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002480 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002481 outOrdered: "a:d,c,b",
2482 },
2483 // Tests to confirm the nonexistence of infinite loops.
2484 // These cases should never happen, so as long as the test terminates and the
2485 // result is deterministic then that should be fine.
2486 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002487 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002488 outOrdered: "a:a",
2489 },
2490 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002491 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002492 allOrdered: "a:b,c; b:c,a; c:a,b",
2493 outOrdered: "a:b; b:c; c:a",
2494 },
2495 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002496 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002497 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2498 outOrdered: "a:c,b; b:a,c; c:b,a",
2499 },
2500}
2501
2502// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2503func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2504 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2505 strippedText := strings.Replace(text, " ", "", -1)
2506 if len(strippedText) < 1 {
2507 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2508 }
2509 allDeps = make(map[android.Path][]android.Path, 0)
2510
2511 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2512 moduleTexts := strings.Split(strippedText, ";")
2513
2514 outputForModuleName := func(moduleName string) android.Path {
2515 return android.PathForTesting(moduleName)
2516 }
2517
2518 for _, moduleText := range moduleTexts {
2519 // convert from "a:b,c" to ["a", "b,c"]
2520 components := strings.Split(moduleText, ":")
2521 if len(components) != 2 {
2522 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2523 }
2524 moduleName := components[0]
2525 moduleOutput := outputForModuleName(moduleName)
2526 modulesInOrder = append(modulesInOrder, moduleOutput)
2527
2528 depString := components[1]
2529 // convert from "b,c" to ["b", "c"]
2530 depNames := strings.Split(depString, ",")
2531 if len(depString) < 1 {
2532 depNames = []string{}
2533 }
2534 var deps []android.Path
2535 for _, depName := range depNames {
2536 deps = append(deps, outputForModuleName(depName))
2537 }
2538 allDeps[moduleOutput] = deps
2539 }
2540 return modulesInOrder, allDeps
2541}
2542
Jeff Gaston294356f2017-09-27 17:05:30 -07002543func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2544 for _, moduleName := range moduleNames {
2545 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2546 output := module.outputFile.Path()
2547 paths = append(paths, output)
2548 }
2549 return paths
2550}
2551
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002552func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002553 ctx := testCc(t, `
2554 cc_library {
2555 name: "a",
2556 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002557 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002558 }
2559 cc_library {
2560 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002561 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002562 }
2563 cc_library {
2564 name: "c",
2565 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002566 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002567 }
2568 cc_library {
2569 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002570 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002571 }
2572
2573 `)
2574
Colin Cross7113d202019-11-20 16:39:12 -08002575 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002576 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002577 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2578 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002579
2580 if !reflect.DeepEqual(actual, expected) {
2581 t.Errorf("staticDeps orderings were not propagated correctly"+
2582 "\nactual: %v"+
2583 "\nexpected: %v",
2584 actual,
2585 expected,
2586 )
2587 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002588}
Jeff Gaston294356f2017-09-27 17:05:30 -07002589
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002590func TestStaticLibDepReorderingWithShared(t *testing.T) {
2591 ctx := testCc(t, `
2592 cc_library {
2593 name: "a",
2594 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002595 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002596 }
2597 cc_library {
2598 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002599 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002600 }
2601 cc_library {
2602 name: "c",
2603 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002604 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002605 }
2606
2607 `)
2608
Colin Cross7113d202019-11-20 16:39:12 -08002609 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002610 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002611 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2612 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002613
2614 if !reflect.DeepEqual(actual, expected) {
2615 t.Errorf("staticDeps orderings did not account for shared libs"+
2616 "\nactual: %v"+
2617 "\nexpected: %v",
2618 actual,
2619 expected,
2620 )
2621 }
2622}
2623
Jooyung Hanb04a4992020-03-13 18:57:35 +09002624func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002625 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002626 if !reflect.DeepEqual(actual, expected) {
2627 t.Errorf(message+
2628 "\nactual: %v"+
2629 "\nexpected: %v",
2630 actual,
2631 expected,
2632 )
2633 }
2634}
2635
Jooyung Han61b66e92020-03-21 14:21:46 +00002636func TestLlndkLibrary(t *testing.T) {
2637 ctx := testCc(t, `
2638 cc_library {
2639 name: "libllndk",
2640 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002641 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002642 }
2643 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002644 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002645 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002646
2647 cc_prebuilt_library_shared {
2648 name: "libllndkprebuilt",
2649 stubs: { versions: ["1", "2"] },
2650 llndk_stubs: "libllndkprebuilt.llndk",
2651 }
2652 llndk_library {
2653 name: "libllndkprebuilt.llndk",
2654 }
2655
2656 cc_library {
2657 name: "libllndk_with_external_headers",
2658 stubs: { versions: ["1", "2"] },
2659 llndk_stubs: "libllndk_with_external_headers.llndk",
2660 header_libs: ["libexternal_headers"],
2661 export_header_lib_headers: ["libexternal_headers"],
2662 }
2663 llndk_library {
2664 name: "libllndk_with_external_headers.llndk",
2665 }
2666 cc_library_headers {
2667 name: "libexternal_headers",
2668 export_include_dirs: ["include"],
2669 vendor_available: true,
2670 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002671 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002672 actual := ctx.ModuleVariantsForTests("libllndk")
2673 for i := 0; i < len(actual); i++ {
2674 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
2675 actual = append(actual[:i], actual[i+1:]...)
2676 i--
2677 }
2678 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002679 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00002680 "android_vendor.VER_arm64_armv8-a_shared_1",
2681 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002682 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002683 "android_vendor.VER_arm_armv7-a-neon_shared_1",
2684 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002685 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002686 }
2687 checkEquals(t, "variants for llndk stubs", expected, actual)
2688
Colin Cross127bb8b2020-12-16 16:46:01 -08002689 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002690 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2691
Colin Cross127bb8b2020-12-16 16:46:01 -08002692 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002693 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2694}
2695
Jiyong Parka46a4d52017-12-14 19:54:34 +09002696func TestLlndkHeaders(t *testing.T) {
2697 ctx := testCc(t, `
2698 llndk_headers {
2699 name: "libllndk_headers",
2700 export_include_dirs: ["my_include"],
2701 }
2702 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002703 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002704 export_llndk_headers: ["libllndk_headers"],
2705 }
2706 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002707 name: "libllndk",
2708 llndk_stubs: "libllndk.llndk",
2709 }
2710
2711 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002712 name: "libvendor",
2713 shared_libs: ["libllndk"],
2714 vendor: true,
2715 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002716 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002717 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002718 }
2719 `)
2720
2721 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002722 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002723 cflags := cc.Args["cFlags"]
2724 if !strings.Contains(cflags, "-Imy_include") {
2725 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2726 }
2727}
2728
Logan Chien43d34c32017-12-20 01:17:32 +08002729func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2730 actual := module.Properties.AndroidMkRuntimeLibs
2731 if !reflect.DeepEqual(actual, expected) {
2732 t.Errorf("incorrect runtime_libs for shared libs"+
2733 "\nactual: %v"+
2734 "\nexpected: %v",
2735 actual,
2736 expected,
2737 )
2738 }
2739}
2740
2741const runtimeLibAndroidBp = `
2742 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002743 name: "liball_available",
2744 vendor_available: true,
2745 product_available: true,
2746 no_libcrt : true,
2747 nocrt : true,
2748 system_shared_libs : [],
2749 }
2750 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002751 name: "libvendor_available1",
2752 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002753 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002754 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002755 nocrt : true,
2756 system_shared_libs : [],
2757 }
2758 cc_library {
2759 name: "libvendor_available2",
2760 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002761 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002762 target: {
2763 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002764 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002765 }
2766 },
Yi Konge7fe9912019-06-02 00:53:50 -07002767 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002768 nocrt : true,
2769 system_shared_libs : [],
2770 }
2771 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002772 name: "libproduct_vendor",
2773 product_specific: true,
2774 vendor_available: true,
2775 no_libcrt : true,
2776 nocrt : true,
2777 system_shared_libs : [],
2778 }
2779 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002780 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002781 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002782 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002783 nocrt : true,
2784 system_shared_libs : [],
2785 }
2786 cc_library {
2787 name: "libvendor1",
2788 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002789 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002790 nocrt : true,
2791 system_shared_libs : [],
2792 }
2793 cc_library {
2794 name: "libvendor2",
2795 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002796 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002797 no_libcrt : true,
2798 nocrt : true,
2799 system_shared_libs : [],
2800 }
2801 cc_library {
2802 name: "libproduct_available1",
2803 product_available: true,
2804 runtime_libs: ["liball_available"],
2805 no_libcrt : true,
2806 nocrt : true,
2807 system_shared_libs : [],
2808 }
2809 cc_library {
2810 name: "libproduct1",
2811 product_specific: true,
2812 no_libcrt : true,
2813 nocrt : true,
2814 system_shared_libs : [],
2815 }
2816 cc_library {
2817 name: "libproduct2",
2818 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002819 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002820 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002821 nocrt : true,
2822 system_shared_libs : [],
2823 }
2824`
2825
2826func TestRuntimeLibs(t *testing.T) {
2827 ctx := testCc(t, runtimeLibAndroidBp)
2828
2829 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002830 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002831
Justin Yun8a2600c2020-12-07 12:44:03 +09002832 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2833 checkRuntimeLibs(t, []string{"liball_available"}, module)
2834
2835 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2836 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002837
2838 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002839 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002840
2841 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2842 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002843 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002844
Justin Yun8a2600c2020-12-07 12:44:03 +09002845 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2846 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002847
2848 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002849 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002850
2851 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2852 // and product variants.
2853 variant = "android_product.VER_arm64_armv8-a_shared"
2854
2855 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2856 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2857
2858 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002859 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002860}
2861
2862func TestExcludeRuntimeLibs(t *testing.T) {
2863 ctx := testCc(t, runtimeLibAndroidBp)
2864
Colin Cross7113d202019-11-20 16:39:12 -08002865 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002866 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2867 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002868
Colin Crossfb0c16e2019-11-20 17:12:35 -08002869 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002870 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002871 checkRuntimeLibs(t, nil, module)
2872}
2873
2874func TestRuntimeLibsNoVndk(t *testing.T) {
2875 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2876
2877 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2878
Colin Cross7113d202019-11-20 16:39:12 -08002879 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002880
Justin Yun8a2600c2020-12-07 12:44:03 +09002881 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2882 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002883
2884 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002885 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002886
2887 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002888 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002889}
2890
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002891func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002892 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002893 actual := module.Properties.AndroidMkStaticLibs
2894 if !reflect.DeepEqual(actual, expected) {
2895 t.Errorf("incorrect static_libs"+
2896 "\nactual: %v"+
2897 "\nexpected: %v",
2898 actual,
2899 expected,
2900 )
2901 }
2902}
2903
2904const staticLibAndroidBp = `
2905 cc_library {
2906 name: "lib1",
2907 }
2908 cc_library {
2909 name: "lib2",
2910 static_libs: ["lib1"],
2911 }
2912`
2913
2914func TestStaticLibDepExport(t *testing.T) {
2915 ctx := testCc(t, staticLibAndroidBp)
2916
2917 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002918 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002919 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002920 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002921
2922 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002923 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002924 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2925 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002926 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002927}
2928
Jiyong Parkd08b6972017-09-26 10:50:54 +09002929var compilerFlagsTestCases = []struct {
2930 in string
2931 out bool
2932}{
2933 {
2934 in: "a",
2935 out: false,
2936 },
2937 {
2938 in: "-a",
2939 out: true,
2940 },
2941 {
2942 in: "-Ipath/to/something",
2943 out: false,
2944 },
2945 {
2946 in: "-isystempath/to/something",
2947 out: false,
2948 },
2949 {
2950 in: "--coverage",
2951 out: false,
2952 },
2953 {
2954 in: "-include a/b",
2955 out: true,
2956 },
2957 {
2958 in: "-include a/b c/d",
2959 out: false,
2960 },
2961 {
2962 in: "-DMACRO",
2963 out: true,
2964 },
2965 {
2966 in: "-DMAC RO",
2967 out: false,
2968 },
2969 {
2970 in: "-a -b",
2971 out: false,
2972 },
2973 {
2974 in: "-DMACRO=definition",
2975 out: true,
2976 },
2977 {
2978 in: "-DMACRO=defi nition",
2979 out: true, // TODO(jiyong): this should be false
2980 },
2981 {
2982 in: "-DMACRO(x)=x + 1",
2983 out: true,
2984 },
2985 {
2986 in: "-DMACRO=\"defi nition\"",
2987 out: true,
2988 },
2989}
2990
2991type mockContext struct {
2992 BaseModuleContext
2993 result bool
2994}
2995
2996func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2997 // CheckBadCompilerFlags calls this function when the flag should be rejected
2998 ctx.result = false
2999}
3000
3001func TestCompilerFlags(t *testing.T) {
3002 for _, testCase := range compilerFlagsTestCases {
3003 ctx := &mockContext{result: true}
3004 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3005 if ctx.result != testCase.out {
3006 t.Errorf("incorrect output:")
3007 t.Errorf(" input: %#v", testCase.in)
3008 t.Errorf(" expected: %#v", testCase.out)
3009 t.Errorf(" got: %#v", ctx.result)
3010 }
3011 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003012}
Jiyong Park374510b2018-03-19 18:23:01 +09003013
3014func TestVendorPublicLibraries(t *testing.T) {
3015 ctx := testCc(t, `
3016 cc_library_headers {
3017 name: "libvendorpublic_headers",
3018 export_include_dirs: ["my_include"],
3019 }
3020 vendor_public_library {
3021 name: "libvendorpublic",
3022 symbol_file: "",
3023 export_public_headers: ["libvendorpublic_headers"],
3024 }
3025 cc_library {
3026 name: "libvendorpublic",
3027 srcs: ["foo.c"],
3028 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003029 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003030 nocrt: true,
3031 }
3032
3033 cc_library {
3034 name: "libsystem",
3035 shared_libs: ["libvendorpublic"],
3036 vendor: false,
3037 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003038 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003039 nocrt: true,
3040 }
3041 cc_library {
3042 name: "libvendor",
3043 shared_libs: ["libvendorpublic"],
3044 vendor: true,
3045 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003046 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003047 nocrt: true,
3048 }
3049 `)
3050
Colin Cross7113d202019-11-20 16:39:12 -08003051 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003052 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003053
3054 // test if header search paths are correctly added
3055 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003056 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003057 cflags := cc.Args["cFlags"]
3058 if !strings.Contains(cflags, "-Imy_include") {
3059 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3060 }
3061
3062 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003063 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003064 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003065 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003066 if !strings.Contains(libflags, stubPaths[0].String()) {
3067 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3068 }
3069
3070 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003071 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003072 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003073 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003074 if !strings.Contains(libflags, stubPaths[0].String()) {
3075 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3076 }
3077
3078}
Jiyong Park37b25202018-07-11 10:49:27 +09003079
3080func TestRecovery(t *testing.T) {
3081 ctx := testCc(t, `
3082 cc_library_shared {
3083 name: "librecovery",
3084 recovery: true,
3085 }
3086 cc_library_shared {
3087 name: "librecovery32",
3088 recovery: true,
3089 compile_multilib:"32",
3090 }
Jiyong Park5baac542018-08-28 09:55:37 +09003091 cc_library_shared {
3092 name: "libHalInRecovery",
3093 recovery_available: true,
3094 vendor: true,
3095 }
Jiyong Park37b25202018-07-11 10:49:27 +09003096 `)
3097
3098 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003099 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003100 if len(variants) != 1 || !android.InList(arm64, variants) {
3101 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3102 }
3103
3104 variants = ctx.ModuleVariantsForTests("librecovery32")
3105 if android.InList(arm64, variants) {
3106 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3107 }
Jiyong Park5baac542018-08-28 09:55:37 +09003108
3109 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3110 if !recoveryModule.Platform() {
3111 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3112 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003113}
Jiyong Park5baac542018-08-28 09:55:37 +09003114
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003115func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3116 bp := `
3117 cc_prebuilt_test_library_shared {
3118 name: "test_lib",
3119 relative_install_path: "foo/bar/baz",
3120 srcs: ["srcpath/dontusethispath/baz.so"],
3121 }
3122
3123 cc_test {
3124 name: "main_test",
3125 data_libs: ["test_lib"],
3126 gtest: false,
3127 }
3128 `
3129
3130 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3131 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3132 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3133 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3134
3135 ctx := testCcWithConfig(t, config)
3136 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3137 testBinary := module.(*Module).linker.(*testBinary)
3138 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3139 if err != nil {
3140 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3141 }
3142 if len(outputFiles) != 1 {
3143 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3144 }
3145 if len(testBinary.dataPaths()) != 1 {
3146 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3147 }
3148
3149 outputPath := outputFiles[0].String()
3150
3151 if !strings.HasSuffix(outputPath, "/main_test") {
3152 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3153 }
Colin Crossaa255532020-07-03 13:18:24 -07003154 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003155 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3156 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3157 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3158 }
3159}
3160
Jiyong Park7ed9de32018-10-15 22:25:07 +09003161func TestVersionedStubs(t *testing.T) {
3162 ctx := testCc(t, `
3163 cc_library_shared {
3164 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003165 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003166 stubs: {
3167 symbol_file: "foo.map.txt",
3168 versions: ["1", "2", "3"],
3169 },
3170 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003171
Jiyong Park7ed9de32018-10-15 22:25:07 +09003172 cc_library_shared {
3173 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003174 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003175 shared_libs: ["libFoo#1"],
3176 }`)
3177
3178 variants := ctx.ModuleVariantsForTests("libFoo")
3179 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003180 "android_arm64_armv8-a_shared",
3181 "android_arm64_armv8-a_shared_1",
3182 "android_arm64_armv8-a_shared_2",
3183 "android_arm64_armv8-a_shared_3",
3184 "android_arm_armv7-a-neon_shared",
3185 "android_arm_armv7-a-neon_shared_1",
3186 "android_arm_armv7-a-neon_shared_2",
3187 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003188 }
3189 variantsMismatch := false
3190 if len(variants) != len(expectedVariants) {
3191 variantsMismatch = true
3192 } else {
3193 for _, v := range expectedVariants {
3194 if !inList(v, variants) {
3195 variantsMismatch = false
3196 }
3197 }
3198 }
3199 if variantsMismatch {
3200 t.Errorf("variants of libFoo expected:\n")
3201 for _, v := range expectedVariants {
3202 t.Errorf("%q\n", v)
3203 }
3204 t.Errorf(", but got:\n")
3205 for _, v := range variants {
3206 t.Errorf("%q\n", v)
3207 }
3208 }
3209
Colin Cross7113d202019-11-20 16:39:12 -08003210 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003211 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003212 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003213 if !strings.Contains(libFlags, libFoo1StubPath) {
3214 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3215 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003216
Colin Cross7113d202019-11-20 16:39:12 -08003217 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003218 cFlags := libBarCompileRule.Args["cFlags"]
3219 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3220 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3221 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3222 }
Jiyong Park37b25202018-07-11 10:49:27 +09003223}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003224
Jooyung Hanb04a4992020-03-13 18:57:35 +09003225func TestVersioningMacro(t *testing.T) {
3226 for _, tc := range []struct{ moduleName, expected string }{
3227 {"libc", "__LIBC_API__"},
3228 {"libfoo", "__LIBFOO_API__"},
3229 {"libfoo@1", "__LIBFOO_1_API__"},
3230 {"libfoo-v1", "__LIBFOO_V1_API__"},
3231 {"libfoo.v1", "__LIBFOO_V1_API__"},
3232 } {
3233 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3234 }
3235}
3236
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003237func TestStaticExecutable(t *testing.T) {
3238 ctx := testCc(t, `
3239 cc_binary {
3240 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003241 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003242 static_executable: true,
3243 }`)
3244
Colin Cross7113d202019-11-20 16:39:12 -08003245 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003246 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3247 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003248 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003249 for _, lib := range systemStaticLibs {
3250 if !strings.Contains(libFlags, lib) {
3251 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3252 }
3253 }
3254 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3255 for _, lib := range systemSharedLibs {
3256 if strings.Contains(libFlags, lib) {
3257 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3258 }
3259 }
3260}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003261
3262func TestStaticDepsOrderWithStubs(t *testing.T) {
3263 ctx := testCc(t, `
3264 cc_binary {
3265 name: "mybin",
3266 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003267 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003268 static_executable: true,
3269 stl: "none",
3270 }
3271
3272 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003273 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003274 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003275 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003276 stl: "none",
3277 }
3278
3279 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003280 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003281 srcs: ["foo.c"],
3282 stl: "none",
3283 stubs: {
3284 versions: ["1"],
3285 },
3286 }`)
3287
Colin Cross0de8a1e2020-09-18 14:15:30 -07003288 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3289 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003290 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003291
3292 if !reflect.DeepEqual(actual, expected) {
3293 t.Errorf("staticDeps orderings were not propagated correctly"+
3294 "\nactual: %v"+
3295 "\nexpected: %v",
3296 actual,
3297 expected,
3298 )
3299 }
3300}
Jooyung Han38002912019-05-16 04:01:54 +09003301
Jooyung Hand48f3c32019-08-23 11:18:57 +09003302func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3303 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3304 cc_library {
3305 name: "libA",
3306 srcs: ["foo.c"],
3307 shared_libs: ["libB"],
3308 stl: "none",
3309 }
3310
3311 cc_library {
3312 name: "libB",
3313 srcs: ["foo.c"],
3314 enabled: false,
3315 stl: "none",
3316 }
3317 `)
3318}
3319
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003320// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3321// correctly.
3322func TestFuzzTarget(t *testing.T) {
3323 ctx := testCc(t, `
3324 cc_fuzz {
3325 name: "fuzz_smoke_test",
3326 srcs: ["foo.c"],
3327 }`)
3328
Paul Duffin075c4172019-12-19 19:06:13 +00003329 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003330 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3331}
3332
Jiyong Park29074592019-07-07 16:27:47 +09003333func TestAidl(t *testing.T) {
3334}
3335
Jooyung Han38002912019-05-16 04:01:54 +09003336func assertString(t *testing.T, got, expected string) {
3337 t.Helper()
3338 if got != expected {
3339 t.Errorf("expected %q got %q", expected, got)
3340 }
3341}
3342
3343func assertArrayString(t *testing.T, got, expected []string) {
3344 t.Helper()
3345 if len(got) != len(expected) {
3346 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3347 return
3348 }
3349 for i := range got {
3350 if got[i] != expected[i] {
3351 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3352 i, expected[i], expected, got[i], got)
3353 return
3354 }
3355 }
3356}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003357
Jooyung Han0302a842019-10-30 18:43:49 +09003358func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3359 t.Helper()
3360 assertArrayString(t, android.SortedStringKeys(m), expected)
3361}
3362
Colin Crosse1bb5d02019-09-24 14:55:04 -07003363func TestDefaults(t *testing.T) {
3364 ctx := testCc(t, `
3365 cc_defaults {
3366 name: "defaults",
3367 srcs: ["foo.c"],
3368 static: {
3369 srcs: ["bar.c"],
3370 },
3371 shared: {
3372 srcs: ["baz.c"],
3373 },
3374 }
3375
3376 cc_library_static {
3377 name: "libstatic",
3378 defaults: ["defaults"],
3379 }
3380
3381 cc_library_shared {
3382 name: "libshared",
3383 defaults: ["defaults"],
3384 }
3385
3386 cc_library {
3387 name: "libboth",
3388 defaults: ["defaults"],
3389 }
3390
3391 cc_binary {
3392 name: "binary",
3393 defaults: ["defaults"],
3394 }`)
3395
3396 pathsToBase := func(paths android.Paths) []string {
3397 var ret []string
3398 for _, p := range paths {
3399 ret = append(ret, p.Base())
3400 }
3401 return ret
3402 }
3403
Colin Cross7113d202019-11-20 16:39:12 -08003404 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003405 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3406 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3407 }
Colin Cross7113d202019-11-20 16:39:12 -08003408 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003409 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3410 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3411 }
Colin Cross7113d202019-11-20 16:39:12 -08003412 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003413 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3414 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3415 }
3416
Colin Cross7113d202019-11-20 16:39:12 -08003417 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003418 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3419 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3420 }
Colin Cross7113d202019-11-20 16:39:12 -08003421 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003422 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3423 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3424 }
3425}
Colin Crosseabaedd2020-02-06 17:01:55 -08003426
3427func TestProductVariableDefaults(t *testing.T) {
3428 bp := `
3429 cc_defaults {
3430 name: "libfoo_defaults",
3431 srcs: ["foo.c"],
3432 cppflags: ["-DFOO"],
3433 product_variables: {
3434 debuggable: {
3435 cppflags: ["-DBAR"],
3436 },
3437 },
3438 }
3439
3440 cc_library {
3441 name: "libfoo",
3442 defaults: ["libfoo_defaults"],
3443 }
3444 `
3445
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003446 result := ccFixtureFactory.Extend(
3447 android.PrepareForTestWithVariables,
Colin Crosseabaedd2020-02-06 17:01:55 -08003448
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003449 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3450 variables.Debuggable = BoolPtr(true)
3451 }),
3452 ).RunTestWithBp(t, bp)
Colin Crosseabaedd2020-02-06 17:01:55 -08003453
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003454 libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
Paul Duffine84b1332021-03-12 11:59:43 +00003455 android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
Colin Crosseabaedd2020-02-06 17:01:55 -08003456}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003457
3458func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3459 t.Parallel()
3460 bp := `
3461 cc_library_static {
3462 name: "libfoo",
3463 srcs: ["foo.c"],
3464 whole_static_libs: ["libbar"],
3465 }
3466
3467 cc_library_static {
3468 name: "libbar",
3469 whole_static_libs: ["libmissing"],
3470 }
3471 `
3472
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003473 result := ccFixtureFactory.Extend(
3474 android.PrepareForTestWithAllowMissingDependencies,
3475 ).RunTestWithBp(t, bp)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003476
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003477 libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003478 android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003479
Paul Duffine84b1332021-03-12 11:59:43 +00003480 android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
Colin Crosse4f6eba2020-09-22 18:11:25 -07003481
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003482 libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003483 android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
Colin Crosse4f6eba2020-09-22 18:11:25 -07003484}
Colin Crosse9fe2942020-11-10 18:12:15 -08003485
3486func TestInstallSharedLibs(t *testing.T) {
3487 bp := `
3488 cc_binary {
3489 name: "bin",
3490 host_supported: true,
3491 shared_libs: ["libshared"],
3492 runtime_libs: ["libruntime"],
3493 srcs: [":gen"],
3494 }
3495
3496 cc_library_shared {
3497 name: "libshared",
3498 host_supported: true,
3499 shared_libs: ["libtransitive"],
3500 }
3501
3502 cc_library_shared {
3503 name: "libtransitive",
3504 host_supported: true,
3505 }
3506
3507 cc_library_shared {
3508 name: "libruntime",
3509 host_supported: true,
3510 }
3511
3512 cc_binary_host {
3513 name: "tool",
3514 srcs: ["foo.cpp"],
3515 }
3516
3517 genrule {
3518 name: "gen",
3519 tools: ["tool"],
3520 out: ["gen.cpp"],
3521 cmd: "$(location tool) $(out)",
3522 }
3523 `
3524
3525 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3526 ctx := testCcWithConfig(t, config)
3527
3528 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3529 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3530 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3531 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3532 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3533
3534 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3535 t.Errorf("expected host bin dependency %q, got %q", w, g)
3536 }
3537
3538 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3539 t.Errorf("expected host bin dependency %q, got %q", w, g)
3540 }
3541
3542 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3543 t.Errorf("expected host bin dependency %q, got %q", w, g)
3544 }
3545
3546 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3547 t.Errorf("expected host bin dependency %q, got %q", w, g)
3548 }
3549
3550 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3551 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3552 }
3553
3554 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3555 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3556 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3557 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3558
3559 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3560 t.Errorf("expected device bin dependency %q, got %q", w, g)
3561 }
3562
3563 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3564 t.Errorf("expected device bin dependency %q, got %q", w, g)
3565 }
3566
3567 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3568 t.Errorf("expected device bin dependency %q, got %q", w, g)
3569 }
3570
3571 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3572 t.Errorf("expected device bin dependency %q, got %q", w, g)
3573 }
3574
3575 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3576 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3577 }
3578
3579}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003580
3581func TestStubsLibReexportsHeaders(t *testing.T) {
3582 ctx := testCc(t, `
3583 cc_library_shared {
3584 name: "libclient",
3585 srcs: ["foo.c"],
3586 shared_libs: ["libfoo#1"],
3587 }
3588
3589 cc_library_shared {
3590 name: "libfoo",
3591 srcs: ["foo.c"],
3592 shared_libs: ["libbar"],
3593 export_shared_lib_headers: ["libbar"],
3594 stubs: {
3595 symbol_file: "foo.map.txt",
3596 versions: ["1", "2", "3"],
3597 },
3598 }
3599
3600 cc_library_shared {
3601 name: "libbar",
3602 export_include_dirs: ["include/libbar"],
3603 srcs: ["foo.c"],
3604 }`)
3605
3606 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3607
3608 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3609 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3610 }
3611}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003612
3613func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3614 ctx := testCc(t, `
3615 cc_library {
3616 name: "libfoo",
3617 srcs: ["a/Foo.aidl"],
3618 aidl: { flags: ["-Werror"], },
3619 }
3620 `)
3621
3622 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3623 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3624 aidlCommand := manifest.Commands[0].GetCommand()
3625 expectedAidlFlag := "-Werror"
3626 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3627 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3628 }
3629}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003630
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003631type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003632
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003633const (
3634 None MemtagNoteType = iota + 1
3635 Sync
3636 Async
3637)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003638
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003639func (t MemtagNoteType) str() string {
3640 switch t {
3641 case None:
3642 return "none"
3643 case Sync:
3644 return "sync"
3645 case Async:
3646 return "async"
3647 default:
3648 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003649 }
3650}
3651
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003652func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3653 note_async := "note_memtag_heap_async"
3654 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003655
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003656 found := None
3657 implicits := m.Rule("ld").Implicits
3658 for _, lib := range implicits {
3659 if strings.Contains(lib.Rel(), note_async) {
3660 found = Async
3661 break
3662 } else if strings.Contains(lib.Rel(), note_sync) {
3663 found = Sync
3664 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003665 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003666 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003667
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003668 if found != expected {
3669 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3670 }
3671}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003672
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003673var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
3674 android.FixtureModifyMockFS(func(fs android.MockFS) {
3675 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003676 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003677 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003678 gtest: false,
3679 }
3680
3681 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003682 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003683 gtest: false,
3684 sanitize: { memtag_heap: false },
3685 }
3686
3687 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003688 name: "%[1]s_test_true",
3689 gtest: false,
3690 sanitize: { memtag_heap: true },
3691 }
3692
3693 cc_test {
3694 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003695 gtest: false,
3696 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3697 }
3698
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003699 cc_test {
3700 name: "%[1]s_test_true_diag",
3701 gtest: false,
3702 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3703 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003704
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003705 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003706 name: "%[1]s_binary",
3707 }
3708
3709 cc_binary {
3710 name: "%[1]s_binary_false",
3711 sanitize: { memtag_heap: false },
3712 }
3713
3714 cc_binary {
3715 name: "%[1]s_binary_true",
3716 sanitize: { memtag_heap: true },
3717 }
3718
3719 cc_binary {
3720 name: "%[1]s_binary_true_nodiag",
3721 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3722 }
3723
3724 cc_binary {
3725 name: "%[1]s_binary_true_diag",
3726 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003727 }
3728 `
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003729 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3730 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3731 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3732 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003733
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003734 fs.Merge(android.MockFS{
3735 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3736 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3737 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3738 "subdir_async/Android.bp": []byte(subdirAsyncBp),
3739 })
3740 }),
3741 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3742 variables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3743 variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3744 variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3745 }),
3746)
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003747
3748func TestSanitizeMemtagHeap(t *testing.T) {
3749 variant := "android_arm64_armv8-a"
3750
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003751 result := ccFixtureFactory.Extend(prepareForTestWithMemtagHeap).RunTest(t)
3752 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003753
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003754 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3755 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3756 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3757 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3758 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3759
3760 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3761 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3762 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3763 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3764 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3765
3766 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3767 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3768 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3769 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3770 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3771
3772 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3773 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3774 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3775 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3776 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3777
3778 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3779 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3780 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3781 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3782 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3783
3784 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3785 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3786 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3787 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3788 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3789
3790 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3791 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3792 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3793 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3794 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3795
3796 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3797 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3798 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3799 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3800 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3801}
3802
3803func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003804 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003805
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003806 result := ccFixtureFactory.Extend(
3807 prepareForTestWithMemtagHeap,
3808 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3809 variables.SanitizeDevice = []string{"memtag_heap"}
3810 }),
3811 ).RunTest(t)
3812 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003813
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003814 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3815 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3816 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3817 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3818 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003819
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003820 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3821 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3822 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3823 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3824 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3825
3826 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3827 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3828 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3829 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3830 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3831
3832 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3833 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3834 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3835 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3836 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3837
3838 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3839 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3840 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3841 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3842 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3843
3844 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3845 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3846 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3847 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3848 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3849
3850 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3851 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3852 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3853 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3854 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3855
3856 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3857 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3858 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3859 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3860 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3861}
3862
3863func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3864 variant := "android_arm64_armv8-a"
3865
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003866 result := ccFixtureFactory.Extend(
3867 prepareForTestWithMemtagHeap,
3868 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3869 variables.SanitizeDevice = []string{"memtag_heap"}
3870 variables.SanitizeDeviceDiag = []string{"memtag_heap"}
3871 }),
3872 ).RunTest(t)
3873 ctx := result.TestContext
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003874
3875 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3876 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3877 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3878 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3879 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3880
3881 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3882 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3883 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3884 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3885 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3886
3887 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3888 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3889 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3890 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3892
3893 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3894 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3895 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3896 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3898
3899 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3900 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3901 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3902 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3903 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3904
3905 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3906 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3907 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3908 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3909 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3910
3911 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3912 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3913 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3914 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3915 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3916
3917 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3918 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3919 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3920 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3921 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003922}
Paul Duffin3cb603e2021-02-19 13:57:10 +00003923
3924func TestIncludeDirsExporting(t *testing.T) {
3925
3926 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
3927 // embedded newline characters alone.
3928 trimIndentingSpaces := func(s string) string {
3929 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
3930 }
3931
3932 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
3933 t.Helper()
3934 expected = trimIndentingSpaces(expected)
3935 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
3936 if expected != actual {
3937 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
3938 }
3939 }
3940
3941 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
3942
3943 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
3944 t.Helper()
3945 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
3946 name := module.Name()
3947
3948 for _, checker := range checkers {
3949 checker(t, name, exported)
3950 }
3951 }
3952
3953 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
3954 return func(t *testing.T, name string, exported FlagExporterInfo) {
3955 t.Helper()
3956 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
3957 }
3958 }
3959
3960 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
3961 return func(t *testing.T, name string, exported FlagExporterInfo) {
3962 t.Helper()
3963 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
3964 }
3965 }
3966
3967 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
3968 return func(t *testing.T, name string, exported FlagExporterInfo) {
3969 t.Helper()
3970 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
3971 }
3972 }
3973
3974 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
3975 return func(t *testing.T, name string, exported FlagExporterInfo) {
3976 t.Helper()
3977 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
3978 }
3979 }
3980
3981 genRuleModules := `
3982 genrule {
3983 name: "genrule_foo",
3984 cmd: "generate-foo",
3985 out: [
3986 "generated_headers/foo/generated_header.h",
3987 ],
3988 export_include_dirs: [
3989 "generated_headers",
3990 ],
3991 }
3992
3993 genrule {
3994 name: "genrule_bar",
3995 cmd: "generate-bar",
3996 out: [
3997 "generated_headers/bar/generated_header.h",
3998 ],
3999 export_include_dirs: [
4000 "generated_headers",
4001 ],
4002 }
4003 `
4004
4005 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
4006 ctx := testCc(t, genRuleModules+`
4007 cc_library {
4008 name: "libfoo",
4009 srcs: ["foo.c"],
4010 export_include_dirs: ["foo/standard"],
4011 export_system_include_dirs: ["foo/system"],
4012 generated_headers: ["genrule_foo"],
4013 export_generated_headers: ["genrule_foo"],
4014 }
4015
4016 cc_library {
4017 name: "libbar",
4018 srcs: ["bar.c"],
4019 shared_libs: ["libfoo"],
4020 export_include_dirs: ["bar/standard"],
4021 export_system_include_dirs: ["bar/system"],
4022 generated_headers: ["genrule_bar"],
4023 export_generated_headers: ["genrule_bar"],
4024 }
4025 `)
4026 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4027 checkIncludeDirs(t, ctx, foo,
4028 expectedIncludeDirs(`
4029 foo/standard
4030 .intermediates/genrule_foo/gen/generated_headers
4031 `),
4032 expectedSystemIncludeDirs(`foo/system`),
4033 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4034 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4035 )
4036
4037 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4038 checkIncludeDirs(t, ctx, bar,
4039 expectedIncludeDirs(`
4040 bar/standard
4041 .intermediates/genrule_bar/gen/generated_headers
4042 `),
4043 expectedSystemIncludeDirs(`bar/system`),
4044 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4045 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4046 )
4047 })
4048
4049 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
4050 ctx := testCc(t, genRuleModules+`
4051 cc_library {
4052 name: "libfoo",
4053 srcs: ["foo.c"],
4054 export_include_dirs: ["foo/standard"],
4055 export_system_include_dirs: ["foo/system"],
4056 generated_headers: ["genrule_foo"],
4057 export_generated_headers: ["genrule_foo"],
4058 }
4059
4060 cc_library {
4061 name: "libbar",
4062 srcs: ["bar.c"],
4063 whole_static_libs: ["libfoo"],
4064 export_include_dirs: ["bar/standard"],
4065 export_system_include_dirs: ["bar/system"],
4066 generated_headers: ["genrule_bar"],
4067 export_generated_headers: ["genrule_bar"],
4068 }
4069 `)
4070 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4071 checkIncludeDirs(t, ctx, foo,
4072 expectedIncludeDirs(`
4073 foo/standard
4074 .intermediates/genrule_foo/gen/generated_headers
4075 `),
4076 expectedSystemIncludeDirs(`foo/system`),
4077 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4078 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4079 )
4080
4081 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4082 checkIncludeDirs(t, ctx, bar,
4083 expectedIncludeDirs(`
4084 bar/standard
4085 foo/standard
4086 .intermediates/genrule_foo/gen/generated_headers
4087 .intermediates/genrule_bar/gen/generated_headers
4088 `),
4089 expectedSystemIncludeDirs(`
4090 bar/system
4091 foo/system
4092 `),
4093 expectedGeneratedHeaders(`
4094 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4095 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4096 `),
4097 expectedOrderOnlyDeps(`
4098 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4099 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4100 `),
4101 )
4102 })
4103
Paul Duffin3cb603e2021-02-19 13:57:10 +00004104 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
4105 ctx := testCc(t, genRuleModules+`
4106 cc_library_shared {
4107 name: "libfoo",
4108 srcs: [
4109 "foo.c",
4110 "b.aidl",
4111 "a.proto",
4112 ],
4113 aidl: {
4114 export_aidl_headers: true,
4115 }
4116 }
4117 `)
4118 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4119 checkIncludeDirs(t, ctx, foo,
4120 expectedIncludeDirs(`
4121 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
4122 `),
4123 expectedSystemIncludeDirs(``),
4124 expectedGeneratedHeaders(`
4125 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4126 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4127 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004128 `),
4129 expectedOrderOnlyDeps(`
4130 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4131 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4132 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004133 `),
4134 )
4135 })
4136
Paul Duffin3cb603e2021-02-19 13:57:10 +00004137 t.Run("ensure only proto headers are exported", func(t *testing.T) {
4138 ctx := testCc(t, genRuleModules+`
4139 cc_library_shared {
4140 name: "libfoo",
4141 srcs: [
4142 "foo.c",
4143 "b.aidl",
4144 "a.proto",
4145 ],
4146 proto: {
4147 export_proto_headers: true,
4148 }
4149 }
4150 `)
4151 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4152 checkIncludeDirs(t, ctx, foo,
4153 expectedIncludeDirs(`
4154 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
4155 `),
4156 expectedSystemIncludeDirs(``),
4157 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004158 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4159 `),
4160 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004161 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4162 `),
4163 )
4164 })
4165
Paul Duffin33056e82021-02-19 13:49:08 +00004166 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00004167 ctx := testCc(t, genRuleModules+`
4168 cc_library_shared {
4169 name: "libfoo",
4170 srcs: [
4171 "foo.c",
4172 "a.sysprop",
4173 "b.aidl",
4174 "a.proto",
4175 ],
4176 }
4177 `)
4178 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4179 checkIncludeDirs(t, ctx, foo,
4180 expectedIncludeDirs(`
4181 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
4182 `),
4183 expectedSystemIncludeDirs(``),
4184 expectedGeneratedHeaders(`
4185 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004186 `),
4187 expectedOrderOnlyDeps(`
4188 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4189 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004190 `),
4191 )
4192 })
4193}