blob: 37cbff115eb5b211172405a67b3944bdd6f6cfeb [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
Colin Cross98be1bb2019-12-13 20:41:13 -080055func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070056 t.Helper()
Colin Crossae8600b2020-10-29 17:09:13 -070057 ctx := CreateTestContext(config)
58 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080059
Jeff Gastond3e141d2017-08-08 17:46:01 -070060 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +080061 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090062 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +080063 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090064
65 return ctx
66}
67
Logan Chienf3511742017-10-31 18:04:35 +080068func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080069 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080070 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070071 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun8a2600c2020-12-07 12:44:03 +090072 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Dan Willemsen674dc7f2018-03-12 18:06:05 -070073 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080074
Colin Cross98be1bb2019-12-13 20:41:13 -080075 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080076}
77
78func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080079 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080080 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070081 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080082
Colin Cross98be1bb2019-12-13 20:41:13 -080083 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080084}
85
Justin Yun8a2600c2020-12-07 12:44:03 +090086func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
87 t.Helper()
88 config := TestConfig(buildDir, android.Android, nil, bp, nil)
89 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
90 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
91
92 return testCcWithConfig(t, config)
93}
94
Justin Yun5f7f7e82019-11-18 19:52:14 +090095func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +080096 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080097
Colin Crossae8600b2020-10-29 17:09:13 -070098 ctx := CreateTestContext(config)
99 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +0800100
101 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
102 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800103 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800104 return
105 }
106
107 _, errs = ctx.PrepareBuildActions(config)
108 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800109 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800110 return
111 }
112
113 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
114}
115
Justin Yun5f7f7e82019-11-18 19:52:14 +0900116func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900117 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900118 config := TestConfig(buildDir, android.Android, nil, bp, nil)
119 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
120 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
121 testCcErrorWithConfig(t, pattern, config)
122 return
123}
124
125func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900126 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900127 config := TestConfig(buildDir, android.Android, nil, bp, nil)
128 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
129 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
130 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
131 testCcErrorWithConfig(t, pattern, config)
132 return
133}
134
Logan Chienf3511742017-10-31 18:04:35 +0800135const (
Colin Cross7113d202019-11-20 16:39:12 -0800136 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800137 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900138 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800139 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800140)
141
Doug Hornc32c6b02019-01-17 14:44:05 -0800142func TestFuchsiaDeps(t *testing.T) {
143 t.Helper()
144
145 bp := `
146 cc_library {
147 name: "libTest",
148 srcs: ["foo.c"],
149 target: {
150 fuchsia: {
151 srcs: ["bar.c"],
152 },
153 },
154 }`
155
Colin Cross98be1bb2019-12-13 20:41:13 -0800156 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
157 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800158
159 rt := false
160 fb := false
161
162 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
163 implicits := ld.Implicits
164 for _, lib := range implicits {
165 if strings.Contains(lib.Rel(), "libcompiler_rt") {
166 rt = true
167 }
168
169 if strings.Contains(lib.Rel(), "libbioniccompat") {
170 fb = true
171 }
172 }
173
174 if !rt || !fb {
175 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
176 }
177}
178
179func TestFuchsiaTargetDecl(t *testing.T) {
180 t.Helper()
181
182 bp := `
183 cc_library {
184 name: "libTest",
185 srcs: ["foo.c"],
186 target: {
187 fuchsia: {
188 srcs: ["bar.c"],
189 },
190 },
191 }`
192
Colin Cross98be1bb2019-12-13 20:41:13 -0800193 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
194 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800195 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
196 var objs []string
197 for _, o := range ld.Inputs {
198 objs = append(objs, o.Base())
199 }
200 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
201 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
202 }
203}
204
Jiyong Park6a43f042017-10-12 23:05:00 +0900205func TestVendorSrc(t *testing.T) {
206 ctx := testCc(t, `
207 cc_library {
208 name: "libTest",
209 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700210 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800211 nocrt: true,
212 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900213 vendor_available: true,
214 target: {
215 vendor: {
216 srcs: ["bar.c"],
217 },
218 },
219 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900220 `)
221
Logan Chienf3511742017-10-31 18:04:35 +0800222 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900223 var objs []string
224 for _, o := range ld.Inputs {
225 objs = append(objs, o.Base())
226 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800227 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900228 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
229 }
230}
231
Logan Chienf3511742017-10-31 18:04:35 +0800232func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900233 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800234
Logan Chiend3c59a22018-03-29 14:08:15 +0800235 t.Helper()
236
Justin Yun0ecf0b22020-02-28 15:07:59 +0900237 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Logan Chienf3511742017-10-31 18:04:35 +0800238
239 // Check library properties.
240 lib, ok := mod.compiler.(*libraryDecorator)
241 if !ok {
242 t.Errorf("%q must have libraryDecorator", name)
243 } else if lib.baseInstaller.subDir != subDir {
244 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
245 lib.baseInstaller.subDir)
246 }
247
248 // Check VNDK properties.
249 if mod.vndkdep == nil {
250 t.Fatalf("%q must have `vndkdep`", name)
251 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700252 if !mod.IsVndk() {
253 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800254 }
255 if mod.isVndkSp() != isVndkSp {
256 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
257 }
258
259 // Check VNDK extension properties.
260 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500261 if mod.IsVndkExt() != isVndkExt {
262 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800263 }
264
265 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
266 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
267 }
268}
269
Jose Galmes0a942a02021-02-03 14:23:15 -0800270func 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 -0700271 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900272 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
273 if !ok {
274 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900275 return
276 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900277 outputFiles, err := mod.OutputFiles("")
278 if err != nil || len(outputFiles) != 1 {
279 t.Errorf("%q must have single output\n", moduleName)
280 return
281 }
282 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900283
Bill Peckham945441c2020-08-31 16:07:58 -0700284 if include {
285 out := singleton.Output(snapshotPath)
Jose Galmes0a942a02021-02-03 14:23:15 -0800286 if fake {
287 if out.Rule == nil {
288 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
289 }
290 } else {
291 if out.Input.String() != outputFiles[0].String() {
292 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
293 }
Bill Peckham945441c2020-08-31 16:07:58 -0700294 }
295 } else {
296 out := singleton.MaybeOutput(snapshotPath)
297 if out.Rule != nil {
298 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
299 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900300 }
301}
302
Bill Peckham945441c2020-08-31 16:07:58 -0700303func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800304 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
Bill Peckham945441c2020-08-31 16:07:58 -0700305}
306
307func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800308 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
309}
310
311func checkSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
312 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
Bill Peckham945441c2020-08-31 16:07:58 -0700313}
314
Jooyung Han2216fb12019-11-06 16:46:15 +0900315func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
316 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800317 content := android.ContentFromFileRuleForTests(t, params)
318 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900319 assertArrayString(t, actual, expected)
320}
321
Jooyung Han097087b2019-10-22 19:32:18 +0900322func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
323 t.Helper()
324 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900325 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
326}
327
328func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
329 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800330 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
331 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900332}
333
Logan Chienf3511742017-10-31 18:04:35 +0800334func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800335 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800336 cc_library {
337 name: "libvndk",
338 vendor_available: true,
339 vndk: {
340 enabled: true,
341 },
342 nocrt: true,
343 }
344
345 cc_library {
346 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900347 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800348 vndk: {
349 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900350 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800351 },
352 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900353 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800354 }
355
356 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900357 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800358 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900359 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800360 vndk: {
361 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900362 },
363 nocrt: true,
364 target: {
365 vendor: {
366 cflags: ["-DTEST"],
367 },
368 product: {
369 cflags: ["-DTEST"],
370 },
371 },
372 }
373
374 cc_library {
375 name: "libvndk_sp",
376 vendor_available: true,
377 vndk: {
378 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800379 support_system_process: true,
380 },
381 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900382 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800383 }
384
385 cc_library {
386 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900387 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800388 vndk: {
389 enabled: true,
390 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900391 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800392 },
393 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900394 target: {
395 vendor: {
396 suffix: "-x",
397 },
398 },
Logan Chienf3511742017-10-31 18:04:35 +0800399 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900400
401 cc_library {
402 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900403 vendor_available: true,
404 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900405 vndk: {
406 enabled: true,
407 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900408 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900409 },
410 nocrt: true,
411 target: {
412 vendor: {
413 suffix: "-x",
414 },
415 product: {
416 suffix: "-x",
417 },
418 },
419 }
420
Colin Crosse4e44bc2020-12-28 13:50:21 -0800421 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900422 name: "llndk.libraries.txt",
423 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800424 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900425 name: "vndkcore.libraries.txt",
426 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800427 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900428 name: "vndksp.libraries.txt",
429 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800430 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900431 name: "vndkprivate.libraries.txt",
432 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800433 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900434 name: "vndkproduct.libraries.txt",
435 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800436 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900437 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800438 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900439 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800440 `
441
442 config := TestConfig(buildDir, android.Android, nil, bp, nil)
443 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900444 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800445 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
446
447 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800448
Jooyung Han261e1582020-10-20 18:54:21 +0900449 // subdir == "" because VNDK libs are not supposed to be installed separately.
450 // They are installed as part of VNDK APEX instead.
451 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
452 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900453 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900454 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
455 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900456 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900457
Justin Yun6977e8a2020-10-29 18:24:11 +0900458 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
459 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900460
Inseob Kim1f086e22019-05-09 13:29:15 +0900461 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900462 snapshotDir := "vndk-snapshot"
463 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
464
465 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
466 "arm64", "armv8-a"))
467 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
468 "arm", "armv7-a-neon"))
469
470 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
471 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
472 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
473 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
474
Colin Crossfb0c16e2019-11-20 17:12:35 -0800475 variant := "android_vendor.VER_arm64_armv8-a_shared"
476 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900477
Inseob Kim7f283f42020-06-01 21:53:49 +0900478 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
479
480 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
481 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900482 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
483 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900484 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
485 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900486
Jooyung Han39edb6c2019-11-06 16:53:07 +0900487 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900488 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
489 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
490 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
491 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900492 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900493
Jooyung Han097087b2019-10-22 19:32:18 +0900494 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
495 "LLNDK: libc.so",
496 "LLNDK: libdl.so",
497 "LLNDK: libft2.so",
498 "LLNDK: libm.so",
499 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900500 "VNDK-SP: libvndk_sp-x.so",
501 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900502 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900503 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900504 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900505 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900506 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900507 "VNDK-private: libvndk-private.so",
508 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900509 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900510 "VNDK-product: libc++.so",
511 "VNDK-product: libvndk_product.so",
512 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900513 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900514 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900515 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
516 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
517 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 +0900518 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 +0900519 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
520}
521
Yo Chiangbba545e2020-06-09 16:15:37 +0800522func TestVndkWithHostSupported(t *testing.T) {
523 ctx := testCc(t, `
524 cc_library {
525 name: "libvndk_host_supported",
526 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900527 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800528 vndk: {
529 enabled: true,
530 },
531 host_supported: true,
532 }
533
534 cc_library {
535 name: "libvndk_host_supported_but_disabled_on_device",
536 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900537 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800538 vndk: {
539 enabled: true,
540 },
541 host_supported: true,
542 enabled: false,
543 target: {
544 host: {
545 enabled: true,
546 }
547 }
548 }
549
Colin Crosse4e44bc2020-12-28 13:50:21 -0800550 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800551 name: "vndkcore.libraries.txt",
552 }
553 `)
554
555 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
556}
557
Jooyung Han2216fb12019-11-06 16:46:15 +0900558func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800559 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800560 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900561 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800562 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800563 }`
564 config := TestConfig(buildDir, android.Android, nil, bp, nil)
565 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
566 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
567 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900568
569 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900570 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900571 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900572}
573
574func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800575 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900576 cc_library {
577 name: "libvndk",
578 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900579 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900580 vndk: {
581 enabled: true,
582 },
583 nocrt: true,
584 }
585
586 cc_library {
587 name: "libvndk_sp",
588 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900589 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900590 vndk: {
591 enabled: true,
592 support_system_process: true,
593 },
594 nocrt: true,
595 }
596
597 cc_library {
598 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900599 vendor_available: true,
600 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900601 vndk: {
602 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900603 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900604 },
605 nocrt: true,
606 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900607
Colin Crosse4e44bc2020-12-28 13:50:21 -0800608 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900609 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800610 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900611 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800612 `
613
614 config := TestConfig(buildDir, android.Android, nil, bp, nil)
615 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
616 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
617 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
618
619 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
620
621 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900622
Jooyung Han2216fb12019-11-06 16:46:15 +0900623 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900624}
625
Chris Parsons79d66a52020-06-05 17:26:16 -0400626func TestDataLibs(t *testing.T) {
627 bp := `
628 cc_test_library {
629 name: "test_lib",
630 srcs: ["test_lib.cpp"],
631 gtest: false,
632 }
633
634 cc_test {
635 name: "main_test",
636 data_libs: ["test_lib"],
637 gtest: false,
638 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400639 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400640
641 config := TestConfig(buildDir, android.Android, nil, bp, nil)
642 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
643 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
644 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
645
646 ctx := testCcWithConfig(t, config)
647 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
648 testBinary := module.(*Module).linker.(*testBinary)
649 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
650 if err != nil {
651 t.Errorf("Expected cc_test to produce output files, error: %s", err)
652 return
653 }
654 if len(outputFiles) != 1 {
655 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
656 return
657 }
658 if len(testBinary.dataPaths()) != 1 {
659 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
660 return
661 }
662
663 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400664 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400665
666 if !strings.HasSuffix(outputPath, "/main_test") {
667 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
668 return
669 }
670 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
671 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
672 return
673 }
674}
675
Chris Parsons216e10a2020-07-09 17:12:52 -0400676func TestDataLibsRelativeInstallPath(t *testing.T) {
677 bp := `
678 cc_test_library {
679 name: "test_lib",
680 srcs: ["test_lib.cpp"],
681 relative_install_path: "foo/bar/baz",
682 gtest: false,
683 }
684
685 cc_test {
686 name: "main_test",
687 data_libs: ["test_lib"],
688 gtest: false,
689 }
690 `
691
692 config := TestConfig(buildDir, android.Android, nil, bp, nil)
693 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
694 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
695 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
696
697 ctx := testCcWithConfig(t, config)
698 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
699 testBinary := module.(*Module).linker.(*testBinary)
700 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
701 if err != nil {
702 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
703 }
704 if len(outputFiles) != 1 {
705 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
706 }
707 if len(testBinary.dataPaths()) != 1 {
708 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
709 }
710
711 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400712
713 if !strings.HasSuffix(outputPath, "/main_test") {
714 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
715 }
716 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
717 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
718 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400719 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400720 }
721}
722
Jooyung Han0302a842019-10-30 18:43:49 +0900723func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900724 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900725 cc_library {
726 name: "libvndk",
727 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900728 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900729 vndk: {
730 enabled: true,
731 },
732 nocrt: true,
733 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900734 cc_library {
735 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900736 vendor_available: true,
737 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900738 vndk: {
739 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900740 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900741 },
742 nocrt: true,
743 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800744
745 cc_library {
746 name: "libllndk",
747 llndk_stubs: "libllndk.llndk",
748 }
749
750 llndk_library {
751 name: "libllndk.llndk",
752 symbol_file: "",
753 export_llndk_headers: ["libllndk_headers"],
754 }
755
756 llndk_headers {
757 name: "libllndk_headers",
758 export_include_dirs: ["include"],
759 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900760 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900761
762 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
763 "LLNDK: libc.so",
764 "LLNDK: libdl.so",
765 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800766 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900767 "LLNDK: libm.so",
768 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900769 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900770 "VNDK-core: libvndk.so",
771 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900772 "VNDK-private: libvndk-private.so",
773 "VNDK-product: libc++.so",
774 "VNDK-product: libvndk-private.so",
775 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900776 })
Logan Chienf3511742017-10-31 18:04:35 +0800777}
778
Justin Yun63e9ec72020-10-29 16:49:43 +0900779func TestVndkModuleError(t *testing.T) {
780 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900781 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900782 cc_library {
783 name: "libvndk",
784 vndk: {
785 enabled: true,
786 },
787 nocrt: true,
788 }
789 `)
790
Justin Yunc0d8c492021-01-07 17:45:31 +0900791 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900792 cc_library {
793 name: "libvndk",
794 product_available: true,
795 vndk: {
796 enabled: true,
797 },
798 nocrt: true,
799 }
800 `)
801
Justin Yun6977e8a2020-10-29 18:24:11 +0900802 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
803 cc_library {
804 name: "libvndkprop",
805 vendor_available: true,
806 product_available: true,
807 vndk: {
808 enabled: true,
809 },
810 nocrt: true,
811 target: {
812 vendor: {
813 cflags: ["-DTEST",],
814 },
815 },
816 }
817 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900818}
819
Logan Chiend3c59a22018-03-29 14:08:15 +0800820func TestVndkDepError(t *testing.T) {
821 // Check whether an error is emitted when a VNDK lib depends on a system lib.
822 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
823 cc_library {
824 name: "libvndk",
825 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900826 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800827 vndk: {
828 enabled: true,
829 },
830 shared_libs: ["libfwk"], // Cause error
831 nocrt: true,
832 }
833
834 cc_library {
835 name: "libfwk",
836 nocrt: true,
837 }
838 `)
839
840 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
841 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
842 cc_library {
843 name: "libvndk",
844 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900845 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800846 vndk: {
847 enabled: true,
848 },
849 shared_libs: ["libvendor"], // Cause error
850 nocrt: true,
851 }
852
853 cc_library {
854 name: "libvendor",
855 vendor: true,
856 nocrt: true,
857 }
858 `)
859
860 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
861 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
862 cc_library {
863 name: "libvndk_sp",
864 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900865 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800866 vndk: {
867 enabled: true,
868 support_system_process: true,
869 },
870 shared_libs: ["libfwk"], // Cause error
871 nocrt: true,
872 }
873
874 cc_library {
875 name: "libfwk",
876 nocrt: true,
877 }
878 `)
879
880 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
881 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
882 cc_library {
883 name: "libvndk_sp",
884 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900885 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800886 vndk: {
887 enabled: true,
888 support_system_process: true,
889 },
890 shared_libs: ["libvendor"], // Cause error
891 nocrt: true,
892 }
893
894 cc_library {
895 name: "libvendor",
896 vendor: true,
897 nocrt: true,
898 }
899 `)
900
901 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
902 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
903 cc_library {
904 name: "libvndk_sp",
905 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900906 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800907 vndk: {
908 enabled: true,
909 support_system_process: true,
910 },
911 shared_libs: ["libvndk"], // Cause error
912 nocrt: true,
913 }
914
915 cc_library {
916 name: "libvndk",
917 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900918 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800919 vndk: {
920 enabled: true,
921 },
922 nocrt: true,
923 }
924 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900925
926 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
927 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
928 cc_library {
929 name: "libvndk",
930 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900931 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900932 vndk: {
933 enabled: true,
934 },
935 shared_libs: ["libnonvndk"],
936 nocrt: true,
937 }
938
939 cc_library {
940 name: "libnonvndk",
941 vendor_available: true,
942 nocrt: true,
943 }
944 `)
945
946 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
947 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
948 cc_library {
949 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900950 vendor_available: true,
951 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900952 vndk: {
953 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900954 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900955 },
956 shared_libs: ["libnonvndk"],
957 nocrt: true,
958 }
959
960 cc_library {
961 name: "libnonvndk",
962 vendor_available: true,
963 nocrt: true,
964 }
965 `)
966
967 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
968 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
969 cc_library {
970 name: "libvndksp",
971 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900972 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900973 vndk: {
974 enabled: true,
975 support_system_process: true,
976 },
977 shared_libs: ["libnonvndk"],
978 nocrt: true,
979 }
980
981 cc_library {
982 name: "libnonvndk",
983 vendor_available: true,
984 nocrt: true,
985 }
986 `)
987
988 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
989 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
990 cc_library {
991 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900992 vendor_available: true,
993 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900994 vndk: {
995 enabled: true,
996 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900997 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900998 },
999 shared_libs: ["libnonvndk"],
1000 nocrt: true,
1001 }
1002
1003 cc_library {
1004 name: "libnonvndk",
1005 vendor_available: true,
1006 nocrt: true,
1007 }
1008 `)
1009}
1010
1011func TestDoubleLoadbleDep(t *testing.T) {
1012 // okay to link : LLNDK -> double_loadable VNDK
1013 testCc(t, `
1014 cc_library {
1015 name: "libllndk",
1016 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001017 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001018 }
1019
1020 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001021 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001022 symbol_file: "",
1023 }
1024
1025 cc_library {
1026 name: "libdoubleloadable",
1027 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001028 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001029 vndk: {
1030 enabled: true,
1031 },
1032 double_loadable: true,
1033 }
1034 `)
1035 // okay to link : LLNDK -> VNDK-SP
1036 testCc(t, `
1037 cc_library {
1038 name: "libllndk",
1039 shared_libs: ["libvndksp"],
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: "libvndksp",
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 support_system_process: true,
1055 },
1056 }
1057 `)
1058 // okay to link : double_loadable -> double_loadable
1059 testCc(t, `
1060 cc_library {
1061 name: "libdoubleloadable1",
1062 shared_libs: ["libdoubleloadable2"],
1063 vendor_available: true,
1064 double_loadable: true,
1065 }
1066
1067 cc_library {
1068 name: "libdoubleloadable2",
1069 vendor_available: true,
1070 double_loadable: true,
1071 }
1072 `)
1073 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1074 testCc(t, `
1075 cc_library {
1076 name: "libdoubleloadable",
1077 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001078 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001079 vndk: {
1080 enabled: true,
1081 },
1082 double_loadable: true,
1083 shared_libs: ["libnondoubleloadable"],
1084 }
1085
1086 cc_library {
1087 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001088 vendor_available: true,
1089 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001090 vndk: {
1091 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001092 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001093 },
1094 double_loadable: true,
1095 }
1096 `)
1097 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1098 testCc(t, `
1099 cc_library {
1100 name: "libllndk",
1101 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001102 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001103 }
1104
1105 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001106 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001107 symbol_file: "",
1108 }
1109
1110 cc_library {
1111 name: "libcoreonly",
1112 shared_libs: ["libvendoravailable"],
1113 }
1114
1115 // indirect dependency of LLNDK
1116 cc_library {
1117 name: "libvendoravailable",
1118 vendor_available: true,
1119 double_loadable: true,
1120 }
1121 `)
1122}
1123
1124func TestDoubleLoadableDepError(t *testing.T) {
1125 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1126 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1127 cc_library {
1128 name: "libllndk",
1129 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001130 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001131 }
1132
1133 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001134 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001135 symbol_file: "",
1136 }
1137
1138 cc_library {
1139 name: "libnondoubleloadable",
1140 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001141 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001142 vndk: {
1143 enabled: true,
1144 },
1145 }
1146 `)
1147
1148 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1149 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1150 cc_library {
1151 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001152 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001153 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001154 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001155 }
1156
1157 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001158 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001159 symbol_file: "",
1160 }
1161
1162 cc_library {
1163 name: "libnondoubleloadable",
1164 vendor_available: true,
1165 }
1166 `)
1167
Jooyung Hana70f0672019-01-18 15:20:43 +09001168 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1169 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1170 cc_library {
1171 name: "libllndk",
1172 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001173 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001174 }
1175
1176 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001177 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001178 symbol_file: "",
1179 }
1180
1181 cc_library {
1182 name: "libcoreonly",
1183 shared_libs: ["libvendoravailable"],
1184 }
1185
1186 // indirect dependency of LLNDK
1187 cc_library {
1188 name: "libvendoravailable",
1189 vendor_available: true,
1190 }
1191 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001192
1193 // The error is not from 'client' but from 'libllndk'
1194 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1195 cc_library {
1196 name: "client",
1197 vendor_available: true,
1198 double_loadable: true,
1199 shared_libs: ["libllndk"],
1200 }
1201 cc_library {
1202 name: "libllndk",
1203 shared_libs: ["libnondoubleloadable"],
1204 llndk_stubs: "libllndk.llndk",
1205 }
1206 llndk_library {
1207 name: "libllndk.llndk",
1208 symbol_file: "",
1209 }
1210 cc_library {
1211 name: "libnondoubleloadable",
1212 vendor_available: true,
1213 }
1214 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001215}
1216
Jooyung Han479ca172020-10-19 18:51:07 +09001217func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1218 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1219 cc_library {
1220 name: "libvndksp",
1221 shared_libs: ["libanothervndksp"],
1222 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001223 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001224 vndk: {
1225 enabled: true,
1226 support_system_process: true,
1227 }
1228 }
1229
1230 cc_library {
1231 name: "libllndk",
1232 shared_libs: ["libanothervndksp"],
1233 }
1234
1235 llndk_library {
1236 name: "libllndk",
1237 symbol_file: "",
1238 }
1239
1240 cc_library {
1241 name: "libanothervndksp",
1242 vendor_available: true,
1243 }
1244 `)
1245}
1246
Logan Chienf3511742017-10-31 18:04:35 +08001247func TestVndkExt(t *testing.T) {
1248 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001249 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001250 cc_library {
1251 name: "libvndk",
1252 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001253 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001254 vndk: {
1255 enabled: true,
1256 },
1257 nocrt: true,
1258 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001259 cc_library {
1260 name: "libvndk2",
1261 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001262 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001263 vndk: {
1264 enabled: true,
1265 },
1266 target: {
1267 vendor: {
1268 suffix: "-suffix",
1269 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001270 product: {
1271 suffix: "-suffix",
1272 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001273 },
1274 nocrt: true,
1275 }
Logan Chienf3511742017-10-31 18:04:35 +08001276
1277 cc_library {
1278 name: "libvndk_ext",
1279 vendor: true,
1280 vndk: {
1281 enabled: true,
1282 extends: "libvndk",
1283 },
1284 nocrt: true,
1285 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001286
1287 cc_library {
1288 name: "libvndk2_ext",
1289 vendor: true,
1290 vndk: {
1291 enabled: true,
1292 extends: "libvndk2",
1293 },
1294 nocrt: true,
1295 }
Logan Chienf3511742017-10-31 18:04:35 +08001296
Justin Yun0ecf0b22020-02-28 15:07:59 +09001297 cc_library {
1298 name: "libvndk_ext_product",
1299 product_specific: true,
1300 vndk: {
1301 enabled: true,
1302 extends: "libvndk",
1303 },
1304 nocrt: true,
1305 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001306
Justin Yun0ecf0b22020-02-28 15:07:59 +09001307 cc_library {
1308 name: "libvndk2_ext_product",
1309 product_specific: true,
1310 vndk: {
1311 enabled: true,
1312 extends: "libvndk2",
1313 },
1314 nocrt: true,
1315 }
1316 `
1317 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1318 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1319 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1320 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1321
1322 ctx := testCcWithConfig(t, config)
1323
1324 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1325 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1326
1327 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1328 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1329
1330 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1331 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001332}
1333
Logan Chiend3c59a22018-03-29 14:08:15 +08001334func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001335 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1336 ctx := testCcNoVndk(t, `
1337 cc_library {
1338 name: "libvndk",
1339 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001340 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001341 vndk: {
1342 enabled: true,
1343 },
1344 nocrt: true,
1345 }
1346
1347 cc_library {
1348 name: "libvndk_ext",
1349 vendor: true,
1350 vndk: {
1351 enabled: true,
1352 extends: "libvndk",
1353 },
1354 nocrt: true,
1355 }
1356 `)
1357
1358 // Ensures that the core variant of "libvndk_ext" can be found.
1359 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1360 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1361 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1362 }
1363}
1364
Justin Yun0ecf0b22020-02-28 15:07:59 +09001365func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1366 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001367 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001368 cc_library {
1369 name: "libvndk",
1370 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001371 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001372 vndk: {
1373 enabled: true,
1374 },
1375 nocrt: true,
1376 }
1377
1378 cc_library {
1379 name: "libvndk_ext_product",
1380 product_specific: true,
1381 vndk: {
1382 enabled: true,
1383 extends: "libvndk",
1384 },
1385 nocrt: true,
1386 }
1387 `)
1388
1389 // Ensures that the core variant of "libvndk_ext_product" can be found.
1390 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1391 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1392 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1393 }
1394}
1395
Logan Chienf3511742017-10-31 18:04:35 +08001396func TestVndkExtError(t *testing.T) {
1397 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001398 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001399 cc_library {
1400 name: "libvndk",
1401 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001402 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001403 vndk: {
1404 enabled: true,
1405 },
1406 nocrt: true,
1407 }
1408
1409 cc_library {
1410 name: "libvndk_ext",
1411 vndk: {
1412 enabled: true,
1413 extends: "libvndk",
1414 },
1415 nocrt: true,
1416 }
1417 `)
1418
1419 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1420 cc_library {
1421 name: "libvndk",
1422 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001423 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001424 vndk: {
1425 enabled: true,
1426 },
1427 nocrt: true,
1428 }
1429
1430 cc_library {
1431 name: "libvndk_ext",
1432 vendor: true,
1433 vndk: {
1434 enabled: true,
1435 },
1436 nocrt: true,
1437 }
1438 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001439
1440 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1441 cc_library {
1442 name: "libvndk",
1443 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001444 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001445 vndk: {
1446 enabled: true,
1447 },
1448 nocrt: true,
1449 }
1450
1451 cc_library {
1452 name: "libvndk_ext_product",
1453 product_specific: true,
1454 vndk: {
1455 enabled: true,
1456 },
1457 nocrt: true,
1458 }
1459 `)
1460
1461 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1462 cc_library {
1463 name: "libvndk",
1464 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001465 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001466 vndk: {
1467 enabled: true,
1468 },
1469 nocrt: true,
1470 }
1471
1472 cc_library {
1473 name: "libvndk_ext_product",
1474 product_specific: true,
1475 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001476 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001477 vndk: {
1478 enabled: true,
1479 extends: "libvndk",
1480 },
1481 nocrt: true,
1482 }
1483 `)
Logan Chienf3511742017-10-31 18:04:35 +08001484}
1485
1486func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1487 // This test ensures an error is emitted for inconsistent support_system_process.
1488 testCcError(t, "module \".*\" with mismatched support_system_process", `
1489 cc_library {
1490 name: "libvndk",
1491 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001492 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001493 vndk: {
1494 enabled: true,
1495 },
1496 nocrt: true,
1497 }
1498
1499 cc_library {
1500 name: "libvndk_sp_ext",
1501 vendor: true,
1502 vndk: {
1503 enabled: true,
1504 extends: "libvndk",
1505 support_system_process: true,
1506 },
1507 nocrt: true,
1508 }
1509 `)
1510
1511 testCcError(t, "module \".*\" with mismatched support_system_process", `
1512 cc_library {
1513 name: "libvndk_sp",
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 support_system_process: true,
1519 },
1520 nocrt: true,
1521 }
1522
1523 cc_library {
1524 name: "libvndk_ext",
1525 vendor: true,
1526 vndk: {
1527 enabled: true,
1528 extends: "libvndk_sp",
1529 },
1530 nocrt: true,
1531 }
1532 `)
1533}
1534
1535func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001536 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001537 // with `private: true`.
1538 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001539 cc_library {
1540 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001541 vendor_available: true,
1542 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001543 vndk: {
1544 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001545 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001546 },
1547 nocrt: true,
1548 }
1549
1550 cc_library {
1551 name: "libvndk_ext",
1552 vendor: true,
1553 vndk: {
1554 enabled: true,
1555 extends: "libvndk",
1556 },
1557 nocrt: true,
1558 }
1559 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001560
Justin Yunfd9e8042020-12-23 18:23:14 +09001561 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001562 cc_library {
1563 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001564 vendor_available: true,
1565 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001566 vndk: {
1567 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001568 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001569 },
1570 nocrt: true,
1571 }
1572
1573 cc_library {
1574 name: "libvndk_ext_product",
1575 product_specific: true,
1576 vndk: {
1577 enabled: true,
1578 extends: "libvndk",
1579 },
1580 nocrt: true,
1581 }
1582 `)
Logan Chienf3511742017-10-31 18:04:35 +08001583}
1584
Logan Chiend3c59a22018-03-29 14:08:15 +08001585func TestVendorModuleUseVndkExt(t *testing.T) {
1586 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001587 testCc(t, `
1588 cc_library {
1589 name: "libvndk",
1590 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001591 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001592 vndk: {
1593 enabled: true,
1594 },
1595 nocrt: true,
1596 }
1597
1598 cc_library {
1599 name: "libvndk_ext",
1600 vendor: true,
1601 vndk: {
1602 enabled: true,
1603 extends: "libvndk",
1604 },
1605 nocrt: true,
1606 }
1607
1608 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001609 name: "libvndk_sp",
1610 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001611 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001612 vndk: {
1613 enabled: true,
1614 support_system_process: true,
1615 },
1616 nocrt: true,
1617 }
1618
1619 cc_library {
1620 name: "libvndk_sp_ext",
1621 vendor: true,
1622 vndk: {
1623 enabled: true,
1624 extends: "libvndk_sp",
1625 support_system_process: true,
1626 },
1627 nocrt: true,
1628 }
1629
1630 cc_library {
1631 name: "libvendor",
1632 vendor: true,
1633 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1634 nocrt: true,
1635 }
1636 `)
1637}
1638
Logan Chiend3c59a22018-03-29 14:08:15 +08001639func TestVndkExtUseVendorLib(t *testing.T) {
1640 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001641 testCc(t, `
1642 cc_library {
1643 name: "libvndk",
1644 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001645 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001646 vndk: {
1647 enabled: true,
1648 },
1649 nocrt: true,
1650 }
1651
1652 cc_library {
1653 name: "libvndk_ext",
1654 vendor: true,
1655 vndk: {
1656 enabled: true,
1657 extends: "libvndk",
1658 },
1659 shared_libs: ["libvendor"],
1660 nocrt: true,
1661 }
1662
1663 cc_library {
1664 name: "libvendor",
1665 vendor: true,
1666 nocrt: true,
1667 }
1668 `)
Logan Chienf3511742017-10-31 18:04:35 +08001669
Logan Chiend3c59a22018-03-29 14:08:15 +08001670 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1671 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001672 cc_library {
1673 name: "libvndk_sp",
1674 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001675 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001676 vndk: {
1677 enabled: true,
1678 support_system_process: true,
1679 },
1680 nocrt: true,
1681 }
1682
1683 cc_library {
1684 name: "libvndk_sp_ext",
1685 vendor: true,
1686 vndk: {
1687 enabled: true,
1688 extends: "libvndk_sp",
1689 support_system_process: true,
1690 },
1691 shared_libs: ["libvendor"], // Cause an error
1692 nocrt: true,
1693 }
1694
1695 cc_library {
1696 name: "libvendor",
1697 vendor: true,
1698 nocrt: true,
1699 }
1700 `)
1701}
1702
Justin Yun0ecf0b22020-02-28 15:07:59 +09001703func TestProductVndkExtDependency(t *testing.T) {
1704 bp := `
1705 cc_library {
1706 name: "libvndk",
1707 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001708 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001709 vndk: {
1710 enabled: true,
1711 },
1712 nocrt: true,
1713 }
1714
1715 cc_library {
1716 name: "libvndk_ext_product",
1717 product_specific: true,
1718 vndk: {
1719 enabled: true,
1720 extends: "libvndk",
1721 },
1722 shared_libs: ["libproduct_for_vndklibs"],
1723 nocrt: true,
1724 }
1725
1726 cc_library {
1727 name: "libvndk_sp",
1728 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001729 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001730 vndk: {
1731 enabled: true,
1732 support_system_process: true,
1733 },
1734 nocrt: true,
1735 }
1736
1737 cc_library {
1738 name: "libvndk_sp_ext_product",
1739 product_specific: true,
1740 vndk: {
1741 enabled: true,
1742 extends: "libvndk_sp",
1743 support_system_process: true,
1744 },
1745 shared_libs: ["libproduct_for_vndklibs"],
1746 nocrt: true,
1747 }
1748
1749 cc_library {
1750 name: "libproduct",
1751 product_specific: true,
1752 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1753 nocrt: true,
1754 }
1755
1756 cc_library {
1757 name: "libproduct_for_vndklibs",
1758 product_specific: true,
1759 nocrt: true,
1760 }
1761 `
1762 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1763 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1764 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1765 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1766
1767 testCcWithConfig(t, config)
1768}
1769
Logan Chiend3c59a22018-03-29 14:08:15 +08001770func TestVndkSpExtUseVndkError(t *testing.T) {
1771 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1772 // library.
1773 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1774 cc_library {
1775 name: "libvndk",
1776 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001777 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001778 vndk: {
1779 enabled: true,
1780 },
1781 nocrt: true,
1782 }
1783
1784 cc_library {
1785 name: "libvndk_sp",
1786 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001787 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001788 vndk: {
1789 enabled: true,
1790 support_system_process: true,
1791 },
1792 nocrt: true,
1793 }
1794
1795 cc_library {
1796 name: "libvndk_sp_ext",
1797 vendor: true,
1798 vndk: {
1799 enabled: true,
1800 extends: "libvndk_sp",
1801 support_system_process: true,
1802 },
1803 shared_libs: ["libvndk"], // Cause an error
1804 nocrt: true,
1805 }
1806 `)
1807
1808 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1809 // library.
1810 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1811 cc_library {
1812 name: "libvndk",
1813 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001814 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001815 vndk: {
1816 enabled: true,
1817 },
1818 nocrt: true,
1819 }
1820
1821 cc_library {
1822 name: "libvndk_ext",
1823 vendor: true,
1824 vndk: {
1825 enabled: true,
1826 extends: "libvndk",
1827 },
1828 nocrt: true,
1829 }
1830
1831 cc_library {
1832 name: "libvndk_sp",
1833 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001834 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001835 vndk: {
1836 enabled: true,
1837 support_system_process: true,
1838 },
1839 nocrt: true,
1840 }
1841
1842 cc_library {
1843 name: "libvndk_sp_ext",
1844 vendor: true,
1845 vndk: {
1846 enabled: true,
1847 extends: "libvndk_sp",
1848 support_system_process: true,
1849 },
1850 shared_libs: ["libvndk_ext"], // Cause an error
1851 nocrt: true,
1852 }
1853 `)
1854}
1855
1856func TestVndkUseVndkExtError(t *testing.T) {
1857 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1858 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001859 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1860 cc_library {
1861 name: "libvndk",
1862 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001863 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001864 vndk: {
1865 enabled: true,
1866 },
1867 nocrt: true,
1868 }
1869
1870 cc_library {
1871 name: "libvndk_ext",
1872 vendor: true,
1873 vndk: {
1874 enabled: true,
1875 extends: "libvndk",
1876 },
1877 nocrt: true,
1878 }
1879
1880 cc_library {
1881 name: "libvndk2",
1882 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001883 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001884 vndk: {
1885 enabled: true,
1886 },
1887 shared_libs: ["libvndk_ext"],
1888 nocrt: true,
1889 }
1890 `)
1891
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001892 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001893 cc_library {
1894 name: "libvndk",
1895 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001896 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001897 vndk: {
1898 enabled: true,
1899 },
1900 nocrt: true,
1901 }
1902
1903 cc_library {
1904 name: "libvndk_ext",
1905 vendor: true,
1906 vndk: {
1907 enabled: true,
1908 extends: "libvndk",
1909 },
1910 nocrt: true,
1911 }
1912
1913 cc_library {
1914 name: "libvndk2",
1915 vendor_available: true,
1916 vndk: {
1917 enabled: true,
1918 },
1919 target: {
1920 vendor: {
1921 shared_libs: ["libvndk_ext"],
1922 },
1923 },
1924 nocrt: true,
1925 }
1926 `)
1927
1928 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1929 cc_library {
1930 name: "libvndk_sp",
1931 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001932 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001933 vndk: {
1934 enabled: true,
1935 support_system_process: true,
1936 },
1937 nocrt: true,
1938 }
1939
1940 cc_library {
1941 name: "libvndk_sp_ext",
1942 vendor: true,
1943 vndk: {
1944 enabled: true,
1945 extends: "libvndk_sp",
1946 support_system_process: true,
1947 },
1948 nocrt: true,
1949 }
1950
1951 cc_library {
1952 name: "libvndk_sp_2",
1953 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001954 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001955 vndk: {
1956 enabled: true,
1957 support_system_process: true,
1958 },
1959 shared_libs: ["libvndk_sp_ext"],
1960 nocrt: true,
1961 }
1962 `)
1963
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001964 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001965 cc_library {
1966 name: "libvndk_sp",
1967 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001968 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001969 vndk: {
1970 enabled: true,
1971 },
1972 nocrt: true,
1973 }
1974
1975 cc_library {
1976 name: "libvndk_sp_ext",
1977 vendor: true,
1978 vndk: {
1979 enabled: true,
1980 extends: "libvndk_sp",
1981 },
1982 nocrt: true,
1983 }
1984
1985 cc_library {
1986 name: "libvndk_sp2",
1987 vendor_available: true,
1988 vndk: {
1989 enabled: true,
1990 },
1991 target: {
1992 vendor: {
1993 shared_libs: ["libvndk_sp_ext"],
1994 },
1995 },
1996 nocrt: true,
1997 }
1998 `)
1999}
2000
Justin Yun5f7f7e82019-11-18 19:52:14 +09002001func TestEnforceProductVndkVersion(t *testing.T) {
2002 bp := `
2003 cc_library {
2004 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002005 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002006 }
2007 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002008 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002009 symbol_file: "",
2010 }
2011 cc_library {
2012 name: "libvndk",
2013 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002014 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002015 vndk: {
2016 enabled: true,
2017 },
2018 nocrt: true,
2019 }
2020 cc_library {
2021 name: "libvndk_sp",
2022 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002023 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002024 vndk: {
2025 enabled: true,
2026 support_system_process: true,
2027 },
2028 nocrt: true,
2029 }
2030 cc_library {
2031 name: "libva",
2032 vendor_available: true,
2033 nocrt: true,
2034 }
2035 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002036 name: "libpa",
2037 product_available: true,
2038 nocrt: true,
2039 }
2040 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002041 name: "libboth_available",
2042 vendor_available: true,
2043 product_available: true,
2044 nocrt: true,
2045 target: {
2046 vendor: {
2047 suffix: "-vendor",
2048 },
2049 product: {
2050 suffix: "-product",
2051 },
2052 }
2053 }
2054 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002055 name: "libproduct_va",
2056 product_specific: true,
2057 vendor_available: true,
2058 nocrt: true,
2059 }
2060 cc_library {
2061 name: "libprod",
2062 product_specific: true,
2063 shared_libs: [
2064 "libllndk",
2065 "libvndk",
2066 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002067 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002068 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002069 "libproduct_va",
2070 ],
2071 nocrt: true,
2072 }
2073 cc_library {
2074 name: "libvendor",
2075 vendor: true,
2076 shared_libs: [
2077 "libllndk",
2078 "libvndk",
2079 "libvndk_sp",
2080 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002081 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002082 "libproduct_va",
2083 ],
2084 nocrt: true,
2085 }
2086 `
2087
2088 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2089 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2090 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2091 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2092
2093 ctx := testCcWithConfig(t, config)
2094
Jooyung Han261e1582020-10-20 18:54:21 +09002095 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2096 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002097
2098 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2099 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2100
2101 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2102 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002103}
2104
2105func TestEnforceProductVndkVersionErrors(t *testing.T) {
2106 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2107 cc_library {
2108 name: "libprod",
2109 product_specific: true,
2110 shared_libs: [
2111 "libvendor",
2112 ],
2113 nocrt: true,
2114 }
2115 cc_library {
2116 name: "libvendor",
2117 vendor: true,
2118 nocrt: true,
2119 }
2120 `)
2121 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2122 cc_library {
2123 name: "libprod",
2124 product_specific: true,
2125 shared_libs: [
2126 "libsystem",
2127 ],
2128 nocrt: true,
2129 }
2130 cc_library {
2131 name: "libsystem",
2132 nocrt: true,
2133 }
2134 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002135 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2136 cc_library {
2137 name: "libprod",
2138 product_specific: true,
2139 shared_libs: [
2140 "libva",
2141 ],
2142 nocrt: true,
2143 }
2144 cc_library {
2145 name: "libva",
2146 vendor_available: true,
2147 nocrt: true,
2148 }
2149 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002150 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002151 cc_library {
2152 name: "libprod",
2153 product_specific: true,
2154 shared_libs: [
2155 "libvndk_private",
2156 ],
2157 nocrt: true,
2158 }
2159 cc_library {
2160 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002161 vendor_available: true,
2162 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002163 vndk: {
2164 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002165 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002166 },
2167 nocrt: true,
2168 }
2169 `)
2170 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2171 cc_library {
2172 name: "libprod",
2173 product_specific: true,
2174 shared_libs: [
2175 "libsystem_ext",
2176 ],
2177 nocrt: true,
2178 }
2179 cc_library {
2180 name: "libsystem_ext",
2181 system_ext_specific: true,
2182 nocrt: true,
2183 }
2184 `)
2185 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2186 cc_library {
2187 name: "libsystem",
2188 shared_libs: [
2189 "libproduct_va",
2190 ],
2191 nocrt: true,
2192 }
2193 cc_library {
2194 name: "libproduct_va",
2195 product_specific: true,
2196 vendor_available: true,
2197 nocrt: true,
2198 }
2199 `)
2200}
2201
Jooyung Han38002912019-05-16 04:01:54 +09002202func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002203 bp := `
2204 cc_library {
2205 name: "libvndk",
2206 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002207 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002208 vndk: {
2209 enabled: true,
2210 },
2211 }
2212 cc_library {
2213 name: "libvndksp",
2214 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002215 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002216 vndk: {
2217 enabled: true,
2218 support_system_process: true,
2219 },
2220 }
2221 cc_library {
2222 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002223 vendor_available: true,
2224 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002225 vndk: {
2226 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002227 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002228 },
2229 }
2230 cc_library {
2231 name: "libvendor",
2232 vendor: true,
2233 }
2234 cc_library {
2235 name: "libvndkext",
2236 vendor: true,
2237 vndk: {
2238 enabled: true,
2239 extends: "libvndk",
2240 },
2241 }
2242 vndk_prebuilt_shared {
2243 name: "prevndk",
2244 version: "27",
2245 target_arch: "arm",
2246 binder32bit: true,
2247 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002248 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002249 vndk: {
2250 enabled: true,
2251 },
2252 arch: {
2253 arm: {
2254 srcs: ["liba.so"],
2255 },
2256 },
2257 }
2258 cc_library {
2259 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002260 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002261 }
2262 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002263 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002264 symbol_file: "",
2265 }
2266 cc_library {
2267 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002268 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002269 }
2270 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002271 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002272 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002273 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002274 }
2275
2276 llndk_libraries_txt {
2277 name: "llndk.libraries.txt",
2278 }
2279 vndkcore_libraries_txt {
2280 name: "vndkcore.libraries.txt",
2281 }
2282 vndksp_libraries_txt {
2283 name: "vndksp.libraries.txt",
2284 }
2285 vndkprivate_libraries_txt {
2286 name: "vndkprivate.libraries.txt",
2287 }
2288 vndkcorevariant_libraries_txt {
2289 name: "vndkcorevariant.libraries.txt",
2290 insert_vndk_version: false,
2291 }
2292 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002293
2294 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002295 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2296 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2297 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002298 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002299
Colin Cross78212242021-01-06 14:51:30 -08002300 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2301 []string{"libvndk.so", "libvndkprivate.so"})
2302 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2303 []string{"libc++.so", "libvndksp.so"})
2304 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2305 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2306 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2307 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002308
Colin Crossfb0c16e2019-11-20 17:12:35 -08002309 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002310
Jooyung Han38002912019-05-16 04:01:54 +09002311 tests := []struct {
2312 variant string
2313 name string
2314 expected string
2315 }{
2316 {vendorVariant, "libvndk", "native:vndk"},
2317 {vendorVariant, "libvndksp", "native:vndk"},
2318 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2319 {vendorVariant, "libvendor", "native:vendor"},
2320 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002321 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002322 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002323 {coreVariant, "libvndk", "native:platform"},
2324 {coreVariant, "libvndkprivate", "native:platform"},
2325 {coreVariant, "libllndk", "native:platform"},
2326 }
2327 for _, test := range tests {
2328 t.Run(test.name, func(t *testing.T) {
2329 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2330 assertString(t, module.makeLinkType, test.expected)
2331 })
2332 }
2333}
2334
Jeff Gaston294356f2017-09-27 17:05:30 -07002335var staticLinkDepOrderTestCases = []struct {
2336 // This is a string representation of a map[moduleName][]moduleDependency .
2337 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002338 inStatic string
2339
2340 // This is a string representation of a map[moduleName][]moduleDependency .
2341 // It models the dependencies declared in an Android.bp file.
2342 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002343
2344 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2345 // The keys of allOrdered specify which modules we would like to check.
2346 // The values of allOrdered specify the expected result (of the transitive closure of all
2347 // dependencies) for each module to test
2348 allOrdered string
2349
2350 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2351 // The keys of outOrdered specify which modules we would like to check.
2352 // The values of outOrdered specify the expected result (of the ordered linker command line)
2353 // for each module to test.
2354 outOrdered string
2355}{
2356 // Simple tests
2357 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002358 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002359 outOrdered: "",
2360 },
2361 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002362 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002363 outOrdered: "a:",
2364 },
2365 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002366 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002367 outOrdered: "a:b; b:",
2368 },
2369 // Tests of reordering
2370 {
2371 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002372 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002373 outOrdered: "a:b,c,d; b:d; c:d; d:",
2374 },
2375 {
2376 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002377 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002378 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2379 },
2380 {
2381 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002382 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002383 outOrdered: "a:d,b,e,c; d:b; e:c",
2384 },
2385 {
2386 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002387 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002388 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2389 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2390 },
2391 {
2392 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002393 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 -07002394 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2395 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2396 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002397 // shared dependencies
2398 {
2399 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2400 // So, we don't actually have to check that a shared dependency of c will change the order
2401 // of a library that depends statically on b and on c. We only need to check that if c has
2402 // a shared dependency on b, that that shows up in allOrdered.
2403 inShared: "c:b",
2404 allOrdered: "c:b",
2405 outOrdered: "c:",
2406 },
2407 {
2408 // This test doesn't actually include any shared dependencies but it's a reminder of what
2409 // the second phase of the above test would look like
2410 inStatic: "a:b,c; c:b",
2411 allOrdered: "a:c,b; c:b",
2412 outOrdered: "a:c,b; c:b",
2413 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002414 // tiebreakers for when two modules specifying different orderings and there is no dependency
2415 // to dictate an order
2416 {
2417 // 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 -08002418 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002419 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2420 },
2421 {
2422 // 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 -08002423 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 -07002424 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2425 },
2426 // Tests involving duplicate dependencies
2427 {
2428 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002429 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002430 outOrdered: "a:c,b",
2431 },
2432 {
2433 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002434 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002435 outOrdered: "a:d,c,b",
2436 },
2437 // Tests to confirm the nonexistence of infinite loops.
2438 // These cases should never happen, so as long as the test terminates and the
2439 // result is deterministic then that should be fine.
2440 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002441 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002442 outOrdered: "a:a",
2443 },
2444 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002445 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002446 allOrdered: "a:b,c; b:c,a; c:a,b",
2447 outOrdered: "a:b; b:c; c:a",
2448 },
2449 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002450 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002451 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2452 outOrdered: "a:c,b; b:a,c; c:b,a",
2453 },
2454}
2455
2456// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2457func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2458 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2459 strippedText := strings.Replace(text, " ", "", -1)
2460 if len(strippedText) < 1 {
2461 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2462 }
2463 allDeps = make(map[android.Path][]android.Path, 0)
2464
2465 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2466 moduleTexts := strings.Split(strippedText, ";")
2467
2468 outputForModuleName := func(moduleName string) android.Path {
2469 return android.PathForTesting(moduleName)
2470 }
2471
2472 for _, moduleText := range moduleTexts {
2473 // convert from "a:b,c" to ["a", "b,c"]
2474 components := strings.Split(moduleText, ":")
2475 if len(components) != 2 {
2476 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2477 }
2478 moduleName := components[0]
2479 moduleOutput := outputForModuleName(moduleName)
2480 modulesInOrder = append(modulesInOrder, moduleOutput)
2481
2482 depString := components[1]
2483 // convert from "b,c" to ["b", "c"]
2484 depNames := strings.Split(depString, ",")
2485 if len(depString) < 1 {
2486 depNames = []string{}
2487 }
2488 var deps []android.Path
2489 for _, depName := range depNames {
2490 deps = append(deps, outputForModuleName(depName))
2491 }
2492 allDeps[moduleOutput] = deps
2493 }
2494 return modulesInOrder, allDeps
2495}
2496
Jeff Gaston294356f2017-09-27 17:05:30 -07002497func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2498 for _, moduleName := range moduleNames {
2499 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2500 output := module.outputFile.Path()
2501 paths = append(paths, output)
2502 }
2503 return paths
2504}
2505
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002506func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002507 ctx := testCc(t, `
2508 cc_library {
2509 name: "a",
2510 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002511 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002512 }
2513 cc_library {
2514 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002515 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002516 }
2517 cc_library {
2518 name: "c",
2519 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002520 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002521 }
2522 cc_library {
2523 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002524 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002525 }
2526
2527 `)
2528
Colin Cross7113d202019-11-20 16:39:12 -08002529 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002530 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002531 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2532 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002533
2534 if !reflect.DeepEqual(actual, expected) {
2535 t.Errorf("staticDeps orderings were not propagated correctly"+
2536 "\nactual: %v"+
2537 "\nexpected: %v",
2538 actual,
2539 expected,
2540 )
2541 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002542}
Jeff Gaston294356f2017-09-27 17:05:30 -07002543
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002544func TestStaticLibDepReorderingWithShared(t *testing.T) {
2545 ctx := testCc(t, `
2546 cc_library {
2547 name: "a",
2548 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002549 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002550 }
2551 cc_library {
2552 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002553 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002554 }
2555 cc_library {
2556 name: "c",
2557 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002558 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002559 }
2560
2561 `)
2562
Colin Cross7113d202019-11-20 16:39:12 -08002563 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002564 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002565 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2566 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002567
2568 if !reflect.DeepEqual(actual, expected) {
2569 t.Errorf("staticDeps orderings did not account for shared libs"+
2570 "\nactual: %v"+
2571 "\nexpected: %v",
2572 actual,
2573 expected,
2574 )
2575 }
2576}
2577
Jooyung Hanb04a4992020-03-13 18:57:35 +09002578func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002579 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002580 if !reflect.DeepEqual(actual, expected) {
2581 t.Errorf(message+
2582 "\nactual: %v"+
2583 "\nexpected: %v",
2584 actual,
2585 expected,
2586 )
2587 }
2588}
2589
Jooyung Han61b66e92020-03-21 14:21:46 +00002590func TestLlndkLibrary(t *testing.T) {
2591 ctx := testCc(t, `
2592 cc_library {
2593 name: "libllndk",
2594 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002595 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002596 }
2597 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002598 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002599 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002600
2601 cc_prebuilt_library_shared {
2602 name: "libllndkprebuilt",
2603 stubs: { versions: ["1", "2"] },
2604 llndk_stubs: "libllndkprebuilt.llndk",
2605 }
2606 llndk_library {
2607 name: "libllndkprebuilt.llndk",
2608 }
2609
2610 cc_library {
2611 name: "libllndk_with_external_headers",
2612 stubs: { versions: ["1", "2"] },
2613 llndk_stubs: "libllndk_with_external_headers.llndk",
2614 header_libs: ["libexternal_headers"],
2615 export_header_lib_headers: ["libexternal_headers"],
2616 }
2617 llndk_library {
2618 name: "libllndk_with_external_headers.llndk",
2619 }
2620 cc_library_headers {
2621 name: "libexternal_headers",
2622 export_include_dirs: ["include"],
2623 vendor_available: true,
2624 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002625 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002626 actual := ctx.ModuleVariantsForTests("libllndk")
2627 for i := 0; i < len(actual); i++ {
2628 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
2629 actual = append(actual[:i], actual[i+1:]...)
2630 i--
2631 }
2632 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002633 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00002634 "android_vendor.VER_arm64_armv8-a_shared_1",
2635 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002636 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002637 "android_vendor.VER_arm_armv7-a-neon_shared_1",
2638 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002639 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002640 }
2641 checkEquals(t, "variants for llndk stubs", expected, actual)
2642
Colin Cross127bb8b2020-12-16 16:46:01 -08002643 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002644 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2645
Colin Cross127bb8b2020-12-16 16:46:01 -08002646 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002647 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2648}
2649
Jiyong Parka46a4d52017-12-14 19:54:34 +09002650func TestLlndkHeaders(t *testing.T) {
2651 ctx := testCc(t, `
2652 llndk_headers {
2653 name: "libllndk_headers",
2654 export_include_dirs: ["my_include"],
2655 }
2656 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002657 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002658 export_llndk_headers: ["libllndk_headers"],
2659 }
2660 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002661 name: "libllndk",
2662 llndk_stubs: "libllndk.llndk",
2663 }
2664
2665 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002666 name: "libvendor",
2667 shared_libs: ["libllndk"],
2668 vendor: true,
2669 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002670 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002671 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002672 }
2673 `)
2674
2675 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002676 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002677 cflags := cc.Args["cFlags"]
2678 if !strings.Contains(cflags, "-Imy_include") {
2679 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2680 }
2681}
2682
Logan Chien43d34c32017-12-20 01:17:32 +08002683func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2684 actual := module.Properties.AndroidMkRuntimeLibs
2685 if !reflect.DeepEqual(actual, expected) {
2686 t.Errorf("incorrect runtime_libs for shared libs"+
2687 "\nactual: %v"+
2688 "\nexpected: %v",
2689 actual,
2690 expected,
2691 )
2692 }
2693}
2694
2695const runtimeLibAndroidBp = `
2696 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002697 name: "liball_available",
2698 vendor_available: true,
2699 product_available: true,
2700 no_libcrt : true,
2701 nocrt : true,
2702 system_shared_libs : [],
2703 }
2704 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002705 name: "libvendor_available1",
2706 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002707 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002708 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002709 nocrt : true,
2710 system_shared_libs : [],
2711 }
2712 cc_library {
2713 name: "libvendor_available2",
2714 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002715 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002716 target: {
2717 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002718 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002719 }
2720 },
Yi Konge7fe9912019-06-02 00:53:50 -07002721 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002722 nocrt : true,
2723 system_shared_libs : [],
2724 }
2725 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002726 name: "libproduct_vendor",
2727 product_specific: true,
2728 vendor_available: true,
2729 no_libcrt : true,
2730 nocrt : true,
2731 system_shared_libs : [],
2732 }
2733 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002734 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002735 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002736 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002737 nocrt : true,
2738 system_shared_libs : [],
2739 }
2740 cc_library {
2741 name: "libvendor1",
2742 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002743 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002744 nocrt : true,
2745 system_shared_libs : [],
2746 }
2747 cc_library {
2748 name: "libvendor2",
2749 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002750 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002751 no_libcrt : true,
2752 nocrt : true,
2753 system_shared_libs : [],
2754 }
2755 cc_library {
2756 name: "libproduct_available1",
2757 product_available: true,
2758 runtime_libs: ["liball_available"],
2759 no_libcrt : true,
2760 nocrt : true,
2761 system_shared_libs : [],
2762 }
2763 cc_library {
2764 name: "libproduct1",
2765 product_specific: true,
2766 no_libcrt : true,
2767 nocrt : true,
2768 system_shared_libs : [],
2769 }
2770 cc_library {
2771 name: "libproduct2",
2772 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002773 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002774 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002775 nocrt : true,
2776 system_shared_libs : [],
2777 }
2778`
2779
2780func TestRuntimeLibs(t *testing.T) {
2781 ctx := testCc(t, runtimeLibAndroidBp)
2782
2783 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002784 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002785
Justin Yun8a2600c2020-12-07 12:44:03 +09002786 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2787 checkRuntimeLibs(t, []string{"liball_available"}, module)
2788
2789 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2790 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002791
2792 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002793 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002794
2795 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2796 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002797 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002798
Justin Yun8a2600c2020-12-07 12:44:03 +09002799 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2800 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002801
2802 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002803 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002804
2805 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2806 // and product variants.
2807 variant = "android_product.VER_arm64_armv8-a_shared"
2808
2809 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2810 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2811
2812 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002813 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002814}
2815
2816func TestExcludeRuntimeLibs(t *testing.T) {
2817 ctx := testCc(t, runtimeLibAndroidBp)
2818
Colin Cross7113d202019-11-20 16:39:12 -08002819 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002820 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2821 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002822
Colin Crossfb0c16e2019-11-20 17:12:35 -08002823 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002824 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002825 checkRuntimeLibs(t, nil, module)
2826}
2827
2828func TestRuntimeLibsNoVndk(t *testing.T) {
2829 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2830
2831 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2832
Colin Cross7113d202019-11-20 16:39:12 -08002833 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002834
Justin Yun8a2600c2020-12-07 12:44:03 +09002835 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2836 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002837
2838 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002839 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002840
2841 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002842 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002843}
2844
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002845func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002846 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002847 actual := module.Properties.AndroidMkStaticLibs
2848 if !reflect.DeepEqual(actual, expected) {
2849 t.Errorf("incorrect static_libs"+
2850 "\nactual: %v"+
2851 "\nexpected: %v",
2852 actual,
2853 expected,
2854 )
2855 }
2856}
2857
2858const staticLibAndroidBp = `
2859 cc_library {
2860 name: "lib1",
2861 }
2862 cc_library {
2863 name: "lib2",
2864 static_libs: ["lib1"],
2865 }
2866`
2867
2868func TestStaticLibDepExport(t *testing.T) {
2869 ctx := testCc(t, staticLibAndroidBp)
2870
2871 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002872 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002873 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002874 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002875
2876 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002877 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002878 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2879 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002880 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002881}
2882
Jiyong Parkd08b6972017-09-26 10:50:54 +09002883var compilerFlagsTestCases = []struct {
2884 in string
2885 out bool
2886}{
2887 {
2888 in: "a",
2889 out: false,
2890 },
2891 {
2892 in: "-a",
2893 out: true,
2894 },
2895 {
2896 in: "-Ipath/to/something",
2897 out: false,
2898 },
2899 {
2900 in: "-isystempath/to/something",
2901 out: false,
2902 },
2903 {
2904 in: "--coverage",
2905 out: false,
2906 },
2907 {
2908 in: "-include a/b",
2909 out: true,
2910 },
2911 {
2912 in: "-include a/b c/d",
2913 out: false,
2914 },
2915 {
2916 in: "-DMACRO",
2917 out: true,
2918 },
2919 {
2920 in: "-DMAC RO",
2921 out: false,
2922 },
2923 {
2924 in: "-a -b",
2925 out: false,
2926 },
2927 {
2928 in: "-DMACRO=definition",
2929 out: true,
2930 },
2931 {
2932 in: "-DMACRO=defi nition",
2933 out: true, // TODO(jiyong): this should be false
2934 },
2935 {
2936 in: "-DMACRO(x)=x + 1",
2937 out: true,
2938 },
2939 {
2940 in: "-DMACRO=\"defi nition\"",
2941 out: true,
2942 },
2943}
2944
2945type mockContext struct {
2946 BaseModuleContext
2947 result bool
2948}
2949
2950func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2951 // CheckBadCompilerFlags calls this function when the flag should be rejected
2952 ctx.result = false
2953}
2954
2955func TestCompilerFlags(t *testing.T) {
2956 for _, testCase := range compilerFlagsTestCases {
2957 ctx := &mockContext{result: true}
2958 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2959 if ctx.result != testCase.out {
2960 t.Errorf("incorrect output:")
2961 t.Errorf(" input: %#v", testCase.in)
2962 t.Errorf(" expected: %#v", testCase.out)
2963 t.Errorf(" got: %#v", ctx.result)
2964 }
2965 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002966}
Jiyong Park374510b2018-03-19 18:23:01 +09002967
2968func TestVendorPublicLibraries(t *testing.T) {
2969 ctx := testCc(t, `
2970 cc_library_headers {
2971 name: "libvendorpublic_headers",
2972 export_include_dirs: ["my_include"],
2973 }
2974 vendor_public_library {
2975 name: "libvendorpublic",
2976 symbol_file: "",
2977 export_public_headers: ["libvendorpublic_headers"],
2978 }
2979 cc_library {
2980 name: "libvendorpublic",
2981 srcs: ["foo.c"],
2982 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002983 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002984 nocrt: true,
2985 }
2986
2987 cc_library {
2988 name: "libsystem",
2989 shared_libs: ["libvendorpublic"],
2990 vendor: false,
2991 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002992 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002993 nocrt: true,
2994 }
2995 cc_library {
2996 name: "libvendor",
2997 shared_libs: ["libvendorpublic"],
2998 vendor: true,
2999 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003000 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003001 nocrt: true,
3002 }
3003 `)
3004
Colin Cross7113d202019-11-20 16:39:12 -08003005 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003006 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003007
3008 // test if header search paths are correctly added
3009 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003010 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003011 cflags := cc.Args["cFlags"]
3012 if !strings.Contains(cflags, "-Imy_include") {
3013 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3014 }
3015
3016 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003017 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003018 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003019 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003020 if !strings.Contains(libflags, stubPaths[0].String()) {
3021 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3022 }
3023
3024 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003025 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003026 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003027 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003028 if !strings.Contains(libflags, stubPaths[0].String()) {
3029 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3030 }
3031
3032}
Jiyong Park37b25202018-07-11 10:49:27 +09003033
3034func TestRecovery(t *testing.T) {
3035 ctx := testCc(t, `
3036 cc_library_shared {
3037 name: "librecovery",
3038 recovery: true,
3039 }
3040 cc_library_shared {
3041 name: "librecovery32",
3042 recovery: true,
3043 compile_multilib:"32",
3044 }
Jiyong Park5baac542018-08-28 09:55:37 +09003045 cc_library_shared {
3046 name: "libHalInRecovery",
3047 recovery_available: true,
3048 vendor: true,
3049 }
Jiyong Park37b25202018-07-11 10:49:27 +09003050 `)
3051
3052 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003053 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003054 if len(variants) != 1 || !android.InList(arm64, variants) {
3055 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3056 }
3057
3058 variants = ctx.ModuleVariantsForTests("librecovery32")
3059 if android.InList(arm64, variants) {
3060 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3061 }
Jiyong Park5baac542018-08-28 09:55:37 +09003062
3063 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3064 if !recoveryModule.Platform() {
3065 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3066 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003067}
Jiyong Park5baac542018-08-28 09:55:37 +09003068
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003069func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3070 bp := `
3071 cc_prebuilt_test_library_shared {
3072 name: "test_lib",
3073 relative_install_path: "foo/bar/baz",
3074 srcs: ["srcpath/dontusethispath/baz.so"],
3075 }
3076
3077 cc_test {
3078 name: "main_test",
3079 data_libs: ["test_lib"],
3080 gtest: false,
3081 }
3082 `
3083
3084 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3085 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3086 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3087 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3088
3089 ctx := testCcWithConfig(t, config)
3090 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3091 testBinary := module.(*Module).linker.(*testBinary)
3092 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3093 if err != nil {
3094 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3095 }
3096 if len(outputFiles) != 1 {
3097 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3098 }
3099 if len(testBinary.dataPaths()) != 1 {
3100 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3101 }
3102
3103 outputPath := outputFiles[0].String()
3104
3105 if !strings.HasSuffix(outputPath, "/main_test") {
3106 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3107 }
3108 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3109 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3110 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3111 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3112 }
3113}
3114
Jiyong Park7ed9de32018-10-15 22:25:07 +09003115func TestVersionedStubs(t *testing.T) {
3116 ctx := testCc(t, `
3117 cc_library_shared {
3118 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003119 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003120 stubs: {
3121 symbol_file: "foo.map.txt",
3122 versions: ["1", "2", "3"],
3123 },
3124 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003125
Jiyong Park7ed9de32018-10-15 22:25:07 +09003126 cc_library_shared {
3127 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003128 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003129 shared_libs: ["libFoo#1"],
3130 }`)
3131
3132 variants := ctx.ModuleVariantsForTests("libFoo")
3133 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003134 "android_arm64_armv8-a_shared",
3135 "android_arm64_armv8-a_shared_1",
3136 "android_arm64_armv8-a_shared_2",
3137 "android_arm64_armv8-a_shared_3",
3138 "android_arm_armv7-a-neon_shared",
3139 "android_arm_armv7-a-neon_shared_1",
3140 "android_arm_armv7-a-neon_shared_2",
3141 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003142 }
3143 variantsMismatch := false
3144 if len(variants) != len(expectedVariants) {
3145 variantsMismatch = true
3146 } else {
3147 for _, v := range expectedVariants {
3148 if !inList(v, variants) {
3149 variantsMismatch = false
3150 }
3151 }
3152 }
3153 if variantsMismatch {
3154 t.Errorf("variants of libFoo expected:\n")
3155 for _, v := range expectedVariants {
3156 t.Errorf("%q\n", v)
3157 }
3158 t.Errorf(", but got:\n")
3159 for _, v := range variants {
3160 t.Errorf("%q\n", v)
3161 }
3162 }
3163
Colin Cross7113d202019-11-20 16:39:12 -08003164 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003165 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003166 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003167 if !strings.Contains(libFlags, libFoo1StubPath) {
3168 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3169 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003170
Colin Cross7113d202019-11-20 16:39:12 -08003171 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003172 cFlags := libBarCompileRule.Args["cFlags"]
3173 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3174 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3175 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3176 }
Jiyong Park37b25202018-07-11 10:49:27 +09003177}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003178
Jooyung Hanb04a4992020-03-13 18:57:35 +09003179func TestVersioningMacro(t *testing.T) {
3180 for _, tc := range []struct{ moduleName, expected string }{
3181 {"libc", "__LIBC_API__"},
3182 {"libfoo", "__LIBFOO_API__"},
3183 {"libfoo@1", "__LIBFOO_1_API__"},
3184 {"libfoo-v1", "__LIBFOO_V1_API__"},
3185 {"libfoo.v1", "__LIBFOO_V1_API__"},
3186 } {
3187 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3188 }
3189}
3190
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003191func TestStaticExecutable(t *testing.T) {
3192 ctx := testCc(t, `
3193 cc_binary {
3194 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003195 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003196 static_executable: true,
3197 }`)
3198
Colin Cross7113d202019-11-20 16:39:12 -08003199 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003200 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3201 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003202 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003203 for _, lib := range systemStaticLibs {
3204 if !strings.Contains(libFlags, lib) {
3205 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3206 }
3207 }
3208 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3209 for _, lib := range systemSharedLibs {
3210 if strings.Contains(libFlags, lib) {
3211 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3212 }
3213 }
3214}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003215
3216func TestStaticDepsOrderWithStubs(t *testing.T) {
3217 ctx := testCc(t, `
3218 cc_binary {
3219 name: "mybin",
3220 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003221 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003222 static_executable: true,
3223 stl: "none",
3224 }
3225
3226 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003227 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003228 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003229 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003230 stl: "none",
3231 }
3232
3233 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003234 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003235 srcs: ["foo.c"],
3236 stl: "none",
3237 stubs: {
3238 versions: ["1"],
3239 },
3240 }`)
3241
Colin Cross0de8a1e2020-09-18 14:15:30 -07003242 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3243 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003244 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003245
3246 if !reflect.DeepEqual(actual, expected) {
3247 t.Errorf("staticDeps orderings were not propagated correctly"+
3248 "\nactual: %v"+
3249 "\nexpected: %v",
3250 actual,
3251 expected,
3252 )
3253 }
3254}
Jooyung Han38002912019-05-16 04:01:54 +09003255
Jooyung Hand48f3c32019-08-23 11:18:57 +09003256func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3257 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3258 cc_library {
3259 name: "libA",
3260 srcs: ["foo.c"],
3261 shared_libs: ["libB"],
3262 stl: "none",
3263 }
3264
3265 cc_library {
3266 name: "libB",
3267 srcs: ["foo.c"],
3268 enabled: false,
3269 stl: "none",
3270 }
3271 `)
3272}
3273
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003274// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3275// correctly.
3276func TestFuzzTarget(t *testing.T) {
3277 ctx := testCc(t, `
3278 cc_fuzz {
3279 name: "fuzz_smoke_test",
3280 srcs: ["foo.c"],
3281 }`)
3282
Paul Duffin075c4172019-12-19 19:06:13 +00003283 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003284 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3285}
3286
Jiyong Park29074592019-07-07 16:27:47 +09003287func TestAidl(t *testing.T) {
3288}
3289
Jooyung Han38002912019-05-16 04:01:54 +09003290func assertString(t *testing.T, got, expected string) {
3291 t.Helper()
3292 if got != expected {
3293 t.Errorf("expected %q got %q", expected, got)
3294 }
3295}
3296
3297func assertArrayString(t *testing.T, got, expected []string) {
3298 t.Helper()
3299 if len(got) != len(expected) {
3300 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3301 return
3302 }
3303 for i := range got {
3304 if got[i] != expected[i] {
3305 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3306 i, expected[i], expected, got[i], got)
3307 return
3308 }
3309 }
3310}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003311
Jooyung Han0302a842019-10-30 18:43:49 +09003312func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3313 t.Helper()
3314 assertArrayString(t, android.SortedStringKeys(m), expected)
3315}
3316
Colin Crosse1bb5d02019-09-24 14:55:04 -07003317func TestDefaults(t *testing.T) {
3318 ctx := testCc(t, `
3319 cc_defaults {
3320 name: "defaults",
3321 srcs: ["foo.c"],
3322 static: {
3323 srcs: ["bar.c"],
3324 },
3325 shared: {
3326 srcs: ["baz.c"],
3327 },
3328 }
3329
3330 cc_library_static {
3331 name: "libstatic",
3332 defaults: ["defaults"],
3333 }
3334
3335 cc_library_shared {
3336 name: "libshared",
3337 defaults: ["defaults"],
3338 }
3339
3340 cc_library {
3341 name: "libboth",
3342 defaults: ["defaults"],
3343 }
3344
3345 cc_binary {
3346 name: "binary",
3347 defaults: ["defaults"],
3348 }`)
3349
3350 pathsToBase := func(paths android.Paths) []string {
3351 var ret []string
3352 for _, p := range paths {
3353 ret = append(ret, p.Base())
3354 }
3355 return ret
3356 }
3357
Colin Cross7113d202019-11-20 16:39:12 -08003358 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003359 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3360 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3361 }
Colin Cross7113d202019-11-20 16:39:12 -08003362 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003363 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3364 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3365 }
Colin Cross7113d202019-11-20 16:39:12 -08003366 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003367 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3368 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3369 }
3370
Colin Cross7113d202019-11-20 16:39:12 -08003371 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003372 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3373 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3374 }
Colin Cross7113d202019-11-20 16:39:12 -08003375 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003376 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3377 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3378 }
3379}
Colin Crosseabaedd2020-02-06 17:01:55 -08003380
3381func TestProductVariableDefaults(t *testing.T) {
3382 bp := `
3383 cc_defaults {
3384 name: "libfoo_defaults",
3385 srcs: ["foo.c"],
3386 cppflags: ["-DFOO"],
3387 product_variables: {
3388 debuggable: {
3389 cppflags: ["-DBAR"],
3390 },
3391 },
3392 }
3393
3394 cc_library {
3395 name: "libfoo",
3396 defaults: ["libfoo_defaults"],
3397 }
3398 `
3399
3400 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3401 config.TestProductVariables.Debuggable = BoolPtr(true)
3402
Colin Crossae8600b2020-10-29 17:09:13 -07003403 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003404 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3405 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3406 })
Colin Crossae8600b2020-10-29 17:09:13 -07003407 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003408
3409 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3410 android.FailIfErrored(t, errs)
3411 _, errs = ctx.PrepareBuildActions(config)
3412 android.FailIfErrored(t, errs)
3413
3414 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3415 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3416 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3417 }
3418}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003419
3420func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3421 t.Parallel()
3422 bp := `
3423 cc_library_static {
3424 name: "libfoo",
3425 srcs: ["foo.c"],
3426 whole_static_libs: ["libbar"],
3427 }
3428
3429 cc_library_static {
3430 name: "libbar",
3431 whole_static_libs: ["libmissing"],
3432 }
3433 `
3434
3435 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3436 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3437
Colin Crossae8600b2020-10-29 17:09:13 -07003438 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003439 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003440 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003441
3442 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3443 android.FailIfErrored(t, errs)
3444 _, errs = ctx.PrepareBuildActions(config)
3445 android.FailIfErrored(t, errs)
3446
3447 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3448 if g, w := libbar.Rule, android.ErrorRule; g != w {
3449 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3450 }
3451
3452 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3453 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
3454 }
3455
3456 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
3457 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
3458 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
3459 }
3460
3461}
Colin Crosse9fe2942020-11-10 18:12:15 -08003462
3463func TestInstallSharedLibs(t *testing.T) {
3464 bp := `
3465 cc_binary {
3466 name: "bin",
3467 host_supported: true,
3468 shared_libs: ["libshared"],
3469 runtime_libs: ["libruntime"],
3470 srcs: [":gen"],
3471 }
3472
3473 cc_library_shared {
3474 name: "libshared",
3475 host_supported: true,
3476 shared_libs: ["libtransitive"],
3477 }
3478
3479 cc_library_shared {
3480 name: "libtransitive",
3481 host_supported: true,
3482 }
3483
3484 cc_library_shared {
3485 name: "libruntime",
3486 host_supported: true,
3487 }
3488
3489 cc_binary_host {
3490 name: "tool",
3491 srcs: ["foo.cpp"],
3492 }
3493
3494 genrule {
3495 name: "gen",
3496 tools: ["tool"],
3497 out: ["gen.cpp"],
3498 cmd: "$(location tool) $(out)",
3499 }
3500 `
3501
3502 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3503 ctx := testCcWithConfig(t, config)
3504
3505 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3506 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3507 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3508 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3509 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3510
3511 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3512 t.Errorf("expected host bin dependency %q, got %q", w, g)
3513 }
3514
3515 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3516 t.Errorf("expected host bin dependency %q, got %q", w, g)
3517 }
3518
3519 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3520 t.Errorf("expected host bin dependency %q, got %q", w, g)
3521 }
3522
3523 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3524 t.Errorf("expected host bin dependency %q, got %q", w, g)
3525 }
3526
3527 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3528 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3529 }
3530
3531 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3532 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3533 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3534 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3535
3536 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3537 t.Errorf("expected device bin dependency %q, got %q", w, g)
3538 }
3539
3540 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3541 t.Errorf("expected device bin dependency %q, got %q", w, g)
3542 }
3543
3544 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3545 t.Errorf("expected device bin dependency %q, got %q", w, g)
3546 }
3547
3548 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3549 t.Errorf("expected device bin dependency %q, got %q", w, g)
3550 }
3551
3552 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3553 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3554 }
3555
3556}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003557
3558func TestStubsLibReexportsHeaders(t *testing.T) {
3559 ctx := testCc(t, `
3560 cc_library_shared {
3561 name: "libclient",
3562 srcs: ["foo.c"],
3563 shared_libs: ["libfoo#1"],
3564 }
3565
3566 cc_library_shared {
3567 name: "libfoo",
3568 srcs: ["foo.c"],
3569 shared_libs: ["libbar"],
3570 export_shared_lib_headers: ["libbar"],
3571 stubs: {
3572 symbol_file: "foo.map.txt",
3573 versions: ["1", "2", "3"],
3574 },
3575 }
3576
3577 cc_library_shared {
3578 name: "libbar",
3579 export_include_dirs: ["include/libbar"],
3580 srcs: ["foo.c"],
3581 }`)
3582
3583 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3584
3585 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3586 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3587 }
3588}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003589
3590func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3591 ctx := testCc(t, `
3592 cc_library {
3593 name: "libfoo",
3594 srcs: ["a/Foo.aidl"],
3595 aidl: { flags: ["-Werror"], },
3596 }
3597 `)
3598
3599 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3600 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3601 aidlCommand := manifest.Commands[0].GetCommand()
3602 expectedAidlFlag := "-Werror"
3603 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3604 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3605 }
3606}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003607
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003608type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003609
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003610const (
3611 None MemtagNoteType = iota + 1
3612 Sync
3613 Async
3614)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003615
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003616func (t MemtagNoteType) str() string {
3617 switch t {
3618 case None:
3619 return "none"
3620 case Sync:
3621 return "sync"
3622 case Async:
3623 return "async"
3624 default:
3625 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003626 }
3627}
3628
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003629func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3630 note_async := "note_memtag_heap_async"
3631 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003632
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003633 found := None
3634 implicits := m.Rule("ld").Implicits
3635 for _, lib := range implicits {
3636 if strings.Contains(lib.Rel(), note_async) {
3637 found = Async
3638 break
3639 } else if strings.Contains(lib.Rel(), note_sync) {
3640 found = Sync
3641 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003642 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003643 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003644
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003645 if found != expected {
3646 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3647 }
3648}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003649
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003650func makeMemtagTestConfig(t *testing.T) android.Config {
3651 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003652 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003653 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003654 gtest: false,
3655 }
3656
3657 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003658 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003659 gtest: false,
3660 sanitize: { memtag_heap: false },
3661 }
3662
3663 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003664 name: "%[1]s_test_true",
3665 gtest: false,
3666 sanitize: { memtag_heap: true },
3667 }
3668
3669 cc_test {
3670 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003671 gtest: false,
3672 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3673 }
3674
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003675 cc_test {
3676 name: "%[1]s_test_true_diag",
3677 gtest: false,
3678 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3679 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003680
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003681 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003682 name: "%[1]s_binary",
3683 }
3684
3685 cc_binary {
3686 name: "%[1]s_binary_false",
3687 sanitize: { memtag_heap: false },
3688 }
3689
3690 cc_binary {
3691 name: "%[1]s_binary_true",
3692 sanitize: { memtag_heap: true },
3693 }
3694
3695 cc_binary {
3696 name: "%[1]s_binary_true_nodiag",
3697 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3698 }
3699
3700 cc_binary {
3701 name: "%[1]s_binary_true_diag",
3702 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003703 }
3704 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003705 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3706 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3707 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3708 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003709
3710 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003711 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3712 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3713 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3714 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003715 }
3716
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003717 return TestConfig(buildDir, android.Android, nil, "", mockFS)
3718}
3719
3720func TestSanitizeMemtagHeap(t *testing.T) {
3721 variant := "android_arm64_armv8-a"
3722
3723 config := makeMemtagTestConfig(t)
3724 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003725 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003726 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003727 ctx := CreateTestContext(config)
3728 ctx.Register()
3729
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003730 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003731 android.FailIfErrored(t, errs)
3732 _, errs = ctx.PrepareBuildActions(config)
3733 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003734
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003735 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3736 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3737 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3738 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3739 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3740
3741 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3742 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3743 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3744 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3745 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3746
3747 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3748 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3749 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3750 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3751 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3752
3753 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3754 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3755 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3756 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3757 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3758
3759 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3760 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3761 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3762 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3763 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3764
3765 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3766 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3767 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3768 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3769 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3770
3771 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3772 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3773 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3774 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3775 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3776
3777 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3778 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3779 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3780 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3781 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3782}
3783
3784func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003785 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003786
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003787 config := makeMemtagTestConfig(t)
3788 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3789 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3790 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3791 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3792 ctx := CreateTestContext(config)
3793 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003794
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003795 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3796 android.FailIfErrored(t, errs)
3797 _, errs = ctx.PrepareBuildActions(config)
3798 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003799
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003800 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3801 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3802 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3803 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3804 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003805
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003806 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3807 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3808 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3809 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3810 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3811
3812 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3813 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3814 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3815 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3816 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3817
3818 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3819 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3820 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3821 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3822 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3823
3824 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3825 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3826 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3827 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3828 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3829
3830 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3831 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3832 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3833 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3834 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3835
3836 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3837 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3838 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3839 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3840 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3841
3842 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3843 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3844 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3845 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3846 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3847}
3848
3849func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3850 variant := "android_arm64_armv8-a"
3851
3852 config := makeMemtagTestConfig(t)
3853 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3854 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3855 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3856 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3857 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
3858 ctx := CreateTestContext(config)
3859 ctx.Register()
3860
3861 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3862 android.FailIfErrored(t, errs)
3863 _, errs = ctx.PrepareBuildActions(config)
3864 android.FailIfErrored(t, errs)
3865
3866 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3869 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3870 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3871
3872 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3873 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3874 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3875 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3876 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3877
3878 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3879 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3880 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3881 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3882 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3883
3884 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3885 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3886 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3887 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3888 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3889
3890 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3892 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3893 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3894 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3895
3896 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3898 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3899 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3900 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3901
3902 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3903 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3904 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3905 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3906 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3907
3908 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3909 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3910 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3911 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3912 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003913}
Paul Duffin3cb603e2021-02-19 13:57:10 +00003914
3915func TestIncludeDirsExporting(t *testing.T) {
3916
3917 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
3918 // embedded newline characters alone.
3919 trimIndentingSpaces := func(s string) string {
3920 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
3921 }
3922
3923 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
3924 t.Helper()
3925 expected = trimIndentingSpaces(expected)
3926 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
3927 if expected != actual {
3928 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
3929 }
3930 }
3931
3932 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
3933
3934 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
3935 t.Helper()
3936 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
3937 name := module.Name()
3938
3939 for _, checker := range checkers {
3940 checker(t, name, exported)
3941 }
3942 }
3943
3944 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
3945 return func(t *testing.T, name string, exported FlagExporterInfo) {
3946 t.Helper()
3947 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
3948 }
3949 }
3950
3951 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
3952 return func(t *testing.T, name string, exported FlagExporterInfo) {
3953 t.Helper()
3954 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
3955 }
3956 }
3957
3958 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
3959 return func(t *testing.T, name string, exported FlagExporterInfo) {
3960 t.Helper()
3961 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
3962 }
3963 }
3964
3965 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
3966 return func(t *testing.T, name string, exported FlagExporterInfo) {
3967 t.Helper()
3968 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
3969 }
3970 }
3971
3972 genRuleModules := `
3973 genrule {
3974 name: "genrule_foo",
3975 cmd: "generate-foo",
3976 out: [
3977 "generated_headers/foo/generated_header.h",
3978 ],
3979 export_include_dirs: [
3980 "generated_headers",
3981 ],
3982 }
3983
3984 genrule {
3985 name: "genrule_bar",
3986 cmd: "generate-bar",
3987 out: [
3988 "generated_headers/bar/generated_header.h",
3989 ],
3990 export_include_dirs: [
3991 "generated_headers",
3992 ],
3993 }
3994 `
3995
3996 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
3997 ctx := testCc(t, genRuleModules+`
3998 cc_library {
3999 name: "libfoo",
4000 srcs: ["foo.c"],
4001 export_include_dirs: ["foo/standard"],
4002 export_system_include_dirs: ["foo/system"],
4003 generated_headers: ["genrule_foo"],
4004 export_generated_headers: ["genrule_foo"],
4005 }
4006
4007 cc_library {
4008 name: "libbar",
4009 srcs: ["bar.c"],
4010 shared_libs: ["libfoo"],
4011 export_include_dirs: ["bar/standard"],
4012 export_system_include_dirs: ["bar/system"],
4013 generated_headers: ["genrule_bar"],
4014 export_generated_headers: ["genrule_bar"],
4015 }
4016 `)
4017 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4018 checkIncludeDirs(t, ctx, foo,
4019 expectedIncludeDirs(`
4020 foo/standard
4021 .intermediates/genrule_foo/gen/generated_headers
4022 `),
4023 expectedSystemIncludeDirs(`foo/system`),
4024 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4025 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4026 )
4027
4028 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4029 checkIncludeDirs(t, ctx, bar,
4030 expectedIncludeDirs(`
4031 bar/standard
4032 .intermediates/genrule_bar/gen/generated_headers
4033 `),
4034 expectedSystemIncludeDirs(`bar/system`),
4035 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4036 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4037 )
4038 })
4039
4040 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
4041 ctx := testCc(t, genRuleModules+`
4042 cc_library {
4043 name: "libfoo",
4044 srcs: ["foo.c"],
4045 export_include_dirs: ["foo/standard"],
4046 export_system_include_dirs: ["foo/system"],
4047 generated_headers: ["genrule_foo"],
4048 export_generated_headers: ["genrule_foo"],
4049 }
4050
4051 cc_library {
4052 name: "libbar",
4053 srcs: ["bar.c"],
4054 whole_static_libs: ["libfoo"],
4055 export_include_dirs: ["bar/standard"],
4056 export_system_include_dirs: ["bar/system"],
4057 generated_headers: ["genrule_bar"],
4058 export_generated_headers: ["genrule_bar"],
4059 }
4060 `)
4061 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4062 checkIncludeDirs(t, ctx, foo,
4063 expectedIncludeDirs(`
4064 foo/standard
4065 .intermediates/genrule_foo/gen/generated_headers
4066 `),
4067 expectedSystemIncludeDirs(`foo/system`),
4068 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4069 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4070 )
4071
4072 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4073 checkIncludeDirs(t, ctx, bar,
4074 expectedIncludeDirs(`
4075 bar/standard
4076 foo/standard
4077 .intermediates/genrule_foo/gen/generated_headers
4078 .intermediates/genrule_bar/gen/generated_headers
4079 `),
4080 expectedSystemIncludeDirs(`
4081 bar/system
4082 foo/system
4083 `),
4084 expectedGeneratedHeaders(`
4085 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4086 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4087 `),
4088 expectedOrderOnlyDeps(`
4089 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4090 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4091 `),
4092 )
4093 })
4094
Paul Duffin3cb603e2021-02-19 13:57:10 +00004095 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
4096 ctx := testCc(t, genRuleModules+`
4097 cc_library_shared {
4098 name: "libfoo",
4099 srcs: [
4100 "foo.c",
4101 "b.aidl",
4102 "a.proto",
4103 ],
4104 aidl: {
4105 export_aidl_headers: true,
4106 }
4107 }
4108 `)
4109 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4110 checkIncludeDirs(t, ctx, foo,
4111 expectedIncludeDirs(`
4112 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
4113 `),
4114 expectedSystemIncludeDirs(``),
4115 expectedGeneratedHeaders(`
4116 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4117 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4118 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004119 `),
4120 expectedOrderOnlyDeps(`
4121 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4122 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4123 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004124 `),
4125 )
4126 })
4127
Paul Duffin3cb603e2021-02-19 13:57:10 +00004128 t.Run("ensure only proto headers are exported", func(t *testing.T) {
4129 ctx := testCc(t, genRuleModules+`
4130 cc_library_shared {
4131 name: "libfoo",
4132 srcs: [
4133 "foo.c",
4134 "b.aidl",
4135 "a.proto",
4136 ],
4137 proto: {
4138 export_proto_headers: true,
4139 }
4140 }
4141 `)
4142 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4143 checkIncludeDirs(t, ctx, foo,
4144 expectedIncludeDirs(`
4145 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
4146 `),
4147 expectedSystemIncludeDirs(``),
4148 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004149 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4150 `),
4151 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004152 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4153 `),
4154 )
4155 })
4156
Paul Duffin33056e82021-02-19 13:49:08 +00004157 // TODO fix this test as it exports the sysprop public and non-public headers irrespective of
4158 // which include directory is exported.
4159 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00004160 ctx := testCc(t, genRuleModules+`
4161 cc_library_shared {
4162 name: "libfoo",
4163 srcs: [
4164 "foo.c",
4165 "a.sysprop",
4166 "b.aidl",
4167 "a.proto",
4168 ],
4169 }
4170 `)
4171 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4172 checkIncludeDirs(t, ctx, foo,
4173 expectedIncludeDirs(`
4174 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
4175 `),
4176 expectedSystemIncludeDirs(``),
4177 expectedGeneratedHeaders(`
4178 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4179 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004180 `),
4181 expectedOrderOnlyDeps(`
4182 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4183 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004184 `),
4185 )
4186 })
4187}