blob: d272a3220e0ee6d4df970c0386dbaa9266662da0 [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 {
Justin Yuncbca3732021-02-03 19:24:13 +09002715 name: "libproduct_vendor",
2716 product_specific: true,
2717 vendor_available: true,
2718 no_libcrt : true,
2719 nocrt : true,
2720 system_shared_libs : [],
2721 }
2722 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002723 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002724 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002725 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002726 nocrt : true,
2727 system_shared_libs : [],
2728 }
2729 cc_library {
2730 name: "libvendor1",
2731 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002732 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002733 nocrt : true,
2734 system_shared_libs : [],
2735 }
2736 cc_library {
2737 name: "libvendor2",
2738 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002739 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002740 no_libcrt : true,
2741 nocrt : true,
2742 system_shared_libs : [],
2743 }
2744 cc_library {
2745 name: "libproduct_available1",
2746 product_available: true,
2747 runtime_libs: ["liball_available"],
2748 no_libcrt : true,
2749 nocrt : true,
2750 system_shared_libs : [],
2751 }
2752 cc_library {
2753 name: "libproduct1",
2754 product_specific: true,
2755 no_libcrt : true,
2756 nocrt : true,
2757 system_shared_libs : [],
2758 }
2759 cc_library {
2760 name: "libproduct2",
2761 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002762 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002763 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002764 nocrt : true,
2765 system_shared_libs : [],
2766 }
2767`
2768
2769func TestRuntimeLibs(t *testing.T) {
2770 ctx := testCc(t, runtimeLibAndroidBp)
2771
2772 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002773 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002774
Justin Yun8a2600c2020-12-07 12:44:03 +09002775 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2776 checkRuntimeLibs(t, []string{"liball_available"}, module)
2777
2778 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2779 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002780
2781 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002782 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002783
2784 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2785 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002786 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002787
Justin Yun8a2600c2020-12-07 12:44:03 +09002788 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2789 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002790
2791 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002792 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002793
2794 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2795 // and product variants.
2796 variant = "android_product.VER_arm64_armv8-a_shared"
2797
2798 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2799 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2800
2801 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002802 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor.product"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002803}
2804
2805func TestExcludeRuntimeLibs(t *testing.T) {
2806 ctx := testCc(t, runtimeLibAndroidBp)
2807
Colin Cross7113d202019-11-20 16:39:12 -08002808 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002809 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2810 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002811
Colin Crossfb0c16e2019-11-20 17:12:35 -08002812 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002813 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002814 checkRuntimeLibs(t, nil, module)
2815}
2816
2817func TestRuntimeLibsNoVndk(t *testing.T) {
2818 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2819
2820 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2821
Colin Cross7113d202019-11-20 16:39:12 -08002822 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002823
Justin Yun8a2600c2020-12-07 12:44:03 +09002824 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2825 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002826
2827 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002828 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002829
2830 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002831 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002832}
2833
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002834func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002835 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002836 actual := module.Properties.AndroidMkStaticLibs
2837 if !reflect.DeepEqual(actual, expected) {
2838 t.Errorf("incorrect static_libs"+
2839 "\nactual: %v"+
2840 "\nexpected: %v",
2841 actual,
2842 expected,
2843 )
2844 }
2845}
2846
2847const staticLibAndroidBp = `
2848 cc_library {
2849 name: "lib1",
2850 }
2851 cc_library {
2852 name: "lib2",
2853 static_libs: ["lib1"],
2854 }
2855`
2856
2857func TestStaticLibDepExport(t *testing.T) {
2858 ctx := testCc(t, staticLibAndroidBp)
2859
2860 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002861 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002862 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002863 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002864
2865 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002866 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002867 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2868 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002869 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002870}
2871
Jiyong Parkd08b6972017-09-26 10:50:54 +09002872var compilerFlagsTestCases = []struct {
2873 in string
2874 out bool
2875}{
2876 {
2877 in: "a",
2878 out: false,
2879 },
2880 {
2881 in: "-a",
2882 out: true,
2883 },
2884 {
2885 in: "-Ipath/to/something",
2886 out: false,
2887 },
2888 {
2889 in: "-isystempath/to/something",
2890 out: false,
2891 },
2892 {
2893 in: "--coverage",
2894 out: false,
2895 },
2896 {
2897 in: "-include a/b",
2898 out: true,
2899 },
2900 {
2901 in: "-include a/b c/d",
2902 out: false,
2903 },
2904 {
2905 in: "-DMACRO",
2906 out: true,
2907 },
2908 {
2909 in: "-DMAC RO",
2910 out: false,
2911 },
2912 {
2913 in: "-a -b",
2914 out: false,
2915 },
2916 {
2917 in: "-DMACRO=definition",
2918 out: true,
2919 },
2920 {
2921 in: "-DMACRO=defi nition",
2922 out: true, // TODO(jiyong): this should be false
2923 },
2924 {
2925 in: "-DMACRO(x)=x + 1",
2926 out: true,
2927 },
2928 {
2929 in: "-DMACRO=\"defi nition\"",
2930 out: true,
2931 },
2932}
2933
2934type mockContext struct {
2935 BaseModuleContext
2936 result bool
2937}
2938
2939func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2940 // CheckBadCompilerFlags calls this function when the flag should be rejected
2941 ctx.result = false
2942}
2943
2944func TestCompilerFlags(t *testing.T) {
2945 for _, testCase := range compilerFlagsTestCases {
2946 ctx := &mockContext{result: true}
2947 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2948 if ctx.result != testCase.out {
2949 t.Errorf("incorrect output:")
2950 t.Errorf(" input: %#v", testCase.in)
2951 t.Errorf(" expected: %#v", testCase.out)
2952 t.Errorf(" got: %#v", ctx.result)
2953 }
2954 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002955}
Jiyong Park374510b2018-03-19 18:23:01 +09002956
2957func TestVendorPublicLibraries(t *testing.T) {
2958 ctx := testCc(t, `
2959 cc_library_headers {
2960 name: "libvendorpublic_headers",
2961 export_include_dirs: ["my_include"],
2962 }
2963 vendor_public_library {
2964 name: "libvendorpublic",
2965 symbol_file: "",
2966 export_public_headers: ["libvendorpublic_headers"],
2967 }
2968 cc_library {
2969 name: "libvendorpublic",
2970 srcs: ["foo.c"],
2971 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002972 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002973 nocrt: true,
2974 }
2975
2976 cc_library {
2977 name: "libsystem",
2978 shared_libs: ["libvendorpublic"],
2979 vendor: false,
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 cc_library {
2985 name: "libvendor",
2986 shared_libs: ["libvendorpublic"],
2987 vendor: true,
2988 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002989 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002990 nocrt: true,
2991 }
2992 `)
2993
Colin Cross7113d202019-11-20 16:39:12 -08002994 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08002995 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09002996
2997 // test if header search paths are correctly added
2998 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08002999 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003000 cflags := cc.Args["cFlags"]
3001 if !strings.Contains(cflags, "-Imy_include") {
3002 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3003 }
3004
3005 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003006 ld := ctx.ModuleForTests("libsystem", coreVariant).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, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003009 if !strings.Contains(libflags, stubPaths[0].String()) {
3010 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3011 }
3012
3013 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003014 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003015 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003016 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003017 if !strings.Contains(libflags, stubPaths[0].String()) {
3018 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3019 }
3020
3021}
Jiyong Park37b25202018-07-11 10:49:27 +09003022
3023func TestRecovery(t *testing.T) {
3024 ctx := testCc(t, `
3025 cc_library_shared {
3026 name: "librecovery",
3027 recovery: true,
3028 }
3029 cc_library_shared {
3030 name: "librecovery32",
3031 recovery: true,
3032 compile_multilib:"32",
3033 }
Jiyong Park5baac542018-08-28 09:55:37 +09003034 cc_library_shared {
3035 name: "libHalInRecovery",
3036 recovery_available: true,
3037 vendor: true,
3038 }
Jiyong Park37b25202018-07-11 10:49:27 +09003039 `)
3040
3041 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003042 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003043 if len(variants) != 1 || !android.InList(arm64, variants) {
3044 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3045 }
3046
3047 variants = ctx.ModuleVariantsForTests("librecovery32")
3048 if android.InList(arm64, variants) {
3049 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3050 }
Jiyong Park5baac542018-08-28 09:55:37 +09003051
3052 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3053 if !recoveryModule.Platform() {
3054 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3055 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003056}
Jiyong Park5baac542018-08-28 09:55:37 +09003057
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003058func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3059 bp := `
3060 cc_prebuilt_test_library_shared {
3061 name: "test_lib",
3062 relative_install_path: "foo/bar/baz",
3063 srcs: ["srcpath/dontusethispath/baz.so"],
3064 }
3065
3066 cc_test {
3067 name: "main_test",
3068 data_libs: ["test_lib"],
3069 gtest: false,
3070 }
3071 `
3072
3073 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3074 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3075 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3076 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3077
3078 ctx := testCcWithConfig(t, config)
3079 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3080 testBinary := module.(*Module).linker.(*testBinary)
3081 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3082 if err != nil {
3083 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3084 }
3085 if len(outputFiles) != 1 {
3086 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3087 }
3088 if len(testBinary.dataPaths()) != 1 {
3089 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3090 }
3091
3092 outputPath := outputFiles[0].String()
3093
3094 if !strings.HasSuffix(outputPath, "/main_test") {
3095 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3096 }
3097 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3098 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3099 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3100 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3101 }
3102}
3103
Jiyong Park7ed9de32018-10-15 22:25:07 +09003104func TestVersionedStubs(t *testing.T) {
3105 ctx := testCc(t, `
3106 cc_library_shared {
3107 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003108 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003109 stubs: {
3110 symbol_file: "foo.map.txt",
3111 versions: ["1", "2", "3"],
3112 },
3113 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003114
Jiyong Park7ed9de32018-10-15 22:25:07 +09003115 cc_library_shared {
3116 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003117 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003118 shared_libs: ["libFoo#1"],
3119 }`)
3120
3121 variants := ctx.ModuleVariantsForTests("libFoo")
3122 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003123 "android_arm64_armv8-a_shared",
3124 "android_arm64_armv8-a_shared_1",
3125 "android_arm64_armv8-a_shared_2",
3126 "android_arm64_armv8-a_shared_3",
3127 "android_arm_armv7-a-neon_shared",
3128 "android_arm_armv7-a-neon_shared_1",
3129 "android_arm_armv7-a-neon_shared_2",
3130 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003131 }
3132 variantsMismatch := false
3133 if len(variants) != len(expectedVariants) {
3134 variantsMismatch = true
3135 } else {
3136 for _, v := range expectedVariants {
3137 if !inList(v, variants) {
3138 variantsMismatch = false
3139 }
3140 }
3141 }
3142 if variantsMismatch {
3143 t.Errorf("variants of libFoo expected:\n")
3144 for _, v := range expectedVariants {
3145 t.Errorf("%q\n", v)
3146 }
3147 t.Errorf(", but got:\n")
3148 for _, v := range variants {
3149 t.Errorf("%q\n", v)
3150 }
3151 }
3152
Colin Cross7113d202019-11-20 16:39:12 -08003153 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003154 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003155 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003156 if !strings.Contains(libFlags, libFoo1StubPath) {
3157 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3158 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003159
Colin Cross7113d202019-11-20 16:39:12 -08003160 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003161 cFlags := libBarCompileRule.Args["cFlags"]
3162 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3163 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3164 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3165 }
Jiyong Park37b25202018-07-11 10:49:27 +09003166}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003167
Jooyung Hanb04a4992020-03-13 18:57:35 +09003168func TestVersioningMacro(t *testing.T) {
3169 for _, tc := range []struct{ moduleName, expected string }{
3170 {"libc", "__LIBC_API__"},
3171 {"libfoo", "__LIBFOO_API__"},
3172 {"libfoo@1", "__LIBFOO_1_API__"},
3173 {"libfoo-v1", "__LIBFOO_V1_API__"},
3174 {"libfoo.v1", "__LIBFOO_V1_API__"},
3175 } {
3176 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3177 }
3178}
3179
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003180func TestStaticExecutable(t *testing.T) {
3181 ctx := testCc(t, `
3182 cc_binary {
3183 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003184 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003185 static_executable: true,
3186 }`)
3187
Colin Cross7113d202019-11-20 16:39:12 -08003188 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003189 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3190 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003191 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003192 for _, lib := range systemStaticLibs {
3193 if !strings.Contains(libFlags, lib) {
3194 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3195 }
3196 }
3197 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3198 for _, lib := range systemSharedLibs {
3199 if strings.Contains(libFlags, lib) {
3200 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3201 }
3202 }
3203}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003204
3205func TestStaticDepsOrderWithStubs(t *testing.T) {
3206 ctx := testCc(t, `
3207 cc_binary {
3208 name: "mybin",
3209 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003210 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003211 static_executable: true,
3212 stl: "none",
3213 }
3214
3215 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003216 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003217 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003218 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003219 stl: "none",
3220 }
3221
3222 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003223 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003224 srcs: ["foo.c"],
3225 stl: "none",
3226 stubs: {
3227 versions: ["1"],
3228 },
3229 }`)
3230
Colin Cross0de8a1e2020-09-18 14:15:30 -07003231 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3232 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003233 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003234
3235 if !reflect.DeepEqual(actual, expected) {
3236 t.Errorf("staticDeps orderings were not propagated correctly"+
3237 "\nactual: %v"+
3238 "\nexpected: %v",
3239 actual,
3240 expected,
3241 )
3242 }
3243}
Jooyung Han38002912019-05-16 04:01:54 +09003244
Jooyung Hand48f3c32019-08-23 11:18:57 +09003245func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3246 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3247 cc_library {
3248 name: "libA",
3249 srcs: ["foo.c"],
3250 shared_libs: ["libB"],
3251 stl: "none",
3252 }
3253
3254 cc_library {
3255 name: "libB",
3256 srcs: ["foo.c"],
3257 enabled: false,
3258 stl: "none",
3259 }
3260 `)
3261}
3262
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003263// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3264// correctly.
3265func TestFuzzTarget(t *testing.T) {
3266 ctx := testCc(t, `
3267 cc_fuzz {
3268 name: "fuzz_smoke_test",
3269 srcs: ["foo.c"],
3270 }`)
3271
Paul Duffin075c4172019-12-19 19:06:13 +00003272 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003273 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3274}
3275
Jiyong Park29074592019-07-07 16:27:47 +09003276func TestAidl(t *testing.T) {
3277}
3278
Jooyung Han38002912019-05-16 04:01:54 +09003279func assertString(t *testing.T, got, expected string) {
3280 t.Helper()
3281 if got != expected {
3282 t.Errorf("expected %q got %q", expected, got)
3283 }
3284}
3285
3286func assertArrayString(t *testing.T, got, expected []string) {
3287 t.Helper()
3288 if len(got) != len(expected) {
3289 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3290 return
3291 }
3292 for i := range got {
3293 if got[i] != expected[i] {
3294 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3295 i, expected[i], expected, got[i], got)
3296 return
3297 }
3298 }
3299}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003300
Jooyung Han0302a842019-10-30 18:43:49 +09003301func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3302 t.Helper()
3303 assertArrayString(t, android.SortedStringKeys(m), expected)
3304}
3305
Colin Crosse1bb5d02019-09-24 14:55:04 -07003306func TestDefaults(t *testing.T) {
3307 ctx := testCc(t, `
3308 cc_defaults {
3309 name: "defaults",
3310 srcs: ["foo.c"],
3311 static: {
3312 srcs: ["bar.c"],
3313 },
3314 shared: {
3315 srcs: ["baz.c"],
3316 },
3317 }
3318
3319 cc_library_static {
3320 name: "libstatic",
3321 defaults: ["defaults"],
3322 }
3323
3324 cc_library_shared {
3325 name: "libshared",
3326 defaults: ["defaults"],
3327 }
3328
3329 cc_library {
3330 name: "libboth",
3331 defaults: ["defaults"],
3332 }
3333
3334 cc_binary {
3335 name: "binary",
3336 defaults: ["defaults"],
3337 }`)
3338
3339 pathsToBase := func(paths android.Paths) []string {
3340 var ret []string
3341 for _, p := range paths {
3342 ret = append(ret, p.Base())
3343 }
3344 return ret
3345 }
3346
Colin Cross7113d202019-11-20 16:39:12 -08003347 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003348 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3349 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3350 }
Colin Cross7113d202019-11-20 16:39:12 -08003351 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003352 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3353 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3354 }
Colin Cross7113d202019-11-20 16:39:12 -08003355 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003356 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3357 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3358 }
3359
Colin Cross7113d202019-11-20 16:39:12 -08003360 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003361 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3362 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3363 }
Colin Cross7113d202019-11-20 16:39:12 -08003364 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003365 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3366 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3367 }
3368}
Colin Crosseabaedd2020-02-06 17:01:55 -08003369
3370func TestProductVariableDefaults(t *testing.T) {
3371 bp := `
3372 cc_defaults {
3373 name: "libfoo_defaults",
3374 srcs: ["foo.c"],
3375 cppflags: ["-DFOO"],
3376 product_variables: {
3377 debuggable: {
3378 cppflags: ["-DBAR"],
3379 },
3380 },
3381 }
3382
3383 cc_library {
3384 name: "libfoo",
3385 defaults: ["libfoo_defaults"],
3386 }
3387 `
3388
3389 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3390 config.TestProductVariables.Debuggable = BoolPtr(true)
3391
Colin Crossae8600b2020-10-29 17:09:13 -07003392 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003393 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3394 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3395 })
Colin Crossae8600b2020-10-29 17:09:13 -07003396 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003397
3398 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3399 android.FailIfErrored(t, errs)
3400 _, errs = ctx.PrepareBuildActions(config)
3401 android.FailIfErrored(t, errs)
3402
3403 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3404 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3405 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3406 }
3407}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003408
3409func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3410 t.Parallel()
3411 bp := `
3412 cc_library_static {
3413 name: "libfoo",
3414 srcs: ["foo.c"],
3415 whole_static_libs: ["libbar"],
3416 }
3417
3418 cc_library_static {
3419 name: "libbar",
3420 whole_static_libs: ["libmissing"],
3421 }
3422 `
3423
3424 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3425 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3426
Colin Crossae8600b2020-10-29 17:09:13 -07003427 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003428 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003429 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003430
3431 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3432 android.FailIfErrored(t, errs)
3433 _, errs = ctx.PrepareBuildActions(config)
3434 android.FailIfErrored(t, errs)
3435
3436 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3437 if g, w := libbar.Rule, android.ErrorRule; g != w {
3438 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3439 }
3440
3441 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3442 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
3443 }
3444
3445 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
3446 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
3447 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
3448 }
3449
3450}
Colin Crosse9fe2942020-11-10 18:12:15 -08003451
3452func TestInstallSharedLibs(t *testing.T) {
3453 bp := `
3454 cc_binary {
3455 name: "bin",
3456 host_supported: true,
3457 shared_libs: ["libshared"],
3458 runtime_libs: ["libruntime"],
3459 srcs: [":gen"],
3460 }
3461
3462 cc_library_shared {
3463 name: "libshared",
3464 host_supported: true,
3465 shared_libs: ["libtransitive"],
3466 }
3467
3468 cc_library_shared {
3469 name: "libtransitive",
3470 host_supported: true,
3471 }
3472
3473 cc_library_shared {
3474 name: "libruntime",
3475 host_supported: true,
3476 }
3477
3478 cc_binary_host {
3479 name: "tool",
3480 srcs: ["foo.cpp"],
3481 }
3482
3483 genrule {
3484 name: "gen",
3485 tools: ["tool"],
3486 out: ["gen.cpp"],
3487 cmd: "$(location tool) $(out)",
3488 }
3489 `
3490
3491 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3492 ctx := testCcWithConfig(t, config)
3493
3494 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3495 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3496 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3497 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3498 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3499
3500 if g, w := hostBin.Implicits.Strings(), hostShared.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(), hostTransitive.Output.String(); !android.InList(w, g) {
3505 t.Errorf("expected host bin dependency %q, got %q", w, g)
3506 }
3507
3508 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3509 t.Errorf("expected host bin dependency %q, got %q", w, g)
3510 }
3511
3512 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3513 t.Errorf("expected host bin dependency %q, got %q", w, g)
3514 }
3515
3516 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3517 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3518 }
3519
3520 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3521 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3522 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3523 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3524
3525 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.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(), deviceTransitive.Output.String(); !android.InList(w, g) {
3530 t.Errorf("expected device bin dependency %q, got %q", w, g)
3531 }
3532
3533 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3534 t.Errorf("expected device bin dependency %q, got %q", w, g)
3535 }
3536
3537 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3538 t.Errorf("expected device bin dependency %q, got %q", w, g)
3539 }
3540
3541 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3542 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3543 }
3544
3545}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003546
3547func TestStubsLibReexportsHeaders(t *testing.T) {
3548 ctx := testCc(t, `
3549 cc_library_shared {
3550 name: "libclient",
3551 srcs: ["foo.c"],
3552 shared_libs: ["libfoo#1"],
3553 }
3554
3555 cc_library_shared {
3556 name: "libfoo",
3557 srcs: ["foo.c"],
3558 shared_libs: ["libbar"],
3559 export_shared_lib_headers: ["libbar"],
3560 stubs: {
3561 symbol_file: "foo.map.txt",
3562 versions: ["1", "2", "3"],
3563 },
3564 }
3565
3566 cc_library_shared {
3567 name: "libbar",
3568 export_include_dirs: ["include/libbar"],
3569 srcs: ["foo.c"],
3570 }`)
3571
3572 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3573
3574 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3575 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3576 }
3577}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003578
3579func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3580 ctx := testCc(t, `
3581 cc_library {
3582 name: "libfoo",
3583 srcs: ["a/Foo.aidl"],
3584 aidl: { flags: ["-Werror"], },
3585 }
3586 `)
3587
3588 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3589 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3590 aidlCommand := manifest.Commands[0].GetCommand()
3591 expectedAidlFlag := "-Werror"
3592 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3593 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3594 }
3595}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003596
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003597type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003598
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003599const (
3600 None MemtagNoteType = iota + 1
3601 Sync
3602 Async
3603)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003604
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003605func (t MemtagNoteType) str() string {
3606 switch t {
3607 case None:
3608 return "none"
3609 case Sync:
3610 return "sync"
3611 case Async:
3612 return "async"
3613 default:
3614 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003615 }
3616}
3617
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003618func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3619 note_async := "note_memtag_heap_async"
3620 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003621
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003622 found := None
3623 implicits := m.Rule("ld").Implicits
3624 for _, lib := range implicits {
3625 if strings.Contains(lib.Rel(), note_async) {
3626 found = Async
3627 break
3628 } else if strings.Contains(lib.Rel(), note_sync) {
3629 found = Sync
3630 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003631 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003632 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003633
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003634 if found != expected {
3635 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3636 }
3637}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003638
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003639func makeMemtagTestConfig(t *testing.T) android.Config {
3640 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003641 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003642 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003643 gtest: false,
3644 }
3645
3646 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003647 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003648 gtest: false,
3649 sanitize: { memtag_heap: false },
3650 }
3651
3652 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003653 name: "%[1]s_test_true",
3654 gtest: false,
3655 sanitize: { memtag_heap: true },
3656 }
3657
3658 cc_test {
3659 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003660 gtest: false,
3661 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3662 }
3663
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003664 cc_test {
3665 name: "%[1]s_test_true_diag",
3666 gtest: false,
3667 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3668 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003669
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003670 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003671 name: "%[1]s_binary",
3672 }
3673
3674 cc_binary {
3675 name: "%[1]s_binary_false",
3676 sanitize: { memtag_heap: false },
3677 }
3678
3679 cc_binary {
3680 name: "%[1]s_binary_true",
3681 sanitize: { memtag_heap: true },
3682 }
3683
3684 cc_binary {
3685 name: "%[1]s_binary_true_nodiag",
3686 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3687 }
3688
3689 cc_binary {
3690 name: "%[1]s_binary_true_diag",
3691 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003692 }
3693 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003694 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3695 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3696 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3697 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003698
3699 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003700 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3701 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3702 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3703 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003704 }
3705
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003706 return TestConfig(buildDir, android.Android, nil, "", mockFS)
3707}
3708
3709func TestSanitizeMemtagHeap(t *testing.T) {
3710 variant := "android_arm64_armv8-a"
3711
3712 config := makeMemtagTestConfig(t)
3713 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003714 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003715 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003716 ctx := CreateTestContext(config)
3717 ctx.Register()
3718
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003719 _, 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 -08003720 android.FailIfErrored(t, errs)
3721 _, errs = ctx.PrepareBuildActions(config)
3722 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003723
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003724 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3725 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3726 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3727 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3728 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3729
3730 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3731 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3732 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3733 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3734 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3735
3736 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3737 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3738 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3739 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3740 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3741
3742 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3743 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3744 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3745 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3746 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3747
3748 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3749 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3750 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3751 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3752 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3753
3754 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3755 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3756 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3757 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3758 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3759
3760 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3761 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3762 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3763 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3764 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3765
3766 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3767 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3768 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3769 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3770 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3771}
3772
3773func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003774 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003775
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003776 config := makeMemtagTestConfig(t)
3777 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3778 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3779 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3780 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3781 ctx := CreateTestContext(config)
3782 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003783
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003784 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3785 android.FailIfErrored(t, errs)
3786 _, errs = ctx.PrepareBuildActions(config)
3787 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003788
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003789 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3790 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3791 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3792 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3793 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003794
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003795 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3796 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3797 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3798 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3799 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3800
3801 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3802 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3803 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3804 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3805 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3806
3807 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3808 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3809 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3810 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3811 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3812
3813 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3814 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3815 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3816 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3817 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3818
3819 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3820 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3821 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3822 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3823 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3824
3825 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3826 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3827 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3828 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3829 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3830
3831 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3832 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3833 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3834 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3835 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3836}
3837
3838func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3839 variant := "android_arm64_armv8-a"
3840
3841 config := makeMemtagTestConfig(t)
3842 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3843 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3844 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3845 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3846 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
3847 ctx := CreateTestContext(config)
3848 ctx.Register()
3849
3850 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3851 android.FailIfErrored(t, errs)
3852 _, errs = ctx.PrepareBuildActions(config)
3853 android.FailIfErrored(t, errs)
3854
3855 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3856 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3857 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3858 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3859 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3860
3861 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3862 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3863 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3864 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3865 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3866
3867 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3869 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3870 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3871 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3872
3873 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3874 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3875 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3876 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3877 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3878
3879 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3880 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3881 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3882 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3883 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3884
3885 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3886 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3887 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3888 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3889 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3890
3891 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3892 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3893 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3894 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3895 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3896
3897 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3898 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3899 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3900 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3901 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003902}