blob: 6d7ad39efb26a4ea6976c51caedd8ebce3448c9e [file] [log] [blame]
Colin Crossd00350c2017-11-17 10:55:38 -08001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross74d1ec02015-04-28 13:30:13 -070015package cc
16
17import (
Jeff Gaston294356f2017-09-27 17:05:30 -070018 "fmt"
Jiyong Park6a43f042017-10-12 23:05:00 +090019 "io/ioutil"
20 "os"
Inseob Kim1f086e22019-05-09 13:29:15 +090021 "path/filepath"
Colin Cross74d1ec02015-04-28 13:30:13 -070022 "reflect"
Jeff Gaston294356f2017-09-27 17:05:30 -070023 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070024 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070025
26 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070027)
28
Jiyong Park6a43f042017-10-12 23:05:00 +090029var buildDir string
30
31func setUp() {
32 var err error
33 buildDir, err = ioutil.TempDir("", "soong_cc_test")
34 if err != nil {
35 panic(err)
36 }
37}
38
39func tearDown() {
40 os.RemoveAll(buildDir)
41}
42
43func TestMain(m *testing.M) {
44 run := func() int {
45 setUp()
46 defer tearDown()
47
48 return m.Run()
49 }
50
51 os.Exit(run())
52}
53
Colin Cross98be1bb2019-12-13 20:41:13 -080054func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070055 t.Helper()
Colin Crossae8600b2020-10-29 17:09:13 -070056 ctx := CreateTestContext(config)
57 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080058
Jeff Gastond3e141d2017-08-08 17:46:01 -070059 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +080060 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090061 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +080062 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090063
64 return ctx
65}
66
Logan Chienf3511742017-10-31 18:04:35 +080067func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080068 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080069 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070070 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun8a2600c2020-12-07 12:44:03 +090071 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Dan Willemsen674dc7f2018-03-12 18:06:05 -070072 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080073
Colin Cross98be1bb2019-12-13 20:41:13 -080074 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080075}
76
77func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080078 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080079 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070080 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080081
Colin Cross98be1bb2019-12-13 20:41:13 -080082 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080083}
84
Justin Yun8a2600c2020-12-07 12:44:03 +090085func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
86 t.Helper()
87 config := TestConfig(buildDir, android.Android, nil, bp, nil)
88 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
89 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
90
91 return testCcWithConfig(t, config)
92}
93
Justin Yun5f7f7e82019-11-18 19:52:14 +090094func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +080095 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080096
Colin Crossae8600b2020-10-29 17:09:13 -070097 ctx := CreateTestContext(config)
98 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080099
100 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
101 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800102 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800103 return
104 }
105
106 _, errs = ctx.PrepareBuildActions(config)
107 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800108 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800109 return
110 }
111
112 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
113}
114
Justin Yun5f7f7e82019-11-18 19:52:14 +0900115func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900116 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900117 config := TestConfig(buildDir, android.Android, nil, bp, nil)
118 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
119 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
120 testCcErrorWithConfig(t, pattern, config)
121 return
122}
123
124func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900125 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900126 config := TestConfig(buildDir, android.Android, nil, bp, nil)
127 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
128 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
129 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
130 testCcErrorWithConfig(t, pattern, config)
131 return
132}
133
Logan Chienf3511742017-10-31 18:04:35 +0800134const (
Colin Cross7113d202019-11-20 16:39:12 -0800135 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800136 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900137 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800138 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800139)
140
Doug Hornc32c6b02019-01-17 14:44:05 -0800141func TestFuchsiaDeps(t *testing.T) {
142 t.Helper()
143
144 bp := `
145 cc_library {
146 name: "libTest",
147 srcs: ["foo.c"],
148 target: {
149 fuchsia: {
150 srcs: ["bar.c"],
151 },
152 },
153 }`
154
Colin Cross98be1bb2019-12-13 20:41:13 -0800155 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
156 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800157
158 rt := false
159 fb := false
160
161 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
162 implicits := ld.Implicits
163 for _, lib := range implicits {
164 if strings.Contains(lib.Rel(), "libcompiler_rt") {
165 rt = true
166 }
167
168 if strings.Contains(lib.Rel(), "libbioniccompat") {
169 fb = true
170 }
171 }
172
173 if !rt || !fb {
174 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
175 }
176}
177
178func TestFuchsiaTargetDecl(t *testing.T) {
179 t.Helper()
180
181 bp := `
182 cc_library {
183 name: "libTest",
184 srcs: ["foo.c"],
185 target: {
186 fuchsia: {
187 srcs: ["bar.c"],
188 },
189 },
190 }`
191
Colin Cross98be1bb2019-12-13 20:41:13 -0800192 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
193 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800194 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
195 var objs []string
196 for _, o := range ld.Inputs {
197 objs = append(objs, o.Base())
198 }
199 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
200 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
201 }
202}
203
Jiyong Park6a43f042017-10-12 23:05:00 +0900204func TestVendorSrc(t *testing.T) {
205 ctx := testCc(t, `
206 cc_library {
207 name: "libTest",
208 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700209 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800210 nocrt: true,
211 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900212 vendor_available: true,
213 target: {
214 vendor: {
215 srcs: ["bar.c"],
216 },
217 },
218 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900219 `)
220
Logan Chienf3511742017-10-31 18:04:35 +0800221 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900222 var objs []string
223 for _, o := range ld.Inputs {
224 objs = append(objs, o.Base())
225 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800226 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900227 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
228 }
229}
230
Logan Chienf3511742017-10-31 18:04:35 +0800231func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900232 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800233
Logan Chiend3c59a22018-03-29 14:08:15 +0800234 t.Helper()
235
Justin Yun0ecf0b22020-02-28 15:07:59 +0900236 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Logan Chienf3511742017-10-31 18:04:35 +0800237
238 // Check library properties.
239 lib, ok := mod.compiler.(*libraryDecorator)
240 if !ok {
241 t.Errorf("%q must have libraryDecorator", name)
242 } else if lib.baseInstaller.subDir != subDir {
243 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
244 lib.baseInstaller.subDir)
245 }
246
247 // Check VNDK properties.
248 if mod.vndkdep == nil {
249 t.Fatalf("%q must have `vndkdep`", name)
250 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700251 if !mod.IsVndk() {
252 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800253 }
254 if mod.isVndkSp() != isVndkSp {
255 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
256 }
257
258 // Check VNDK extension properties.
259 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500260 if mod.IsVndkExt() != isVndkExt {
261 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800262 }
263
264 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
265 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
266 }
267}
268
Jose Galmes0a942a02021-02-03 14:23:15 -0800269func 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 -0700270 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900271 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
272 if !ok {
273 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900274 return
275 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900276 outputFiles, err := mod.OutputFiles("")
277 if err != nil || len(outputFiles) != 1 {
278 t.Errorf("%q must have single output\n", moduleName)
279 return
280 }
281 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900282
Bill Peckham945441c2020-08-31 16:07:58 -0700283 if include {
284 out := singleton.Output(snapshotPath)
Jose Galmes0a942a02021-02-03 14:23:15 -0800285 if fake {
286 if out.Rule == nil {
287 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
288 }
289 } else {
290 if out.Input.String() != outputFiles[0].String() {
291 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
292 }
Bill Peckham945441c2020-08-31 16:07:58 -0700293 }
294 } else {
295 out := singleton.MaybeOutput(snapshotPath)
296 if out.Rule != nil {
297 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
298 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900299 }
300}
301
Bill Peckham945441c2020-08-31 16:07:58 -0700302func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800303 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
Bill Peckham945441c2020-08-31 16:07:58 -0700304}
305
306func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800307 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
308}
309
310func checkSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
311 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
Bill Peckham945441c2020-08-31 16:07:58 -0700312}
313
Jooyung Han2216fb12019-11-06 16:46:15 +0900314func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
315 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800316 content := android.ContentFromFileRuleForTests(t, params)
317 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900318 assertArrayString(t, actual, expected)
319}
320
Jooyung Han097087b2019-10-22 19:32:18 +0900321func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
322 t.Helper()
323 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900324 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
325}
326
327func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
328 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800329 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
330 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900331}
332
Logan Chienf3511742017-10-31 18:04:35 +0800333func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800334 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800335 cc_library {
336 name: "libvndk",
337 vendor_available: true,
338 vndk: {
339 enabled: true,
340 },
341 nocrt: true,
342 }
343
344 cc_library {
345 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900346 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800347 vndk: {
348 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900349 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800350 },
351 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900352 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800353 }
354
355 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900356 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800357 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900358 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800359 vndk: {
360 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900361 },
362 nocrt: true,
363 target: {
364 vendor: {
365 cflags: ["-DTEST"],
366 },
367 product: {
368 cflags: ["-DTEST"],
369 },
370 },
371 }
372
373 cc_library {
374 name: "libvndk_sp",
375 vendor_available: true,
376 vndk: {
377 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800378 support_system_process: true,
379 },
380 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900381 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800382 }
383
384 cc_library {
385 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900386 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800387 vndk: {
388 enabled: true,
389 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900390 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800391 },
392 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900393 target: {
394 vendor: {
395 suffix: "-x",
396 },
397 },
Logan Chienf3511742017-10-31 18:04:35 +0800398 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900399
400 cc_library {
401 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900402 vendor_available: true,
403 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900404 vndk: {
405 enabled: true,
406 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900407 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900408 },
409 nocrt: true,
410 target: {
411 vendor: {
412 suffix: "-x",
413 },
414 product: {
415 suffix: "-x",
416 },
417 },
418 }
419
Colin Crosse4e44bc2020-12-28 13:50:21 -0800420 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900421 name: "llndk.libraries.txt",
422 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800423 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900424 name: "vndkcore.libraries.txt",
425 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800426 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900427 name: "vndksp.libraries.txt",
428 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800429 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900430 name: "vndkprivate.libraries.txt",
431 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800432 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900433 name: "vndkproduct.libraries.txt",
434 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800435 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900436 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800437 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900438 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800439 `
440
441 config := TestConfig(buildDir, android.Android, nil, bp, nil)
442 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900443 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800444 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
445
446 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800447
Jooyung Han261e1582020-10-20 18:54:21 +0900448 // subdir == "" because VNDK libs are not supposed to be installed separately.
449 // They are installed as part of VNDK APEX instead.
450 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
451 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900452 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900453 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
454 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900455 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900456
Justin Yun6977e8a2020-10-29 18:24:11 +0900457 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
458 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900459
Inseob Kim1f086e22019-05-09 13:29:15 +0900460 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900461 snapshotDir := "vndk-snapshot"
462 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
463
464 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
465 "arm64", "armv8-a"))
466 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
467 "arm", "armv7-a-neon"))
468
469 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
470 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
471 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
472 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
473
Colin Crossfb0c16e2019-11-20 17:12:35 -0800474 variant := "android_vendor.VER_arm64_armv8-a_shared"
475 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900476
Inseob Kim7f283f42020-06-01 21:53:49 +0900477 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
478
479 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
480 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900481 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
482 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900483 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
484 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900485
Jooyung Han39edb6c2019-11-06 16:53:07 +0900486 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900487 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
488 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
489 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
490 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900491 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900492
Jooyung Han097087b2019-10-22 19:32:18 +0900493 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
494 "LLNDK: libc.so",
495 "LLNDK: libdl.so",
496 "LLNDK: libft2.so",
497 "LLNDK: libm.so",
498 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900499 "VNDK-SP: libvndk_sp-x.so",
500 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900501 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900502 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900503 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900504 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900505 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900506 "VNDK-private: libvndk-private.so",
507 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900508 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900509 "VNDK-product: libc++.so",
510 "VNDK-product: libvndk_product.so",
511 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900512 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900513 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900514 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
515 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
516 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 +0900517 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 +0900518 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
519}
520
Yo Chiangbba545e2020-06-09 16:15:37 +0800521func TestVndkWithHostSupported(t *testing.T) {
522 ctx := testCc(t, `
523 cc_library {
524 name: "libvndk_host_supported",
525 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900526 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800527 vndk: {
528 enabled: true,
529 },
530 host_supported: true,
531 }
532
533 cc_library {
534 name: "libvndk_host_supported_but_disabled_on_device",
535 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900536 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800537 vndk: {
538 enabled: true,
539 },
540 host_supported: true,
541 enabled: false,
542 target: {
543 host: {
544 enabled: true,
545 }
546 }
547 }
548
Colin Crosse4e44bc2020-12-28 13:50:21 -0800549 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800550 name: "vndkcore.libraries.txt",
551 }
552 `)
553
554 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
555}
556
Jooyung Han2216fb12019-11-06 16:46:15 +0900557func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800558 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800559 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900560 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800561 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800562 }`
563 config := TestConfig(buildDir, android.Android, nil, bp, nil)
564 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
565 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
566 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900567
568 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900569 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900570 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900571}
572
573func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800574 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900575 cc_library {
576 name: "libvndk",
577 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900578 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900579 vndk: {
580 enabled: true,
581 },
582 nocrt: true,
583 }
584
585 cc_library {
586 name: "libvndk_sp",
587 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900588 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900589 vndk: {
590 enabled: true,
591 support_system_process: true,
592 },
593 nocrt: true,
594 }
595
596 cc_library {
597 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900598 vendor_available: true,
599 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900600 vndk: {
601 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900602 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900603 },
604 nocrt: true,
605 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900606
Colin Crosse4e44bc2020-12-28 13:50:21 -0800607 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900608 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800609 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900610 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800611 `
612
613 config := TestConfig(buildDir, android.Android, nil, bp, nil)
614 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
615 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
616 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
617
618 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
619
620 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900621
Jooyung Han2216fb12019-11-06 16:46:15 +0900622 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900623}
624
Chris Parsons79d66a52020-06-05 17:26:16 -0400625func TestDataLibs(t *testing.T) {
626 bp := `
627 cc_test_library {
628 name: "test_lib",
629 srcs: ["test_lib.cpp"],
630 gtest: false,
631 }
632
633 cc_test {
634 name: "main_test",
635 data_libs: ["test_lib"],
636 gtest: false,
637 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400638 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400639
640 config := TestConfig(buildDir, android.Android, nil, bp, nil)
641 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
642 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
643 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
644
645 ctx := testCcWithConfig(t, config)
646 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
647 testBinary := module.(*Module).linker.(*testBinary)
648 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
649 if err != nil {
650 t.Errorf("Expected cc_test to produce output files, error: %s", err)
651 return
652 }
653 if len(outputFiles) != 1 {
654 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
655 return
656 }
657 if len(testBinary.dataPaths()) != 1 {
658 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
659 return
660 }
661
662 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400663 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400664
665 if !strings.HasSuffix(outputPath, "/main_test") {
666 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
667 return
668 }
669 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
670 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
671 return
672 }
673}
674
Chris Parsons216e10a2020-07-09 17:12:52 -0400675func TestDataLibsRelativeInstallPath(t *testing.T) {
676 bp := `
677 cc_test_library {
678 name: "test_lib",
679 srcs: ["test_lib.cpp"],
680 relative_install_path: "foo/bar/baz",
681 gtest: false,
682 }
683
684 cc_test {
685 name: "main_test",
686 data_libs: ["test_lib"],
687 gtest: false,
688 }
689 `
690
691 config := TestConfig(buildDir, android.Android, nil, bp, nil)
692 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
693 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
694 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
695
696 ctx := testCcWithConfig(t, config)
697 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
698 testBinary := module.(*Module).linker.(*testBinary)
699 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
700 if err != nil {
701 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
702 }
703 if len(outputFiles) != 1 {
704 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
705 }
706 if len(testBinary.dataPaths()) != 1 {
707 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
708 }
709
710 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400711
712 if !strings.HasSuffix(outputPath, "/main_test") {
713 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
714 }
715 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
716 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
717 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400718 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400719 }
720}
721
Jooyung Han0302a842019-10-30 18:43:49 +0900722func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900723 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900724 cc_library {
725 name: "libvndk",
726 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900727 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900728 vndk: {
729 enabled: true,
730 },
731 nocrt: true,
732 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900733 cc_library {
734 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900735 vendor_available: true,
736 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900737 vndk: {
738 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900739 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900740 },
741 nocrt: true,
742 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800743
744 cc_library {
745 name: "libllndk",
746 llndk_stubs: "libllndk.llndk",
747 }
748
749 llndk_library {
750 name: "libllndk.llndk",
751 symbol_file: "",
752 export_llndk_headers: ["libllndk_headers"],
753 }
754
755 llndk_headers {
756 name: "libllndk_headers",
757 export_include_dirs: ["include"],
758 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900759 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900760
761 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
762 "LLNDK: libc.so",
763 "LLNDK: libdl.so",
764 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800765 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900766 "LLNDK: libm.so",
767 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900768 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900769 "VNDK-core: libvndk.so",
770 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900771 "VNDK-private: libvndk-private.so",
772 "VNDK-product: libc++.so",
773 "VNDK-product: libvndk-private.so",
774 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900775 })
Logan Chienf3511742017-10-31 18:04:35 +0800776}
777
Justin Yun63e9ec72020-10-29 16:49:43 +0900778func TestVndkModuleError(t *testing.T) {
779 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900780 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900781 cc_library {
782 name: "libvndk",
783 vndk: {
784 enabled: true,
785 },
786 nocrt: true,
787 }
788 `)
789
Justin Yunc0d8c492021-01-07 17:45:31 +0900790 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900791 cc_library {
792 name: "libvndk",
793 product_available: true,
794 vndk: {
795 enabled: true,
796 },
797 nocrt: true,
798 }
799 `)
800
Justin Yun6977e8a2020-10-29 18:24:11 +0900801 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
802 cc_library {
803 name: "libvndkprop",
804 vendor_available: true,
805 product_available: true,
806 vndk: {
807 enabled: true,
808 },
809 nocrt: true,
810 target: {
811 vendor: {
812 cflags: ["-DTEST",],
813 },
814 },
815 }
816 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900817}
818
Logan Chiend3c59a22018-03-29 14:08:15 +0800819func TestVndkDepError(t *testing.T) {
820 // Check whether an error is emitted when a VNDK lib depends on a system lib.
821 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
822 cc_library {
823 name: "libvndk",
824 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900825 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800826 vndk: {
827 enabled: true,
828 },
829 shared_libs: ["libfwk"], // Cause error
830 nocrt: true,
831 }
832
833 cc_library {
834 name: "libfwk",
835 nocrt: true,
836 }
837 `)
838
839 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
840 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
841 cc_library {
842 name: "libvndk",
843 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900844 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800845 vndk: {
846 enabled: true,
847 },
848 shared_libs: ["libvendor"], // Cause error
849 nocrt: true,
850 }
851
852 cc_library {
853 name: "libvendor",
854 vendor: true,
855 nocrt: true,
856 }
857 `)
858
859 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
860 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
861 cc_library {
862 name: "libvndk_sp",
863 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900864 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800865 vndk: {
866 enabled: true,
867 support_system_process: true,
868 },
869 shared_libs: ["libfwk"], // Cause error
870 nocrt: true,
871 }
872
873 cc_library {
874 name: "libfwk",
875 nocrt: true,
876 }
877 `)
878
879 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
880 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
881 cc_library {
882 name: "libvndk_sp",
883 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900884 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800885 vndk: {
886 enabled: true,
887 support_system_process: true,
888 },
889 shared_libs: ["libvendor"], // Cause error
890 nocrt: true,
891 }
892
893 cc_library {
894 name: "libvendor",
895 vendor: true,
896 nocrt: true,
897 }
898 `)
899
900 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
901 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
902 cc_library {
903 name: "libvndk_sp",
904 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900905 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800906 vndk: {
907 enabled: true,
908 support_system_process: true,
909 },
910 shared_libs: ["libvndk"], // Cause error
911 nocrt: true,
912 }
913
914 cc_library {
915 name: "libvndk",
916 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900917 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800918 vndk: {
919 enabled: true,
920 },
921 nocrt: true,
922 }
923 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900924
925 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
926 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
927 cc_library {
928 name: "libvndk",
929 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900930 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900931 vndk: {
932 enabled: true,
933 },
934 shared_libs: ["libnonvndk"],
935 nocrt: true,
936 }
937
938 cc_library {
939 name: "libnonvndk",
940 vendor_available: true,
941 nocrt: true,
942 }
943 `)
944
945 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
946 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
947 cc_library {
948 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900949 vendor_available: true,
950 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900951 vndk: {
952 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900953 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900954 },
955 shared_libs: ["libnonvndk"],
956 nocrt: true,
957 }
958
959 cc_library {
960 name: "libnonvndk",
961 vendor_available: true,
962 nocrt: true,
963 }
964 `)
965
966 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
967 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
968 cc_library {
969 name: "libvndksp",
970 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900971 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900972 vndk: {
973 enabled: true,
974 support_system_process: true,
975 },
976 shared_libs: ["libnonvndk"],
977 nocrt: true,
978 }
979
980 cc_library {
981 name: "libnonvndk",
982 vendor_available: true,
983 nocrt: true,
984 }
985 `)
986
987 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
988 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
989 cc_library {
990 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900991 vendor_available: true,
992 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900993 vndk: {
994 enabled: true,
995 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900996 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900997 },
998 shared_libs: ["libnonvndk"],
999 nocrt: true,
1000 }
1001
1002 cc_library {
1003 name: "libnonvndk",
1004 vendor_available: true,
1005 nocrt: true,
1006 }
1007 `)
1008}
1009
1010func TestDoubleLoadbleDep(t *testing.T) {
1011 // okay to link : LLNDK -> double_loadable VNDK
1012 testCc(t, `
1013 cc_library {
1014 name: "libllndk",
1015 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001016 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001017 }
1018
1019 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001020 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001021 symbol_file: "",
1022 }
1023
1024 cc_library {
1025 name: "libdoubleloadable",
1026 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001027 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001028 vndk: {
1029 enabled: true,
1030 },
1031 double_loadable: true,
1032 }
1033 `)
1034 // okay to link : LLNDK -> VNDK-SP
1035 testCc(t, `
1036 cc_library {
1037 name: "libllndk",
1038 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -07001039 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001040 }
1041
1042 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001043 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001044 symbol_file: "",
1045 }
1046
1047 cc_library {
1048 name: "libvndksp",
1049 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001050 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001051 vndk: {
1052 enabled: true,
1053 support_system_process: true,
1054 },
1055 }
1056 `)
1057 // okay to link : double_loadable -> double_loadable
1058 testCc(t, `
1059 cc_library {
1060 name: "libdoubleloadable1",
1061 shared_libs: ["libdoubleloadable2"],
1062 vendor_available: true,
1063 double_loadable: true,
1064 }
1065
1066 cc_library {
1067 name: "libdoubleloadable2",
1068 vendor_available: true,
1069 double_loadable: true,
1070 }
1071 `)
1072 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1073 testCc(t, `
1074 cc_library {
1075 name: "libdoubleloadable",
1076 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001077 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001078 vndk: {
1079 enabled: true,
1080 },
1081 double_loadable: true,
1082 shared_libs: ["libnondoubleloadable"],
1083 }
1084
1085 cc_library {
1086 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001087 vendor_available: true,
1088 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001089 vndk: {
1090 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001091 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001092 },
1093 double_loadable: true,
1094 }
1095 `)
1096 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1097 testCc(t, `
1098 cc_library {
1099 name: "libllndk",
1100 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001101 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001102 }
1103
1104 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001105 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001106 symbol_file: "",
1107 }
1108
1109 cc_library {
1110 name: "libcoreonly",
1111 shared_libs: ["libvendoravailable"],
1112 }
1113
1114 // indirect dependency of LLNDK
1115 cc_library {
1116 name: "libvendoravailable",
1117 vendor_available: true,
1118 double_loadable: true,
1119 }
1120 `)
1121}
1122
1123func TestDoubleLoadableDepError(t *testing.T) {
1124 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1125 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1126 cc_library {
1127 name: "libllndk",
1128 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001129 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001130 }
1131
1132 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001133 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001134 symbol_file: "",
1135 }
1136
1137 cc_library {
1138 name: "libnondoubleloadable",
1139 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001140 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001141 vndk: {
1142 enabled: true,
1143 },
1144 }
1145 `)
1146
1147 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1148 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1149 cc_library {
1150 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001151 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001152 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001153 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001154 }
1155
1156 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001157 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001158 symbol_file: "",
1159 }
1160
1161 cc_library {
1162 name: "libnondoubleloadable",
1163 vendor_available: true,
1164 }
1165 `)
1166
Jooyung Hana70f0672019-01-18 15:20:43 +09001167 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1168 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1169 cc_library {
1170 name: "libllndk",
1171 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001172 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001173 }
1174
1175 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001176 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001177 symbol_file: "",
1178 }
1179
1180 cc_library {
1181 name: "libcoreonly",
1182 shared_libs: ["libvendoravailable"],
1183 }
1184
1185 // indirect dependency of LLNDK
1186 cc_library {
1187 name: "libvendoravailable",
1188 vendor_available: true,
1189 }
1190 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001191
1192 // The error is not from 'client' but from 'libllndk'
1193 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1194 cc_library {
1195 name: "client",
1196 vendor_available: true,
1197 double_loadable: true,
1198 shared_libs: ["libllndk"],
1199 }
1200 cc_library {
1201 name: "libllndk",
1202 shared_libs: ["libnondoubleloadable"],
1203 llndk_stubs: "libllndk.llndk",
1204 }
1205 llndk_library {
1206 name: "libllndk.llndk",
1207 symbol_file: "",
1208 }
1209 cc_library {
1210 name: "libnondoubleloadable",
1211 vendor_available: true,
1212 }
1213 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001214}
1215
Jooyung Han479ca172020-10-19 18:51:07 +09001216func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1217 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1218 cc_library {
1219 name: "libvndksp",
1220 shared_libs: ["libanothervndksp"],
1221 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001222 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001223 vndk: {
1224 enabled: true,
1225 support_system_process: true,
1226 }
1227 }
1228
1229 cc_library {
1230 name: "libllndk",
1231 shared_libs: ["libanothervndksp"],
1232 }
1233
1234 llndk_library {
1235 name: "libllndk",
1236 symbol_file: "",
1237 }
1238
1239 cc_library {
1240 name: "libanothervndksp",
1241 vendor_available: true,
1242 }
1243 `)
1244}
1245
Logan Chienf3511742017-10-31 18:04:35 +08001246func TestVndkExt(t *testing.T) {
1247 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001248 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001249 cc_library {
1250 name: "libvndk",
1251 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001252 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001253 vndk: {
1254 enabled: true,
1255 },
1256 nocrt: true,
1257 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001258 cc_library {
1259 name: "libvndk2",
1260 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001261 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001262 vndk: {
1263 enabled: true,
1264 },
1265 target: {
1266 vendor: {
1267 suffix: "-suffix",
1268 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001269 product: {
1270 suffix: "-suffix",
1271 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001272 },
1273 nocrt: true,
1274 }
Logan Chienf3511742017-10-31 18:04:35 +08001275
1276 cc_library {
1277 name: "libvndk_ext",
1278 vendor: true,
1279 vndk: {
1280 enabled: true,
1281 extends: "libvndk",
1282 },
1283 nocrt: true,
1284 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001285
1286 cc_library {
1287 name: "libvndk2_ext",
1288 vendor: true,
1289 vndk: {
1290 enabled: true,
1291 extends: "libvndk2",
1292 },
1293 nocrt: true,
1294 }
Logan Chienf3511742017-10-31 18:04:35 +08001295
Justin Yun0ecf0b22020-02-28 15:07:59 +09001296 cc_library {
1297 name: "libvndk_ext_product",
1298 product_specific: true,
1299 vndk: {
1300 enabled: true,
1301 extends: "libvndk",
1302 },
1303 nocrt: true,
1304 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001305
Justin Yun0ecf0b22020-02-28 15:07:59 +09001306 cc_library {
1307 name: "libvndk2_ext_product",
1308 product_specific: true,
1309 vndk: {
1310 enabled: true,
1311 extends: "libvndk2",
1312 },
1313 nocrt: true,
1314 }
1315 `
1316 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1317 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1318 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1319 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1320
1321 ctx := testCcWithConfig(t, config)
1322
1323 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1324 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1325
1326 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1327 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1328
1329 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1330 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001331}
1332
Logan Chiend3c59a22018-03-29 14:08:15 +08001333func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001334 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1335 ctx := testCcNoVndk(t, `
1336 cc_library {
1337 name: "libvndk",
1338 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001339 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001340 vndk: {
1341 enabled: true,
1342 },
1343 nocrt: true,
1344 }
1345
1346 cc_library {
1347 name: "libvndk_ext",
1348 vendor: true,
1349 vndk: {
1350 enabled: true,
1351 extends: "libvndk",
1352 },
1353 nocrt: true,
1354 }
1355 `)
1356
1357 // Ensures that the core variant of "libvndk_ext" can be found.
1358 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1359 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1360 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1361 }
1362}
1363
Justin Yun0ecf0b22020-02-28 15:07:59 +09001364func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1365 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001366 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001367 cc_library {
1368 name: "libvndk",
1369 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001370 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001371 vndk: {
1372 enabled: true,
1373 },
1374 nocrt: true,
1375 }
1376
1377 cc_library {
1378 name: "libvndk_ext_product",
1379 product_specific: true,
1380 vndk: {
1381 enabled: true,
1382 extends: "libvndk",
1383 },
1384 nocrt: true,
1385 }
1386 `)
1387
1388 // Ensures that the core variant of "libvndk_ext_product" can be found.
1389 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1390 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1391 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1392 }
1393}
1394
Logan Chienf3511742017-10-31 18:04:35 +08001395func TestVndkExtError(t *testing.T) {
1396 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001397 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001398 cc_library {
1399 name: "libvndk",
1400 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001401 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001402 vndk: {
1403 enabled: true,
1404 },
1405 nocrt: true,
1406 }
1407
1408 cc_library {
1409 name: "libvndk_ext",
1410 vndk: {
1411 enabled: true,
1412 extends: "libvndk",
1413 },
1414 nocrt: true,
1415 }
1416 `)
1417
1418 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1419 cc_library {
1420 name: "libvndk",
1421 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001422 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001423 vndk: {
1424 enabled: true,
1425 },
1426 nocrt: true,
1427 }
1428
1429 cc_library {
1430 name: "libvndk_ext",
1431 vendor: true,
1432 vndk: {
1433 enabled: true,
1434 },
1435 nocrt: true,
1436 }
1437 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001438
1439 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1440 cc_library {
1441 name: "libvndk",
1442 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001443 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001444 vndk: {
1445 enabled: true,
1446 },
1447 nocrt: true,
1448 }
1449
1450 cc_library {
1451 name: "libvndk_ext_product",
1452 product_specific: true,
1453 vndk: {
1454 enabled: true,
1455 },
1456 nocrt: true,
1457 }
1458 `)
1459
1460 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1461 cc_library {
1462 name: "libvndk",
1463 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001464 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001465 vndk: {
1466 enabled: true,
1467 },
1468 nocrt: true,
1469 }
1470
1471 cc_library {
1472 name: "libvndk_ext_product",
1473 product_specific: true,
1474 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001475 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001476 vndk: {
1477 enabled: true,
1478 extends: "libvndk",
1479 },
1480 nocrt: true,
1481 }
1482 `)
Logan Chienf3511742017-10-31 18:04:35 +08001483}
1484
1485func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1486 // This test ensures an error is emitted for inconsistent support_system_process.
1487 testCcError(t, "module \".*\" with mismatched support_system_process", `
1488 cc_library {
1489 name: "libvndk",
1490 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001491 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001492 vndk: {
1493 enabled: true,
1494 },
1495 nocrt: true,
1496 }
1497
1498 cc_library {
1499 name: "libvndk_sp_ext",
1500 vendor: true,
1501 vndk: {
1502 enabled: true,
1503 extends: "libvndk",
1504 support_system_process: true,
1505 },
1506 nocrt: true,
1507 }
1508 `)
1509
1510 testCcError(t, "module \".*\" with mismatched support_system_process", `
1511 cc_library {
1512 name: "libvndk_sp",
1513 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001514 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001515 vndk: {
1516 enabled: true,
1517 support_system_process: true,
1518 },
1519 nocrt: true,
1520 }
1521
1522 cc_library {
1523 name: "libvndk_ext",
1524 vendor: true,
1525 vndk: {
1526 enabled: true,
1527 extends: "libvndk_sp",
1528 },
1529 nocrt: true,
1530 }
1531 `)
1532}
1533
1534func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001535 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001536 // with `private: true`.
1537 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001538 cc_library {
1539 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001540 vendor_available: true,
1541 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001542 vndk: {
1543 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001544 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001545 },
1546 nocrt: true,
1547 }
1548
1549 cc_library {
1550 name: "libvndk_ext",
1551 vendor: true,
1552 vndk: {
1553 enabled: true,
1554 extends: "libvndk",
1555 },
1556 nocrt: true,
1557 }
1558 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001559
Justin Yunfd9e8042020-12-23 18:23:14 +09001560 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001561 cc_library {
1562 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001563 vendor_available: true,
1564 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001565 vndk: {
1566 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001567 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001568 },
1569 nocrt: true,
1570 }
1571
1572 cc_library {
1573 name: "libvndk_ext_product",
1574 product_specific: true,
1575 vndk: {
1576 enabled: true,
1577 extends: "libvndk",
1578 },
1579 nocrt: true,
1580 }
1581 `)
Logan Chienf3511742017-10-31 18:04:35 +08001582}
1583
Logan Chiend3c59a22018-03-29 14:08:15 +08001584func TestVendorModuleUseVndkExt(t *testing.T) {
1585 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001586 testCc(t, `
1587 cc_library {
1588 name: "libvndk",
1589 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001590 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001591 vndk: {
1592 enabled: true,
1593 },
1594 nocrt: true,
1595 }
1596
1597 cc_library {
1598 name: "libvndk_ext",
1599 vendor: true,
1600 vndk: {
1601 enabled: true,
1602 extends: "libvndk",
1603 },
1604 nocrt: true,
1605 }
1606
1607 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001608 name: "libvndk_sp",
1609 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001610 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001611 vndk: {
1612 enabled: true,
1613 support_system_process: true,
1614 },
1615 nocrt: true,
1616 }
1617
1618 cc_library {
1619 name: "libvndk_sp_ext",
1620 vendor: true,
1621 vndk: {
1622 enabled: true,
1623 extends: "libvndk_sp",
1624 support_system_process: true,
1625 },
1626 nocrt: true,
1627 }
1628
1629 cc_library {
1630 name: "libvendor",
1631 vendor: true,
1632 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1633 nocrt: true,
1634 }
1635 `)
1636}
1637
Logan Chiend3c59a22018-03-29 14:08:15 +08001638func TestVndkExtUseVendorLib(t *testing.T) {
1639 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001640 testCc(t, `
1641 cc_library {
1642 name: "libvndk",
1643 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001644 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001645 vndk: {
1646 enabled: true,
1647 },
1648 nocrt: true,
1649 }
1650
1651 cc_library {
1652 name: "libvndk_ext",
1653 vendor: true,
1654 vndk: {
1655 enabled: true,
1656 extends: "libvndk",
1657 },
1658 shared_libs: ["libvendor"],
1659 nocrt: true,
1660 }
1661
1662 cc_library {
1663 name: "libvendor",
1664 vendor: true,
1665 nocrt: true,
1666 }
1667 `)
Logan Chienf3511742017-10-31 18:04:35 +08001668
Logan Chiend3c59a22018-03-29 14:08:15 +08001669 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1670 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001671 cc_library {
1672 name: "libvndk_sp",
1673 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001674 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001675 vndk: {
1676 enabled: true,
1677 support_system_process: true,
1678 },
1679 nocrt: true,
1680 }
1681
1682 cc_library {
1683 name: "libvndk_sp_ext",
1684 vendor: true,
1685 vndk: {
1686 enabled: true,
1687 extends: "libvndk_sp",
1688 support_system_process: true,
1689 },
1690 shared_libs: ["libvendor"], // Cause an error
1691 nocrt: true,
1692 }
1693
1694 cc_library {
1695 name: "libvendor",
1696 vendor: true,
1697 nocrt: true,
1698 }
1699 `)
1700}
1701
Justin Yun0ecf0b22020-02-28 15:07:59 +09001702func TestProductVndkExtDependency(t *testing.T) {
1703 bp := `
1704 cc_library {
1705 name: "libvndk",
1706 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001707 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001708 vndk: {
1709 enabled: true,
1710 },
1711 nocrt: true,
1712 }
1713
1714 cc_library {
1715 name: "libvndk_ext_product",
1716 product_specific: true,
1717 vndk: {
1718 enabled: true,
1719 extends: "libvndk",
1720 },
1721 shared_libs: ["libproduct_for_vndklibs"],
1722 nocrt: true,
1723 }
1724
1725 cc_library {
1726 name: "libvndk_sp",
1727 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001728 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001729 vndk: {
1730 enabled: true,
1731 support_system_process: true,
1732 },
1733 nocrt: true,
1734 }
1735
1736 cc_library {
1737 name: "libvndk_sp_ext_product",
1738 product_specific: true,
1739 vndk: {
1740 enabled: true,
1741 extends: "libvndk_sp",
1742 support_system_process: true,
1743 },
1744 shared_libs: ["libproduct_for_vndklibs"],
1745 nocrt: true,
1746 }
1747
1748 cc_library {
1749 name: "libproduct",
1750 product_specific: true,
1751 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1752 nocrt: true,
1753 }
1754
1755 cc_library {
1756 name: "libproduct_for_vndklibs",
1757 product_specific: true,
1758 nocrt: true,
1759 }
1760 `
1761 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1762 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1763 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1764 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1765
1766 testCcWithConfig(t, config)
1767}
1768
Logan Chiend3c59a22018-03-29 14:08:15 +08001769func TestVndkSpExtUseVndkError(t *testing.T) {
1770 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1771 // library.
1772 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1773 cc_library {
1774 name: "libvndk",
1775 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001776 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001777 vndk: {
1778 enabled: true,
1779 },
1780 nocrt: true,
1781 }
1782
1783 cc_library {
1784 name: "libvndk_sp",
1785 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001786 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001787 vndk: {
1788 enabled: true,
1789 support_system_process: true,
1790 },
1791 nocrt: true,
1792 }
1793
1794 cc_library {
1795 name: "libvndk_sp_ext",
1796 vendor: true,
1797 vndk: {
1798 enabled: true,
1799 extends: "libvndk_sp",
1800 support_system_process: true,
1801 },
1802 shared_libs: ["libvndk"], // Cause an error
1803 nocrt: true,
1804 }
1805 `)
1806
1807 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1808 // library.
1809 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1810 cc_library {
1811 name: "libvndk",
1812 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001813 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001814 vndk: {
1815 enabled: true,
1816 },
1817 nocrt: true,
1818 }
1819
1820 cc_library {
1821 name: "libvndk_ext",
1822 vendor: true,
1823 vndk: {
1824 enabled: true,
1825 extends: "libvndk",
1826 },
1827 nocrt: true,
1828 }
1829
1830 cc_library {
1831 name: "libvndk_sp",
1832 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001833 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001834 vndk: {
1835 enabled: true,
1836 support_system_process: true,
1837 },
1838 nocrt: true,
1839 }
1840
1841 cc_library {
1842 name: "libvndk_sp_ext",
1843 vendor: true,
1844 vndk: {
1845 enabled: true,
1846 extends: "libvndk_sp",
1847 support_system_process: true,
1848 },
1849 shared_libs: ["libvndk_ext"], // Cause an error
1850 nocrt: true,
1851 }
1852 `)
1853}
1854
1855func TestVndkUseVndkExtError(t *testing.T) {
1856 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1857 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001858 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1859 cc_library {
1860 name: "libvndk",
1861 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001862 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001863 vndk: {
1864 enabled: true,
1865 },
1866 nocrt: true,
1867 }
1868
1869 cc_library {
1870 name: "libvndk_ext",
1871 vendor: true,
1872 vndk: {
1873 enabled: true,
1874 extends: "libvndk",
1875 },
1876 nocrt: true,
1877 }
1878
1879 cc_library {
1880 name: "libvndk2",
1881 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001882 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001883 vndk: {
1884 enabled: true,
1885 },
1886 shared_libs: ["libvndk_ext"],
1887 nocrt: true,
1888 }
1889 `)
1890
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001891 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001892 cc_library {
1893 name: "libvndk",
1894 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001895 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001896 vndk: {
1897 enabled: true,
1898 },
1899 nocrt: true,
1900 }
1901
1902 cc_library {
1903 name: "libvndk_ext",
1904 vendor: true,
1905 vndk: {
1906 enabled: true,
1907 extends: "libvndk",
1908 },
1909 nocrt: true,
1910 }
1911
1912 cc_library {
1913 name: "libvndk2",
1914 vendor_available: true,
1915 vndk: {
1916 enabled: true,
1917 },
1918 target: {
1919 vendor: {
1920 shared_libs: ["libvndk_ext"],
1921 },
1922 },
1923 nocrt: true,
1924 }
1925 `)
1926
1927 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1928 cc_library {
1929 name: "libvndk_sp",
1930 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001931 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001932 vndk: {
1933 enabled: true,
1934 support_system_process: true,
1935 },
1936 nocrt: true,
1937 }
1938
1939 cc_library {
1940 name: "libvndk_sp_ext",
1941 vendor: true,
1942 vndk: {
1943 enabled: true,
1944 extends: "libvndk_sp",
1945 support_system_process: true,
1946 },
1947 nocrt: true,
1948 }
1949
1950 cc_library {
1951 name: "libvndk_sp_2",
1952 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001953 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001954 vndk: {
1955 enabled: true,
1956 support_system_process: true,
1957 },
1958 shared_libs: ["libvndk_sp_ext"],
1959 nocrt: true,
1960 }
1961 `)
1962
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001963 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001964 cc_library {
1965 name: "libvndk_sp",
1966 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001967 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001968 vndk: {
1969 enabled: true,
1970 },
1971 nocrt: true,
1972 }
1973
1974 cc_library {
1975 name: "libvndk_sp_ext",
1976 vendor: true,
1977 vndk: {
1978 enabled: true,
1979 extends: "libvndk_sp",
1980 },
1981 nocrt: true,
1982 }
1983
1984 cc_library {
1985 name: "libvndk_sp2",
1986 vendor_available: true,
1987 vndk: {
1988 enabled: true,
1989 },
1990 target: {
1991 vendor: {
1992 shared_libs: ["libvndk_sp_ext"],
1993 },
1994 },
1995 nocrt: true,
1996 }
1997 `)
1998}
1999
Justin Yun5f7f7e82019-11-18 19:52:14 +09002000func TestEnforceProductVndkVersion(t *testing.T) {
2001 bp := `
2002 cc_library {
2003 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002004 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002005 }
2006 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002007 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002008 symbol_file: "",
2009 }
2010 cc_library {
2011 name: "libvndk",
2012 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002013 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002014 vndk: {
2015 enabled: true,
2016 },
2017 nocrt: true,
2018 }
2019 cc_library {
2020 name: "libvndk_sp",
2021 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002022 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002023 vndk: {
2024 enabled: true,
2025 support_system_process: true,
2026 },
2027 nocrt: true,
2028 }
2029 cc_library {
2030 name: "libva",
2031 vendor_available: true,
2032 nocrt: true,
2033 }
2034 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002035 name: "libpa",
2036 product_available: true,
2037 nocrt: true,
2038 }
2039 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002040 name: "libboth_available",
2041 vendor_available: true,
2042 product_available: true,
2043 nocrt: true,
2044 target: {
2045 vendor: {
2046 suffix: "-vendor",
2047 },
2048 product: {
2049 suffix: "-product",
2050 },
2051 }
2052 }
2053 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002054 name: "libproduct_va",
2055 product_specific: true,
2056 vendor_available: true,
2057 nocrt: true,
2058 }
2059 cc_library {
2060 name: "libprod",
2061 product_specific: true,
2062 shared_libs: [
2063 "libllndk",
2064 "libvndk",
2065 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002066 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002067 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002068 "libproduct_va",
2069 ],
2070 nocrt: true,
2071 }
2072 cc_library {
2073 name: "libvendor",
2074 vendor: true,
2075 shared_libs: [
2076 "libllndk",
2077 "libvndk",
2078 "libvndk_sp",
2079 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002080 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002081 "libproduct_va",
2082 ],
2083 nocrt: true,
2084 }
2085 `
2086
2087 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2088 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2089 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2090 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2091
2092 ctx := testCcWithConfig(t, config)
2093
Jooyung Han261e1582020-10-20 18:54:21 +09002094 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2095 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002096
2097 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2098 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2099
2100 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2101 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002102}
2103
2104func TestEnforceProductVndkVersionErrors(t *testing.T) {
2105 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2106 cc_library {
2107 name: "libprod",
2108 product_specific: true,
2109 shared_libs: [
2110 "libvendor",
2111 ],
2112 nocrt: true,
2113 }
2114 cc_library {
2115 name: "libvendor",
2116 vendor: true,
2117 nocrt: true,
2118 }
2119 `)
2120 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2121 cc_library {
2122 name: "libprod",
2123 product_specific: true,
2124 shared_libs: [
2125 "libsystem",
2126 ],
2127 nocrt: true,
2128 }
2129 cc_library {
2130 name: "libsystem",
2131 nocrt: true,
2132 }
2133 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002134 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2135 cc_library {
2136 name: "libprod",
2137 product_specific: true,
2138 shared_libs: [
2139 "libva",
2140 ],
2141 nocrt: true,
2142 }
2143 cc_library {
2144 name: "libva",
2145 vendor_available: true,
2146 nocrt: true,
2147 }
2148 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002149 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002150 cc_library {
2151 name: "libprod",
2152 product_specific: true,
2153 shared_libs: [
2154 "libvndk_private",
2155 ],
2156 nocrt: true,
2157 }
2158 cc_library {
2159 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002160 vendor_available: true,
2161 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002162 vndk: {
2163 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002164 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002165 },
2166 nocrt: true,
2167 }
2168 `)
2169 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2170 cc_library {
2171 name: "libprod",
2172 product_specific: true,
2173 shared_libs: [
2174 "libsystem_ext",
2175 ],
2176 nocrt: true,
2177 }
2178 cc_library {
2179 name: "libsystem_ext",
2180 system_ext_specific: true,
2181 nocrt: true,
2182 }
2183 `)
2184 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2185 cc_library {
2186 name: "libsystem",
2187 shared_libs: [
2188 "libproduct_va",
2189 ],
2190 nocrt: true,
2191 }
2192 cc_library {
2193 name: "libproduct_va",
2194 product_specific: true,
2195 vendor_available: true,
2196 nocrt: true,
2197 }
2198 `)
2199}
2200
Jooyung Han38002912019-05-16 04:01:54 +09002201func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002202 bp := `
2203 cc_library {
2204 name: "libvndk",
2205 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002206 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002207 vndk: {
2208 enabled: true,
2209 },
2210 }
2211 cc_library {
2212 name: "libvndksp",
2213 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002214 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002215 vndk: {
2216 enabled: true,
2217 support_system_process: true,
2218 },
2219 }
2220 cc_library {
2221 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002222 vendor_available: true,
2223 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002224 vndk: {
2225 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002226 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002227 },
2228 }
2229 cc_library {
2230 name: "libvendor",
2231 vendor: true,
2232 }
2233 cc_library {
2234 name: "libvndkext",
2235 vendor: true,
2236 vndk: {
2237 enabled: true,
2238 extends: "libvndk",
2239 },
2240 }
2241 vndk_prebuilt_shared {
2242 name: "prevndk",
2243 version: "27",
2244 target_arch: "arm",
2245 binder32bit: true,
2246 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002247 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002248 vndk: {
2249 enabled: true,
2250 },
2251 arch: {
2252 arm: {
2253 srcs: ["liba.so"],
2254 },
2255 },
2256 }
2257 cc_library {
2258 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002259 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002260 }
2261 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002262 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002263 symbol_file: "",
2264 }
2265 cc_library {
2266 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002267 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002268 }
2269 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002270 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002271 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002272 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002273 }
2274
2275 llndk_libraries_txt {
2276 name: "llndk.libraries.txt",
2277 }
2278 vndkcore_libraries_txt {
2279 name: "vndkcore.libraries.txt",
2280 }
2281 vndksp_libraries_txt {
2282 name: "vndksp.libraries.txt",
2283 }
2284 vndkprivate_libraries_txt {
2285 name: "vndkprivate.libraries.txt",
2286 }
2287 vndkcorevariant_libraries_txt {
2288 name: "vndkcorevariant.libraries.txt",
2289 insert_vndk_version: false,
2290 }
2291 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002292
2293 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002294 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2295 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2296 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002297 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002298
Colin Cross78212242021-01-06 14:51:30 -08002299 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2300 []string{"libvndk.so", "libvndkprivate.so"})
2301 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2302 []string{"libc++.so", "libvndksp.so"})
2303 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2304 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2305 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2306 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002307
Colin Crossfb0c16e2019-11-20 17:12:35 -08002308 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002309
Jooyung Han38002912019-05-16 04:01:54 +09002310 tests := []struct {
2311 variant string
2312 name string
2313 expected string
2314 }{
2315 {vendorVariant, "libvndk", "native:vndk"},
2316 {vendorVariant, "libvndksp", "native:vndk"},
2317 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2318 {vendorVariant, "libvendor", "native:vendor"},
2319 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002320 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002321 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002322 {coreVariant, "libvndk", "native:platform"},
2323 {coreVariant, "libvndkprivate", "native:platform"},
2324 {coreVariant, "libllndk", "native:platform"},
2325 }
2326 for _, test := range tests {
2327 t.Run(test.name, func(t *testing.T) {
2328 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2329 assertString(t, module.makeLinkType, test.expected)
2330 })
2331 }
2332}
2333
Jeff Gaston294356f2017-09-27 17:05:30 -07002334var staticLinkDepOrderTestCases = []struct {
2335 // This is a string representation of a map[moduleName][]moduleDependency .
2336 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002337 inStatic string
2338
2339 // This is a string representation of a map[moduleName][]moduleDependency .
2340 // It models the dependencies declared in an Android.bp file.
2341 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002342
2343 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2344 // The keys of allOrdered specify which modules we would like to check.
2345 // The values of allOrdered specify the expected result (of the transitive closure of all
2346 // dependencies) for each module to test
2347 allOrdered string
2348
2349 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2350 // The keys of outOrdered specify which modules we would like to check.
2351 // The values of outOrdered specify the expected result (of the ordered linker command line)
2352 // for each module to test.
2353 outOrdered string
2354}{
2355 // Simple tests
2356 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002357 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002358 outOrdered: "",
2359 },
2360 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002361 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002362 outOrdered: "a:",
2363 },
2364 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002365 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002366 outOrdered: "a:b; b:",
2367 },
2368 // Tests of reordering
2369 {
2370 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002371 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002372 outOrdered: "a:b,c,d; b:d; c:d; d:",
2373 },
2374 {
2375 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002376 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002377 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2378 },
2379 {
2380 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002381 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002382 outOrdered: "a:d,b,e,c; d:b; e:c",
2383 },
2384 {
2385 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002386 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002387 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2388 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2389 },
2390 {
2391 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002392 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 -07002393 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2394 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2395 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002396 // shared dependencies
2397 {
2398 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2399 // So, we don't actually have to check that a shared dependency of c will change the order
2400 // of a library that depends statically on b and on c. We only need to check that if c has
2401 // a shared dependency on b, that that shows up in allOrdered.
2402 inShared: "c:b",
2403 allOrdered: "c:b",
2404 outOrdered: "c:",
2405 },
2406 {
2407 // This test doesn't actually include any shared dependencies but it's a reminder of what
2408 // the second phase of the above test would look like
2409 inStatic: "a:b,c; c:b",
2410 allOrdered: "a:c,b; c:b",
2411 outOrdered: "a:c,b; c:b",
2412 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002413 // tiebreakers for when two modules specifying different orderings and there is no dependency
2414 // to dictate an order
2415 {
2416 // 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 -08002417 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002418 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2419 },
2420 {
2421 // 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 -08002422 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 -07002423 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2424 },
2425 // Tests involving duplicate dependencies
2426 {
2427 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002428 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002429 outOrdered: "a:c,b",
2430 },
2431 {
2432 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002433 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002434 outOrdered: "a:d,c,b",
2435 },
2436 // Tests to confirm the nonexistence of infinite loops.
2437 // These cases should never happen, so as long as the test terminates and the
2438 // result is deterministic then that should be fine.
2439 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002440 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002441 outOrdered: "a:a",
2442 },
2443 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002444 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002445 allOrdered: "a:b,c; b:c,a; c:a,b",
2446 outOrdered: "a:b; b:c; c:a",
2447 },
2448 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002449 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002450 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2451 outOrdered: "a:c,b; b:a,c; c:b,a",
2452 },
2453}
2454
2455// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2456func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2457 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2458 strippedText := strings.Replace(text, " ", "", -1)
2459 if len(strippedText) < 1 {
2460 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2461 }
2462 allDeps = make(map[android.Path][]android.Path, 0)
2463
2464 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2465 moduleTexts := strings.Split(strippedText, ";")
2466
2467 outputForModuleName := func(moduleName string) android.Path {
2468 return android.PathForTesting(moduleName)
2469 }
2470
2471 for _, moduleText := range moduleTexts {
2472 // convert from "a:b,c" to ["a", "b,c"]
2473 components := strings.Split(moduleText, ":")
2474 if len(components) != 2 {
2475 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2476 }
2477 moduleName := components[0]
2478 moduleOutput := outputForModuleName(moduleName)
2479 modulesInOrder = append(modulesInOrder, moduleOutput)
2480
2481 depString := components[1]
2482 // convert from "b,c" to ["b", "c"]
2483 depNames := strings.Split(depString, ",")
2484 if len(depString) < 1 {
2485 depNames = []string{}
2486 }
2487 var deps []android.Path
2488 for _, depName := range depNames {
2489 deps = append(deps, outputForModuleName(depName))
2490 }
2491 allDeps[moduleOutput] = deps
2492 }
2493 return modulesInOrder, allDeps
2494}
2495
Jeff Gaston294356f2017-09-27 17:05:30 -07002496func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2497 for _, moduleName := range moduleNames {
2498 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2499 output := module.outputFile.Path()
2500 paths = append(paths, output)
2501 }
2502 return paths
2503}
2504
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002505func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002506 ctx := testCc(t, `
2507 cc_library {
2508 name: "a",
2509 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002510 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002511 }
2512 cc_library {
2513 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002514 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002515 }
2516 cc_library {
2517 name: "c",
2518 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002519 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002520 }
2521 cc_library {
2522 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002523 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002524 }
2525
2526 `)
2527
Colin Cross7113d202019-11-20 16:39:12 -08002528 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002529 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002530 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2531 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002532
2533 if !reflect.DeepEqual(actual, expected) {
2534 t.Errorf("staticDeps orderings were not propagated correctly"+
2535 "\nactual: %v"+
2536 "\nexpected: %v",
2537 actual,
2538 expected,
2539 )
2540 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002541}
Jeff Gaston294356f2017-09-27 17:05:30 -07002542
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002543func TestStaticLibDepReorderingWithShared(t *testing.T) {
2544 ctx := testCc(t, `
2545 cc_library {
2546 name: "a",
2547 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002548 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002549 }
2550 cc_library {
2551 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002552 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002553 }
2554 cc_library {
2555 name: "c",
2556 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002557 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002558 }
2559
2560 `)
2561
Colin Cross7113d202019-11-20 16:39:12 -08002562 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002563 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002564 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2565 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002566
2567 if !reflect.DeepEqual(actual, expected) {
2568 t.Errorf("staticDeps orderings did not account for shared libs"+
2569 "\nactual: %v"+
2570 "\nexpected: %v",
2571 actual,
2572 expected,
2573 )
2574 }
2575}
2576
Jooyung Hanb04a4992020-03-13 18:57:35 +09002577func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002578 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002579 if !reflect.DeepEqual(actual, expected) {
2580 t.Errorf(message+
2581 "\nactual: %v"+
2582 "\nexpected: %v",
2583 actual,
2584 expected,
2585 )
2586 }
2587}
2588
Jooyung Han61b66e92020-03-21 14:21:46 +00002589func TestLlndkLibrary(t *testing.T) {
2590 ctx := testCc(t, `
2591 cc_library {
2592 name: "libllndk",
2593 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002594 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002595 }
2596 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002597 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002598 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002599
2600 cc_prebuilt_library_shared {
2601 name: "libllndkprebuilt",
2602 stubs: { versions: ["1", "2"] },
2603 llndk_stubs: "libllndkprebuilt.llndk",
2604 }
2605 llndk_library {
2606 name: "libllndkprebuilt.llndk",
2607 }
2608
2609 cc_library {
2610 name: "libllndk_with_external_headers",
2611 stubs: { versions: ["1", "2"] },
2612 llndk_stubs: "libllndk_with_external_headers.llndk",
2613 header_libs: ["libexternal_headers"],
2614 export_header_lib_headers: ["libexternal_headers"],
2615 }
2616 llndk_library {
2617 name: "libllndk_with_external_headers.llndk",
2618 }
2619 cc_library_headers {
2620 name: "libexternal_headers",
2621 export_include_dirs: ["include"],
2622 vendor_available: true,
2623 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002624 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002625 actual := ctx.ModuleVariantsForTests("libllndk")
2626 for i := 0; i < len(actual); i++ {
2627 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
2628 actual = append(actual[:i], actual[i+1:]...)
2629 i--
2630 }
2631 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002632 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00002633 "android_vendor.VER_arm64_armv8-a_shared_1",
2634 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002635 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002636 "android_vendor.VER_arm_armv7-a-neon_shared_1",
2637 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002638 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002639 }
2640 checkEquals(t, "variants for llndk stubs", expected, actual)
2641
Colin Cross127bb8b2020-12-16 16:46:01 -08002642 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002643 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2644
Colin Cross127bb8b2020-12-16 16:46:01 -08002645 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002646 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2647}
2648
Jiyong Parka46a4d52017-12-14 19:54:34 +09002649func TestLlndkHeaders(t *testing.T) {
2650 ctx := testCc(t, `
2651 llndk_headers {
2652 name: "libllndk_headers",
2653 export_include_dirs: ["my_include"],
2654 }
2655 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002656 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002657 export_llndk_headers: ["libllndk_headers"],
2658 }
2659 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002660 name: "libllndk",
2661 llndk_stubs: "libllndk.llndk",
2662 }
2663
2664 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002665 name: "libvendor",
2666 shared_libs: ["libllndk"],
2667 vendor: true,
2668 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002669 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002670 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002671 }
2672 `)
2673
2674 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002675 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002676 cflags := cc.Args["cFlags"]
2677 if !strings.Contains(cflags, "-Imy_include") {
2678 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2679 }
2680}
2681
Logan Chien43d34c32017-12-20 01:17:32 +08002682func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2683 actual := module.Properties.AndroidMkRuntimeLibs
2684 if !reflect.DeepEqual(actual, expected) {
2685 t.Errorf("incorrect runtime_libs for shared libs"+
2686 "\nactual: %v"+
2687 "\nexpected: %v",
2688 actual,
2689 expected,
2690 )
2691 }
2692}
2693
2694const runtimeLibAndroidBp = `
2695 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002696 name: "liball_available",
2697 vendor_available: true,
2698 product_available: true,
2699 no_libcrt : true,
2700 nocrt : true,
2701 system_shared_libs : [],
2702 }
2703 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002704 name: "libvendor_available1",
2705 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002706 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002707 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002708 nocrt : true,
2709 system_shared_libs : [],
2710 }
2711 cc_library {
2712 name: "libvendor_available2",
2713 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002714 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002715 target: {
2716 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002717 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002718 }
2719 },
Yi Konge7fe9912019-06-02 00:53:50 -07002720 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002721 nocrt : true,
2722 system_shared_libs : [],
2723 }
2724 cc_library {
2725 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002726 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002727 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002728 nocrt : true,
2729 system_shared_libs : [],
2730 }
2731 cc_library {
2732 name: "libvendor1",
2733 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002734 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002735 nocrt : true,
2736 system_shared_libs : [],
2737 }
2738 cc_library {
2739 name: "libvendor2",
2740 vendor: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002741 runtime_libs: ["liball_available", "libvendor1"],
2742 no_libcrt : true,
2743 nocrt : true,
2744 system_shared_libs : [],
2745 }
2746 cc_library {
2747 name: "libproduct_available1",
2748 product_available: true,
2749 runtime_libs: ["liball_available"],
2750 no_libcrt : true,
2751 nocrt : true,
2752 system_shared_libs : [],
2753 }
2754 cc_library {
2755 name: "libproduct1",
2756 product_specific: true,
2757 no_libcrt : true,
2758 nocrt : true,
2759 system_shared_libs : [],
2760 }
2761 cc_library {
2762 name: "libproduct2",
2763 product_specific: true,
2764 runtime_libs: ["liball_available", "libproduct1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002765 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002766 nocrt : true,
2767 system_shared_libs : [],
2768 }
2769`
2770
2771func TestRuntimeLibs(t *testing.T) {
2772 ctx := testCc(t, runtimeLibAndroidBp)
2773
2774 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002775 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002776
Justin Yun8a2600c2020-12-07 12:44:03 +09002777 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2778 checkRuntimeLibs(t, []string{"liball_available"}, module)
2779
2780 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2781 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002782
2783 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002784 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002785
2786 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2787 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002788 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002789
Justin Yun8a2600c2020-12-07 12:44:03 +09002790 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2791 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002792
2793 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002794 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1"}, module)
2795
2796 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2797 // and product variants.
2798 variant = "android_product.VER_arm64_armv8-a_shared"
2799
2800 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2801 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2802
2803 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
2804 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002805}
2806
2807func TestExcludeRuntimeLibs(t *testing.T) {
2808 ctx := testCc(t, runtimeLibAndroidBp)
2809
Colin Cross7113d202019-11-20 16:39:12 -08002810 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002811 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2812 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002813
Colin Crossfb0c16e2019-11-20 17:12:35 -08002814 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002815 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002816 checkRuntimeLibs(t, nil, module)
2817}
2818
2819func TestRuntimeLibsNoVndk(t *testing.T) {
2820 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2821
2822 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2823
Colin Cross7113d202019-11-20 16:39:12 -08002824 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002825
Justin Yun8a2600c2020-12-07 12:44:03 +09002826 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2827 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002828
2829 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002830 checkRuntimeLibs(t, []string{"liball_available", "libvendor1"}, module)
2831
2832 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
2833 checkRuntimeLibs(t, []string{"liball_available", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002834}
2835
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002836func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002837 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002838 actual := module.Properties.AndroidMkStaticLibs
2839 if !reflect.DeepEqual(actual, expected) {
2840 t.Errorf("incorrect static_libs"+
2841 "\nactual: %v"+
2842 "\nexpected: %v",
2843 actual,
2844 expected,
2845 )
2846 }
2847}
2848
2849const staticLibAndroidBp = `
2850 cc_library {
2851 name: "lib1",
2852 }
2853 cc_library {
2854 name: "lib2",
2855 static_libs: ["lib1"],
2856 }
2857`
2858
2859func TestStaticLibDepExport(t *testing.T) {
2860 ctx := testCc(t, staticLibAndroidBp)
2861
2862 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002863 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002864 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002865 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002866
2867 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002868 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002869 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2870 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002871 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002872}
2873
Jiyong Parkd08b6972017-09-26 10:50:54 +09002874var compilerFlagsTestCases = []struct {
2875 in string
2876 out bool
2877}{
2878 {
2879 in: "a",
2880 out: false,
2881 },
2882 {
2883 in: "-a",
2884 out: true,
2885 },
2886 {
2887 in: "-Ipath/to/something",
2888 out: false,
2889 },
2890 {
2891 in: "-isystempath/to/something",
2892 out: false,
2893 },
2894 {
2895 in: "--coverage",
2896 out: false,
2897 },
2898 {
2899 in: "-include a/b",
2900 out: true,
2901 },
2902 {
2903 in: "-include a/b c/d",
2904 out: false,
2905 },
2906 {
2907 in: "-DMACRO",
2908 out: true,
2909 },
2910 {
2911 in: "-DMAC RO",
2912 out: false,
2913 },
2914 {
2915 in: "-a -b",
2916 out: false,
2917 },
2918 {
2919 in: "-DMACRO=definition",
2920 out: true,
2921 },
2922 {
2923 in: "-DMACRO=defi nition",
2924 out: true, // TODO(jiyong): this should be false
2925 },
2926 {
2927 in: "-DMACRO(x)=x + 1",
2928 out: true,
2929 },
2930 {
2931 in: "-DMACRO=\"defi nition\"",
2932 out: true,
2933 },
2934}
2935
2936type mockContext struct {
2937 BaseModuleContext
2938 result bool
2939}
2940
2941func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2942 // CheckBadCompilerFlags calls this function when the flag should be rejected
2943 ctx.result = false
2944}
2945
2946func TestCompilerFlags(t *testing.T) {
2947 for _, testCase := range compilerFlagsTestCases {
2948 ctx := &mockContext{result: true}
2949 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2950 if ctx.result != testCase.out {
2951 t.Errorf("incorrect output:")
2952 t.Errorf(" input: %#v", testCase.in)
2953 t.Errorf(" expected: %#v", testCase.out)
2954 t.Errorf(" got: %#v", ctx.result)
2955 }
2956 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002957}
Jiyong Park374510b2018-03-19 18:23:01 +09002958
2959func TestVendorPublicLibraries(t *testing.T) {
2960 ctx := testCc(t, `
2961 cc_library_headers {
2962 name: "libvendorpublic_headers",
2963 export_include_dirs: ["my_include"],
2964 }
2965 vendor_public_library {
2966 name: "libvendorpublic",
2967 symbol_file: "",
2968 export_public_headers: ["libvendorpublic_headers"],
2969 }
2970 cc_library {
2971 name: "libvendorpublic",
2972 srcs: ["foo.c"],
2973 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002974 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002975 nocrt: true,
2976 }
2977
2978 cc_library {
2979 name: "libsystem",
2980 shared_libs: ["libvendorpublic"],
2981 vendor: false,
2982 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002983 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002984 nocrt: true,
2985 }
2986 cc_library {
2987 name: "libvendor",
2988 shared_libs: ["libvendorpublic"],
2989 vendor: true,
2990 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002991 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002992 nocrt: true,
2993 }
2994 `)
2995
Colin Cross7113d202019-11-20 16:39:12 -08002996 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08002997 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09002998
2999 // test if header search paths are correctly added
3000 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003001 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003002 cflags := cc.Args["cFlags"]
3003 if !strings.Contains(cflags, "-Imy_include") {
3004 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3005 }
3006
3007 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003008 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003009 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003010 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003011 if !strings.Contains(libflags, stubPaths[0].String()) {
3012 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3013 }
3014
3015 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003016 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003017 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003018 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003019 if !strings.Contains(libflags, stubPaths[0].String()) {
3020 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3021 }
3022
3023}
Jiyong Park37b25202018-07-11 10:49:27 +09003024
3025func TestRecovery(t *testing.T) {
3026 ctx := testCc(t, `
3027 cc_library_shared {
3028 name: "librecovery",
3029 recovery: true,
3030 }
3031 cc_library_shared {
3032 name: "librecovery32",
3033 recovery: true,
3034 compile_multilib:"32",
3035 }
Jiyong Park5baac542018-08-28 09:55:37 +09003036 cc_library_shared {
3037 name: "libHalInRecovery",
3038 recovery_available: true,
3039 vendor: true,
3040 }
Jiyong Park37b25202018-07-11 10:49:27 +09003041 `)
3042
3043 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003044 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003045 if len(variants) != 1 || !android.InList(arm64, variants) {
3046 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3047 }
3048
3049 variants = ctx.ModuleVariantsForTests("librecovery32")
3050 if android.InList(arm64, variants) {
3051 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3052 }
Jiyong Park5baac542018-08-28 09:55:37 +09003053
3054 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3055 if !recoveryModule.Platform() {
3056 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3057 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003058}
Jiyong Park5baac542018-08-28 09:55:37 +09003059
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003060func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3061 bp := `
3062 cc_prebuilt_test_library_shared {
3063 name: "test_lib",
3064 relative_install_path: "foo/bar/baz",
3065 srcs: ["srcpath/dontusethispath/baz.so"],
3066 }
3067
3068 cc_test {
3069 name: "main_test",
3070 data_libs: ["test_lib"],
3071 gtest: false,
3072 }
3073 `
3074
3075 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3076 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3077 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3078 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3079
3080 ctx := testCcWithConfig(t, config)
3081 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3082 testBinary := module.(*Module).linker.(*testBinary)
3083 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3084 if err != nil {
3085 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3086 }
3087 if len(outputFiles) != 1 {
3088 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3089 }
3090 if len(testBinary.dataPaths()) != 1 {
3091 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3092 }
3093
3094 outputPath := outputFiles[0].String()
3095
3096 if !strings.HasSuffix(outputPath, "/main_test") {
3097 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3098 }
3099 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3100 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3101 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3102 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3103 }
3104}
3105
Jiyong Park7ed9de32018-10-15 22:25:07 +09003106func TestVersionedStubs(t *testing.T) {
3107 ctx := testCc(t, `
3108 cc_library_shared {
3109 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003110 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003111 stubs: {
3112 symbol_file: "foo.map.txt",
3113 versions: ["1", "2", "3"],
3114 },
3115 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003116
Jiyong Park7ed9de32018-10-15 22:25:07 +09003117 cc_library_shared {
3118 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003119 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003120 shared_libs: ["libFoo#1"],
3121 }`)
3122
3123 variants := ctx.ModuleVariantsForTests("libFoo")
3124 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003125 "android_arm64_armv8-a_shared",
3126 "android_arm64_armv8-a_shared_1",
3127 "android_arm64_armv8-a_shared_2",
3128 "android_arm64_armv8-a_shared_3",
3129 "android_arm_armv7-a-neon_shared",
3130 "android_arm_armv7-a-neon_shared_1",
3131 "android_arm_armv7-a-neon_shared_2",
3132 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003133 }
3134 variantsMismatch := false
3135 if len(variants) != len(expectedVariants) {
3136 variantsMismatch = true
3137 } else {
3138 for _, v := range expectedVariants {
3139 if !inList(v, variants) {
3140 variantsMismatch = false
3141 }
3142 }
3143 }
3144 if variantsMismatch {
3145 t.Errorf("variants of libFoo expected:\n")
3146 for _, v := range expectedVariants {
3147 t.Errorf("%q\n", v)
3148 }
3149 t.Errorf(", but got:\n")
3150 for _, v := range variants {
3151 t.Errorf("%q\n", v)
3152 }
3153 }
3154
Colin Cross7113d202019-11-20 16:39:12 -08003155 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003156 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003157 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003158 if !strings.Contains(libFlags, libFoo1StubPath) {
3159 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3160 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003161
Colin Cross7113d202019-11-20 16:39:12 -08003162 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003163 cFlags := libBarCompileRule.Args["cFlags"]
3164 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3165 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3166 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3167 }
Jiyong Park37b25202018-07-11 10:49:27 +09003168}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003169
Jooyung Hanb04a4992020-03-13 18:57:35 +09003170func TestVersioningMacro(t *testing.T) {
3171 for _, tc := range []struct{ moduleName, expected string }{
3172 {"libc", "__LIBC_API__"},
3173 {"libfoo", "__LIBFOO_API__"},
3174 {"libfoo@1", "__LIBFOO_1_API__"},
3175 {"libfoo-v1", "__LIBFOO_V1_API__"},
3176 {"libfoo.v1", "__LIBFOO_V1_API__"},
3177 } {
3178 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3179 }
3180}
3181
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003182func TestStaticExecutable(t *testing.T) {
3183 ctx := testCc(t, `
3184 cc_binary {
3185 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003186 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003187 static_executable: true,
3188 }`)
3189
Colin Cross7113d202019-11-20 16:39:12 -08003190 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003191 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3192 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003193 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003194 for _, lib := range systemStaticLibs {
3195 if !strings.Contains(libFlags, lib) {
3196 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3197 }
3198 }
3199 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3200 for _, lib := range systemSharedLibs {
3201 if strings.Contains(libFlags, lib) {
3202 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3203 }
3204 }
3205}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003206
3207func TestStaticDepsOrderWithStubs(t *testing.T) {
3208 ctx := testCc(t, `
3209 cc_binary {
3210 name: "mybin",
3211 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003212 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003213 static_executable: true,
3214 stl: "none",
3215 }
3216
3217 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003218 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003219 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003220 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003221 stl: "none",
3222 }
3223
3224 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003225 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003226 srcs: ["foo.c"],
3227 stl: "none",
3228 stubs: {
3229 versions: ["1"],
3230 },
3231 }`)
3232
Colin Cross0de8a1e2020-09-18 14:15:30 -07003233 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3234 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003235 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003236
3237 if !reflect.DeepEqual(actual, expected) {
3238 t.Errorf("staticDeps orderings were not propagated correctly"+
3239 "\nactual: %v"+
3240 "\nexpected: %v",
3241 actual,
3242 expected,
3243 )
3244 }
3245}
Jooyung Han38002912019-05-16 04:01:54 +09003246
Jooyung Hand48f3c32019-08-23 11:18:57 +09003247func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3248 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3249 cc_library {
3250 name: "libA",
3251 srcs: ["foo.c"],
3252 shared_libs: ["libB"],
3253 stl: "none",
3254 }
3255
3256 cc_library {
3257 name: "libB",
3258 srcs: ["foo.c"],
3259 enabled: false,
3260 stl: "none",
3261 }
3262 `)
3263}
3264
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003265// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3266// correctly.
3267func TestFuzzTarget(t *testing.T) {
3268 ctx := testCc(t, `
3269 cc_fuzz {
3270 name: "fuzz_smoke_test",
3271 srcs: ["foo.c"],
3272 }`)
3273
Paul Duffin075c4172019-12-19 19:06:13 +00003274 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003275 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3276}
3277
Jiyong Park29074592019-07-07 16:27:47 +09003278func TestAidl(t *testing.T) {
3279}
3280
Jooyung Han38002912019-05-16 04:01:54 +09003281func assertString(t *testing.T, got, expected string) {
3282 t.Helper()
3283 if got != expected {
3284 t.Errorf("expected %q got %q", expected, got)
3285 }
3286}
3287
3288func assertArrayString(t *testing.T, got, expected []string) {
3289 t.Helper()
3290 if len(got) != len(expected) {
3291 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3292 return
3293 }
3294 for i := range got {
3295 if got[i] != expected[i] {
3296 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3297 i, expected[i], expected, got[i], got)
3298 return
3299 }
3300 }
3301}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003302
Jooyung Han0302a842019-10-30 18:43:49 +09003303func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3304 t.Helper()
3305 assertArrayString(t, android.SortedStringKeys(m), expected)
3306}
3307
Colin Crosse1bb5d02019-09-24 14:55:04 -07003308func TestDefaults(t *testing.T) {
3309 ctx := testCc(t, `
3310 cc_defaults {
3311 name: "defaults",
3312 srcs: ["foo.c"],
3313 static: {
3314 srcs: ["bar.c"],
3315 },
3316 shared: {
3317 srcs: ["baz.c"],
3318 },
3319 }
3320
3321 cc_library_static {
3322 name: "libstatic",
3323 defaults: ["defaults"],
3324 }
3325
3326 cc_library_shared {
3327 name: "libshared",
3328 defaults: ["defaults"],
3329 }
3330
3331 cc_library {
3332 name: "libboth",
3333 defaults: ["defaults"],
3334 }
3335
3336 cc_binary {
3337 name: "binary",
3338 defaults: ["defaults"],
3339 }`)
3340
3341 pathsToBase := func(paths android.Paths) []string {
3342 var ret []string
3343 for _, p := range paths {
3344 ret = append(ret, p.Base())
3345 }
3346 return ret
3347 }
3348
Colin Cross7113d202019-11-20 16:39:12 -08003349 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003350 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3351 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3352 }
Colin Cross7113d202019-11-20 16:39:12 -08003353 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003354 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3355 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3356 }
Colin Cross7113d202019-11-20 16:39:12 -08003357 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003358 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3359 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3360 }
3361
Colin Cross7113d202019-11-20 16:39:12 -08003362 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003363 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3364 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3365 }
Colin Cross7113d202019-11-20 16:39:12 -08003366 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003367 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3368 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3369 }
3370}
Colin Crosseabaedd2020-02-06 17:01:55 -08003371
3372func TestProductVariableDefaults(t *testing.T) {
3373 bp := `
3374 cc_defaults {
3375 name: "libfoo_defaults",
3376 srcs: ["foo.c"],
3377 cppflags: ["-DFOO"],
3378 product_variables: {
3379 debuggable: {
3380 cppflags: ["-DBAR"],
3381 },
3382 },
3383 }
3384
3385 cc_library {
3386 name: "libfoo",
3387 defaults: ["libfoo_defaults"],
3388 }
3389 `
3390
3391 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3392 config.TestProductVariables.Debuggable = BoolPtr(true)
3393
Colin Crossae8600b2020-10-29 17:09:13 -07003394 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003395 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3396 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3397 })
Colin Crossae8600b2020-10-29 17:09:13 -07003398 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003399
3400 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3401 android.FailIfErrored(t, errs)
3402 _, errs = ctx.PrepareBuildActions(config)
3403 android.FailIfErrored(t, errs)
3404
3405 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3406 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3407 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3408 }
3409}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003410
3411func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3412 t.Parallel()
3413 bp := `
3414 cc_library_static {
3415 name: "libfoo",
3416 srcs: ["foo.c"],
3417 whole_static_libs: ["libbar"],
3418 }
3419
3420 cc_library_static {
3421 name: "libbar",
3422 whole_static_libs: ["libmissing"],
3423 }
3424 `
3425
3426 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3427 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3428
Colin Crossae8600b2020-10-29 17:09:13 -07003429 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003430 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003431 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003432
3433 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3434 android.FailIfErrored(t, errs)
3435 _, errs = ctx.PrepareBuildActions(config)
3436 android.FailIfErrored(t, errs)
3437
3438 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3439 if g, w := libbar.Rule, android.ErrorRule; g != w {
3440 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3441 }
3442
3443 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3444 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
3445 }
3446
3447 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
3448 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
3449 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
3450 }
3451
3452}
Colin Crosse9fe2942020-11-10 18:12:15 -08003453
3454func TestInstallSharedLibs(t *testing.T) {
3455 bp := `
3456 cc_binary {
3457 name: "bin",
3458 host_supported: true,
3459 shared_libs: ["libshared"],
3460 runtime_libs: ["libruntime"],
3461 srcs: [":gen"],
3462 }
3463
3464 cc_library_shared {
3465 name: "libshared",
3466 host_supported: true,
3467 shared_libs: ["libtransitive"],
3468 }
3469
3470 cc_library_shared {
3471 name: "libtransitive",
3472 host_supported: true,
3473 }
3474
3475 cc_library_shared {
3476 name: "libruntime",
3477 host_supported: true,
3478 }
3479
3480 cc_binary_host {
3481 name: "tool",
3482 srcs: ["foo.cpp"],
3483 }
3484
3485 genrule {
3486 name: "gen",
3487 tools: ["tool"],
3488 out: ["gen.cpp"],
3489 cmd: "$(location tool) $(out)",
3490 }
3491 `
3492
3493 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3494 ctx := testCcWithConfig(t, config)
3495
3496 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3497 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3498 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3499 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3500 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3501
3502 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3503 t.Errorf("expected host bin dependency %q, got %q", w, g)
3504 }
3505
3506 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3507 t.Errorf("expected host bin dependency %q, got %q", w, g)
3508 }
3509
3510 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3511 t.Errorf("expected host bin dependency %q, got %q", w, g)
3512 }
3513
3514 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3515 t.Errorf("expected host bin dependency %q, got %q", w, g)
3516 }
3517
3518 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3519 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3520 }
3521
3522 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3523 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3524 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3525 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3526
3527 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3528 t.Errorf("expected device bin dependency %q, got %q", w, g)
3529 }
3530
3531 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3532 t.Errorf("expected device bin dependency %q, got %q", w, g)
3533 }
3534
3535 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3536 t.Errorf("expected device bin dependency %q, got %q", w, g)
3537 }
3538
3539 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3540 t.Errorf("expected device bin dependency %q, got %q", w, g)
3541 }
3542
3543 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3544 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3545 }
3546
3547}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003548
3549func TestStubsLibReexportsHeaders(t *testing.T) {
3550 ctx := testCc(t, `
3551 cc_library_shared {
3552 name: "libclient",
3553 srcs: ["foo.c"],
3554 shared_libs: ["libfoo#1"],
3555 }
3556
3557 cc_library_shared {
3558 name: "libfoo",
3559 srcs: ["foo.c"],
3560 shared_libs: ["libbar"],
3561 export_shared_lib_headers: ["libbar"],
3562 stubs: {
3563 symbol_file: "foo.map.txt",
3564 versions: ["1", "2", "3"],
3565 },
3566 }
3567
3568 cc_library_shared {
3569 name: "libbar",
3570 export_include_dirs: ["include/libbar"],
3571 srcs: ["foo.c"],
3572 }`)
3573
3574 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3575
3576 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3577 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3578 }
3579}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003580
3581func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3582 ctx := testCc(t, `
3583 cc_library {
3584 name: "libfoo",
3585 srcs: ["a/Foo.aidl"],
3586 aidl: { flags: ["-Werror"], },
3587 }
3588 `)
3589
3590 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3591 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3592 aidlCommand := manifest.Commands[0].GetCommand()
3593 expectedAidlFlag := "-Werror"
3594 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3595 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3596 }
3597}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003598
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003599type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003600
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003601const (
3602 None MemtagNoteType = iota + 1
3603 Sync
3604 Async
3605)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003606
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003607func (t MemtagNoteType) str() string {
3608 switch t {
3609 case None:
3610 return "none"
3611 case Sync:
3612 return "sync"
3613 case Async:
3614 return "async"
3615 default:
3616 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003617 }
3618}
3619
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003620func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3621 note_async := "note_memtag_heap_async"
3622 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003623
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003624 found := None
3625 implicits := m.Rule("ld").Implicits
3626 for _, lib := range implicits {
3627 if strings.Contains(lib.Rel(), note_async) {
3628 found = Async
3629 break
3630 } else if strings.Contains(lib.Rel(), note_sync) {
3631 found = Sync
3632 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003633 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003634 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003635
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003636 if found != expected {
3637 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3638 }
3639}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003640
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003641func makeMemtagTestConfig(t *testing.T) android.Config {
3642 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003643 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003644 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003645 gtest: false,
3646 }
3647
3648 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003649 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003650 gtest: false,
3651 sanitize: { memtag_heap: false },
3652 }
3653
3654 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003655 name: "%[1]s_test_true",
3656 gtest: false,
3657 sanitize: { memtag_heap: true },
3658 }
3659
3660 cc_test {
3661 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003662 gtest: false,
3663 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3664 }
3665
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003666 cc_test {
3667 name: "%[1]s_test_true_diag",
3668 gtest: false,
3669 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3670 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003671
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003672 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003673 name: "%[1]s_binary",
3674 }
3675
3676 cc_binary {
3677 name: "%[1]s_binary_false",
3678 sanitize: { memtag_heap: false },
3679 }
3680
3681 cc_binary {
3682 name: "%[1]s_binary_true",
3683 sanitize: { memtag_heap: true },
3684 }
3685
3686 cc_binary {
3687 name: "%[1]s_binary_true_nodiag",
3688 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3689 }
3690
3691 cc_binary {
3692 name: "%[1]s_binary_true_diag",
3693 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003694 }
3695 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003696 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3697 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3698 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3699 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003700
3701 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003702 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3703 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3704 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3705 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003706 }
3707
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003708 return TestConfig(buildDir, android.Android, nil, "", mockFS)
3709}
3710
3711func TestSanitizeMemtagHeap(t *testing.T) {
3712 variant := "android_arm64_armv8-a"
3713
3714 config := makeMemtagTestConfig(t)
3715 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003716 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003717 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003718 ctx := CreateTestContext(config)
3719 ctx.Register()
3720
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003721 _, 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 -08003722 android.FailIfErrored(t, errs)
3723 _, errs = ctx.PrepareBuildActions(config)
3724 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003725
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003726 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3727 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3728 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3729 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3730 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3731
3732 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3733 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3734 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3735 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3736 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3737
3738 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3739 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3740 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3741 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3742 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3743
3744 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3745 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3746 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3747 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3748 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3749
3750 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3751 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3752 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3753 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3754 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3755
3756 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3757 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3758 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3759 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3760 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3761
3762 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3763 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3764 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3765 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3766 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3767
3768 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3769 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3770 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3771 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3772 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3773}
3774
3775func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003776 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003777
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003778 config := makeMemtagTestConfig(t)
3779 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3780 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3781 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3782 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3783 ctx := CreateTestContext(config)
3784 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003785
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003786 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3787 android.FailIfErrored(t, errs)
3788 _, errs = ctx.PrepareBuildActions(config)
3789 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003790
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003791 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3792 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3793 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3794 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3795 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003796
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003797 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3798 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3799 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3800 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3801 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3802
3803 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3804 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3805 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3806 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3807 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3808
3809 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3810 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3811 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3812 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3813 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3814
3815 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3816 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3817 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3818 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3819 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3820
3821 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3822 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3823 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3824 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3825 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3826
3827 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3828 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3829 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3830 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3831 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3832
3833 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3834 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3835 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3836 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3837 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3838}
3839
3840func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3841 variant := "android_arm64_armv8-a"
3842
3843 config := makeMemtagTestConfig(t)
3844 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3845 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3846 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3847 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3848 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
3849 ctx := CreateTestContext(config)
3850 ctx.Register()
3851
3852 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3853 android.FailIfErrored(t, errs)
3854 _, errs = ctx.PrepareBuildActions(config)
3855 android.FailIfErrored(t, errs)
3856
3857 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3858 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3859 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3860 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3861 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3862
3863 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3864 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3865 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3866 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3868
3869 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3870 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3871 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3872 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3873 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3874
3875 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3876 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3877 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3878 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3879 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3880
3881 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3882 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3883 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3884 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3885 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3886
3887 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3888 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3889 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3890 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3892
3893 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3894 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3895 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3896 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3898
3899 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3900 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3901 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3902 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3903 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003904}