blob: 7288cc476382af35880035d2c0a448be752dabc8 [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
Bill Peckham945441c2020-08-31 16:07:58 -0700269func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool) {
270 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)
285 if out.Input.String() != outputFiles[0].String() {
286 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
287 }
288 } else {
289 out := singleton.MaybeOutput(snapshotPath)
290 if out.Rule != nil {
291 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
292 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900293 }
294}
295
Bill Peckham945441c2020-08-31 16:07:58 -0700296func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
297 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true)
298}
299
300func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
301 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false)
302}
303
Jooyung Han2216fb12019-11-06 16:46:15 +0900304func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
305 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800306 content := android.ContentFromFileRuleForTests(t, params)
307 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900308 assertArrayString(t, actual, expected)
309}
310
Jooyung Han097087b2019-10-22 19:32:18 +0900311func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
312 t.Helper()
313 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900314 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
315}
316
317func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
318 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800319 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
320 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900321}
322
Logan Chienf3511742017-10-31 18:04:35 +0800323func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800324 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800325 cc_library {
326 name: "libvndk",
327 vendor_available: true,
328 vndk: {
329 enabled: true,
330 },
331 nocrt: true,
332 }
333
334 cc_library {
335 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900336 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800337 vndk: {
338 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900339 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800340 },
341 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900342 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800343 }
344
345 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900346 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800347 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900348 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800349 vndk: {
350 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900351 },
352 nocrt: true,
353 target: {
354 vendor: {
355 cflags: ["-DTEST"],
356 },
357 product: {
358 cflags: ["-DTEST"],
359 },
360 },
361 }
362
363 cc_library {
364 name: "libvndk_sp",
365 vendor_available: true,
366 vndk: {
367 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800368 support_system_process: true,
369 },
370 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900371 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800372 }
373
374 cc_library {
375 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900376 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800377 vndk: {
378 enabled: true,
379 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900380 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800381 },
382 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900383 target: {
384 vendor: {
385 suffix: "-x",
386 },
387 },
Logan Chienf3511742017-10-31 18:04:35 +0800388 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900389
390 cc_library {
391 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900392 vendor_available: true,
393 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900394 vndk: {
395 enabled: true,
396 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900397 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900398 },
399 nocrt: true,
400 target: {
401 vendor: {
402 suffix: "-x",
403 },
404 product: {
405 suffix: "-x",
406 },
407 },
408 }
409
Colin Crosse4e44bc2020-12-28 13:50:21 -0800410 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900411 name: "llndk.libraries.txt",
412 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800413 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900414 name: "vndkcore.libraries.txt",
415 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800416 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900417 name: "vndksp.libraries.txt",
418 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800419 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900420 name: "vndkprivate.libraries.txt",
421 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800422 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900423 name: "vndkproduct.libraries.txt",
424 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800425 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900426 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800427 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900428 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800429 `
430
431 config := TestConfig(buildDir, android.Android, nil, bp, nil)
432 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900433 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800434 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
435
436 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800437
Jooyung Han261e1582020-10-20 18:54:21 +0900438 // subdir == "" because VNDK libs are not supposed to be installed separately.
439 // They are installed as part of VNDK APEX instead.
440 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
441 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900442 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900443 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
444 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900445 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900446
Justin Yun6977e8a2020-10-29 18:24:11 +0900447 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
448 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900449
Inseob Kim1f086e22019-05-09 13:29:15 +0900450 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900451 snapshotDir := "vndk-snapshot"
452 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
453
454 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
455 "arm64", "armv8-a"))
456 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
457 "arm", "armv7-a-neon"))
458
459 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
460 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
461 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
462 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
463
Colin Crossfb0c16e2019-11-20 17:12:35 -0800464 variant := "android_vendor.VER_arm64_armv8-a_shared"
465 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900466
Inseob Kim7f283f42020-06-01 21:53:49 +0900467 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
468
469 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
470 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900471 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
472 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900473 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
474 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900475
Jooyung Han39edb6c2019-11-06 16:53:07 +0900476 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900477 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
478 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
479 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
480 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900481 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900482
Jooyung Han097087b2019-10-22 19:32:18 +0900483 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
484 "LLNDK: libc.so",
485 "LLNDK: libdl.so",
486 "LLNDK: libft2.so",
487 "LLNDK: libm.so",
488 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900489 "VNDK-SP: libvndk_sp-x.so",
490 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900491 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900492 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900493 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900494 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900495 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900496 "VNDK-private: libvndk-private.so",
497 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900498 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900499 "VNDK-product: libc++.so",
500 "VNDK-product: libvndk_product.so",
501 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900502 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900503 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900504 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
505 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
506 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 +0900507 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 +0900508 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
509}
510
Yo Chiangbba545e2020-06-09 16:15:37 +0800511func TestVndkWithHostSupported(t *testing.T) {
512 ctx := testCc(t, `
513 cc_library {
514 name: "libvndk_host_supported",
515 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900516 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800517 vndk: {
518 enabled: true,
519 },
520 host_supported: true,
521 }
522
523 cc_library {
524 name: "libvndk_host_supported_but_disabled_on_device",
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 enabled: false,
532 target: {
533 host: {
534 enabled: true,
535 }
536 }
537 }
538
Colin Crosse4e44bc2020-12-28 13:50:21 -0800539 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800540 name: "vndkcore.libraries.txt",
541 }
542 `)
543
544 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
545}
546
Jooyung Han2216fb12019-11-06 16:46:15 +0900547func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800548 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800549 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900550 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800551 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800552 }`
553 config := TestConfig(buildDir, android.Android, nil, bp, nil)
554 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
555 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
556 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900557
558 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900559 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900560 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900561}
562
563func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800564 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900565 cc_library {
566 name: "libvndk",
567 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900568 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900569 vndk: {
570 enabled: true,
571 },
572 nocrt: true,
573 }
574
575 cc_library {
576 name: "libvndk_sp",
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 support_system_process: true,
582 },
583 nocrt: true,
584 }
585
586 cc_library {
587 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900588 vendor_available: true,
589 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900590 vndk: {
591 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900592 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900593 },
594 nocrt: true,
595 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900596
Colin Crosse4e44bc2020-12-28 13:50:21 -0800597 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900598 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800599 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900600 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800601 `
602
603 config := TestConfig(buildDir, android.Android, nil, bp, nil)
604 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
605 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
606 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
607
608 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
609
610 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900611
Jooyung Han2216fb12019-11-06 16:46:15 +0900612 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900613}
614
Chris Parsons79d66a52020-06-05 17:26:16 -0400615func TestDataLibs(t *testing.T) {
616 bp := `
617 cc_test_library {
618 name: "test_lib",
619 srcs: ["test_lib.cpp"],
620 gtest: false,
621 }
622
623 cc_test {
624 name: "main_test",
625 data_libs: ["test_lib"],
626 gtest: false,
627 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400628 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400629
630 config := TestConfig(buildDir, android.Android, nil, bp, nil)
631 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
632 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
633 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
634
635 ctx := testCcWithConfig(t, config)
636 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
637 testBinary := module.(*Module).linker.(*testBinary)
638 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
639 if err != nil {
640 t.Errorf("Expected cc_test to produce output files, error: %s", err)
641 return
642 }
643 if len(outputFiles) != 1 {
644 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
645 return
646 }
647 if len(testBinary.dataPaths()) != 1 {
648 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
649 return
650 }
651
652 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400653 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400654
655 if !strings.HasSuffix(outputPath, "/main_test") {
656 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
657 return
658 }
659 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
660 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
661 return
662 }
663}
664
Chris Parsons216e10a2020-07-09 17:12:52 -0400665func TestDataLibsRelativeInstallPath(t *testing.T) {
666 bp := `
667 cc_test_library {
668 name: "test_lib",
669 srcs: ["test_lib.cpp"],
670 relative_install_path: "foo/bar/baz",
671 gtest: false,
672 }
673
674 cc_test {
675 name: "main_test",
676 data_libs: ["test_lib"],
677 gtest: false,
678 }
679 `
680
681 config := TestConfig(buildDir, android.Android, nil, bp, nil)
682 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
683 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
684 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
685
686 ctx := testCcWithConfig(t, config)
687 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
688 testBinary := module.(*Module).linker.(*testBinary)
689 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
690 if err != nil {
691 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
692 }
693 if len(outputFiles) != 1 {
694 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
695 }
696 if len(testBinary.dataPaths()) != 1 {
697 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
698 }
699
700 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400701
702 if !strings.HasSuffix(outputPath, "/main_test") {
703 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
704 }
705 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
706 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
707 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400708 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400709 }
710}
711
Jooyung Han0302a842019-10-30 18:43:49 +0900712func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900713 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900714 cc_library {
715 name: "libvndk",
716 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900717 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900718 vndk: {
719 enabled: true,
720 },
721 nocrt: true,
722 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900723 cc_library {
724 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900725 vendor_available: true,
726 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900727 vndk: {
728 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900729 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900730 },
731 nocrt: true,
732 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800733
734 cc_library {
735 name: "libllndk",
736 llndk_stubs: "libllndk.llndk",
737 }
738
739 llndk_library {
740 name: "libllndk.llndk",
741 symbol_file: "",
742 export_llndk_headers: ["libllndk_headers"],
743 }
744
745 llndk_headers {
746 name: "libllndk_headers",
747 export_include_dirs: ["include"],
748 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900749 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900750
751 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
752 "LLNDK: libc.so",
753 "LLNDK: libdl.so",
754 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800755 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900756 "LLNDK: libm.so",
757 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900758 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900759 "VNDK-core: libvndk.so",
760 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900761 "VNDK-private: libvndk-private.so",
762 "VNDK-product: libc++.so",
763 "VNDK-product: libvndk-private.so",
764 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900765 })
Logan Chienf3511742017-10-31 18:04:35 +0800766}
767
Justin Yun63e9ec72020-10-29 16:49:43 +0900768func TestVndkModuleError(t *testing.T) {
769 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900770 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900771 cc_library {
772 name: "libvndk",
773 vndk: {
774 enabled: true,
775 },
776 nocrt: true,
777 }
778 `)
779
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 product_available: true,
784 vndk: {
785 enabled: true,
786 },
787 nocrt: true,
788 }
789 `)
790
Justin Yun6977e8a2020-10-29 18:24:11 +0900791 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
792 cc_library {
793 name: "libvndkprop",
794 vendor_available: true,
795 product_available: true,
796 vndk: {
797 enabled: true,
798 },
799 nocrt: true,
800 target: {
801 vendor: {
802 cflags: ["-DTEST",],
803 },
804 },
805 }
806 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900807}
808
Logan Chiend3c59a22018-03-29 14:08:15 +0800809func TestVndkDepError(t *testing.T) {
810 // Check whether an error is emitted when a VNDK lib depends on a system lib.
811 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
812 cc_library {
813 name: "libvndk",
814 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900815 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800816 vndk: {
817 enabled: true,
818 },
819 shared_libs: ["libfwk"], // Cause error
820 nocrt: true,
821 }
822
823 cc_library {
824 name: "libfwk",
825 nocrt: true,
826 }
827 `)
828
829 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
830 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
831 cc_library {
832 name: "libvndk",
833 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900834 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800835 vndk: {
836 enabled: true,
837 },
838 shared_libs: ["libvendor"], // Cause error
839 nocrt: true,
840 }
841
842 cc_library {
843 name: "libvendor",
844 vendor: true,
845 nocrt: true,
846 }
847 `)
848
849 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
850 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
851 cc_library {
852 name: "libvndk_sp",
853 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900854 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800855 vndk: {
856 enabled: true,
857 support_system_process: true,
858 },
859 shared_libs: ["libfwk"], // Cause error
860 nocrt: true,
861 }
862
863 cc_library {
864 name: "libfwk",
865 nocrt: true,
866 }
867 `)
868
869 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
870 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
871 cc_library {
872 name: "libvndk_sp",
873 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900874 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800875 vndk: {
876 enabled: true,
877 support_system_process: true,
878 },
879 shared_libs: ["libvendor"], // Cause error
880 nocrt: true,
881 }
882
883 cc_library {
884 name: "libvendor",
885 vendor: true,
886 nocrt: true,
887 }
888 `)
889
890 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
891 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
892 cc_library {
893 name: "libvndk_sp",
894 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900895 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800896 vndk: {
897 enabled: true,
898 support_system_process: true,
899 },
900 shared_libs: ["libvndk"], // Cause error
901 nocrt: true,
902 }
903
904 cc_library {
905 name: "libvndk",
906 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900907 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800908 vndk: {
909 enabled: true,
910 },
911 nocrt: true,
912 }
913 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900914
915 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
916 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
917 cc_library {
918 name: "libvndk",
919 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900920 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900921 vndk: {
922 enabled: true,
923 },
924 shared_libs: ["libnonvndk"],
925 nocrt: true,
926 }
927
928 cc_library {
929 name: "libnonvndk",
930 vendor_available: true,
931 nocrt: true,
932 }
933 `)
934
935 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
936 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
937 cc_library {
938 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900939 vendor_available: true,
940 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900941 vndk: {
942 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900943 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900944 },
945 shared_libs: ["libnonvndk"],
946 nocrt: true,
947 }
948
949 cc_library {
950 name: "libnonvndk",
951 vendor_available: true,
952 nocrt: true,
953 }
954 `)
955
956 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
957 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
958 cc_library {
959 name: "libvndksp",
960 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900961 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900962 vndk: {
963 enabled: true,
964 support_system_process: true,
965 },
966 shared_libs: ["libnonvndk"],
967 nocrt: true,
968 }
969
970 cc_library {
971 name: "libnonvndk",
972 vendor_available: true,
973 nocrt: true,
974 }
975 `)
976
977 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
978 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
979 cc_library {
980 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900981 vendor_available: true,
982 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900983 vndk: {
984 enabled: true,
985 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900986 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900987 },
988 shared_libs: ["libnonvndk"],
989 nocrt: true,
990 }
991
992 cc_library {
993 name: "libnonvndk",
994 vendor_available: true,
995 nocrt: true,
996 }
997 `)
998}
999
1000func TestDoubleLoadbleDep(t *testing.T) {
1001 // okay to link : LLNDK -> double_loadable VNDK
1002 testCc(t, `
1003 cc_library {
1004 name: "libllndk",
1005 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001006 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001007 }
1008
1009 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001010 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001011 symbol_file: "",
1012 }
1013
1014 cc_library {
1015 name: "libdoubleloadable",
1016 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001017 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001018 vndk: {
1019 enabled: true,
1020 },
1021 double_loadable: true,
1022 }
1023 `)
1024 // okay to link : LLNDK -> VNDK-SP
1025 testCc(t, `
1026 cc_library {
1027 name: "libllndk",
1028 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -07001029 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001030 }
1031
1032 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001033 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001034 symbol_file: "",
1035 }
1036
1037 cc_library {
1038 name: "libvndksp",
1039 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001040 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001041 vndk: {
1042 enabled: true,
1043 support_system_process: true,
1044 },
1045 }
1046 `)
1047 // okay to link : double_loadable -> double_loadable
1048 testCc(t, `
1049 cc_library {
1050 name: "libdoubleloadable1",
1051 shared_libs: ["libdoubleloadable2"],
1052 vendor_available: true,
1053 double_loadable: true,
1054 }
1055
1056 cc_library {
1057 name: "libdoubleloadable2",
1058 vendor_available: true,
1059 double_loadable: true,
1060 }
1061 `)
1062 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1063 testCc(t, `
1064 cc_library {
1065 name: "libdoubleloadable",
1066 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001067 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001068 vndk: {
1069 enabled: true,
1070 },
1071 double_loadable: true,
1072 shared_libs: ["libnondoubleloadable"],
1073 }
1074
1075 cc_library {
1076 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001077 vendor_available: true,
1078 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001079 vndk: {
1080 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001081 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001082 },
1083 double_loadable: true,
1084 }
1085 `)
1086 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1087 testCc(t, `
1088 cc_library {
1089 name: "libllndk",
1090 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001091 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001092 }
1093
1094 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001095 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001096 symbol_file: "",
1097 }
1098
1099 cc_library {
1100 name: "libcoreonly",
1101 shared_libs: ["libvendoravailable"],
1102 }
1103
1104 // indirect dependency of LLNDK
1105 cc_library {
1106 name: "libvendoravailable",
1107 vendor_available: true,
1108 double_loadable: true,
1109 }
1110 `)
1111}
1112
1113func TestDoubleLoadableDepError(t *testing.T) {
1114 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1115 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1116 cc_library {
1117 name: "libllndk",
1118 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001119 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001120 }
1121
1122 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001123 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001124 symbol_file: "",
1125 }
1126
1127 cc_library {
1128 name: "libnondoubleloadable",
1129 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001130 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001131 vndk: {
1132 enabled: true,
1133 },
1134 }
1135 `)
1136
1137 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1138 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1139 cc_library {
1140 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001141 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001142 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001143 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001144 }
1145
1146 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001147 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001148 symbol_file: "",
1149 }
1150
1151 cc_library {
1152 name: "libnondoubleloadable",
1153 vendor_available: true,
1154 }
1155 `)
1156
Jooyung Hana70f0672019-01-18 15:20:43 +09001157 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1158 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1159 cc_library {
1160 name: "libllndk",
1161 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001162 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001163 }
1164
1165 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001166 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001167 symbol_file: "",
1168 }
1169
1170 cc_library {
1171 name: "libcoreonly",
1172 shared_libs: ["libvendoravailable"],
1173 }
1174
1175 // indirect dependency of LLNDK
1176 cc_library {
1177 name: "libvendoravailable",
1178 vendor_available: true,
1179 }
1180 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001181
1182 // The error is not from 'client' but from 'libllndk'
1183 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1184 cc_library {
1185 name: "client",
1186 vendor_available: true,
1187 double_loadable: true,
1188 shared_libs: ["libllndk"],
1189 }
1190 cc_library {
1191 name: "libllndk",
1192 shared_libs: ["libnondoubleloadable"],
1193 llndk_stubs: "libllndk.llndk",
1194 }
1195 llndk_library {
1196 name: "libllndk.llndk",
1197 symbol_file: "",
1198 }
1199 cc_library {
1200 name: "libnondoubleloadable",
1201 vendor_available: true,
1202 }
1203 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001204}
1205
Jooyung Han479ca172020-10-19 18:51:07 +09001206func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1207 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1208 cc_library {
1209 name: "libvndksp",
1210 shared_libs: ["libanothervndksp"],
1211 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001212 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001213 vndk: {
1214 enabled: true,
1215 support_system_process: true,
1216 }
1217 }
1218
1219 cc_library {
1220 name: "libllndk",
1221 shared_libs: ["libanothervndksp"],
1222 }
1223
1224 llndk_library {
1225 name: "libllndk",
1226 symbol_file: "",
1227 }
1228
1229 cc_library {
1230 name: "libanothervndksp",
1231 vendor_available: true,
1232 }
1233 `)
1234}
1235
Logan Chienf3511742017-10-31 18:04:35 +08001236func TestVndkExt(t *testing.T) {
1237 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001238 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001239 cc_library {
1240 name: "libvndk",
1241 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001242 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001243 vndk: {
1244 enabled: true,
1245 },
1246 nocrt: true,
1247 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001248 cc_library {
1249 name: "libvndk2",
1250 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001251 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001252 vndk: {
1253 enabled: true,
1254 },
1255 target: {
1256 vendor: {
1257 suffix: "-suffix",
1258 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001259 product: {
1260 suffix: "-suffix",
1261 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001262 },
1263 nocrt: true,
1264 }
Logan Chienf3511742017-10-31 18:04:35 +08001265
1266 cc_library {
1267 name: "libvndk_ext",
1268 vendor: true,
1269 vndk: {
1270 enabled: true,
1271 extends: "libvndk",
1272 },
1273 nocrt: true,
1274 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001275
1276 cc_library {
1277 name: "libvndk2_ext",
1278 vendor: true,
1279 vndk: {
1280 enabled: true,
1281 extends: "libvndk2",
1282 },
1283 nocrt: true,
1284 }
Logan Chienf3511742017-10-31 18:04:35 +08001285
Justin Yun0ecf0b22020-02-28 15:07:59 +09001286 cc_library {
1287 name: "libvndk_ext_product",
1288 product_specific: true,
1289 vndk: {
1290 enabled: true,
1291 extends: "libvndk",
1292 },
1293 nocrt: true,
1294 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001295
Justin Yun0ecf0b22020-02-28 15:07:59 +09001296 cc_library {
1297 name: "libvndk2_ext_product",
1298 product_specific: true,
1299 vndk: {
1300 enabled: true,
1301 extends: "libvndk2",
1302 },
1303 nocrt: true,
1304 }
1305 `
1306 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1307 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1308 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1309 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1310
1311 ctx := testCcWithConfig(t, config)
1312
1313 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1314 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1315
1316 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1317 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1318
1319 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1320 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001321}
1322
Logan Chiend3c59a22018-03-29 14:08:15 +08001323func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001324 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1325 ctx := testCcNoVndk(t, `
1326 cc_library {
1327 name: "libvndk",
1328 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001329 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001330 vndk: {
1331 enabled: true,
1332 },
1333 nocrt: true,
1334 }
1335
1336 cc_library {
1337 name: "libvndk_ext",
1338 vendor: true,
1339 vndk: {
1340 enabled: true,
1341 extends: "libvndk",
1342 },
1343 nocrt: true,
1344 }
1345 `)
1346
1347 // Ensures that the core variant of "libvndk_ext" can be found.
1348 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1349 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1350 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1351 }
1352}
1353
Justin Yun0ecf0b22020-02-28 15:07:59 +09001354func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1355 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001356 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001357 cc_library {
1358 name: "libvndk",
1359 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001360 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001361 vndk: {
1362 enabled: true,
1363 },
1364 nocrt: true,
1365 }
1366
1367 cc_library {
1368 name: "libvndk_ext_product",
1369 product_specific: true,
1370 vndk: {
1371 enabled: true,
1372 extends: "libvndk",
1373 },
1374 nocrt: true,
1375 }
1376 `)
1377
1378 // Ensures that the core variant of "libvndk_ext_product" can be found.
1379 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1380 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1381 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1382 }
1383}
1384
Logan Chienf3511742017-10-31 18:04:35 +08001385func TestVndkExtError(t *testing.T) {
1386 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001387 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001388 cc_library {
1389 name: "libvndk",
1390 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001391 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001392 vndk: {
1393 enabled: true,
1394 },
1395 nocrt: true,
1396 }
1397
1398 cc_library {
1399 name: "libvndk_ext",
1400 vndk: {
1401 enabled: true,
1402 extends: "libvndk",
1403 },
1404 nocrt: true,
1405 }
1406 `)
1407
1408 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1409 cc_library {
1410 name: "libvndk",
1411 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001412 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001413 vndk: {
1414 enabled: true,
1415 },
1416 nocrt: true,
1417 }
1418
1419 cc_library {
1420 name: "libvndk_ext",
1421 vendor: true,
1422 vndk: {
1423 enabled: true,
1424 },
1425 nocrt: true,
1426 }
1427 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001428
1429 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1430 cc_library {
1431 name: "libvndk",
1432 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001433 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001434 vndk: {
1435 enabled: true,
1436 },
1437 nocrt: true,
1438 }
1439
1440 cc_library {
1441 name: "libvndk_ext_product",
1442 product_specific: true,
1443 vndk: {
1444 enabled: true,
1445 },
1446 nocrt: true,
1447 }
1448 `)
1449
1450 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1451 cc_library {
1452 name: "libvndk",
1453 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001454 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001455 vndk: {
1456 enabled: true,
1457 },
1458 nocrt: true,
1459 }
1460
1461 cc_library {
1462 name: "libvndk_ext_product",
1463 product_specific: true,
1464 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001465 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001466 vndk: {
1467 enabled: true,
1468 extends: "libvndk",
1469 },
1470 nocrt: true,
1471 }
1472 `)
Logan Chienf3511742017-10-31 18:04:35 +08001473}
1474
1475func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1476 // This test ensures an error is emitted for inconsistent support_system_process.
1477 testCcError(t, "module \".*\" with mismatched support_system_process", `
1478 cc_library {
1479 name: "libvndk",
1480 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001481 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001482 vndk: {
1483 enabled: true,
1484 },
1485 nocrt: true,
1486 }
1487
1488 cc_library {
1489 name: "libvndk_sp_ext",
1490 vendor: true,
1491 vndk: {
1492 enabled: true,
1493 extends: "libvndk",
1494 support_system_process: true,
1495 },
1496 nocrt: true,
1497 }
1498 `)
1499
1500 testCcError(t, "module \".*\" with mismatched support_system_process", `
1501 cc_library {
1502 name: "libvndk_sp",
1503 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001504 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001505 vndk: {
1506 enabled: true,
1507 support_system_process: true,
1508 },
1509 nocrt: true,
1510 }
1511
1512 cc_library {
1513 name: "libvndk_ext",
1514 vendor: true,
1515 vndk: {
1516 enabled: true,
1517 extends: "libvndk_sp",
1518 },
1519 nocrt: true,
1520 }
1521 `)
1522}
1523
1524func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001525 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001526 // with `private: true`.
1527 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001528 cc_library {
1529 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001530 vendor_available: true,
1531 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001532 vndk: {
1533 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001534 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001535 },
1536 nocrt: true,
1537 }
1538
1539 cc_library {
1540 name: "libvndk_ext",
1541 vendor: true,
1542 vndk: {
1543 enabled: true,
1544 extends: "libvndk",
1545 },
1546 nocrt: true,
1547 }
1548 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001549
Justin Yunfd9e8042020-12-23 18:23:14 +09001550 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001551 cc_library {
1552 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001553 vendor_available: true,
1554 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001555 vndk: {
1556 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001557 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001558 },
1559 nocrt: true,
1560 }
1561
1562 cc_library {
1563 name: "libvndk_ext_product",
1564 product_specific: true,
1565 vndk: {
1566 enabled: true,
1567 extends: "libvndk",
1568 },
1569 nocrt: true,
1570 }
1571 `)
Logan Chienf3511742017-10-31 18:04:35 +08001572}
1573
Logan Chiend3c59a22018-03-29 14:08:15 +08001574func TestVendorModuleUseVndkExt(t *testing.T) {
1575 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001576 testCc(t, `
1577 cc_library {
1578 name: "libvndk",
1579 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001580 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001581 vndk: {
1582 enabled: true,
1583 },
1584 nocrt: true,
1585 }
1586
1587 cc_library {
1588 name: "libvndk_ext",
1589 vendor: true,
1590 vndk: {
1591 enabled: true,
1592 extends: "libvndk",
1593 },
1594 nocrt: true,
1595 }
1596
1597 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001598 name: "libvndk_sp",
1599 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001600 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001601 vndk: {
1602 enabled: true,
1603 support_system_process: true,
1604 },
1605 nocrt: true,
1606 }
1607
1608 cc_library {
1609 name: "libvndk_sp_ext",
1610 vendor: true,
1611 vndk: {
1612 enabled: true,
1613 extends: "libvndk_sp",
1614 support_system_process: true,
1615 },
1616 nocrt: true,
1617 }
1618
1619 cc_library {
1620 name: "libvendor",
1621 vendor: true,
1622 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1623 nocrt: true,
1624 }
1625 `)
1626}
1627
Logan Chiend3c59a22018-03-29 14:08:15 +08001628func TestVndkExtUseVendorLib(t *testing.T) {
1629 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001630 testCc(t, `
1631 cc_library {
1632 name: "libvndk",
1633 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001634 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001635 vndk: {
1636 enabled: true,
1637 },
1638 nocrt: true,
1639 }
1640
1641 cc_library {
1642 name: "libvndk_ext",
1643 vendor: true,
1644 vndk: {
1645 enabled: true,
1646 extends: "libvndk",
1647 },
1648 shared_libs: ["libvendor"],
1649 nocrt: true,
1650 }
1651
1652 cc_library {
1653 name: "libvendor",
1654 vendor: true,
1655 nocrt: true,
1656 }
1657 `)
Logan Chienf3511742017-10-31 18:04:35 +08001658
Logan Chiend3c59a22018-03-29 14:08:15 +08001659 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1660 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001661 cc_library {
1662 name: "libvndk_sp",
1663 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001664 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001665 vndk: {
1666 enabled: true,
1667 support_system_process: true,
1668 },
1669 nocrt: true,
1670 }
1671
1672 cc_library {
1673 name: "libvndk_sp_ext",
1674 vendor: true,
1675 vndk: {
1676 enabled: true,
1677 extends: "libvndk_sp",
1678 support_system_process: true,
1679 },
1680 shared_libs: ["libvendor"], // Cause an error
1681 nocrt: true,
1682 }
1683
1684 cc_library {
1685 name: "libvendor",
1686 vendor: true,
1687 nocrt: true,
1688 }
1689 `)
1690}
1691
Justin Yun0ecf0b22020-02-28 15:07:59 +09001692func TestProductVndkExtDependency(t *testing.T) {
1693 bp := `
1694 cc_library {
1695 name: "libvndk",
1696 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001697 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001698 vndk: {
1699 enabled: true,
1700 },
1701 nocrt: true,
1702 }
1703
1704 cc_library {
1705 name: "libvndk_ext_product",
1706 product_specific: true,
1707 vndk: {
1708 enabled: true,
1709 extends: "libvndk",
1710 },
1711 shared_libs: ["libproduct_for_vndklibs"],
1712 nocrt: true,
1713 }
1714
1715 cc_library {
1716 name: "libvndk_sp",
1717 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001718 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001719 vndk: {
1720 enabled: true,
1721 support_system_process: true,
1722 },
1723 nocrt: true,
1724 }
1725
1726 cc_library {
1727 name: "libvndk_sp_ext_product",
1728 product_specific: true,
1729 vndk: {
1730 enabled: true,
1731 extends: "libvndk_sp",
1732 support_system_process: true,
1733 },
1734 shared_libs: ["libproduct_for_vndklibs"],
1735 nocrt: true,
1736 }
1737
1738 cc_library {
1739 name: "libproduct",
1740 product_specific: true,
1741 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1742 nocrt: true,
1743 }
1744
1745 cc_library {
1746 name: "libproduct_for_vndklibs",
1747 product_specific: true,
1748 nocrt: true,
1749 }
1750 `
1751 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1752 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1753 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1754 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1755
1756 testCcWithConfig(t, config)
1757}
1758
Logan Chiend3c59a22018-03-29 14:08:15 +08001759func TestVndkSpExtUseVndkError(t *testing.T) {
1760 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1761 // library.
1762 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1763 cc_library {
1764 name: "libvndk",
1765 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001766 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001767 vndk: {
1768 enabled: true,
1769 },
1770 nocrt: true,
1771 }
1772
1773 cc_library {
1774 name: "libvndk_sp",
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 support_system_process: true,
1780 },
1781 nocrt: true,
1782 }
1783
1784 cc_library {
1785 name: "libvndk_sp_ext",
1786 vendor: true,
1787 vndk: {
1788 enabled: true,
1789 extends: "libvndk_sp",
1790 support_system_process: true,
1791 },
1792 shared_libs: ["libvndk"], // Cause an error
1793 nocrt: true,
1794 }
1795 `)
1796
1797 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1798 // library.
1799 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1800 cc_library {
1801 name: "libvndk",
1802 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001803 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001804 vndk: {
1805 enabled: true,
1806 },
1807 nocrt: true,
1808 }
1809
1810 cc_library {
1811 name: "libvndk_ext",
1812 vendor: true,
1813 vndk: {
1814 enabled: true,
1815 extends: "libvndk",
1816 },
1817 nocrt: true,
1818 }
1819
1820 cc_library {
1821 name: "libvndk_sp",
1822 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001823 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001824 vndk: {
1825 enabled: true,
1826 support_system_process: true,
1827 },
1828 nocrt: true,
1829 }
1830
1831 cc_library {
1832 name: "libvndk_sp_ext",
1833 vendor: true,
1834 vndk: {
1835 enabled: true,
1836 extends: "libvndk_sp",
1837 support_system_process: true,
1838 },
1839 shared_libs: ["libvndk_ext"], // Cause an error
1840 nocrt: true,
1841 }
1842 `)
1843}
1844
1845func TestVndkUseVndkExtError(t *testing.T) {
1846 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1847 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001848 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1849 cc_library {
1850 name: "libvndk",
1851 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001852 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001853 vndk: {
1854 enabled: true,
1855 },
1856 nocrt: true,
1857 }
1858
1859 cc_library {
1860 name: "libvndk_ext",
1861 vendor: true,
1862 vndk: {
1863 enabled: true,
1864 extends: "libvndk",
1865 },
1866 nocrt: true,
1867 }
1868
1869 cc_library {
1870 name: "libvndk2",
1871 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001872 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001873 vndk: {
1874 enabled: true,
1875 },
1876 shared_libs: ["libvndk_ext"],
1877 nocrt: true,
1878 }
1879 `)
1880
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001881 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001882 cc_library {
1883 name: "libvndk",
1884 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001885 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001886 vndk: {
1887 enabled: true,
1888 },
1889 nocrt: true,
1890 }
1891
1892 cc_library {
1893 name: "libvndk_ext",
1894 vendor: true,
1895 vndk: {
1896 enabled: true,
1897 extends: "libvndk",
1898 },
1899 nocrt: true,
1900 }
1901
1902 cc_library {
1903 name: "libvndk2",
1904 vendor_available: true,
1905 vndk: {
1906 enabled: true,
1907 },
1908 target: {
1909 vendor: {
1910 shared_libs: ["libvndk_ext"],
1911 },
1912 },
1913 nocrt: true,
1914 }
1915 `)
1916
1917 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1918 cc_library {
1919 name: "libvndk_sp",
1920 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001921 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001922 vndk: {
1923 enabled: true,
1924 support_system_process: true,
1925 },
1926 nocrt: true,
1927 }
1928
1929 cc_library {
1930 name: "libvndk_sp_ext",
1931 vendor: true,
1932 vndk: {
1933 enabled: true,
1934 extends: "libvndk_sp",
1935 support_system_process: true,
1936 },
1937 nocrt: true,
1938 }
1939
1940 cc_library {
1941 name: "libvndk_sp_2",
1942 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001943 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001944 vndk: {
1945 enabled: true,
1946 support_system_process: true,
1947 },
1948 shared_libs: ["libvndk_sp_ext"],
1949 nocrt: true,
1950 }
1951 `)
1952
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001953 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001954 cc_library {
1955 name: "libvndk_sp",
1956 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001957 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001958 vndk: {
1959 enabled: true,
1960 },
1961 nocrt: true,
1962 }
1963
1964 cc_library {
1965 name: "libvndk_sp_ext",
1966 vendor: true,
1967 vndk: {
1968 enabled: true,
1969 extends: "libvndk_sp",
1970 },
1971 nocrt: true,
1972 }
1973
1974 cc_library {
1975 name: "libvndk_sp2",
1976 vendor_available: true,
1977 vndk: {
1978 enabled: true,
1979 },
1980 target: {
1981 vendor: {
1982 shared_libs: ["libvndk_sp_ext"],
1983 },
1984 },
1985 nocrt: true,
1986 }
1987 `)
1988}
1989
Justin Yun5f7f7e82019-11-18 19:52:14 +09001990func TestEnforceProductVndkVersion(t *testing.T) {
1991 bp := `
1992 cc_library {
1993 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07001994 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09001995 }
1996 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001997 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09001998 symbol_file: "",
1999 }
2000 cc_library {
2001 name: "libvndk",
2002 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002003 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002004 vndk: {
2005 enabled: true,
2006 },
2007 nocrt: true,
2008 }
2009 cc_library {
2010 name: "libvndk_sp",
2011 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002012 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002013 vndk: {
2014 enabled: true,
2015 support_system_process: true,
2016 },
2017 nocrt: true,
2018 }
2019 cc_library {
2020 name: "libva",
2021 vendor_available: true,
2022 nocrt: true,
2023 }
2024 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002025 name: "libpa",
2026 product_available: true,
2027 nocrt: true,
2028 }
2029 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002030 name: "libboth_available",
2031 vendor_available: true,
2032 product_available: true,
2033 nocrt: true,
2034 target: {
2035 vendor: {
2036 suffix: "-vendor",
2037 },
2038 product: {
2039 suffix: "-product",
2040 },
2041 }
2042 }
2043 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002044 name: "libproduct_va",
2045 product_specific: true,
2046 vendor_available: true,
2047 nocrt: true,
2048 }
2049 cc_library {
2050 name: "libprod",
2051 product_specific: true,
2052 shared_libs: [
2053 "libllndk",
2054 "libvndk",
2055 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002056 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002057 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002058 "libproduct_va",
2059 ],
2060 nocrt: true,
2061 }
2062 cc_library {
2063 name: "libvendor",
2064 vendor: true,
2065 shared_libs: [
2066 "libllndk",
2067 "libvndk",
2068 "libvndk_sp",
2069 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002070 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002071 "libproduct_va",
2072 ],
2073 nocrt: true,
2074 }
2075 `
2076
2077 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2078 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2079 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2080 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2081
2082 ctx := testCcWithConfig(t, config)
2083
Jooyung Han261e1582020-10-20 18:54:21 +09002084 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2085 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002086
2087 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2088 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2089
2090 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2091 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002092}
2093
2094func TestEnforceProductVndkVersionErrors(t *testing.T) {
2095 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2096 cc_library {
2097 name: "libprod",
2098 product_specific: true,
2099 shared_libs: [
2100 "libvendor",
2101 ],
2102 nocrt: true,
2103 }
2104 cc_library {
2105 name: "libvendor",
2106 vendor: true,
2107 nocrt: true,
2108 }
2109 `)
2110 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2111 cc_library {
2112 name: "libprod",
2113 product_specific: true,
2114 shared_libs: [
2115 "libsystem",
2116 ],
2117 nocrt: true,
2118 }
2119 cc_library {
2120 name: "libsystem",
2121 nocrt: true,
2122 }
2123 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002124 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2125 cc_library {
2126 name: "libprod",
2127 product_specific: true,
2128 shared_libs: [
2129 "libva",
2130 ],
2131 nocrt: true,
2132 }
2133 cc_library {
2134 name: "libva",
2135 vendor_available: true,
2136 nocrt: true,
2137 }
2138 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002139 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002140 cc_library {
2141 name: "libprod",
2142 product_specific: true,
2143 shared_libs: [
2144 "libvndk_private",
2145 ],
2146 nocrt: true,
2147 }
2148 cc_library {
2149 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002150 vendor_available: true,
2151 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002152 vndk: {
2153 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002154 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002155 },
2156 nocrt: true,
2157 }
2158 `)
2159 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2160 cc_library {
2161 name: "libprod",
2162 product_specific: true,
2163 shared_libs: [
2164 "libsystem_ext",
2165 ],
2166 nocrt: true,
2167 }
2168 cc_library {
2169 name: "libsystem_ext",
2170 system_ext_specific: true,
2171 nocrt: true,
2172 }
2173 `)
2174 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2175 cc_library {
2176 name: "libsystem",
2177 shared_libs: [
2178 "libproduct_va",
2179 ],
2180 nocrt: true,
2181 }
2182 cc_library {
2183 name: "libproduct_va",
2184 product_specific: true,
2185 vendor_available: true,
2186 nocrt: true,
2187 }
2188 `)
2189}
2190
Jooyung Han38002912019-05-16 04:01:54 +09002191func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002192 bp := `
2193 cc_library {
2194 name: "libvndk",
2195 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002196 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002197 vndk: {
2198 enabled: true,
2199 },
2200 }
2201 cc_library {
2202 name: "libvndksp",
2203 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002204 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002205 vndk: {
2206 enabled: true,
2207 support_system_process: true,
2208 },
2209 }
2210 cc_library {
2211 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002212 vendor_available: true,
2213 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002214 vndk: {
2215 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002216 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002217 },
2218 }
2219 cc_library {
2220 name: "libvendor",
2221 vendor: true,
2222 }
2223 cc_library {
2224 name: "libvndkext",
2225 vendor: true,
2226 vndk: {
2227 enabled: true,
2228 extends: "libvndk",
2229 },
2230 }
2231 vndk_prebuilt_shared {
2232 name: "prevndk",
2233 version: "27",
2234 target_arch: "arm",
2235 binder32bit: true,
2236 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002237 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002238 vndk: {
2239 enabled: true,
2240 },
2241 arch: {
2242 arm: {
2243 srcs: ["liba.so"],
2244 },
2245 },
2246 }
2247 cc_library {
2248 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002249 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002250 }
2251 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002252 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002253 symbol_file: "",
2254 }
2255 cc_library {
2256 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002257 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002258 }
2259 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002260 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002261 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002262 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002263 }
2264
2265 llndk_libraries_txt {
2266 name: "llndk.libraries.txt",
2267 }
2268 vndkcore_libraries_txt {
2269 name: "vndkcore.libraries.txt",
2270 }
2271 vndksp_libraries_txt {
2272 name: "vndksp.libraries.txt",
2273 }
2274 vndkprivate_libraries_txt {
2275 name: "vndkprivate.libraries.txt",
2276 }
2277 vndkcorevariant_libraries_txt {
2278 name: "vndkcorevariant.libraries.txt",
2279 insert_vndk_version: false,
2280 }
2281 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002282
2283 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002284 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2285 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2286 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002287 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002288
Colin Cross78212242021-01-06 14:51:30 -08002289 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2290 []string{"libvndk.so", "libvndkprivate.so"})
2291 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2292 []string{"libc++.so", "libvndksp.so"})
2293 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2294 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2295 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2296 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002297
Colin Crossfb0c16e2019-11-20 17:12:35 -08002298 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002299
Jooyung Han38002912019-05-16 04:01:54 +09002300 tests := []struct {
2301 variant string
2302 name string
2303 expected string
2304 }{
2305 {vendorVariant, "libvndk", "native:vndk"},
2306 {vendorVariant, "libvndksp", "native:vndk"},
2307 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2308 {vendorVariant, "libvendor", "native:vendor"},
2309 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002310 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002311 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002312 {coreVariant, "libvndk", "native:platform"},
2313 {coreVariant, "libvndkprivate", "native:platform"},
2314 {coreVariant, "libllndk", "native:platform"},
2315 }
2316 for _, test := range tests {
2317 t.Run(test.name, func(t *testing.T) {
2318 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2319 assertString(t, module.makeLinkType, test.expected)
2320 })
2321 }
2322}
2323
Jeff Gaston294356f2017-09-27 17:05:30 -07002324var staticLinkDepOrderTestCases = []struct {
2325 // This is a string representation of a map[moduleName][]moduleDependency .
2326 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002327 inStatic string
2328
2329 // This is a string representation of a map[moduleName][]moduleDependency .
2330 // It models the dependencies declared in an Android.bp file.
2331 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002332
2333 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2334 // The keys of allOrdered specify which modules we would like to check.
2335 // The values of allOrdered specify the expected result (of the transitive closure of all
2336 // dependencies) for each module to test
2337 allOrdered string
2338
2339 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2340 // The keys of outOrdered specify which modules we would like to check.
2341 // The values of outOrdered specify the expected result (of the ordered linker command line)
2342 // for each module to test.
2343 outOrdered string
2344}{
2345 // Simple tests
2346 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002347 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002348 outOrdered: "",
2349 },
2350 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002351 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002352 outOrdered: "a:",
2353 },
2354 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002355 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002356 outOrdered: "a:b; b:",
2357 },
2358 // Tests of reordering
2359 {
2360 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002361 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002362 outOrdered: "a:b,c,d; b:d; c:d; d:",
2363 },
2364 {
2365 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002366 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002367 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2368 },
2369 {
2370 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002371 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002372 outOrdered: "a:d,b,e,c; d:b; e:c",
2373 },
2374 {
2375 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002376 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002377 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2378 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2379 },
2380 {
2381 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002382 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 -07002383 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2384 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2385 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002386 // shared dependencies
2387 {
2388 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2389 // So, we don't actually have to check that a shared dependency of c will change the order
2390 // of a library that depends statically on b and on c. We only need to check that if c has
2391 // a shared dependency on b, that that shows up in allOrdered.
2392 inShared: "c:b",
2393 allOrdered: "c:b",
2394 outOrdered: "c:",
2395 },
2396 {
2397 // This test doesn't actually include any shared dependencies but it's a reminder of what
2398 // the second phase of the above test would look like
2399 inStatic: "a:b,c; c:b",
2400 allOrdered: "a:c,b; c:b",
2401 outOrdered: "a:c,b; c:b",
2402 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002403 // tiebreakers for when two modules specifying different orderings and there is no dependency
2404 // to dictate an order
2405 {
2406 // 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 -08002407 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002408 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2409 },
2410 {
2411 // 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 -08002412 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 -07002413 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2414 },
2415 // Tests involving duplicate dependencies
2416 {
2417 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002418 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002419 outOrdered: "a:c,b",
2420 },
2421 {
2422 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002423 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002424 outOrdered: "a:d,c,b",
2425 },
2426 // Tests to confirm the nonexistence of infinite loops.
2427 // These cases should never happen, so as long as the test terminates and the
2428 // result is deterministic then that should be fine.
2429 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002430 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002431 outOrdered: "a:a",
2432 },
2433 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002434 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002435 allOrdered: "a:b,c; b:c,a; c:a,b",
2436 outOrdered: "a:b; b:c; c:a",
2437 },
2438 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002439 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002440 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2441 outOrdered: "a:c,b; b:a,c; c:b,a",
2442 },
2443}
2444
2445// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2446func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2447 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2448 strippedText := strings.Replace(text, " ", "", -1)
2449 if len(strippedText) < 1 {
2450 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2451 }
2452 allDeps = make(map[android.Path][]android.Path, 0)
2453
2454 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2455 moduleTexts := strings.Split(strippedText, ";")
2456
2457 outputForModuleName := func(moduleName string) android.Path {
2458 return android.PathForTesting(moduleName)
2459 }
2460
2461 for _, moduleText := range moduleTexts {
2462 // convert from "a:b,c" to ["a", "b,c"]
2463 components := strings.Split(moduleText, ":")
2464 if len(components) != 2 {
2465 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2466 }
2467 moduleName := components[0]
2468 moduleOutput := outputForModuleName(moduleName)
2469 modulesInOrder = append(modulesInOrder, moduleOutput)
2470
2471 depString := components[1]
2472 // convert from "b,c" to ["b", "c"]
2473 depNames := strings.Split(depString, ",")
2474 if len(depString) < 1 {
2475 depNames = []string{}
2476 }
2477 var deps []android.Path
2478 for _, depName := range depNames {
2479 deps = append(deps, outputForModuleName(depName))
2480 }
2481 allDeps[moduleOutput] = deps
2482 }
2483 return modulesInOrder, allDeps
2484}
2485
Jeff Gaston294356f2017-09-27 17:05:30 -07002486func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2487 for _, moduleName := range moduleNames {
2488 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2489 output := module.outputFile.Path()
2490 paths = append(paths, output)
2491 }
2492 return paths
2493}
2494
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002495func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002496 ctx := testCc(t, `
2497 cc_library {
2498 name: "a",
2499 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002500 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002501 }
2502 cc_library {
2503 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002504 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002505 }
2506 cc_library {
2507 name: "c",
2508 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002509 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002510 }
2511 cc_library {
2512 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002513 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002514 }
2515
2516 `)
2517
Colin Cross7113d202019-11-20 16:39:12 -08002518 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002519 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002520 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2521 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002522
2523 if !reflect.DeepEqual(actual, expected) {
2524 t.Errorf("staticDeps orderings were not propagated correctly"+
2525 "\nactual: %v"+
2526 "\nexpected: %v",
2527 actual,
2528 expected,
2529 )
2530 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002531}
Jeff Gaston294356f2017-09-27 17:05:30 -07002532
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002533func TestStaticLibDepReorderingWithShared(t *testing.T) {
2534 ctx := testCc(t, `
2535 cc_library {
2536 name: "a",
2537 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002538 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002539 }
2540 cc_library {
2541 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002542 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002543 }
2544 cc_library {
2545 name: "c",
2546 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002547 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002548 }
2549
2550 `)
2551
Colin Cross7113d202019-11-20 16:39:12 -08002552 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002553 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002554 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2555 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002556
2557 if !reflect.DeepEqual(actual, expected) {
2558 t.Errorf("staticDeps orderings did not account for shared libs"+
2559 "\nactual: %v"+
2560 "\nexpected: %v",
2561 actual,
2562 expected,
2563 )
2564 }
2565}
2566
Jooyung Hanb04a4992020-03-13 18:57:35 +09002567func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002568 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002569 if !reflect.DeepEqual(actual, expected) {
2570 t.Errorf(message+
2571 "\nactual: %v"+
2572 "\nexpected: %v",
2573 actual,
2574 expected,
2575 )
2576 }
2577}
2578
Jooyung Han61b66e92020-03-21 14:21:46 +00002579func TestLlndkLibrary(t *testing.T) {
2580 ctx := testCc(t, `
2581 cc_library {
2582 name: "libllndk",
2583 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002584 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002585 }
2586 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002587 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002588 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002589
2590 cc_prebuilt_library_shared {
2591 name: "libllndkprebuilt",
2592 stubs: { versions: ["1", "2"] },
2593 llndk_stubs: "libllndkprebuilt.llndk",
2594 }
2595 llndk_library {
2596 name: "libllndkprebuilt.llndk",
2597 }
2598
2599 cc_library {
2600 name: "libllndk_with_external_headers",
2601 stubs: { versions: ["1", "2"] },
2602 llndk_stubs: "libllndk_with_external_headers.llndk",
2603 header_libs: ["libexternal_headers"],
2604 export_header_lib_headers: ["libexternal_headers"],
2605 }
2606 llndk_library {
2607 name: "libllndk_with_external_headers.llndk",
2608 }
2609 cc_library_headers {
2610 name: "libexternal_headers",
2611 export_include_dirs: ["include"],
2612 vendor_available: true,
2613 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002614 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002615 actual := ctx.ModuleVariantsForTests("libllndk")
2616 for i := 0; i < len(actual); i++ {
2617 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
2618 actual = append(actual[:i], actual[i+1:]...)
2619 i--
2620 }
2621 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002622 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00002623 "android_vendor.VER_arm64_armv8-a_shared_1",
2624 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002625 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002626 "android_vendor.VER_arm_armv7-a-neon_shared_1",
2627 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002628 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002629 }
2630 checkEquals(t, "variants for llndk stubs", expected, actual)
2631
Colin Cross127bb8b2020-12-16 16:46:01 -08002632 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002633 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2634
Colin Cross127bb8b2020-12-16 16:46:01 -08002635 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002636 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2637}
2638
Jiyong Parka46a4d52017-12-14 19:54:34 +09002639func TestLlndkHeaders(t *testing.T) {
2640 ctx := testCc(t, `
2641 llndk_headers {
2642 name: "libllndk_headers",
2643 export_include_dirs: ["my_include"],
2644 }
2645 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002646 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002647 export_llndk_headers: ["libllndk_headers"],
2648 }
2649 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002650 name: "libllndk",
2651 llndk_stubs: "libllndk.llndk",
2652 }
2653
2654 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002655 name: "libvendor",
2656 shared_libs: ["libllndk"],
2657 vendor: true,
2658 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002659 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002660 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002661 }
2662 `)
2663
2664 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002665 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002666 cflags := cc.Args["cFlags"]
2667 if !strings.Contains(cflags, "-Imy_include") {
2668 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2669 }
2670}
2671
Logan Chien43d34c32017-12-20 01:17:32 +08002672func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2673 actual := module.Properties.AndroidMkRuntimeLibs
2674 if !reflect.DeepEqual(actual, expected) {
2675 t.Errorf("incorrect runtime_libs for shared libs"+
2676 "\nactual: %v"+
2677 "\nexpected: %v",
2678 actual,
2679 expected,
2680 )
2681 }
2682}
2683
2684const runtimeLibAndroidBp = `
2685 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002686 name: "liball_available",
2687 vendor_available: true,
2688 product_available: true,
2689 no_libcrt : true,
2690 nocrt : true,
2691 system_shared_libs : [],
2692 }
2693 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002694 name: "libvendor_available1",
2695 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002696 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002697 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002698 nocrt : true,
2699 system_shared_libs : [],
2700 }
2701 cc_library {
2702 name: "libvendor_available2",
2703 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002704 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002705 target: {
2706 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002707 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002708 }
2709 },
Yi Konge7fe9912019-06-02 00:53:50 -07002710 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002711 nocrt : true,
2712 system_shared_libs : [],
2713 }
2714 cc_library {
2715 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002716 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002717 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002718 nocrt : true,
2719 system_shared_libs : [],
2720 }
2721 cc_library {
2722 name: "libvendor1",
2723 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002724 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002725 nocrt : true,
2726 system_shared_libs : [],
2727 }
2728 cc_library {
2729 name: "libvendor2",
2730 vendor: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002731 runtime_libs: ["liball_available", "libvendor1"],
2732 no_libcrt : true,
2733 nocrt : true,
2734 system_shared_libs : [],
2735 }
2736 cc_library {
2737 name: "libproduct_available1",
2738 product_available: true,
2739 runtime_libs: ["liball_available"],
2740 no_libcrt : true,
2741 nocrt : true,
2742 system_shared_libs : [],
2743 }
2744 cc_library {
2745 name: "libproduct1",
2746 product_specific: true,
2747 no_libcrt : true,
2748 nocrt : true,
2749 system_shared_libs : [],
2750 }
2751 cc_library {
2752 name: "libproduct2",
2753 product_specific: true,
2754 runtime_libs: ["liball_available", "libproduct1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002755 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002756 nocrt : true,
2757 system_shared_libs : [],
2758 }
2759`
2760
2761func TestRuntimeLibs(t *testing.T) {
2762 ctx := testCc(t, runtimeLibAndroidBp)
2763
2764 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002765 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002766
Justin Yun8a2600c2020-12-07 12:44:03 +09002767 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2768 checkRuntimeLibs(t, []string{"liball_available"}, module)
2769
2770 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2771 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002772
2773 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002774 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002775
2776 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2777 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002778 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002779
Justin Yun8a2600c2020-12-07 12:44:03 +09002780 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2781 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002782
2783 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002784 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1"}, module)
2785
2786 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2787 // and product variants.
2788 variant = "android_product.VER_arm64_armv8-a_shared"
2789
2790 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2791 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2792
2793 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
2794 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002795}
2796
2797func TestExcludeRuntimeLibs(t *testing.T) {
2798 ctx := testCc(t, runtimeLibAndroidBp)
2799
Colin Cross7113d202019-11-20 16:39:12 -08002800 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002801 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2802 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002803
Colin Crossfb0c16e2019-11-20 17:12:35 -08002804 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002805 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002806 checkRuntimeLibs(t, nil, module)
2807}
2808
2809func TestRuntimeLibsNoVndk(t *testing.T) {
2810 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2811
2812 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2813
Colin Cross7113d202019-11-20 16:39:12 -08002814 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002815
Justin Yun8a2600c2020-12-07 12:44:03 +09002816 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2817 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002818
2819 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002820 checkRuntimeLibs(t, []string{"liball_available", "libvendor1"}, module)
2821
2822 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
2823 checkRuntimeLibs(t, []string{"liball_available", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002824}
2825
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002826func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002827 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002828 actual := module.Properties.AndroidMkStaticLibs
2829 if !reflect.DeepEqual(actual, expected) {
2830 t.Errorf("incorrect static_libs"+
2831 "\nactual: %v"+
2832 "\nexpected: %v",
2833 actual,
2834 expected,
2835 )
2836 }
2837}
2838
2839const staticLibAndroidBp = `
2840 cc_library {
2841 name: "lib1",
2842 }
2843 cc_library {
2844 name: "lib2",
2845 static_libs: ["lib1"],
2846 }
2847`
2848
2849func TestStaticLibDepExport(t *testing.T) {
2850 ctx := testCc(t, staticLibAndroidBp)
2851
2852 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002853 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002854 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002855 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002856
2857 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002858 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002859 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2860 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002861 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002862}
2863
Jiyong Parkd08b6972017-09-26 10:50:54 +09002864var compilerFlagsTestCases = []struct {
2865 in string
2866 out bool
2867}{
2868 {
2869 in: "a",
2870 out: false,
2871 },
2872 {
2873 in: "-a",
2874 out: true,
2875 },
2876 {
2877 in: "-Ipath/to/something",
2878 out: false,
2879 },
2880 {
2881 in: "-isystempath/to/something",
2882 out: false,
2883 },
2884 {
2885 in: "--coverage",
2886 out: false,
2887 },
2888 {
2889 in: "-include a/b",
2890 out: true,
2891 },
2892 {
2893 in: "-include a/b c/d",
2894 out: false,
2895 },
2896 {
2897 in: "-DMACRO",
2898 out: true,
2899 },
2900 {
2901 in: "-DMAC RO",
2902 out: false,
2903 },
2904 {
2905 in: "-a -b",
2906 out: false,
2907 },
2908 {
2909 in: "-DMACRO=definition",
2910 out: true,
2911 },
2912 {
2913 in: "-DMACRO=defi nition",
2914 out: true, // TODO(jiyong): this should be false
2915 },
2916 {
2917 in: "-DMACRO(x)=x + 1",
2918 out: true,
2919 },
2920 {
2921 in: "-DMACRO=\"defi nition\"",
2922 out: true,
2923 },
2924}
2925
2926type mockContext struct {
2927 BaseModuleContext
2928 result bool
2929}
2930
2931func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2932 // CheckBadCompilerFlags calls this function when the flag should be rejected
2933 ctx.result = false
2934}
2935
2936func TestCompilerFlags(t *testing.T) {
2937 for _, testCase := range compilerFlagsTestCases {
2938 ctx := &mockContext{result: true}
2939 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2940 if ctx.result != testCase.out {
2941 t.Errorf("incorrect output:")
2942 t.Errorf(" input: %#v", testCase.in)
2943 t.Errorf(" expected: %#v", testCase.out)
2944 t.Errorf(" got: %#v", ctx.result)
2945 }
2946 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002947}
Jiyong Park374510b2018-03-19 18:23:01 +09002948
2949func TestVendorPublicLibraries(t *testing.T) {
2950 ctx := testCc(t, `
2951 cc_library_headers {
2952 name: "libvendorpublic_headers",
2953 export_include_dirs: ["my_include"],
2954 }
2955 vendor_public_library {
2956 name: "libvendorpublic",
2957 symbol_file: "",
2958 export_public_headers: ["libvendorpublic_headers"],
2959 }
2960 cc_library {
2961 name: "libvendorpublic",
2962 srcs: ["foo.c"],
2963 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002964 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002965 nocrt: true,
2966 }
2967
2968 cc_library {
2969 name: "libsystem",
2970 shared_libs: ["libvendorpublic"],
2971 vendor: false,
2972 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002973 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002974 nocrt: true,
2975 }
2976 cc_library {
2977 name: "libvendor",
2978 shared_libs: ["libvendorpublic"],
2979 vendor: true,
2980 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002981 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002982 nocrt: true,
2983 }
2984 `)
2985
Colin Cross7113d202019-11-20 16:39:12 -08002986 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08002987 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09002988
2989 // test if header search paths are correctly added
2990 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08002991 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09002992 cflags := cc.Args["cFlags"]
2993 if !strings.Contains(cflags, "-Imy_include") {
2994 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
2995 }
2996
2997 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08002998 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09002999 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003000 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003001 if !strings.Contains(libflags, stubPaths[0].String()) {
3002 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3003 }
3004
3005 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003006 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003007 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003008 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003009 if !strings.Contains(libflags, stubPaths[0].String()) {
3010 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3011 }
3012
3013}
Jiyong Park37b25202018-07-11 10:49:27 +09003014
3015func TestRecovery(t *testing.T) {
3016 ctx := testCc(t, `
3017 cc_library_shared {
3018 name: "librecovery",
3019 recovery: true,
3020 }
3021 cc_library_shared {
3022 name: "librecovery32",
3023 recovery: true,
3024 compile_multilib:"32",
3025 }
Jiyong Park5baac542018-08-28 09:55:37 +09003026 cc_library_shared {
3027 name: "libHalInRecovery",
3028 recovery_available: true,
3029 vendor: true,
3030 }
Jiyong Park37b25202018-07-11 10:49:27 +09003031 `)
3032
3033 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003034 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003035 if len(variants) != 1 || !android.InList(arm64, variants) {
3036 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3037 }
3038
3039 variants = ctx.ModuleVariantsForTests("librecovery32")
3040 if android.InList(arm64, variants) {
3041 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3042 }
Jiyong Park5baac542018-08-28 09:55:37 +09003043
3044 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3045 if !recoveryModule.Platform() {
3046 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3047 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003048}
Jiyong Park5baac542018-08-28 09:55:37 +09003049
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003050func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3051 bp := `
3052 cc_prebuilt_test_library_shared {
3053 name: "test_lib",
3054 relative_install_path: "foo/bar/baz",
3055 srcs: ["srcpath/dontusethispath/baz.so"],
3056 }
3057
3058 cc_test {
3059 name: "main_test",
3060 data_libs: ["test_lib"],
3061 gtest: false,
3062 }
3063 `
3064
3065 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3066 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3067 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3068 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3069
3070 ctx := testCcWithConfig(t, config)
3071 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3072 testBinary := module.(*Module).linker.(*testBinary)
3073 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3074 if err != nil {
3075 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3076 }
3077 if len(outputFiles) != 1 {
3078 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3079 }
3080 if len(testBinary.dataPaths()) != 1 {
3081 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3082 }
3083
3084 outputPath := outputFiles[0].String()
3085
3086 if !strings.HasSuffix(outputPath, "/main_test") {
3087 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3088 }
3089 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3090 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3091 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3092 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3093 }
3094}
3095
Jiyong Park7ed9de32018-10-15 22:25:07 +09003096func TestVersionedStubs(t *testing.T) {
3097 ctx := testCc(t, `
3098 cc_library_shared {
3099 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003100 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003101 stubs: {
3102 symbol_file: "foo.map.txt",
3103 versions: ["1", "2", "3"],
3104 },
3105 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003106
Jiyong Park7ed9de32018-10-15 22:25:07 +09003107 cc_library_shared {
3108 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003109 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003110 shared_libs: ["libFoo#1"],
3111 }`)
3112
3113 variants := ctx.ModuleVariantsForTests("libFoo")
3114 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003115 "android_arm64_armv8-a_shared",
3116 "android_arm64_armv8-a_shared_1",
3117 "android_arm64_armv8-a_shared_2",
3118 "android_arm64_armv8-a_shared_3",
3119 "android_arm_armv7-a-neon_shared",
3120 "android_arm_armv7-a-neon_shared_1",
3121 "android_arm_armv7-a-neon_shared_2",
3122 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003123 }
3124 variantsMismatch := false
3125 if len(variants) != len(expectedVariants) {
3126 variantsMismatch = true
3127 } else {
3128 for _, v := range expectedVariants {
3129 if !inList(v, variants) {
3130 variantsMismatch = false
3131 }
3132 }
3133 }
3134 if variantsMismatch {
3135 t.Errorf("variants of libFoo expected:\n")
3136 for _, v := range expectedVariants {
3137 t.Errorf("%q\n", v)
3138 }
3139 t.Errorf(", but got:\n")
3140 for _, v := range variants {
3141 t.Errorf("%q\n", v)
3142 }
3143 }
3144
Colin Cross7113d202019-11-20 16:39:12 -08003145 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003146 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003147 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003148 if !strings.Contains(libFlags, libFoo1StubPath) {
3149 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3150 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003151
Colin Cross7113d202019-11-20 16:39:12 -08003152 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003153 cFlags := libBarCompileRule.Args["cFlags"]
3154 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3155 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3156 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3157 }
Jiyong Park37b25202018-07-11 10:49:27 +09003158}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003159
Jooyung Hanb04a4992020-03-13 18:57:35 +09003160func TestVersioningMacro(t *testing.T) {
3161 for _, tc := range []struct{ moduleName, expected string }{
3162 {"libc", "__LIBC_API__"},
3163 {"libfoo", "__LIBFOO_API__"},
3164 {"libfoo@1", "__LIBFOO_1_API__"},
3165 {"libfoo-v1", "__LIBFOO_V1_API__"},
3166 {"libfoo.v1", "__LIBFOO_V1_API__"},
3167 } {
3168 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3169 }
3170}
3171
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003172func TestStaticExecutable(t *testing.T) {
3173 ctx := testCc(t, `
3174 cc_binary {
3175 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003176 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003177 static_executable: true,
3178 }`)
3179
Colin Cross7113d202019-11-20 16:39:12 -08003180 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003181 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3182 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003183 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003184 for _, lib := range systemStaticLibs {
3185 if !strings.Contains(libFlags, lib) {
3186 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3187 }
3188 }
3189 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3190 for _, lib := range systemSharedLibs {
3191 if strings.Contains(libFlags, lib) {
3192 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3193 }
3194 }
3195}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003196
3197func TestStaticDepsOrderWithStubs(t *testing.T) {
3198 ctx := testCc(t, `
3199 cc_binary {
3200 name: "mybin",
3201 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003202 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003203 static_executable: true,
3204 stl: "none",
3205 }
3206
3207 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003208 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003209 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003210 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003211 stl: "none",
3212 }
3213
3214 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003215 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003216 srcs: ["foo.c"],
3217 stl: "none",
3218 stubs: {
3219 versions: ["1"],
3220 },
3221 }`)
3222
Colin Cross0de8a1e2020-09-18 14:15:30 -07003223 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3224 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003225 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003226
3227 if !reflect.DeepEqual(actual, expected) {
3228 t.Errorf("staticDeps orderings were not propagated correctly"+
3229 "\nactual: %v"+
3230 "\nexpected: %v",
3231 actual,
3232 expected,
3233 )
3234 }
3235}
Jooyung Han38002912019-05-16 04:01:54 +09003236
Jooyung Hand48f3c32019-08-23 11:18:57 +09003237func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3238 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3239 cc_library {
3240 name: "libA",
3241 srcs: ["foo.c"],
3242 shared_libs: ["libB"],
3243 stl: "none",
3244 }
3245
3246 cc_library {
3247 name: "libB",
3248 srcs: ["foo.c"],
3249 enabled: false,
3250 stl: "none",
3251 }
3252 `)
3253}
3254
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003255// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3256// correctly.
3257func TestFuzzTarget(t *testing.T) {
3258 ctx := testCc(t, `
3259 cc_fuzz {
3260 name: "fuzz_smoke_test",
3261 srcs: ["foo.c"],
3262 }`)
3263
Paul Duffin075c4172019-12-19 19:06:13 +00003264 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003265 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3266}
3267
Jiyong Park29074592019-07-07 16:27:47 +09003268func TestAidl(t *testing.T) {
3269}
3270
Jooyung Han38002912019-05-16 04:01:54 +09003271func assertString(t *testing.T, got, expected string) {
3272 t.Helper()
3273 if got != expected {
3274 t.Errorf("expected %q got %q", expected, got)
3275 }
3276}
3277
3278func assertArrayString(t *testing.T, got, expected []string) {
3279 t.Helper()
3280 if len(got) != len(expected) {
3281 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3282 return
3283 }
3284 for i := range got {
3285 if got[i] != expected[i] {
3286 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3287 i, expected[i], expected, got[i], got)
3288 return
3289 }
3290 }
3291}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003292
Jooyung Han0302a842019-10-30 18:43:49 +09003293func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3294 t.Helper()
3295 assertArrayString(t, android.SortedStringKeys(m), expected)
3296}
3297
Colin Crosse1bb5d02019-09-24 14:55:04 -07003298func TestDefaults(t *testing.T) {
3299 ctx := testCc(t, `
3300 cc_defaults {
3301 name: "defaults",
3302 srcs: ["foo.c"],
3303 static: {
3304 srcs: ["bar.c"],
3305 },
3306 shared: {
3307 srcs: ["baz.c"],
3308 },
3309 }
3310
3311 cc_library_static {
3312 name: "libstatic",
3313 defaults: ["defaults"],
3314 }
3315
3316 cc_library_shared {
3317 name: "libshared",
3318 defaults: ["defaults"],
3319 }
3320
3321 cc_library {
3322 name: "libboth",
3323 defaults: ["defaults"],
3324 }
3325
3326 cc_binary {
3327 name: "binary",
3328 defaults: ["defaults"],
3329 }`)
3330
3331 pathsToBase := func(paths android.Paths) []string {
3332 var ret []string
3333 for _, p := range paths {
3334 ret = append(ret, p.Base())
3335 }
3336 return ret
3337 }
3338
Colin Cross7113d202019-11-20 16:39:12 -08003339 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003340 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3341 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3342 }
Colin Cross7113d202019-11-20 16:39:12 -08003343 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003344 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3345 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3346 }
Colin Cross7113d202019-11-20 16:39:12 -08003347 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003348 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3349 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3350 }
3351
Colin Cross7113d202019-11-20 16:39:12 -08003352 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003353 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3354 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3355 }
Colin Cross7113d202019-11-20 16:39:12 -08003356 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003357 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3358 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3359 }
3360}
Colin Crosseabaedd2020-02-06 17:01:55 -08003361
3362func TestProductVariableDefaults(t *testing.T) {
3363 bp := `
3364 cc_defaults {
3365 name: "libfoo_defaults",
3366 srcs: ["foo.c"],
3367 cppflags: ["-DFOO"],
3368 product_variables: {
3369 debuggable: {
3370 cppflags: ["-DBAR"],
3371 },
3372 },
3373 }
3374
3375 cc_library {
3376 name: "libfoo",
3377 defaults: ["libfoo_defaults"],
3378 }
3379 `
3380
3381 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3382 config.TestProductVariables.Debuggable = BoolPtr(true)
3383
Colin Crossae8600b2020-10-29 17:09:13 -07003384 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003385 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3386 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3387 })
Colin Crossae8600b2020-10-29 17:09:13 -07003388 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003389
3390 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3391 android.FailIfErrored(t, errs)
3392 _, errs = ctx.PrepareBuildActions(config)
3393 android.FailIfErrored(t, errs)
3394
3395 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3396 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3397 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3398 }
3399}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003400
3401func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3402 t.Parallel()
3403 bp := `
3404 cc_library_static {
3405 name: "libfoo",
3406 srcs: ["foo.c"],
3407 whole_static_libs: ["libbar"],
3408 }
3409
3410 cc_library_static {
3411 name: "libbar",
3412 whole_static_libs: ["libmissing"],
3413 }
3414 `
3415
3416 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3417 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3418
Colin Crossae8600b2020-10-29 17:09:13 -07003419 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003420 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003421 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003422
3423 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3424 android.FailIfErrored(t, errs)
3425 _, errs = ctx.PrepareBuildActions(config)
3426 android.FailIfErrored(t, errs)
3427
3428 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3429 if g, w := libbar.Rule, android.ErrorRule; g != w {
3430 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3431 }
3432
3433 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3434 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
3435 }
3436
3437 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
3438 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
3439 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
3440 }
3441
3442}
Colin Crosse9fe2942020-11-10 18:12:15 -08003443
3444func TestInstallSharedLibs(t *testing.T) {
3445 bp := `
3446 cc_binary {
3447 name: "bin",
3448 host_supported: true,
3449 shared_libs: ["libshared"],
3450 runtime_libs: ["libruntime"],
3451 srcs: [":gen"],
3452 }
3453
3454 cc_library_shared {
3455 name: "libshared",
3456 host_supported: true,
3457 shared_libs: ["libtransitive"],
3458 }
3459
3460 cc_library_shared {
3461 name: "libtransitive",
3462 host_supported: true,
3463 }
3464
3465 cc_library_shared {
3466 name: "libruntime",
3467 host_supported: true,
3468 }
3469
3470 cc_binary_host {
3471 name: "tool",
3472 srcs: ["foo.cpp"],
3473 }
3474
3475 genrule {
3476 name: "gen",
3477 tools: ["tool"],
3478 out: ["gen.cpp"],
3479 cmd: "$(location tool) $(out)",
3480 }
3481 `
3482
3483 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3484 ctx := testCcWithConfig(t, config)
3485
3486 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3487 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3488 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3489 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3490 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3491
3492 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3493 t.Errorf("expected host bin dependency %q, got %q", w, g)
3494 }
3495
3496 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3497 t.Errorf("expected host bin dependency %q, got %q", w, g)
3498 }
3499
3500 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3501 t.Errorf("expected host bin dependency %q, got %q", w, g)
3502 }
3503
3504 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3505 t.Errorf("expected host bin dependency %q, got %q", w, g)
3506 }
3507
3508 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3509 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3510 }
3511
3512 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3513 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3514 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3515 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3516
3517 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3518 t.Errorf("expected device bin dependency %q, got %q", w, g)
3519 }
3520
3521 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3522 t.Errorf("expected device bin dependency %q, got %q", w, g)
3523 }
3524
3525 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3526 t.Errorf("expected device bin dependency %q, got %q", w, g)
3527 }
3528
3529 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3530 t.Errorf("expected device bin dependency %q, got %q", w, g)
3531 }
3532
3533 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3534 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3535 }
3536
3537}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003538
3539func TestStubsLibReexportsHeaders(t *testing.T) {
3540 ctx := testCc(t, `
3541 cc_library_shared {
3542 name: "libclient",
3543 srcs: ["foo.c"],
3544 shared_libs: ["libfoo#1"],
3545 }
3546
3547 cc_library_shared {
3548 name: "libfoo",
3549 srcs: ["foo.c"],
3550 shared_libs: ["libbar"],
3551 export_shared_lib_headers: ["libbar"],
3552 stubs: {
3553 symbol_file: "foo.map.txt",
3554 versions: ["1", "2", "3"],
3555 },
3556 }
3557
3558 cc_library_shared {
3559 name: "libbar",
3560 export_include_dirs: ["include/libbar"],
3561 srcs: ["foo.c"],
3562 }`)
3563
3564 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3565
3566 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3567 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3568 }
3569}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003570
3571func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3572 ctx := testCc(t, `
3573 cc_library {
3574 name: "libfoo",
3575 srcs: ["a/Foo.aidl"],
3576 aidl: { flags: ["-Werror"], },
3577 }
3578 `)
3579
3580 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3581 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3582 aidlCommand := manifest.Commands[0].GetCommand()
3583 expectedAidlFlag := "-Werror"
3584 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3585 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3586 }
3587}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003588
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003589type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003590
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003591const (
3592 None MemtagNoteType = iota + 1
3593 Sync
3594 Async
3595)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003596
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003597func (t MemtagNoteType) str() string {
3598 switch t {
3599 case None:
3600 return "none"
3601 case Sync:
3602 return "sync"
3603 case Async:
3604 return "async"
3605 default:
3606 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003607 }
3608}
3609
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003610func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3611 note_async := "note_memtag_heap_async"
3612 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003613
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003614 found := None
3615 implicits := m.Rule("ld").Implicits
3616 for _, lib := range implicits {
3617 if strings.Contains(lib.Rel(), note_async) {
3618 found = Async
3619 break
3620 } else if strings.Contains(lib.Rel(), note_sync) {
3621 found = Sync
3622 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003623 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003624 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003625
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003626 if found != expected {
3627 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3628 }
3629}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003630
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003631func makeMemtagTestConfig(t *testing.T) android.Config {
3632 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003633 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003634 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003635 gtest: false,
3636 }
3637
3638 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003639 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003640 gtest: false,
3641 sanitize: { memtag_heap: false },
3642 }
3643
3644 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003645 name: "%[1]s_test_true",
3646 gtest: false,
3647 sanitize: { memtag_heap: true },
3648 }
3649
3650 cc_test {
3651 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003652 gtest: false,
3653 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3654 }
3655
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003656 cc_test {
3657 name: "%[1]s_test_true_diag",
3658 gtest: false,
3659 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3660 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003661
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003662 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003663 name: "%[1]s_binary",
3664 }
3665
3666 cc_binary {
3667 name: "%[1]s_binary_false",
3668 sanitize: { memtag_heap: false },
3669 }
3670
3671 cc_binary {
3672 name: "%[1]s_binary_true",
3673 sanitize: { memtag_heap: true },
3674 }
3675
3676 cc_binary {
3677 name: "%[1]s_binary_true_nodiag",
3678 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3679 }
3680
3681 cc_binary {
3682 name: "%[1]s_binary_true_diag",
3683 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003684 }
3685 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003686 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3687 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3688 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3689 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003690
3691 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003692 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3693 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3694 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3695 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003696 }
3697
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003698 return TestConfig(buildDir, android.Android, nil, "", mockFS)
3699}
3700
3701func TestSanitizeMemtagHeap(t *testing.T) {
3702 variant := "android_arm64_armv8-a"
3703
3704 config := makeMemtagTestConfig(t)
3705 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003706 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003707 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003708 ctx := CreateTestContext(config)
3709 ctx.Register()
3710
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003711 _, 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 -08003712 android.FailIfErrored(t, errs)
3713 _, errs = ctx.PrepareBuildActions(config)
3714 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003715
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003716 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3717 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3718 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3719 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3720 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3721
3722 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3723 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3724 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3725 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3726 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3727
3728 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3729 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3730 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3731 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3732 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3733
3734 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3735 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3736 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3737 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3738 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3739
3740 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3741 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3742 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3743 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3744 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3745
3746 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3747 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3748 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3749 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3750 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3751
3752 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3753 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3754 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3755 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3756 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3757
3758 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3759 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3760 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3761 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3762 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3763}
3764
3765func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003766 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003767
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003768 config := makeMemtagTestConfig(t)
3769 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3770 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3771 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3772 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3773 ctx := CreateTestContext(config)
3774 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003775
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003776 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3777 android.FailIfErrored(t, errs)
3778 _, errs = ctx.PrepareBuildActions(config)
3779 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003780
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003781 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3782 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3783 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3784 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3785 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003786
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003787 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3788 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3789 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3790 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3791 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3792
3793 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3794 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3795 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3796 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3797 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3798
3799 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3800 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3801 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3802 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3803 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3804
3805 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3806 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3807 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3808 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3809 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3810
3811 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3812 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3813 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3814 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3815 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3816
3817 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3818 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3819 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3820 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3821 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3822
3823 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3824 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3825 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3826 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3827 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3828}
3829
3830func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3831 variant := "android_arm64_armv8-a"
3832
3833 config := makeMemtagTestConfig(t)
3834 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3835 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3836 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3837 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3838 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
3839 ctx := CreateTestContext(config)
3840 ctx.Register()
3841
3842 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3843 android.FailIfErrored(t, errs)
3844 _, errs = ctx.PrepareBuildActions(config)
3845 android.FailIfErrored(t, errs)
3846
3847 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3848 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3849 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3850 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3851 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3852
3853 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3854 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3855 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3856 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3857 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3858
3859 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3860 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3861 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3862 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3863 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3864
3865 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3866 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3869 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3870
3871 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3872 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3873 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3874 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3875 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3876
3877 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3878 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3879 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3880 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3881 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3882
3883 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3884 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3885 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3886 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3887 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3888
3889 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3890 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3892 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3893 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003894}