blob: b1c1b2e8dbfb077eea4bd89a72831898f7386e2b [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 {
Justin Yuncbca3732021-02-03 19:24:13 +09002725 name: "libproduct_vendor",
2726 product_specific: true,
2727 vendor_available: true,
2728 no_libcrt : true,
2729 nocrt : true,
2730 system_shared_libs : [],
2731 }
2732 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002733 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002734 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002735 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002736 nocrt : true,
2737 system_shared_libs : [],
2738 }
2739 cc_library {
2740 name: "libvendor1",
2741 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002742 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002743 nocrt : true,
2744 system_shared_libs : [],
2745 }
2746 cc_library {
2747 name: "libvendor2",
2748 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002749 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002750 no_libcrt : true,
2751 nocrt : true,
2752 system_shared_libs : [],
2753 }
2754 cc_library {
2755 name: "libproduct_available1",
2756 product_available: true,
2757 runtime_libs: ["liball_available"],
2758 no_libcrt : true,
2759 nocrt : true,
2760 system_shared_libs : [],
2761 }
2762 cc_library {
2763 name: "libproduct1",
2764 product_specific: true,
2765 no_libcrt : true,
2766 nocrt : true,
2767 system_shared_libs : [],
2768 }
2769 cc_library {
2770 name: "libproduct2",
2771 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002772 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002773 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002774 nocrt : true,
2775 system_shared_libs : [],
2776 }
2777`
2778
2779func TestRuntimeLibs(t *testing.T) {
2780 ctx := testCc(t, runtimeLibAndroidBp)
2781
2782 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002783 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002784
Justin Yun8a2600c2020-12-07 12:44:03 +09002785 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2786 checkRuntimeLibs(t, []string{"liball_available"}, module)
2787
2788 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2789 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002790
2791 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002792 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002793
2794 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2795 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002796 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002797
Justin Yun8a2600c2020-12-07 12:44:03 +09002798 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2799 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002800
2801 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002802 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002803
2804 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2805 // and product variants.
2806 variant = "android_product.VER_arm64_armv8-a_shared"
2807
2808 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2809 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2810
2811 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002812 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002813}
2814
2815func TestExcludeRuntimeLibs(t *testing.T) {
2816 ctx := testCc(t, runtimeLibAndroidBp)
2817
Colin Cross7113d202019-11-20 16:39:12 -08002818 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002819 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2820 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002821
Colin Crossfb0c16e2019-11-20 17:12:35 -08002822 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002823 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002824 checkRuntimeLibs(t, nil, module)
2825}
2826
2827func TestRuntimeLibsNoVndk(t *testing.T) {
2828 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2829
2830 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2831
Colin Cross7113d202019-11-20 16:39:12 -08002832 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002833
Justin Yun8a2600c2020-12-07 12:44:03 +09002834 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2835 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002836
2837 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002838 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002839
2840 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002841 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002842}
2843
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002844func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002845 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002846 actual := module.Properties.AndroidMkStaticLibs
2847 if !reflect.DeepEqual(actual, expected) {
2848 t.Errorf("incorrect static_libs"+
2849 "\nactual: %v"+
2850 "\nexpected: %v",
2851 actual,
2852 expected,
2853 )
2854 }
2855}
2856
2857const staticLibAndroidBp = `
2858 cc_library {
2859 name: "lib1",
2860 }
2861 cc_library {
2862 name: "lib2",
2863 static_libs: ["lib1"],
2864 }
2865`
2866
2867func TestStaticLibDepExport(t *testing.T) {
2868 ctx := testCc(t, staticLibAndroidBp)
2869
2870 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002871 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002872 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002873 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002874
2875 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002876 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002877 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2878 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002879 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002880}
2881
Jiyong Parkd08b6972017-09-26 10:50:54 +09002882var compilerFlagsTestCases = []struct {
2883 in string
2884 out bool
2885}{
2886 {
2887 in: "a",
2888 out: false,
2889 },
2890 {
2891 in: "-a",
2892 out: true,
2893 },
2894 {
2895 in: "-Ipath/to/something",
2896 out: false,
2897 },
2898 {
2899 in: "-isystempath/to/something",
2900 out: false,
2901 },
2902 {
2903 in: "--coverage",
2904 out: false,
2905 },
2906 {
2907 in: "-include a/b",
2908 out: true,
2909 },
2910 {
2911 in: "-include a/b c/d",
2912 out: false,
2913 },
2914 {
2915 in: "-DMACRO",
2916 out: true,
2917 },
2918 {
2919 in: "-DMAC RO",
2920 out: false,
2921 },
2922 {
2923 in: "-a -b",
2924 out: false,
2925 },
2926 {
2927 in: "-DMACRO=definition",
2928 out: true,
2929 },
2930 {
2931 in: "-DMACRO=defi nition",
2932 out: true, // TODO(jiyong): this should be false
2933 },
2934 {
2935 in: "-DMACRO(x)=x + 1",
2936 out: true,
2937 },
2938 {
2939 in: "-DMACRO=\"defi nition\"",
2940 out: true,
2941 },
2942}
2943
2944type mockContext struct {
2945 BaseModuleContext
2946 result bool
2947}
2948
2949func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2950 // CheckBadCompilerFlags calls this function when the flag should be rejected
2951 ctx.result = false
2952}
2953
2954func TestCompilerFlags(t *testing.T) {
2955 for _, testCase := range compilerFlagsTestCases {
2956 ctx := &mockContext{result: true}
2957 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2958 if ctx.result != testCase.out {
2959 t.Errorf("incorrect output:")
2960 t.Errorf(" input: %#v", testCase.in)
2961 t.Errorf(" expected: %#v", testCase.out)
2962 t.Errorf(" got: %#v", ctx.result)
2963 }
2964 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002965}
Jiyong Park374510b2018-03-19 18:23:01 +09002966
2967func TestVendorPublicLibraries(t *testing.T) {
2968 ctx := testCc(t, `
2969 cc_library_headers {
2970 name: "libvendorpublic_headers",
2971 export_include_dirs: ["my_include"],
2972 }
2973 vendor_public_library {
2974 name: "libvendorpublic",
2975 symbol_file: "",
2976 export_public_headers: ["libvendorpublic_headers"],
2977 }
2978 cc_library {
2979 name: "libvendorpublic",
2980 srcs: ["foo.c"],
2981 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002982 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002983 nocrt: true,
2984 }
2985
2986 cc_library {
2987 name: "libsystem",
2988 shared_libs: ["libvendorpublic"],
2989 vendor: false,
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 cc_library {
2995 name: "libvendor",
2996 shared_libs: ["libvendorpublic"],
2997 vendor: true,
2998 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002999 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003000 nocrt: true,
3001 }
3002 `)
3003
Colin Cross7113d202019-11-20 16:39:12 -08003004 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003005 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003006
3007 // test if header search paths are correctly added
3008 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003009 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003010 cflags := cc.Args["cFlags"]
3011 if !strings.Contains(cflags, "-Imy_include") {
3012 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3013 }
3014
3015 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003016 ld := ctx.ModuleForTests("libsystem", coreVariant).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, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003019 if !strings.Contains(libflags, stubPaths[0].String()) {
3020 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3021 }
3022
3023 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003024 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003025 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003026 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003027 if !strings.Contains(libflags, stubPaths[0].String()) {
3028 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3029 }
3030
3031}
Jiyong Park37b25202018-07-11 10:49:27 +09003032
3033func TestRecovery(t *testing.T) {
3034 ctx := testCc(t, `
3035 cc_library_shared {
3036 name: "librecovery",
3037 recovery: true,
3038 }
3039 cc_library_shared {
3040 name: "librecovery32",
3041 recovery: true,
3042 compile_multilib:"32",
3043 }
Jiyong Park5baac542018-08-28 09:55:37 +09003044 cc_library_shared {
3045 name: "libHalInRecovery",
3046 recovery_available: true,
3047 vendor: true,
3048 }
Jiyong Park37b25202018-07-11 10:49:27 +09003049 `)
3050
3051 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003052 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003053 if len(variants) != 1 || !android.InList(arm64, variants) {
3054 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3055 }
3056
3057 variants = ctx.ModuleVariantsForTests("librecovery32")
3058 if android.InList(arm64, variants) {
3059 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3060 }
Jiyong Park5baac542018-08-28 09:55:37 +09003061
3062 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3063 if !recoveryModule.Platform() {
3064 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3065 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003066}
Jiyong Park5baac542018-08-28 09:55:37 +09003067
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003068func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3069 bp := `
3070 cc_prebuilt_test_library_shared {
3071 name: "test_lib",
3072 relative_install_path: "foo/bar/baz",
3073 srcs: ["srcpath/dontusethispath/baz.so"],
3074 }
3075
3076 cc_test {
3077 name: "main_test",
3078 data_libs: ["test_lib"],
3079 gtest: false,
3080 }
3081 `
3082
3083 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3084 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3085 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3086 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3087
3088 ctx := testCcWithConfig(t, config)
3089 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3090 testBinary := module.(*Module).linker.(*testBinary)
3091 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3092 if err != nil {
3093 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3094 }
3095 if len(outputFiles) != 1 {
3096 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3097 }
3098 if len(testBinary.dataPaths()) != 1 {
3099 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3100 }
3101
3102 outputPath := outputFiles[0].String()
3103
3104 if !strings.HasSuffix(outputPath, "/main_test") {
3105 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3106 }
3107 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3108 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3109 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3110 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3111 }
3112}
3113
Jiyong Park7ed9de32018-10-15 22:25:07 +09003114func TestVersionedStubs(t *testing.T) {
3115 ctx := testCc(t, `
3116 cc_library_shared {
3117 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003118 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003119 stubs: {
3120 symbol_file: "foo.map.txt",
3121 versions: ["1", "2", "3"],
3122 },
3123 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003124
Jiyong Park7ed9de32018-10-15 22:25:07 +09003125 cc_library_shared {
3126 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003127 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003128 shared_libs: ["libFoo#1"],
3129 }`)
3130
3131 variants := ctx.ModuleVariantsForTests("libFoo")
3132 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003133 "android_arm64_armv8-a_shared",
3134 "android_arm64_armv8-a_shared_1",
3135 "android_arm64_armv8-a_shared_2",
3136 "android_arm64_armv8-a_shared_3",
3137 "android_arm_armv7-a-neon_shared",
3138 "android_arm_armv7-a-neon_shared_1",
3139 "android_arm_armv7-a-neon_shared_2",
3140 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003141 }
3142 variantsMismatch := false
3143 if len(variants) != len(expectedVariants) {
3144 variantsMismatch = true
3145 } else {
3146 for _, v := range expectedVariants {
3147 if !inList(v, variants) {
3148 variantsMismatch = false
3149 }
3150 }
3151 }
3152 if variantsMismatch {
3153 t.Errorf("variants of libFoo expected:\n")
3154 for _, v := range expectedVariants {
3155 t.Errorf("%q\n", v)
3156 }
3157 t.Errorf(", but got:\n")
3158 for _, v := range variants {
3159 t.Errorf("%q\n", v)
3160 }
3161 }
3162
Colin Cross7113d202019-11-20 16:39:12 -08003163 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003164 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003165 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003166 if !strings.Contains(libFlags, libFoo1StubPath) {
3167 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3168 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003169
Colin Cross7113d202019-11-20 16:39:12 -08003170 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003171 cFlags := libBarCompileRule.Args["cFlags"]
3172 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3173 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3174 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3175 }
Jiyong Park37b25202018-07-11 10:49:27 +09003176}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003177
Jooyung Hanb04a4992020-03-13 18:57:35 +09003178func TestVersioningMacro(t *testing.T) {
3179 for _, tc := range []struct{ moduleName, expected string }{
3180 {"libc", "__LIBC_API__"},
3181 {"libfoo", "__LIBFOO_API__"},
3182 {"libfoo@1", "__LIBFOO_1_API__"},
3183 {"libfoo-v1", "__LIBFOO_V1_API__"},
3184 {"libfoo.v1", "__LIBFOO_V1_API__"},
3185 } {
3186 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3187 }
3188}
3189
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003190func TestStaticExecutable(t *testing.T) {
3191 ctx := testCc(t, `
3192 cc_binary {
3193 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003194 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003195 static_executable: true,
3196 }`)
3197
Colin Cross7113d202019-11-20 16:39:12 -08003198 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003199 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3200 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003201 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003202 for _, lib := range systemStaticLibs {
3203 if !strings.Contains(libFlags, lib) {
3204 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3205 }
3206 }
3207 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3208 for _, lib := range systemSharedLibs {
3209 if strings.Contains(libFlags, lib) {
3210 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3211 }
3212 }
3213}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003214
3215func TestStaticDepsOrderWithStubs(t *testing.T) {
3216 ctx := testCc(t, `
3217 cc_binary {
3218 name: "mybin",
3219 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003220 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003221 static_executable: true,
3222 stl: "none",
3223 }
3224
3225 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003226 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003227 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003228 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003229 stl: "none",
3230 }
3231
3232 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003233 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003234 srcs: ["foo.c"],
3235 stl: "none",
3236 stubs: {
3237 versions: ["1"],
3238 },
3239 }`)
3240
Colin Cross0de8a1e2020-09-18 14:15:30 -07003241 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3242 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003243 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003244
3245 if !reflect.DeepEqual(actual, expected) {
3246 t.Errorf("staticDeps orderings were not propagated correctly"+
3247 "\nactual: %v"+
3248 "\nexpected: %v",
3249 actual,
3250 expected,
3251 )
3252 }
3253}
Jooyung Han38002912019-05-16 04:01:54 +09003254
Jooyung Hand48f3c32019-08-23 11:18:57 +09003255func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3256 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3257 cc_library {
3258 name: "libA",
3259 srcs: ["foo.c"],
3260 shared_libs: ["libB"],
3261 stl: "none",
3262 }
3263
3264 cc_library {
3265 name: "libB",
3266 srcs: ["foo.c"],
3267 enabled: false,
3268 stl: "none",
3269 }
3270 `)
3271}
3272
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003273// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3274// correctly.
3275func TestFuzzTarget(t *testing.T) {
3276 ctx := testCc(t, `
3277 cc_fuzz {
3278 name: "fuzz_smoke_test",
3279 srcs: ["foo.c"],
3280 }`)
3281
Paul Duffin075c4172019-12-19 19:06:13 +00003282 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003283 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3284}
3285
Jiyong Park29074592019-07-07 16:27:47 +09003286func TestAidl(t *testing.T) {
3287}
3288
Jooyung Han38002912019-05-16 04:01:54 +09003289func assertString(t *testing.T, got, expected string) {
3290 t.Helper()
3291 if got != expected {
3292 t.Errorf("expected %q got %q", expected, got)
3293 }
3294}
3295
3296func assertArrayString(t *testing.T, got, expected []string) {
3297 t.Helper()
3298 if len(got) != len(expected) {
3299 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3300 return
3301 }
3302 for i := range got {
3303 if got[i] != expected[i] {
3304 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3305 i, expected[i], expected, got[i], got)
3306 return
3307 }
3308 }
3309}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003310
Jooyung Han0302a842019-10-30 18:43:49 +09003311func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3312 t.Helper()
3313 assertArrayString(t, android.SortedStringKeys(m), expected)
3314}
3315
Colin Crosse1bb5d02019-09-24 14:55:04 -07003316func TestDefaults(t *testing.T) {
3317 ctx := testCc(t, `
3318 cc_defaults {
3319 name: "defaults",
3320 srcs: ["foo.c"],
3321 static: {
3322 srcs: ["bar.c"],
3323 },
3324 shared: {
3325 srcs: ["baz.c"],
3326 },
3327 }
3328
3329 cc_library_static {
3330 name: "libstatic",
3331 defaults: ["defaults"],
3332 }
3333
3334 cc_library_shared {
3335 name: "libshared",
3336 defaults: ["defaults"],
3337 }
3338
3339 cc_library {
3340 name: "libboth",
3341 defaults: ["defaults"],
3342 }
3343
3344 cc_binary {
3345 name: "binary",
3346 defaults: ["defaults"],
3347 }`)
3348
3349 pathsToBase := func(paths android.Paths) []string {
3350 var ret []string
3351 for _, p := range paths {
3352 ret = append(ret, p.Base())
3353 }
3354 return ret
3355 }
3356
Colin Cross7113d202019-11-20 16:39:12 -08003357 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003358 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3359 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3360 }
Colin Cross7113d202019-11-20 16:39:12 -08003361 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003362 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3363 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3364 }
Colin Cross7113d202019-11-20 16:39:12 -08003365 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003366 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3367 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3368 }
3369
Colin Cross7113d202019-11-20 16:39:12 -08003370 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003371 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3372 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3373 }
Colin Cross7113d202019-11-20 16:39:12 -08003374 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003375 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3376 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3377 }
3378}
Colin Crosseabaedd2020-02-06 17:01:55 -08003379
3380func TestProductVariableDefaults(t *testing.T) {
3381 bp := `
3382 cc_defaults {
3383 name: "libfoo_defaults",
3384 srcs: ["foo.c"],
3385 cppflags: ["-DFOO"],
3386 product_variables: {
3387 debuggable: {
3388 cppflags: ["-DBAR"],
3389 },
3390 },
3391 }
3392
3393 cc_library {
3394 name: "libfoo",
3395 defaults: ["libfoo_defaults"],
3396 }
3397 `
3398
3399 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3400 config.TestProductVariables.Debuggable = BoolPtr(true)
3401
Colin Crossae8600b2020-10-29 17:09:13 -07003402 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003403 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3404 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3405 })
Colin Crossae8600b2020-10-29 17:09:13 -07003406 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003407
3408 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3409 android.FailIfErrored(t, errs)
3410 _, errs = ctx.PrepareBuildActions(config)
3411 android.FailIfErrored(t, errs)
3412
3413 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3414 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3415 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3416 }
3417}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003418
3419func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3420 t.Parallel()
3421 bp := `
3422 cc_library_static {
3423 name: "libfoo",
3424 srcs: ["foo.c"],
3425 whole_static_libs: ["libbar"],
3426 }
3427
3428 cc_library_static {
3429 name: "libbar",
3430 whole_static_libs: ["libmissing"],
3431 }
3432 `
3433
3434 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3435 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3436
Colin Crossae8600b2020-10-29 17:09:13 -07003437 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003438 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003439 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003440
3441 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3442 android.FailIfErrored(t, errs)
3443 _, errs = ctx.PrepareBuildActions(config)
3444 android.FailIfErrored(t, errs)
3445
3446 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3447 if g, w := libbar.Rule, android.ErrorRule; g != w {
3448 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3449 }
3450
3451 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3452 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
3453 }
3454
3455 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
3456 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
3457 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
3458 }
3459
3460}
Colin Crosse9fe2942020-11-10 18:12:15 -08003461
3462func TestInstallSharedLibs(t *testing.T) {
3463 bp := `
3464 cc_binary {
3465 name: "bin",
3466 host_supported: true,
3467 shared_libs: ["libshared"],
3468 runtime_libs: ["libruntime"],
3469 srcs: [":gen"],
3470 }
3471
3472 cc_library_shared {
3473 name: "libshared",
3474 host_supported: true,
3475 shared_libs: ["libtransitive"],
3476 }
3477
3478 cc_library_shared {
3479 name: "libtransitive",
3480 host_supported: true,
3481 }
3482
3483 cc_library_shared {
3484 name: "libruntime",
3485 host_supported: true,
3486 }
3487
3488 cc_binary_host {
3489 name: "tool",
3490 srcs: ["foo.cpp"],
3491 }
3492
3493 genrule {
3494 name: "gen",
3495 tools: ["tool"],
3496 out: ["gen.cpp"],
3497 cmd: "$(location tool) $(out)",
3498 }
3499 `
3500
3501 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3502 ctx := testCcWithConfig(t, config)
3503
3504 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3505 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3506 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3507 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3508 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3509
3510 if g, w := hostBin.Implicits.Strings(), hostShared.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(), hostTransitive.Output.String(); !android.InList(w, g) {
3515 t.Errorf("expected host bin dependency %q, got %q", w, g)
3516 }
3517
3518 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3519 t.Errorf("expected host bin dependency %q, got %q", w, g)
3520 }
3521
3522 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3523 t.Errorf("expected host bin dependency %q, got %q", w, g)
3524 }
3525
3526 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3527 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3528 }
3529
3530 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3531 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3532 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3533 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3534
3535 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.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(), deviceTransitive.Output.String(); !android.InList(w, g) {
3540 t.Errorf("expected device bin dependency %q, got %q", w, g)
3541 }
3542
3543 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3544 t.Errorf("expected device bin dependency %q, got %q", w, g)
3545 }
3546
3547 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3548 t.Errorf("expected device bin dependency %q, got %q", w, g)
3549 }
3550
3551 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3552 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3553 }
3554
3555}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003556
3557func TestStubsLibReexportsHeaders(t *testing.T) {
3558 ctx := testCc(t, `
3559 cc_library_shared {
3560 name: "libclient",
3561 srcs: ["foo.c"],
3562 shared_libs: ["libfoo#1"],
3563 }
3564
3565 cc_library_shared {
3566 name: "libfoo",
3567 srcs: ["foo.c"],
3568 shared_libs: ["libbar"],
3569 export_shared_lib_headers: ["libbar"],
3570 stubs: {
3571 symbol_file: "foo.map.txt",
3572 versions: ["1", "2", "3"],
3573 },
3574 }
3575
3576 cc_library_shared {
3577 name: "libbar",
3578 export_include_dirs: ["include/libbar"],
3579 srcs: ["foo.c"],
3580 }`)
3581
3582 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3583
3584 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3585 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3586 }
3587}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003588
3589func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3590 ctx := testCc(t, `
3591 cc_library {
3592 name: "libfoo",
3593 srcs: ["a/Foo.aidl"],
3594 aidl: { flags: ["-Werror"], },
3595 }
3596 `)
3597
3598 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3599 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3600 aidlCommand := manifest.Commands[0].GetCommand()
3601 expectedAidlFlag := "-Werror"
3602 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3603 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3604 }
3605}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003606
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003607type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003608
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003609const (
3610 None MemtagNoteType = iota + 1
3611 Sync
3612 Async
3613)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003614
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003615func (t MemtagNoteType) str() string {
3616 switch t {
3617 case None:
3618 return "none"
3619 case Sync:
3620 return "sync"
3621 case Async:
3622 return "async"
3623 default:
3624 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003625 }
3626}
3627
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003628func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3629 note_async := "note_memtag_heap_async"
3630 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003631
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003632 found := None
3633 implicits := m.Rule("ld").Implicits
3634 for _, lib := range implicits {
3635 if strings.Contains(lib.Rel(), note_async) {
3636 found = Async
3637 break
3638 } else if strings.Contains(lib.Rel(), note_sync) {
3639 found = Sync
3640 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003641 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003642 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003643
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003644 if found != expected {
3645 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3646 }
3647}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003648
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003649func makeMemtagTestConfig(t *testing.T) android.Config {
3650 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003651 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003652 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003653 gtest: false,
3654 }
3655
3656 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003657 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003658 gtest: false,
3659 sanitize: { memtag_heap: false },
3660 }
3661
3662 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003663 name: "%[1]s_test_true",
3664 gtest: false,
3665 sanitize: { memtag_heap: true },
3666 }
3667
3668 cc_test {
3669 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003670 gtest: false,
3671 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3672 }
3673
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003674 cc_test {
3675 name: "%[1]s_test_true_diag",
3676 gtest: false,
3677 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3678 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003679
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003680 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003681 name: "%[1]s_binary",
3682 }
3683
3684 cc_binary {
3685 name: "%[1]s_binary_false",
3686 sanitize: { memtag_heap: false },
3687 }
3688
3689 cc_binary {
3690 name: "%[1]s_binary_true",
3691 sanitize: { memtag_heap: true },
3692 }
3693
3694 cc_binary {
3695 name: "%[1]s_binary_true_nodiag",
3696 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3697 }
3698
3699 cc_binary {
3700 name: "%[1]s_binary_true_diag",
3701 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003702 }
3703 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003704 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3705 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3706 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3707 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003708
3709 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003710 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3711 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3712 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3713 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003714 }
3715
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003716 return TestConfig(buildDir, android.Android, nil, "", mockFS)
3717}
3718
3719func TestSanitizeMemtagHeap(t *testing.T) {
3720 variant := "android_arm64_armv8-a"
3721
3722 config := makeMemtagTestConfig(t)
3723 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003724 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003725 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003726 ctx := CreateTestContext(config)
3727 ctx.Register()
3728
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003729 _, 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 -08003730 android.FailIfErrored(t, errs)
3731 _, errs = ctx.PrepareBuildActions(config)
3732 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003733
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003734 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3735 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3736 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3737 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3738 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3739
3740 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3741 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3742 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3743 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3744 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3745
3746 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3747 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3748 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3749 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3750 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3751
3752 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3753 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3754 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3755 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3756 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3757
3758 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3759 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3760 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3761 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3762 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3763
3764 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3765 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3766 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3767 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3768 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3769
3770 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3771 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3772 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3773 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3774 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3775
3776 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3777 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3778 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3779 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3780 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3781}
3782
3783func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003784 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003785
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003786 config := makeMemtagTestConfig(t)
3787 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3788 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3789 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3790 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3791 ctx := CreateTestContext(config)
3792 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003793
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003794 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3795 android.FailIfErrored(t, errs)
3796 _, errs = ctx.PrepareBuildActions(config)
3797 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003798
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003799 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3800 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3801 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3802 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3803 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003804
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003805 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3806 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3807 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3808 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3809 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3810
3811 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3812 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3813 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3814 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3815 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3816
3817 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3818 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3819 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3820 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3821 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3822
3823 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3824 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3825 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3826 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3827 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3828
3829 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3830 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3831 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3832 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3833 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3834
3835 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3836 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3837 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3838 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3839 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3840
3841 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3842 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3843 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3844 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3845 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3846}
3847
3848func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3849 variant := "android_arm64_armv8-a"
3850
3851 config := makeMemtagTestConfig(t)
3852 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3853 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3854 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3855 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3856 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
3857 ctx := CreateTestContext(config)
3858 ctx.Register()
3859
3860 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3861 android.FailIfErrored(t, errs)
3862 _, errs = ctx.PrepareBuildActions(config)
3863 android.FailIfErrored(t, errs)
3864
3865 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3866 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3869 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3870
3871 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3872 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3873 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3874 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3875 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3876
3877 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3878 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3879 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3880 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3881 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3882
3883 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3884 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3885 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3886 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3887 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3888
3889 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3890 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3892 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3893 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3894
3895 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3896 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3898 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3899 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3900
3901 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3902 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3903 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3904 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3905 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3906
3907 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3908 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3909 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3910 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3911 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003912}