blob: d0d875996bcdbf52b0b7afabf8c17598a38094e9 [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
Inseob Kim5f58ff72020-09-07 19:53:31 +09001113func TestVendorSnapshotCapture(t *testing.T) {
Inseob Kim8471cda2019-11-15 09:59:12 +09001114 bp := `
1115 cc_library {
1116 name: "libvndk",
1117 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001118 product_available: true,
Inseob Kim8471cda2019-11-15 09:59:12 +09001119 vndk: {
1120 enabled: true,
1121 },
1122 nocrt: true,
1123 }
1124
1125 cc_library {
1126 name: "libvendor",
1127 vendor: true,
1128 nocrt: true,
1129 }
1130
1131 cc_library {
1132 name: "libvendor_available",
1133 vendor_available: true,
1134 nocrt: true,
1135 }
1136
1137 cc_library_headers {
1138 name: "libvendor_headers",
1139 vendor_available: true,
1140 nocrt: true,
1141 }
1142
1143 cc_binary {
1144 name: "vendor_bin",
1145 vendor: true,
1146 nocrt: true,
1147 }
1148
1149 cc_binary {
1150 name: "vendor_available_bin",
1151 vendor_available: true,
1152 nocrt: true,
1153 }
Inseob Kim7f283f42020-06-01 21:53:49 +09001154
1155 toolchain_library {
1156 name: "libb",
1157 vendor_available: true,
1158 src: "libb.a",
1159 }
Inseob Kim1042d292020-06-01 23:23:05 +09001160
1161 cc_object {
1162 name: "obj",
1163 vendor_available: true,
1164 }
Colin Cross127bb8b2020-12-16 16:46:01 -08001165
1166 cc_library {
1167 name: "libllndk",
1168 llndk_stubs: "libllndk.llndk",
1169 }
1170
1171 llndk_library {
1172 name: "libllndk.llndk",
1173 symbol_file: "",
1174 }
Inseob Kim8471cda2019-11-15 09:59:12 +09001175`
1176 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1177 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1178 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1179 ctx := testCcWithConfig(t, config)
1180
1181 // Check Vendor snapshot output.
1182
1183 snapshotDir := "vendor-snapshot"
1184 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
Inseob Kim7f283f42020-06-01 21:53:49 +09001185 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1186
1187 var jsonFiles []string
Inseob Kim8471cda2019-11-15 09:59:12 +09001188
1189 for _, arch := range [][]string{
1190 []string{"arm64", "armv8-a"},
1191 []string{"arm", "armv7-a-neon"},
1192 } {
1193 archType := arch[0]
1194 archVariant := arch[1]
1195 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1196
1197 // For shared libraries, only non-VNDK vendor_available modules are captured
1198 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1199 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Inseob Kim7f283f42020-06-01 21:53:49 +09001200 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1201 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1202 jsonFiles = append(jsonFiles,
1203 filepath.Join(sharedDir, "libvendor.so.json"),
1204 filepath.Join(sharedDir, "libvendor_available.so.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001205
Colin Cross127bb8b2020-12-16 16:46:01 -08001206 // LLNDK modules are not captured
1207 checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
1208
Inseob Kim8471cda2019-11-15 09:59:12 +09001209 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
Inseob Kimc42f2f22020-07-29 20:32:10 +09001210 // Also cfi variants are captured, except for prebuilts like toolchain_library
Inseob Kim8471cda2019-11-15 09:59:12 +09001211 staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001212 staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant)
Inseob Kim8471cda2019-11-15 09:59:12 +09001213 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Inseob Kim7f283f42020-06-01 21:53:49 +09001214 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1215 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001216 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001217 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001218 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001219 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001220 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001221 jsonFiles = append(jsonFiles,
1222 filepath.Join(staticDir, "libb.a.json"),
1223 filepath.Join(staticDir, "libvndk.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001224 filepath.Join(staticDir, "libvndk.cfi.a.json"),
Inseob Kim7f283f42020-06-01 21:53:49 +09001225 filepath.Join(staticDir, "libvendor.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001226 filepath.Join(staticDir, "libvendor.cfi.a.json"),
1227 filepath.Join(staticDir, "libvendor_available.a.json"),
1228 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001229
Inseob Kim7f283f42020-06-01 21:53:49 +09001230 // For binary executables, all vendor:true and vendor_available modules are captured.
Inseob Kim8471cda2019-11-15 09:59:12 +09001231 if archType == "arm64" {
1232 binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1233 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Inseob Kim7f283f42020-06-01 21:53:49 +09001234 checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
1235 checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
1236 jsonFiles = append(jsonFiles,
1237 filepath.Join(binaryDir, "vendor_bin.json"),
1238 filepath.Join(binaryDir, "vendor_available_bin.json"))
1239 }
1240
1241 // For header libraries, all vendor:true and vendor_available modules are captured.
1242 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1243 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
Inseob Kim1042d292020-06-01 23:23:05 +09001244
1245 // For object modules, all vendor:true and vendor_available modules are captured.
1246 objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1247 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1248 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1249 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
Inseob Kim7f283f42020-06-01 21:53:49 +09001250 }
1251
1252 for _, jsonFile := range jsonFiles {
1253 // verify all json files exist
1254 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1255 t.Errorf("%q expected but not found", jsonFile)
Inseob Kim8471cda2019-11-15 09:59:12 +09001256 }
1257 }
Inseob Kime9aec6a2021-01-05 20:03:22 +09001258
1259 // fake snapshot should have all outputs in the normal snapshot.
1260 fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
1261 for _, output := range snapshotSingleton.AllOutputs() {
1262 fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
1263 if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
1264 t.Errorf("%q expected but not found", fakeOutput)
1265 }
1266 }
Inseob Kim8471cda2019-11-15 09:59:12 +09001267}
1268
Inseob Kim7cf14652021-01-06 23:06:52 +09001269func TestVendorSnapshotDirected(t *testing.T) {
1270 bp := `
1271 cc_library_shared {
1272 name: "libvendor",
1273 vendor: true,
1274 nocrt: true,
1275 }
1276
1277 cc_library_shared {
1278 name: "libvendor_available",
1279 vendor_available: true,
1280 nocrt: true,
1281 }
1282
1283 genrule {
1284 name: "libfoo_gen",
1285 cmd: "",
1286 out: ["libfoo.so"],
1287 }
1288
1289 cc_prebuilt_library_shared {
1290 name: "libfoo",
1291 vendor: true,
1292 prefer: true,
1293 srcs: [":libfoo_gen"],
1294 }
1295
1296 cc_library_shared {
1297 name: "libfoo",
1298 vendor: true,
1299 nocrt: true,
1300 }
1301`
1302 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1303 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1304 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1305 config.TestProductVariables.DirectedVendorSnapshot = true
1306 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
1307 config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
1308 config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
1309 ctx := testCcWithConfig(t, config)
1310
1311 // Check Vendor snapshot output.
1312
1313 snapshotDir := "vendor-snapshot"
1314 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1315 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1316
1317 var includeJsonFiles []string
1318 var excludeJsonFiles []string
1319
1320 for _, arch := range [][]string{
1321 []string{"arm64", "armv8-a"},
1322 []string{"arm", "armv7-a-neon"},
1323 } {
1324 archType := arch[0]
1325 archVariant := arch[1]
1326 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1327
1328 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1329 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1330
1331 // Included modules
1332 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1333 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1334 // Check that snapshot captures "prefer: true" prebuilt
1335 checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
1336 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
1337
1338 // Excluded modules
1339 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1340 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
1341 }
1342
1343 // Verify that each json file for an included module has a rule.
1344 for _, jsonFile := range includeJsonFiles {
1345 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1346 t.Errorf("include json file %q not found", jsonFile)
1347 }
1348 }
1349
1350 // Verify that each json file for an excluded module has no rule.
1351 for _, jsonFile := range excludeJsonFiles {
1352 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1353 t.Errorf("exclude json file %q found", jsonFile)
1354 }
1355 }
1356}
1357
Inseob Kim5f58ff72020-09-07 19:53:31 +09001358func TestVendorSnapshotUse(t *testing.T) {
1359 frameworkBp := `
1360 cc_library {
1361 name: "libvndk",
1362 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001363 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001364 vndk: {
1365 enabled: true,
1366 },
1367 nocrt: true,
1368 compile_multilib: "64",
1369 }
1370
1371 cc_library {
1372 name: "libvendor",
1373 vendor: true,
1374 nocrt: true,
1375 no_libcrt: true,
1376 stl: "none",
1377 system_shared_libs: [],
1378 compile_multilib: "64",
1379 }
1380
1381 cc_binary {
1382 name: "bin",
1383 vendor: true,
1384 nocrt: true,
1385 no_libcrt: true,
1386 stl: "none",
1387 system_shared_libs: [],
1388 compile_multilib: "64",
1389 }
1390`
1391
1392 vndkBp := `
1393 vndk_prebuilt_shared {
1394 name: "libvndk",
1395 version: "BOARD",
1396 target_arch: "arm64",
1397 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001398 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001399 vndk: {
1400 enabled: true,
1401 },
1402 arch: {
1403 arm64: {
1404 srcs: ["libvndk.so"],
Inseob Kim67be7322020-10-19 10:15:28 +09001405 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001406 },
1407 },
1408 }
1409`
1410
1411 vendorProprietaryBp := `
1412 cc_library {
1413 name: "libvendor_without_snapshot",
1414 vendor: true,
1415 nocrt: true,
1416 no_libcrt: true,
1417 stl: "none",
1418 system_shared_libs: [],
1419 compile_multilib: "64",
1420 }
1421
1422 cc_library_shared {
1423 name: "libclient",
1424 vendor: true,
1425 nocrt: true,
1426 no_libcrt: true,
1427 stl: "none",
1428 system_shared_libs: [],
1429 shared_libs: ["libvndk"],
1430 static_libs: ["libvendor", "libvendor_without_snapshot"],
1431 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001432 srcs: ["client.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001433 }
1434
1435 cc_binary {
1436 name: "bin_without_snapshot",
1437 vendor: true,
1438 nocrt: true,
1439 no_libcrt: true,
1440 stl: "none",
1441 system_shared_libs: [],
1442 static_libs: ["libvndk"],
1443 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001444 srcs: ["bin.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001445 }
1446
1447 vendor_snapshot_static {
1448 name: "libvndk",
1449 version: "BOARD",
1450 target_arch: "arm64",
1451 vendor: true,
1452 arch: {
1453 arm64: {
1454 src: "libvndk.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001455 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001456 },
1457 },
1458 }
1459
1460 vendor_snapshot_shared {
1461 name: "libvendor",
1462 version: "BOARD",
1463 target_arch: "arm64",
1464 vendor: true,
1465 arch: {
1466 arm64: {
1467 src: "libvendor.so",
Inseob Kim67be7322020-10-19 10:15:28 +09001468 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001469 },
1470 },
1471 }
1472
1473 vendor_snapshot_static {
1474 name: "libvendor",
1475 version: "BOARD",
1476 target_arch: "arm64",
1477 vendor: true,
1478 arch: {
1479 arm64: {
1480 src: "libvendor.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001481 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001482 },
1483 },
1484 }
1485
1486 vendor_snapshot_binary {
1487 name: "bin",
1488 version: "BOARD",
1489 target_arch: "arm64",
1490 vendor: true,
1491 arch: {
1492 arm64: {
1493 src: "bin",
1494 },
1495 },
1496 }
1497`
1498 depsBp := GatherRequiredDepsForTest(android.Android)
1499
1500 mockFS := map[string][]byte{
Inseob Kim67be7322020-10-19 10:15:28 +09001501 "deps/Android.bp": []byte(depsBp),
1502 "framework/Android.bp": []byte(frameworkBp),
1503 "vendor/Android.bp": []byte(vendorProprietaryBp),
1504 "vendor/bin": nil,
1505 "vendor/bin.cpp": nil,
1506 "vendor/client.cpp": nil,
1507 "vendor/include/libvndk/a.h": nil,
1508 "vendor/include/libvendor/b.h": nil,
1509 "vendor/libvndk.a": nil,
1510 "vendor/libvendor.a": nil,
1511 "vendor/libvendor.so": nil,
1512 "vndk/Android.bp": []byte(vndkBp),
1513 "vndk/include/libvndk/a.h": nil,
1514 "vndk/libvndk.so": nil,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001515 }
1516
1517 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1518 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1519 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001520 ctx := CreateTestContext(config)
1521 ctx.Register()
Inseob Kim5f58ff72020-09-07 19:53:31 +09001522
1523 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
1524 android.FailIfErrored(t, errs)
1525 _, errs = ctx.PrepareBuildActions(config)
1526 android.FailIfErrored(t, errs)
1527
1528 sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared"
1529 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1530 binaryVariant := "android_vendor.BOARD_arm64_armv8-a"
1531
1532 // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot
Inseob Kim67be7322020-10-19 10:15:28 +09001533 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
1534 for _, includeFlags := range []string{
1535 "-Ivndk/include/libvndk", // libvndk
1536 "-Ivendor/include/libvendor", // libvendor
1537 } {
1538 if !strings.Contains(libclientCcFlags, includeFlags) {
1539 t.Errorf("flags for libclient must contain %#v, but was %#v.",
1540 includeFlags, libclientCcFlags)
1541 }
1542 }
Inseob Kim5f58ff72020-09-07 19:53:31 +09001543
Inseob Kim67be7322020-10-19 10:15:28 +09001544 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001545 for _, input := range [][]string{
1546 []string{sharedVariant, "libvndk.vndk.BOARD.arm64"},
1547 []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"},
1548 []string{staticVariant, "libvendor_without_snapshot"},
1549 } {
1550 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Inseob Kim67be7322020-10-19 10:15:28 +09001551 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
1552 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001553 }
1554 }
1555
1556 // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64
Inseob Kim67be7322020-10-19 10:15:28 +09001557 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
1558 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
1559 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
1560 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
1561 }
1562
1563 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001564 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"})
Inseob Kim67be7322020-10-19 10:15:28 +09001565 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
Inseob Kim5f58ff72020-09-07 19:53:31 +09001566 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
Inseob Kim67be7322020-10-19 10:15:28 +09001567 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001568 }
1569
1570 // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64
1571 ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so")
1572
1573 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
1574 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
1575
1576 // bin is installed by bin.vendor_binary.BOARD.arm64
1577 ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin")
1578
1579 // bin_without_snapshot is installed by bin_without_snapshot
1580 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1581
1582 // libvendor and bin don't have vendor.BOARD variant
1583 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1584 if inList(sharedVariant, libvendorVariants) {
1585 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1586 }
1587
1588 binVariants := ctx.ModuleVariantsForTests("bin")
1589 if inList(binaryVariant, binVariants) {
1590 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1591 }
1592}
1593
Inseob Kimc42f2f22020-07-29 20:32:10 +09001594func TestVendorSnapshotSanitizer(t *testing.T) {
1595 bp := `
1596 vendor_snapshot_static {
1597 name: "libsnapshot",
1598 vendor: true,
1599 target_arch: "arm64",
1600 version: "BOARD",
1601 arch: {
1602 arm64: {
1603 src: "libsnapshot.a",
1604 cfi: {
1605 src: "libsnapshot.cfi.a",
1606 }
1607 },
1608 },
1609 }
1610`
1611 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1612 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1613 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1614 ctx := testCcWithConfig(t, config)
1615
1616 // Check non-cfi and cfi variant.
1617 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1618 staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi"
1619
1620 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module)
1621 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1622
1623 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module)
1624 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1625}
1626
Justin Yune09ac172021-01-20 19:49:01 +09001627func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
Bill Peckham945441c2020-08-31 16:07:58 -07001628 t.Helper()
Justin Yune09ac172021-01-20 19:49:01 +09001629 m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
1630 if m.ExcludeFromVendorSnapshot() != expected {
1631 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
Bill Peckham945441c2020-08-31 16:07:58 -07001632 }
1633}
1634
Justin Yune09ac172021-01-20 19:49:01 +09001635func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
Jose Galmes6f843bc2020-12-11 13:36:29 -08001636 t.Helper()
Justin Yune09ac172021-01-20 19:49:01 +09001637 m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
1638 if m.ExcludeFromRecoverySnapshot() != expected {
1639 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001640 }
1641}
1642
Bill Peckham945441c2020-08-31 16:07:58 -07001643func TestVendorSnapshotExclude(t *testing.T) {
1644
1645 // This test verifies that the exclude_from_vendor_snapshot property
1646 // makes its way from the Android.bp source file into the module data
1647 // structure. It also verifies that modules are correctly included or
1648 // excluded in the vendor snapshot based on their path (framework or
1649 // vendor) and the exclude_from_vendor_snapshot property.
1650
1651 frameworkBp := `
1652 cc_library_shared {
1653 name: "libinclude",
1654 srcs: ["src/include.cpp"],
1655 vendor_available: true,
1656 }
1657 cc_library_shared {
1658 name: "libexclude",
1659 srcs: ["src/exclude.cpp"],
1660 vendor: true,
1661 exclude_from_vendor_snapshot: true,
1662 }
Justin Yune09ac172021-01-20 19:49:01 +09001663 cc_library_shared {
1664 name: "libavailable_exclude",
1665 srcs: ["src/exclude.cpp"],
1666 vendor_available: true,
1667 exclude_from_vendor_snapshot: true,
1668 }
Bill Peckham945441c2020-08-31 16:07:58 -07001669 `
1670
1671 vendorProprietaryBp := `
1672 cc_library_shared {
1673 name: "libvendor",
1674 srcs: ["vendor.cpp"],
1675 vendor: true,
1676 }
1677 `
1678
1679 depsBp := GatherRequiredDepsForTest(android.Android)
1680
1681 mockFS := map[string][]byte{
1682 "deps/Android.bp": []byte(depsBp),
1683 "framework/Android.bp": []byte(frameworkBp),
1684 "framework/include.cpp": nil,
1685 "framework/exclude.cpp": nil,
1686 "device/Android.bp": []byte(vendorProprietaryBp),
1687 "device/vendor.cpp": nil,
1688 }
1689
1690 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1691 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1692 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001693 ctx := CreateTestContext(config)
1694 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001695
1696 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1697 android.FailIfErrored(t, errs)
1698 _, errs = ctx.PrepareBuildActions(config)
1699 android.FailIfErrored(t, errs)
1700
1701 // Test an include and exclude framework module.
Justin Yune09ac172021-01-20 19:49:01 +09001702 assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false)
1703 assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true)
1704 assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true)
Bill Peckham945441c2020-08-31 16:07:58 -07001705
1706 // A vendor module is excluded, but by its path, not the
1707 // exclude_from_vendor_snapshot property.
Justin Yune09ac172021-01-20 19:49:01 +09001708 assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false)
Bill Peckham945441c2020-08-31 16:07:58 -07001709
1710 // Verify the content of the vendor snapshot.
1711
1712 snapshotDir := "vendor-snapshot"
1713 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1714 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1715
1716 var includeJsonFiles []string
1717 var excludeJsonFiles []string
1718
1719 for _, arch := range [][]string{
1720 []string{"arm64", "armv8-a"},
1721 []string{"arm", "armv7-a-neon"},
1722 } {
1723 archType := arch[0]
1724 archVariant := arch[1]
1725 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1726
1727 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1728 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1729
1730 // Included modules
1731 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1732 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1733
1734 // Excluded modules
1735 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1736 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1737 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1738 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
Justin Yune09ac172021-01-20 19:49:01 +09001739 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
1740 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
Bill Peckham945441c2020-08-31 16:07:58 -07001741 }
1742
1743 // Verify that each json file for an included module has a rule.
1744 for _, jsonFile := range includeJsonFiles {
1745 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1746 t.Errorf("include json file %q not found", jsonFile)
1747 }
1748 }
1749
1750 // Verify that each json file for an excluded module has no rule.
1751 for _, jsonFile := range excludeJsonFiles {
1752 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1753 t.Errorf("exclude json file %q found", jsonFile)
1754 }
1755 }
1756}
1757
1758func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1759
1760 // This test verifies that using the exclude_from_vendor_snapshot
1761 // property on a module in a vendor proprietary path generates an
1762 // error. These modules are already excluded, so we prohibit using the
1763 // property in this way, which could add to confusion.
1764
1765 vendorProprietaryBp := `
1766 cc_library_shared {
1767 name: "libvendor",
1768 srcs: ["vendor.cpp"],
1769 vendor: true,
1770 exclude_from_vendor_snapshot: true,
1771 }
1772 `
1773
1774 depsBp := GatherRequiredDepsForTest(android.Android)
1775
1776 mockFS := map[string][]byte{
1777 "deps/Android.bp": []byte(depsBp),
1778 "device/Android.bp": []byte(vendorProprietaryBp),
1779 "device/vendor.cpp": nil,
1780 }
1781
1782 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1783 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1784 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001785 ctx := CreateTestContext(config)
1786 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001787
1788 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1789 android.FailIfErrored(t, errs)
1790
1791 _, errs = ctx.PrepareBuildActions(config)
1792 android.CheckErrorsAgainstExpectations(t, errs, []string{
1793 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1794 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
Jose Galmesf7294582020-11-13 12:07:36 -08001795 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1796 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
Inseob Kime9aec6a2021-01-05 20:03:22 +09001797 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1798 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
Bill Peckham945441c2020-08-31 16:07:58 -07001799 })
1800}
1801
Jose Galmesf7294582020-11-13 12:07:36 -08001802func TestRecoverySnapshotCapture(t *testing.T) {
1803 bp := `
1804 cc_library {
1805 name: "libvndk",
1806 vendor_available: true,
1807 recovery_available: true,
1808 product_available: true,
1809 vndk: {
1810 enabled: true,
1811 },
1812 nocrt: true,
1813 }
1814
1815 cc_library {
1816 name: "librecovery",
1817 recovery: true,
1818 nocrt: true,
1819 }
1820
1821 cc_library {
1822 name: "librecovery_available",
1823 recovery_available: true,
1824 nocrt: true,
1825 }
1826
1827 cc_library_headers {
1828 name: "librecovery_headers",
1829 recovery_available: true,
1830 nocrt: true,
1831 }
1832
1833 cc_binary {
1834 name: "recovery_bin",
1835 recovery: true,
1836 nocrt: true,
1837 }
1838
1839 cc_binary {
1840 name: "recovery_available_bin",
1841 recovery_available: true,
1842 nocrt: true,
1843 }
1844
1845 toolchain_library {
1846 name: "libb",
1847 recovery_available: true,
1848 src: "libb.a",
1849 }
1850
1851 cc_object {
1852 name: "obj",
1853 recovery_available: true,
1854 }
1855`
1856 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001857 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jose Galmesf7294582020-11-13 12:07:36 -08001858 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1859 ctx := testCcWithConfig(t, config)
1860
1861 // Check Recovery snapshot output.
1862
1863 snapshotDir := "recovery-snapshot"
1864 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1865 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1866
1867 var jsonFiles []string
1868
1869 for _, arch := range [][]string{
1870 []string{"arm64", "armv8-a"},
1871 } {
1872 archType := arch[0]
1873 archVariant := arch[1]
1874 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1875
1876 // For shared libraries, only recovery_available modules are captured.
1877 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1878 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1879 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1880 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1881 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1882 jsonFiles = append(jsonFiles,
1883 filepath.Join(sharedDir, "libvndk.so.json"),
1884 filepath.Join(sharedDir, "librecovery.so.json"),
1885 filepath.Join(sharedDir, "librecovery_available.so.json"))
1886
1887 // For static libraries, all recovery:true and recovery_available modules are captured.
1888 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1889 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1890 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1891 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1892 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1893 jsonFiles = append(jsonFiles,
1894 filepath.Join(staticDir, "libb.a.json"),
1895 filepath.Join(staticDir, "librecovery.a.json"),
1896 filepath.Join(staticDir, "librecovery_available.a.json"))
1897
1898 // For binary executables, all recovery:true and recovery_available modules are captured.
1899 if archType == "arm64" {
1900 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1901 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1902 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1903 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1904 jsonFiles = append(jsonFiles,
1905 filepath.Join(binaryDir, "recovery_bin.json"),
1906 filepath.Join(binaryDir, "recovery_available_bin.json"))
1907 }
1908
1909 // For header libraries, all vendor:true and vendor_available modules are captured.
1910 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1911 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1912
1913 // For object modules, all vendor:true and vendor_available modules are captured.
1914 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1915 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1916 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1917 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1918 }
1919
1920 for _, jsonFile := range jsonFiles {
1921 // verify all json files exist
1922 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1923 t.Errorf("%q expected but not found", jsonFile)
1924 }
1925 }
1926}
1927
Jose Galmes6f843bc2020-12-11 13:36:29 -08001928func TestRecoverySnapshotExclude(t *testing.T) {
1929 // This test verifies that the exclude_from_recovery_snapshot property
1930 // makes its way from the Android.bp source file into the module data
1931 // structure. It also verifies that modules are correctly included or
1932 // excluded in the recovery snapshot based on their path (framework or
1933 // vendor) and the exclude_from_recovery_snapshot property.
1934
1935 frameworkBp := `
1936 cc_library_shared {
1937 name: "libinclude",
1938 srcs: ["src/include.cpp"],
Justin Yune09ac172021-01-20 19:49:01 +09001939 recovery_available: true,
Jose Galmes6f843bc2020-12-11 13:36:29 -08001940 }
1941 cc_library_shared {
1942 name: "libexclude",
1943 srcs: ["src/exclude.cpp"],
1944 recovery: true,
1945 exclude_from_recovery_snapshot: true,
1946 }
Justin Yune09ac172021-01-20 19:49:01 +09001947 cc_library_shared {
1948 name: "libavailable_exclude",
1949 srcs: ["src/exclude.cpp"],
1950 recovery_available: true,
1951 exclude_from_recovery_snapshot: true,
1952 }
Jose Galmes6f843bc2020-12-11 13:36:29 -08001953 `
1954
1955 vendorProprietaryBp := `
1956 cc_library_shared {
Justin Yune09ac172021-01-20 19:49:01 +09001957 name: "librecovery",
1958 srcs: ["recovery.cpp"],
Jose Galmes6f843bc2020-12-11 13:36:29 -08001959 recovery: true,
1960 }
1961 `
1962
1963 depsBp := GatherRequiredDepsForTest(android.Android)
1964
1965 mockFS := map[string][]byte{
1966 "deps/Android.bp": []byte(depsBp),
1967 "framework/Android.bp": []byte(frameworkBp),
1968 "framework/include.cpp": nil,
1969 "framework/exclude.cpp": nil,
1970 "device/Android.bp": []byte(vendorProprietaryBp),
Justin Yune09ac172021-01-20 19:49:01 +09001971 "device/recovery.cpp": nil,
Jose Galmes6f843bc2020-12-11 13:36:29 -08001972 }
1973
1974 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1975 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
1976 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1977 ctx := CreateTestContext(config)
1978 ctx.Register()
1979
1980 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1981 android.FailIfErrored(t, errs)
1982 _, errs = ctx.PrepareBuildActions(config)
1983 android.FailIfErrored(t, errs)
1984
1985 // Test an include and exclude framework module.
Justin Yune09ac172021-01-20 19:49:01 +09001986 assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
1987 assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
1988 assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001989
Justin Yune09ac172021-01-20 19:49:01 +09001990 // A recovery module is excluded, but by its path, not the
Jose Galmes6f843bc2020-12-11 13:36:29 -08001991 // exclude_from_recovery_snapshot property.
Justin Yune09ac172021-01-20 19:49:01 +09001992 assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001993
1994 // Verify the content of the recovery snapshot.
1995
1996 snapshotDir := "recovery-snapshot"
1997 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1998 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1999
2000 var includeJsonFiles []string
2001 var excludeJsonFiles []string
2002
2003 for _, arch := range [][]string{
2004 []string{"arm64", "armv8-a"},
2005 } {
2006 archType := arch[0]
2007 archVariant := arch[1]
2008 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
2009
2010 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
2011 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
2012
2013 // Included modules
2014 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
2015 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
2016
2017 // Excluded modules
2018 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
2019 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
Justin Yune09ac172021-01-20 19:49:01 +09002020 checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
2021 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
2022 checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
2023 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
Jose Galmes6f843bc2020-12-11 13:36:29 -08002024 }
2025
2026 // Verify that each json file for an included module has a rule.
2027 for _, jsonFile := range includeJsonFiles {
2028 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
2029 t.Errorf("include json file %q not found", jsonFile)
2030 }
2031 }
2032
2033 // Verify that each json file for an excluded module has no rule.
2034 for _, jsonFile := range excludeJsonFiles {
2035 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
2036 t.Errorf("exclude json file %q found", jsonFile)
2037 }
2038 }
2039}
2040
Jooyung Hana70f0672019-01-18 15:20:43 +09002041func TestDoubleLoadableDepError(t *testing.T) {
2042 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
2043 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2044 cc_library {
2045 name: "libllndk",
2046 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07002047 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002048 }
2049
2050 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002051 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002052 symbol_file: "",
2053 }
2054
2055 cc_library {
2056 name: "libnondoubleloadable",
2057 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002058 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002059 vndk: {
2060 enabled: true,
2061 },
2062 }
2063 `)
2064
2065 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
2066 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2067 cc_library {
2068 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07002069 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002070 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07002071 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002072 }
2073
2074 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002075 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002076 symbol_file: "",
2077 }
2078
2079 cc_library {
2080 name: "libnondoubleloadable",
2081 vendor_available: true,
2082 }
2083 `)
2084
Jooyung Hana70f0672019-01-18 15:20:43 +09002085 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
2086 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2087 cc_library {
2088 name: "libllndk",
2089 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07002090 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002091 }
2092
2093 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002094 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002095 symbol_file: "",
2096 }
2097
2098 cc_library {
2099 name: "libcoreonly",
2100 shared_libs: ["libvendoravailable"],
2101 }
2102
2103 // indirect dependency of LLNDK
2104 cc_library {
2105 name: "libvendoravailable",
2106 vendor_available: true,
2107 }
2108 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09002109
2110 // The error is not from 'client' but from 'libllndk'
2111 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
2112 cc_library {
2113 name: "client",
2114 vendor_available: true,
2115 double_loadable: true,
2116 shared_libs: ["libllndk"],
2117 }
2118 cc_library {
2119 name: "libllndk",
2120 shared_libs: ["libnondoubleloadable"],
2121 llndk_stubs: "libllndk.llndk",
2122 }
2123 llndk_library {
2124 name: "libllndk.llndk",
2125 symbol_file: "",
2126 }
2127 cc_library {
2128 name: "libnondoubleloadable",
2129 vendor_available: true,
2130 }
2131 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08002132}
2133
Jooyung Han479ca172020-10-19 18:51:07 +09002134func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
2135 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
2136 cc_library {
2137 name: "libvndksp",
2138 shared_libs: ["libanothervndksp"],
2139 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002140 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09002141 vndk: {
2142 enabled: true,
2143 support_system_process: true,
2144 }
2145 }
2146
2147 cc_library {
2148 name: "libllndk",
2149 shared_libs: ["libanothervndksp"],
2150 }
2151
2152 llndk_library {
2153 name: "libllndk",
2154 symbol_file: "",
2155 }
2156
2157 cc_library {
2158 name: "libanothervndksp",
2159 vendor_available: true,
2160 }
2161 `)
2162}
2163
Logan Chienf3511742017-10-31 18:04:35 +08002164func TestVndkExt(t *testing.T) {
2165 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002166 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08002167 cc_library {
2168 name: "libvndk",
2169 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002170 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002171 vndk: {
2172 enabled: true,
2173 },
2174 nocrt: true,
2175 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002176 cc_library {
2177 name: "libvndk2",
2178 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002179 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09002180 vndk: {
2181 enabled: true,
2182 },
2183 target: {
2184 vendor: {
2185 suffix: "-suffix",
2186 },
Justin Yun63e9ec72020-10-29 16:49:43 +09002187 product: {
2188 suffix: "-suffix",
2189 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09002190 },
2191 nocrt: true,
2192 }
Logan Chienf3511742017-10-31 18:04:35 +08002193
2194 cc_library {
2195 name: "libvndk_ext",
2196 vendor: true,
2197 vndk: {
2198 enabled: true,
2199 extends: "libvndk",
2200 },
2201 nocrt: true,
2202 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002203
2204 cc_library {
2205 name: "libvndk2_ext",
2206 vendor: true,
2207 vndk: {
2208 enabled: true,
2209 extends: "libvndk2",
2210 },
2211 nocrt: true,
2212 }
Logan Chienf3511742017-10-31 18:04:35 +08002213
Justin Yun0ecf0b22020-02-28 15:07:59 +09002214 cc_library {
2215 name: "libvndk_ext_product",
2216 product_specific: true,
2217 vndk: {
2218 enabled: true,
2219 extends: "libvndk",
2220 },
2221 nocrt: true,
2222 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002223
Justin Yun0ecf0b22020-02-28 15:07:59 +09002224 cc_library {
2225 name: "libvndk2_ext_product",
2226 product_specific: true,
2227 vndk: {
2228 enabled: true,
2229 extends: "libvndk2",
2230 },
2231 nocrt: true,
2232 }
2233 `
2234 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2235 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2236 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2237 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2238
2239 ctx := testCcWithConfig(t, config)
2240
2241 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
2242 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
2243
2244 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
2245 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
2246
2247 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
2248 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08002249}
2250
Logan Chiend3c59a22018-03-29 14:08:15 +08002251func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08002252 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
2253 ctx := testCcNoVndk(t, `
2254 cc_library {
2255 name: "libvndk",
2256 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002257 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002258 vndk: {
2259 enabled: true,
2260 },
2261 nocrt: true,
2262 }
2263
2264 cc_library {
2265 name: "libvndk_ext",
2266 vendor: true,
2267 vndk: {
2268 enabled: true,
2269 extends: "libvndk",
2270 },
2271 nocrt: true,
2272 }
2273 `)
2274
2275 // Ensures that the core variant of "libvndk_ext" can be found.
2276 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
2277 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2278 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
2279 }
2280}
2281
Justin Yun0ecf0b22020-02-28 15:07:59 +09002282func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
2283 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09002284 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002285 cc_library {
2286 name: "libvndk",
2287 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002288 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002289 vndk: {
2290 enabled: true,
2291 },
2292 nocrt: true,
2293 }
2294
2295 cc_library {
2296 name: "libvndk_ext_product",
2297 product_specific: true,
2298 vndk: {
2299 enabled: true,
2300 extends: "libvndk",
2301 },
2302 nocrt: true,
2303 }
2304 `)
2305
2306 // Ensures that the core variant of "libvndk_ext_product" can be found.
2307 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
2308 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2309 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
2310 }
2311}
2312
Logan Chienf3511742017-10-31 18:04:35 +08002313func TestVndkExtError(t *testing.T) {
2314 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002315 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08002316 cc_library {
2317 name: "libvndk",
2318 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002319 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002320 vndk: {
2321 enabled: true,
2322 },
2323 nocrt: true,
2324 }
2325
2326 cc_library {
2327 name: "libvndk_ext",
2328 vndk: {
2329 enabled: true,
2330 extends: "libvndk",
2331 },
2332 nocrt: true,
2333 }
2334 `)
2335
2336 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2337 cc_library {
2338 name: "libvndk",
2339 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002340 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002341 vndk: {
2342 enabled: true,
2343 },
2344 nocrt: true,
2345 }
2346
2347 cc_library {
2348 name: "libvndk_ext",
2349 vendor: true,
2350 vndk: {
2351 enabled: true,
2352 },
2353 nocrt: true,
2354 }
2355 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002356
2357 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2358 cc_library {
2359 name: "libvndk",
2360 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002361 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002362 vndk: {
2363 enabled: true,
2364 },
2365 nocrt: true,
2366 }
2367
2368 cc_library {
2369 name: "libvndk_ext_product",
2370 product_specific: true,
2371 vndk: {
2372 enabled: true,
2373 },
2374 nocrt: true,
2375 }
2376 `)
2377
2378 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
2379 cc_library {
2380 name: "libvndk",
2381 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002382 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002383 vndk: {
2384 enabled: true,
2385 },
2386 nocrt: true,
2387 }
2388
2389 cc_library {
2390 name: "libvndk_ext_product",
2391 product_specific: true,
2392 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002393 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002394 vndk: {
2395 enabled: true,
2396 extends: "libvndk",
2397 },
2398 nocrt: true,
2399 }
2400 `)
Logan Chienf3511742017-10-31 18:04:35 +08002401}
2402
2403func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
2404 // This test ensures an error is emitted for inconsistent support_system_process.
2405 testCcError(t, "module \".*\" with mismatched support_system_process", `
2406 cc_library {
2407 name: "libvndk",
2408 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002409 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002410 vndk: {
2411 enabled: true,
2412 },
2413 nocrt: true,
2414 }
2415
2416 cc_library {
2417 name: "libvndk_sp_ext",
2418 vendor: true,
2419 vndk: {
2420 enabled: true,
2421 extends: "libvndk",
2422 support_system_process: true,
2423 },
2424 nocrt: true,
2425 }
2426 `)
2427
2428 testCcError(t, "module \".*\" with mismatched support_system_process", `
2429 cc_library {
2430 name: "libvndk_sp",
2431 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002432 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002433 vndk: {
2434 enabled: true,
2435 support_system_process: true,
2436 },
2437 nocrt: true,
2438 }
2439
2440 cc_library {
2441 name: "libvndk_ext",
2442 vendor: true,
2443 vndk: {
2444 enabled: true,
2445 extends: "libvndk_sp",
2446 },
2447 nocrt: true,
2448 }
2449 `)
2450}
2451
2452func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08002453 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09002454 // with `private: true`.
2455 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08002456 cc_library {
2457 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002458 vendor_available: true,
2459 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002460 vndk: {
2461 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002462 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08002463 },
2464 nocrt: true,
2465 }
2466
2467 cc_library {
2468 name: "libvndk_ext",
2469 vendor: true,
2470 vndk: {
2471 enabled: true,
2472 extends: "libvndk",
2473 },
2474 nocrt: true,
2475 }
2476 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002477
Justin Yunfd9e8042020-12-23 18:23:14 +09002478 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002479 cc_library {
2480 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002481 vendor_available: true,
2482 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002483 vndk: {
2484 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002485 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002486 },
2487 nocrt: true,
2488 }
2489
2490 cc_library {
2491 name: "libvndk_ext_product",
2492 product_specific: true,
2493 vndk: {
2494 enabled: true,
2495 extends: "libvndk",
2496 },
2497 nocrt: true,
2498 }
2499 `)
Logan Chienf3511742017-10-31 18:04:35 +08002500}
2501
Logan Chiend3c59a22018-03-29 14:08:15 +08002502func TestVendorModuleUseVndkExt(t *testing.T) {
2503 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002504 testCc(t, `
2505 cc_library {
2506 name: "libvndk",
2507 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002508 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002509 vndk: {
2510 enabled: true,
2511 },
2512 nocrt: true,
2513 }
2514
2515 cc_library {
2516 name: "libvndk_ext",
2517 vendor: true,
2518 vndk: {
2519 enabled: true,
2520 extends: "libvndk",
2521 },
2522 nocrt: true,
2523 }
2524
2525 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08002526 name: "libvndk_sp",
2527 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002528 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002529 vndk: {
2530 enabled: true,
2531 support_system_process: true,
2532 },
2533 nocrt: true,
2534 }
2535
2536 cc_library {
2537 name: "libvndk_sp_ext",
2538 vendor: true,
2539 vndk: {
2540 enabled: true,
2541 extends: "libvndk_sp",
2542 support_system_process: true,
2543 },
2544 nocrt: true,
2545 }
2546
2547 cc_library {
2548 name: "libvendor",
2549 vendor: true,
2550 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
2551 nocrt: true,
2552 }
2553 `)
2554}
2555
Logan Chiend3c59a22018-03-29 14:08:15 +08002556func TestVndkExtUseVendorLib(t *testing.T) {
2557 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08002558 testCc(t, `
2559 cc_library {
2560 name: "libvndk",
2561 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002562 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002563 vndk: {
2564 enabled: true,
2565 },
2566 nocrt: true,
2567 }
2568
2569 cc_library {
2570 name: "libvndk_ext",
2571 vendor: true,
2572 vndk: {
2573 enabled: true,
2574 extends: "libvndk",
2575 },
2576 shared_libs: ["libvendor"],
2577 nocrt: true,
2578 }
2579
2580 cc_library {
2581 name: "libvendor",
2582 vendor: true,
2583 nocrt: true,
2584 }
2585 `)
Logan Chienf3511742017-10-31 18:04:35 +08002586
Logan Chiend3c59a22018-03-29 14:08:15 +08002587 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
2588 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08002589 cc_library {
2590 name: "libvndk_sp",
2591 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002592 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002593 vndk: {
2594 enabled: true,
2595 support_system_process: true,
2596 },
2597 nocrt: true,
2598 }
2599
2600 cc_library {
2601 name: "libvndk_sp_ext",
2602 vendor: true,
2603 vndk: {
2604 enabled: true,
2605 extends: "libvndk_sp",
2606 support_system_process: true,
2607 },
2608 shared_libs: ["libvendor"], // Cause an error
2609 nocrt: true,
2610 }
2611
2612 cc_library {
2613 name: "libvendor",
2614 vendor: true,
2615 nocrt: true,
2616 }
2617 `)
2618}
2619
Justin Yun0ecf0b22020-02-28 15:07:59 +09002620func TestProductVndkExtDependency(t *testing.T) {
2621 bp := `
2622 cc_library {
2623 name: "libvndk",
2624 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002625 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002626 vndk: {
2627 enabled: true,
2628 },
2629 nocrt: true,
2630 }
2631
2632 cc_library {
2633 name: "libvndk_ext_product",
2634 product_specific: true,
2635 vndk: {
2636 enabled: true,
2637 extends: "libvndk",
2638 },
2639 shared_libs: ["libproduct_for_vndklibs"],
2640 nocrt: true,
2641 }
2642
2643 cc_library {
2644 name: "libvndk_sp",
2645 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002646 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002647 vndk: {
2648 enabled: true,
2649 support_system_process: true,
2650 },
2651 nocrt: true,
2652 }
2653
2654 cc_library {
2655 name: "libvndk_sp_ext_product",
2656 product_specific: true,
2657 vndk: {
2658 enabled: true,
2659 extends: "libvndk_sp",
2660 support_system_process: true,
2661 },
2662 shared_libs: ["libproduct_for_vndklibs"],
2663 nocrt: true,
2664 }
2665
2666 cc_library {
2667 name: "libproduct",
2668 product_specific: true,
2669 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
2670 nocrt: true,
2671 }
2672
2673 cc_library {
2674 name: "libproduct_for_vndklibs",
2675 product_specific: true,
2676 nocrt: true,
2677 }
2678 `
2679 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2680 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2681 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2682 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2683
2684 testCcWithConfig(t, config)
2685}
2686
Logan Chiend3c59a22018-03-29 14:08:15 +08002687func TestVndkSpExtUseVndkError(t *testing.T) {
2688 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
2689 // library.
2690 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2691 cc_library {
2692 name: "libvndk",
2693 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002694 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002695 vndk: {
2696 enabled: true,
2697 },
2698 nocrt: true,
2699 }
2700
2701 cc_library {
2702 name: "libvndk_sp",
2703 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002704 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002705 vndk: {
2706 enabled: true,
2707 support_system_process: true,
2708 },
2709 nocrt: true,
2710 }
2711
2712 cc_library {
2713 name: "libvndk_sp_ext",
2714 vendor: true,
2715 vndk: {
2716 enabled: true,
2717 extends: "libvndk_sp",
2718 support_system_process: true,
2719 },
2720 shared_libs: ["libvndk"], // Cause an error
2721 nocrt: true,
2722 }
2723 `)
2724
2725 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
2726 // library.
2727 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2728 cc_library {
2729 name: "libvndk",
2730 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002731 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002732 vndk: {
2733 enabled: true,
2734 },
2735 nocrt: true,
2736 }
2737
2738 cc_library {
2739 name: "libvndk_ext",
2740 vendor: true,
2741 vndk: {
2742 enabled: true,
2743 extends: "libvndk",
2744 },
2745 nocrt: true,
2746 }
2747
2748 cc_library {
2749 name: "libvndk_sp",
2750 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002751 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002752 vndk: {
2753 enabled: true,
2754 support_system_process: true,
2755 },
2756 nocrt: true,
2757 }
2758
2759 cc_library {
2760 name: "libvndk_sp_ext",
2761 vendor: true,
2762 vndk: {
2763 enabled: true,
2764 extends: "libvndk_sp",
2765 support_system_process: true,
2766 },
2767 shared_libs: ["libvndk_ext"], // Cause an error
2768 nocrt: true,
2769 }
2770 `)
2771}
2772
2773func TestVndkUseVndkExtError(t *testing.T) {
2774 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
2775 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002776 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2777 cc_library {
2778 name: "libvndk",
2779 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002780 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002781 vndk: {
2782 enabled: true,
2783 },
2784 nocrt: true,
2785 }
2786
2787 cc_library {
2788 name: "libvndk_ext",
2789 vendor: true,
2790 vndk: {
2791 enabled: true,
2792 extends: "libvndk",
2793 },
2794 nocrt: true,
2795 }
2796
2797 cc_library {
2798 name: "libvndk2",
2799 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002800 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002801 vndk: {
2802 enabled: true,
2803 },
2804 shared_libs: ["libvndk_ext"],
2805 nocrt: true,
2806 }
2807 `)
2808
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002809 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002810 cc_library {
2811 name: "libvndk",
2812 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002813 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002814 vndk: {
2815 enabled: true,
2816 },
2817 nocrt: true,
2818 }
2819
2820 cc_library {
2821 name: "libvndk_ext",
2822 vendor: true,
2823 vndk: {
2824 enabled: true,
2825 extends: "libvndk",
2826 },
2827 nocrt: true,
2828 }
2829
2830 cc_library {
2831 name: "libvndk2",
2832 vendor_available: true,
2833 vndk: {
2834 enabled: true,
2835 },
2836 target: {
2837 vendor: {
2838 shared_libs: ["libvndk_ext"],
2839 },
2840 },
2841 nocrt: true,
2842 }
2843 `)
2844
2845 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2846 cc_library {
2847 name: "libvndk_sp",
2848 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002849 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002850 vndk: {
2851 enabled: true,
2852 support_system_process: true,
2853 },
2854 nocrt: true,
2855 }
2856
2857 cc_library {
2858 name: "libvndk_sp_ext",
2859 vendor: true,
2860 vndk: {
2861 enabled: true,
2862 extends: "libvndk_sp",
2863 support_system_process: true,
2864 },
2865 nocrt: true,
2866 }
2867
2868 cc_library {
2869 name: "libvndk_sp_2",
2870 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002871 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002872 vndk: {
2873 enabled: true,
2874 support_system_process: true,
2875 },
2876 shared_libs: ["libvndk_sp_ext"],
2877 nocrt: true,
2878 }
2879 `)
2880
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002881 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002882 cc_library {
2883 name: "libvndk_sp",
2884 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002885 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002886 vndk: {
2887 enabled: true,
2888 },
2889 nocrt: true,
2890 }
2891
2892 cc_library {
2893 name: "libvndk_sp_ext",
2894 vendor: true,
2895 vndk: {
2896 enabled: true,
2897 extends: "libvndk_sp",
2898 },
2899 nocrt: true,
2900 }
2901
2902 cc_library {
2903 name: "libvndk_sp2",
2904 vendor_available: true,
2905 vndk: {
2906 enabled: true,
2907 },
2908 target: {
2909 vendor: {
2910 shared_libs: ["libvndk_sp_ext"],
2911 },
2912 },
2913 nocrt: true,
2914 }
2915 `)
2916}
2917
Justin Yun5f7f7e82019-11-18 19:52:14 +09002918func TestEnforceProductVndkVersion(t *testing.T) {
2919 bp := `
2920 cc_library {
2921 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002922 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002923 }
2924 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002925 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002926 symbol_file: "",
2927 }
2928 cc_library {
2929 name: "libvndk",
2930 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002931 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002932 vndk: {
2933 enabled: true,
2934 },
2935 nocrt: true,
2936 }
2937 cc_library {
2938 name: "libvndk_sp",
2939 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002940 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002941 vndk: {
2942 enabled: true,
2943 support_system_process: true,
2944 },
2945 nocrt: true,
2946 }
2947 cc_library {
2948 name: "libva",
2949 vendor_available: true,
2950 nocrt: true,
2951 }
2952 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002953 name: "libpa",
2954 product_available: true,
2955 nocrt: true,
2956 }
2957 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002958 name: "libboth_available",
2959 vendor_available: true,
2960 product_available: true,
2961 nocrt: true,
2962 target: {
2963 vendor: {
2964 suffix: "-vendor",
2965 },
2966 product: {
2967 suffix: "-product",
2968 },
2969 }
2970 }
2971 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002972 name: "libproduct_va",
2973 product_specific: true,
2974 vendor_available: true,
2975 nocrt: true,
2976 }
2977 cc_library {
2978 name: "libprod",
2979 product_specific: true,
2980 shared_libs: [
2981 "libllndk",
2982 "libvndk",
2983 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002984 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002985 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002986 "libproduct_va",
2987 ],
2988 nocrt: true,
2989 }
2990 cc_library {
2991 name: "libvendor",
2992 vendor: true,
2993 shared_libs: [
2994 "libllndk",
2995 "libvndk",
2996 "libvndk_sp",
2997 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002998 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002999 "libproduct_va",
3000 ],
3001 nocrt: true,
3002 }
3003 `
3004
3005 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3006 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3007 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
3008 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3009
3010 ctx := testCcWithConfig(t, config)
3011
Jooyung Han261e1582020-10-20 18:54:21 +09003012 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
3013 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09003014
3015 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
3016 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
3017
3018 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
3019 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09003020}
3021
3022func TestEnforceProductVndkVersionErrors(t *testing.T) {
3023 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3024 cc_library {
3025 name: "libprod",
3026 product_specific: true,
3027 shared_libs: [
3028 "libvendor",
3029 ],
3030 nocrt: true,
3031 }
3032 cc_library {
3033 name: "libvendor",
3034 vendor: true,
3035 nocrt: true,
3036 }
3037 `)
3038 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3039 cc_library {
3040 name: "libprod",
3041 product_specific: true,
3042 shared_libs: [
3043 "libsystem",
3044 ],
3045 nocrt: true,
3046 }
3047 cc_library {
3048 name: "libsystem",
3049 nocrt: true,
3050 }
3051 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09003052 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3053 cc_library {
3054 name: "libprod",
3055 product_specific: true,
3056 shared_libs: [
3057 "libva",
3058 ],
3059 nocrt: true,
3060 }
3061 cc_library {
3062 name: "libva",
3063 vendor_available: true,
3064 nocrt: true,
3065 }
3066 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09003067 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09003068 cc_library {
3069 name: "libprod",
3070 product_specific: true,
3071 shared_libs: [
3072 "libvndk_private",
3073 ],
3074 nocrt: true,
3075 }
3076 cc_library {
3077 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09003078 vendor_available: true,
3079 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003080 vndk: {
3081 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09003082 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003083 },
3084 nocrt: true,
3085 }
3086 `)
3087 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3088 cc_library {
3089 name: "libprod",
3090 product_specific: true,
3091 shared_libs: [
3092 "libsystem_ext",
3093 ],
3094 nocrt: true,
3095 }
3096 cc_library {
3097 name: "libsystem_ext",
3098 system_ext_specific: true,
3099 nocrt: true,
3100 }
3101 `)
3102 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
3103 cc_library {
3104 name: "libsystem",
3105 shared_libs: [
3106 "libproduct_va",
3107 ],
3108 nocrt: true,
3109 }
3110 cc_library {
3111 name: "libproduct_va",
3112 product_specific: true,
3113 vendor_available: true,
3114 nocrt: true,
3115 }
3116 `)
3117}
3118
Jooyung Han38002912019-05-16 04:01:54 +09003119func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08003120 bp := `
3121 cc_library {
3122 name: "libvndk",
3123 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003124 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003125 vndk: {
3126 enabled: true,
3127 },
3128 }
3129 cc_library {
3130 name: "libvndksp",
3131 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003132 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003133 vndk: {
3134 enabled: true,
3135 support_system_process: true,
3136 },
3137 }
3138 cc_library {
3139 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09003140 vendor_available: true,
3141 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003142 vndk: {
3143 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09003144 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003145 },
3146 }
3147 cc_library {
3148 name: "libvendor",
3149 vendor: true,
3150 }
3151 cc_library {
3152 name: "libvndkext",
3153 vendor: true,
3154 vndk: {
3155 enabled: true,
3156 extends: "libvndk",
3157 },
3158 }
3159 vndk_prebuilt_shared {
3160 name: "prevndk",
3161 version: "27",
3162 target_arch: "arm",
3163 binder32bit: true,
3164 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003165 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003166 vndk: {
3167 enabled: true,
3168 },
3169 arch: {
3170 arm: {
3171 srcs: ["liba.so"],
3172 },
3173 },
3174 }
3175 cc_library {
3176 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07003177 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003178 }
3179 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003180 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003181 symbol_file: "",
3182 }
3183 cc_library {
3184 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07003185 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003186 }
3187 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003188 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09003189 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003190 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08003191 }
3192
3193 llndk_libraries_txt {
3194 name: "llndk.libraries.txt",
3195 }
3196 vndkcore_libraries_txt {
3197 name: "vndkcore.libraries.txt",
3198 }
3199 vndksp_libraries_txt {
3200 name: "vndksp.libraries.txt",
3201 }
3202 vndkprivate_libraries_txt {
3203 name: "vndkprivate.libraries.txt",
3204 }
3205 vndkcorevariant_libraries_txt {
3206 name: "vndkcorevariant.libraries.txt",
3207 insert_vndk_version: false,
3208 }
3209 `
Colin Cross98be1bb2019-12-13 20:41:13 -08003210
3211 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09003212 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3213 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3214 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08003215 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09003216
Colin Cross78212242021-01-06 14:51:30 -08003217 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
3218 []string{"libvndk.so", "libvndkprivate.so"})
3219 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
3220 []string{"libc++.so", "libvndksp.so"})
3221 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
3222 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
3223 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
3224 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09003225
Colin Crossfb0c16e2019-11-20 17:12:35 -08003226 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09003227
Jooyung Han38002912019-05-16 04:01:54 +09003228 tests := []struct {
3229 variant string
3230 name string
3231 expected string
3232 }{
3233 {vendorVariant, "libvndk", "native:vndk"},
3234 {vendorVariant, "libvndksp", "native:vndk"},
3235 {vendorVariant, "libvndkprivate", "native:vndk_private"},
3236 {vendorVariant, "libvendor", "native:vendor"},
3237 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08003238 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09003239 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09003240 {coreVariant, "libvndk", "native:platform"},
3241 {coreVariant, "libvndkprivate", "native:platform"},
3242 {coreVariant, "libllndk", "native:platform"},
3243 }
3244 for _, test := range tests {
3245 t.Run(test.name, func(t *testing.T) {
3246 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
3247 assertString(t, module.makeLinkType, test.expected)
3248 })
3249 }
3250}
3251
Jeff Gaston294356f2017-09-27 17:05:30 -07003252var staticLinkDepOrderTestCases = []struct {
3253 // This is a string representation of a map[moduleName][]moduleDependency .
3254 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003255 inStatic string
3256
3257 // This is a string representation of a map[moduleName][]moduleDependency .
3258 // It models the dependencies declared in an Android.bp file.
3259 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07003260
3261 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
3262 // The keys of allOrdered specify which modules we would like to check.
3263 // The values of allOrdered specify the expected result (of the transitive closure of all
3264 // dependencies) for each module to test
3265 allOrdered string
3266
3267 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
3268 // The keys of outOrdered specify which modules we would like to check.
3269 // The values of outOrdered specify the expected result (of the ordered linker command line)
3270 // for each module to test.
3271 outOrdered string
3272}{
3273 // Simple tests
3274 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003275 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07003276 outOrdered: "",
3277 },
3278 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003279 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003280 outOrdered: "a:",
3281 },
3282 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003283 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003284 outOrdered: "a:b; b:",
3285 },
3286 // Tests of reordering
3287 {
3288 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003289 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003290 outOrdered: "a:b,c,d; b:d; c:d; d:",
3291 },
3292 {
3293 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003294 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003295 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
3296 },
3297 {
3298 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003299 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07003300 outOrdered: "a:d,b,e,c; d:b; e:c",
3301 },
3302 {
3303 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003304 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07003305 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
3306 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
3307 },
3308 {
3309 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003310 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 -07003311 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3312 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3313 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003314 // shared dependencies
3315 {
3316 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
3317 // So, we don't actually have to check that a shared dependency of c will change the order
3318 // of a library that depends statically on b and on c. We only need to check that if c has
3319 // a shared dependency on b, that that shows up in allOrdered.
3320 inShared: "c:b",
3321 allOrdered: "c:b",
3322 outOrdered: "c:",
3323 },
3324 {
3325 // This test doesn't actually include any shared dependencies but it's a reminder of what
3326 // the second phase of the above test would look like
3327 inStatic: "a:b,c; c:b",
3328 allOrdered: "a:c,b; c:b",
3329 outOrdered: "a:c,b; c:b",
3330 },
Jeff Gaston294356f2017-09-27 17:05:30 -07003331 // tiebreakers for when two modules specifying different orderings and there is no dependency
3332 // to dictate an order
3333 {
3334 // 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 -08003335 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07003336 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
3337 },
3338 {
3339 // 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 -08003340 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 -07003341 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
3342 },
3343 // Tests involving duplicate dependencies
3344 {
3345 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003346 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003347 outOrdered: "a:c,b",
3348 },
3349 {
3350 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003351 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003352 outOrdered: "a:d,c,b",
3353 },
3354 // Tests to confirm the nonexistence of infinite loops.
3355 // These cases should never happen, so as long as the test terminates and the
3356 // result is deterministic then that should be fine.
3357 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003358 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003359 outOrdered: "a:a",
3360 },
3361 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003362 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003363 allOrdered: "a:b,c; b:c,a; c:a,b",
3364 outOrdered: "a:b; b:c; c:a",
3365 },
3366 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003367 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003368 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
3369 outOrdered: "a:c,b; b:a,c; c:b,a",
3370 },
3371}
3372
3373// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
3374func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
3375 // convert from "a:b,c; d:e" to "a:b,c;d:e"
3376 strippedText := strings.Replace(text, " ", "", -1)
3377 if len(strippedText) < 1 {
3378 return []android.Path{}, make(map[android.Path][]android.Path, 0)
3379 }
3380 allDeps = make(map[android.Path][]android.Path, 0)
3381
3382 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
3383 moduleTexts := strings.Split(strippedText, ";")
3384
3385 outputForModuleName := func(moduleName string) android.Path {
3386 return android.PathForTesting(moduleName)
3387 }
3388
3389 for _, moduleText := range moduleTexts {
3390 // convert from "a:b,c" to ["a", "b,c"]
3391 components := strings.Split(moduleText, ":")
3392 if len(components) != 2 {
3393 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
3394 }
3395 moduleName := components[0]
3396 moduleOutput := outputForModuleName(moduleName)
3397 modulesInOrder = append(modulesInOrder, moduleOutput)
3398
3399 depString := components[1]
3400 // convert from "b,c" to ["b", "c"]
3401 depNames := strings.Split(depString, ",")
3402 if len(depString) < 1 {
3403 depNames = []string{}
3404 }
3405 var deps []android.Path
3406 for _, depName := range depNames {
3407 deps = append(deps, outputForModuleName(depName))
3408 }
3409 allDeps[moduleOutput] = deps
3410 }
3411 return modulesInOrder, allDeps
3412}
3413
Jeff Gaston294356f2017-09-27 17:05:30 -07003414func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
3415 for _, moduleName := range moduleNames {
3416 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
3417 output := module.outputFile.Path()
3418 paths = append(paths, output)
3419 }
3420 return paths
3421}
3422
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003423func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07003424 ctx := testCc(t, `
3425 cc_library {
3426 name: "a",
3427 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09003428 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003429 }
3430 cc_library {
3431 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003432 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003433 }
3434 cc_library {
3435 name: "c",
3436 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003437 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003438 }
3439 cc_library {
3440 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09003441 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003442 }
3443
3444 `)
3445
Colin Cross7113d202019-11-20 16:39:12 -08003446 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07003447 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003448 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3449 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07003450
3451 if !reflect.DeepEqual(actual, expected) {
3452 t.Errorf("staticDeps orderings were not propagated correctly"+
3453 "\nactual: %v"+
3454 "\nexpected: %v",
3455 actual,
3456 expected,
3457 )
3458 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09003459}
Jeff Gaston294356f2017-09-27 17:05:30 -07003460
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003461func TestStaticLibDepReorderingWithShared(t *testing.T) {
3462 ctx := testCc(t, `
3463 cc_library {
3464 name: "a",
3465 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09003466 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003467 }
3468 cc_library {
3469 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003470 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003471 }
3472 cc_library {
3473 name: "c",
3474 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003475 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003476 }
3477
3478 `)
3479
Colin Cross7113d202019-11-20 16:39:12 -08003480 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003481 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003482 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3483 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003484
3485 if !reflect.DeepEqual(actual, expected) {
3486 t.Errorf("staticDeps orderings did not account for shared libs"+
3487 "\nactual: %v"+
3488 "\nexpected: %v",
3489 actual,
3490 expected,
3491 )
3492 }
3493}
3494
Jooyung Hanb04a4992020-03-13 18:57:35 +09003495func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07003496 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09003497 if !reflect.DeepEqual(actual, expected) {
3498 t.Errorf(message+
3499 "\nactual: %v"+
3500 "\nexpected: %v",
3501 actual,
3502 expected,
3503 )
3504 }
3505}
3506
Jooyung Han61b66e92020-03-21 14:21:46 +00003507func TestLlndkLibrary(t *testing.T) {
3508 ctx := testCc(t, `
3509 cc_library {
3510 name: "libllndk",
3511 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07003512 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003513 }
3514 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003515 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003516 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003517
3518 cc_prebuilt_library_shared {
3519 name: "libllndkprebuilt",
3520 stubs: { versions: ["1", "2"] },
3521 llndk_stubs: "libllndkprebuilt.llndk",
3522 }
3523 llndk_library {
3524 name: "libllndkprebuilt.llndk",
3525 }
3526
3527 cc_library {
3528 name: "libllndk_with_external_headers",
3529 stubs: { versions: ["1", "2"] },
3530 llndk_stubs: "libllndk_with_external_headers.llndk",
3531 header_libs: ["libexternal_headers"],
3532 export_header_lib_headers: ["libexternal_headers"],
3533 }
3534 llndk_library {
3535 name: "libllndk_with_external_headers.llndk",
3536 }
3537 cc_library_headers {
3538 name: "libexternal_headers",
3539 export_include_dirs: ["include"],
3540 vendor_available: true,
3541 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003542 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08003543 actual := ctx.ModuleVariantsForTests("libllndk")
3544 for i := 0; i < len(actual); i++ {
3545 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
3546 actual = append(actual[:i], actual[i+1:]...)
3547 i--
3548 }
3549 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003550 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00003551 "android_vendor.VER_arm64_armv8-a_shared_1",
3552 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003553 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003554 "android_vendor.VER_arm_armv7-a-neon_shared_1",
3555 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003556 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003557 }
3558 checkEquals(t, "variants for llndk stubs", expected, actual)
3559
Colin Cross127bb8b2020-12-16 16:46:01 -08003560 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003561 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
3562
Colin Cross127bb8b2020-12-16 16:46:01 -08003563 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003564 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
3565}
3566
Jiyong Parka46a4d52017-12-14 19:54:34 +09003567func TestLlndkHeaders(t *testing.T) {
3568 ctx := testCc(t, `
3569 llndk_headers {
3570 name: "libllndk_headers",
3571 export_include_dirs: ["my_include"],
3572 }
3573 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003574 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09003575 export_llndk_headers: ["libllndk_headers"],
3576 }
3577 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07003578 name: "libllndk",
3579 llndk_stubs: "libllndk.llndk",
3580 }
3581
3582 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09003583 name: "libvendor",
3584 shared_libs: ["libllndk"],
3585 vendor: true,
3586 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003587 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08003588 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09003589 }
3590 `)
3591
3592 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08003593 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09003594 cflags := cc.Args["cFlags"]
3595 if !strings.Contains(cflags, "-Imy_include") {
3596 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
3597 }
3598}
3599
Logan Chien43d34c32017-12-20 01:17:32 +08003600func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
3601 actual := module.Properties.AndroidMkRuntimeLibs
3602 if !reflect.DeepEqual(actual, expected) {
3603 t.Errorf("incorrect runtime_libs for shared libs"+
3604 "\nactual: %v"+
3605 "\nexpected: %v",
3606 actual,
3607 expected,
3608 )
3609 }
3610}
3611
3612const runtimeLibAndroidBp = `
3613 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09003614 name: "liball_available",
3615 vendor_available: true,
3616 product_available: true,
3617 no_libcrt : true,
3618 nocrt : true,
3619 system_shared_libs : [],
3620 }
3621 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08003622 name: "libvendor_available1",
3623 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003624 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07003625 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003626 nocrt : true,
3627 system_shared_libs : [],
3628 }
3629 cc_library {
3630 name: "libvendor_available2",
3631 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003632 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08003633 target: {
3634 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09003635 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08003636 }
3637 },
Yi Konge7fe9912019-06-02 00:53:50 -07003638 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003639 nocrt : true,
3640 system_shared_libs : [],
3641 }
3642 cc_library {
3643 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09003644 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07003645 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003646 nocrt : true,
3647 system_shared_libs : [],
3648 }
3649 cc_library {
3650 name: "libvendor1",
3651 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003652 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003653 nocrt : true,
3654 system_shared_libs : [],
3655 }
3656 cc_library {
3657 name: "libvendor2",
3658 vendor: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003659 runtime_libs: ["liball_available", "libvendor1"],
3660 no_libcrt : true,
3661 nocrt : true,
3662 system_shared_libs : [],
3663 }
3664 cc_library {
3665 name: "libproduct_available1",
3666 product_available: true,
3667 runtime_libs: ["liball_available"],
3668 no_libcrt : true,
3669 nocrt : true,
3670 system_shared_libs : [],
3671 }
3672 cc_library {
3673 name: "libproduct1",
3674 product_specific: true,
3675 no_libcrt : true,
3676 nocrt : true,
3677 system_shared_libs : [],
3678 }
3679 cc_library {
3680 name: "libproduct2",
3681 product_specific: true,
3682 runtime_libs: ["liball_available", "libproduct1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003683 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003684 nocrt : true,
3685 system_shared_libs : [],
3686 }
3687`
3688
3689func TestRuntimeLibs(t *testing.T) {
3690 ctx := testCc(t, runtimeLibAndroidBp)
3691
3692 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08003693 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003694
Justin Yun8a2600c2020-12-07 12:44:03 +09003695 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3696 checkRuntimeLibs(t, []string{"liball_available"}, module)
3697
3698 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3699 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003700
3701 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003702 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003703
3704 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
3705 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08003706 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003707
Justin Yun8a2600c2020-12-07 12:44:03 +09003708 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3709 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003710
3711 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003712 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1"}, module)
3713
3714 // runtime_libs for product variants have '.product' suffixes if the modules have both core
3715 // and product variants.
3716 variant = "android_product.VER_arm64_armv8-a_shared"
3717
3718 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3719 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
3720
3721 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
3722 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003723}
3724
3725func TestExcludeRuntimeLibs(t *testing.T) {
3726 ctx := testCc(t, runtimeLibAndroidBp)
3727
Colin Cross7113d202019-11-20 16:39:12 -08003728 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003729 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3730 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003731
Colin Crossfb0c16e2019-11-20 17:12:35 -08003732 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003733 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08003734 checkRuntimeLibs(t, nil, module)
3735}
3736
3737func TestRuntimeLibsNoVndk(t *testing.T) {
3738 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
3739
3740 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
3741
Colin Cross7113d202019-11-20 16:39:12 -08003742 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003743
Justin Yun8a2600c2020-12-07 12:44:03 +09003744 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3745 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003746
3747 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003748 checkRuntimeLibs(t, []string{"liball_available", "libvendor1"}, module)
3749
3750 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
3751 checkRuntimeLibs(t, []string{"liball_available", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003752}
3753
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003754func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09003755 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003756 actual := module.Properties.AndroidMkStaticLibs
3757 if !reflect.DeepEqual(actual, expected) {
3758 t.Errorf("incorrect static_libs"+
3759 "\nactual: %v"+
3760 "\nexpected: %v",
3761 actual,
3762 expected,
3763 )
3764 }
3765}
3766
3767const staticLibAndroidBp = `
3768 cc_library {
3769 name: "lib1",
3770 }
3771 cc_library {
3772 name: "lib2",
3773 static_libs: ["lib1"],
3774 }
3775`
3776
3777func TestStaticLibDepExport(t *testing.T) {
3778 ctx := testCc(t, staticLibAndroidBp)
3779
3780 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003781 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003782 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003783 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003784
3785 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003786 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003787 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
3788 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003789 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003790}
3791
Jiyong Parkd08b6972017-09-26 10:50:54 +09003792var compilerFlagsTestCases = []struct {
3793 in string
3794 out bool
3795}{
3796 {
3797 in: "a",
3798 out: false,
3799 },
3800 {
3801 in: "-a",
3802 out: true,
3803 },
3804 {
3805 in: "-Ipath/to/something",
3806 out: false,
3807 },
3808 {
3809 in: "-isystempath/to/something",
3810 out: false,
3811 },
3812 {
3813 in: "--coverage",
3814 out: false,
3815 },
3816 {
3817 in: "-include a/b",
3818 out: true,
3819 },
3820 {
3821 in: "-include a/b c/d",
3822 out: false,
3823 },
3824 {
3825 in: "-DMACRO",
3826 out: true,
3827 },
3828 {
3829 in: "-DMAC RO",
3830 out: false,
3831 },
3832 {
3833 in: "-a -b",
3834 out: false,
3835 },
3836 {
3837 in: "-DMACRO=definition",
3838 out: true,
3839 },
3840 {
3841 in: "-DMACRO=defi nition",
3842 out: true, // TODO(jiyong): this should be false
3843 },
3844 {
3845 in: "-DMACRO(x)=x + 1",
3846 out: true,
3847 },
3848 {
3849 in: "-DMACRO=\"defi nition\"",
3850 out: true,
3851 },
3852}
3853
3854type mockContext struct {
3855 BaseModuleContext
3856 result bool
3857}
3858
3859func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3860 // CheckBadCompilerFlags calls this function when the flag should be rejected
3861 ctx.result = false
3862}
3863
3864func TestCompilerFlags(t *testing.T) {
3865 for _, testCase := range compilerFlagsTestCases {
3866 ctx := &mockContext{result: true}
3867 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3868 if ctx.result != testCase.out {
3869 t.Errorf("incorrect output:")
3870 t.Errorf(" input: %#v", testCase.in)
3871 t.Errorf(" expected: %#v", testCase.out)
3872 t.Errorf(" got: %#v", ctx.result)
3873 }
3874 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003875}
Jiyong Park374510b2018-03-19 18:23:01 +09003876
3877func TestVendorPublicLibraries(t *testing.T) {
3878 ctx := testCc(t, `
3879 cc_library_headers {
3880 name: "libvendorpublic_headers",
3881 export_include_dirs: ["my_include"],
3882 }
3883 vendor_public_library {
3884 name: "libvendorpublic",
3885 symbol_file: "",
3886 export_public_headers: ["libvendorpublic_headers"],
3887 }
3888 cc_library {
3889 name: "libvendorpublic",
3890 srcs: ["foo.c"],
3891 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003892 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003893 nocrt: true,
3894 }
3895
3896 cc_library {
3897 name: "libsystem",
3898 shared_libs: ["libvendorpublic"],
3899 vendor: false,
3900 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003901 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003902 nocrt: true,
3903 }
3904 cc_library {
3905 name: "libvendor",
3906 shared_libs: ["libvendorpublic"],
3907 vendor: true,
3908 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003909 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003910 nocrt: true,
3911 }
3912 `)
3913
Colin Cross7113d202019-11-20 16:39:12 -08003914 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003915 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003916
3917 // test if header search paths are correctly added
3918 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003919 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003920 cflags := cc.Args["cFlags"]
3921 if !strings.Contains(cflags, "-Imy_include") {
3922 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3923 }
3924
3925 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003926 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003927 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003928 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003929 if !strings.Contains(libflags, stubPaths[0].String()) {
3930 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3931 }
3932
3933 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003934 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003935 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003936 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003937 if !strings.Contains(libflags, stubPaths[0].String()) {
3938 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3939 }
3940
3941}
Jiyong Park37b25202018-07-11 10:49:27 +09003942
3943func TestRecovery(t *testing.T) {
3944 ctx := testCc(t, `
3945 cc_library_shared {
3946 name: "librecovery",
3947 recovery: true,
3948 }
3949 cc_library_shared {
3950 name: "librecovery32",
3951 recovery: true,
3952 compile_multilib:"32",
3953 }
Jiyong Park5baac542018-08-28 09:55:37 +09003954 cc_library_shared {
3955 name: "libHalInRecovery",
3956 recovery_available: true,
3957 vendor: true,
3958 }
Jiyong Park37b25202018-07-11 10:49:27 +09003959 `)
3960
3961 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003962 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003963 if len(variants) != 1 || !android.InList(arm64, variants) {
3964 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3965 }
3966
3967 variants = ctx.ModuleVariantsForTests("librecovery32")
3968 if android.InList(arm64, variants) {
3969 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3970 }
Jiyong Park5baac542018-08-28 09:55:37 +09003971
3972 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3973 if !recoveryModule.Platform() {
3974 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3975 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003976}
Jiyong Park5baac542018-08-28 09:55:37 +09003977
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003978func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3979 bp := `
3980 cc_prebuilt_test_library_shared {
3981 name: "test_lib",
3982 relative_install_path: "foo/bar/baz",
3983 srcs: ["srcpath/dontusethispath/baz.so"],
3984 }
3985
3986 cc_test {
3987 name: "main_test",
3988 data_libs: ["test_lib"],
3989 gtest: false,
3990 }
3991 `
3992
3993 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3994 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3995 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3996 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3997
3998 ctx := testCcWithConfig(t, config)
3999 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
4000 testBinary := module.(*Module).linker.(*testBinary)
4001 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
4002 if err != nil {
4003 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
4004 }
4005 if len(outputFiles) != 1 {
4006 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
4007 }
4008 if len(testBinary.dataPaths()) != 1 {
4009 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
4010 }
4011
4012 outputPath := outputFiles[0].String()
4013
4014 if !strings.HasSuffix(outputPath, "/main_test") {
4015 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
4016 }
4017 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
4018 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
4019 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
4020 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
4021 }
4022}
4023
Jiyong Park7ed9de32018-10-15 22:25:07 +09004024func TestVersionedStubs(t *testing.T) {
4025 ctx := testCc(t, `
4026 cc_library_shared {
4027 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09004028 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09004029 stubs: {
4030 symbol_file: "foo.map.txt",
4031 versions: ["1", "2", "3"],
4032 },
4033 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09004034
Jiyong Park7ed9de32018-10-15 22:25:07 +09004035 cc_library_shared {
4036 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09004037 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09004038 shared_libs: ["libFoo#1"],
4039 }`)
4040
4041 variants := ctx.ModuleVariantsForTests("libFoo")
4042 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08004043 "android_arm64_armv8-a_shared",
4044 "android_arm64_armv8-a_shared_1",
4045 "android_arm64_armv8-a_shared_2",
4046 "android_arm64_armv8-a_shared_3",
4047 "android_arm_armv7-a-neon_shared",
4048 "android_arm_armv7-a-neon_shared_1",
4049 "android_arm_armv7-a-neon_shared_2",
4050 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09004051 }
4052 variantsMismatch := false
4053 if len(variants) != len(expectedVariants) {
4054 variantsMismatch = true
4055 } else {
4056 for _, v := range expectedVariants {
4057 if !inList(v, variants) {
4058 variantsMismatch = false
4059 }
4060 }
4061 }
4062 if variantsMismatch {
4063 t.Errorf("variants of libFoo expected:\n")
4064 for _, v := range expectedVariants {
4065 t.Errorf("%q\n", v)
4066 }
4067 t.Errorf(", but got:\n")
4068 for _, v := range variants {
4069 t.Errorf("%q\n", v)
4070 }
4071 }
4072
Colin Cross7113d202019-11-20 16:39:12 -08004073 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09004074 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08004075 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09004076 if !strings.Contains(libFlags, libFoo1StubPath) {
4077 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
4078 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09004079
Colin Cross7113d202019-11-20 16:39:12 -08004080 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09004081 cFlags := libBarCompileRule.Args["cFlags"]
4082 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
4083 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
4084 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
4085 }
Jiyong Park37b25202018-07-11 10:49:27 +09004086}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004087
Jooyung Hanb04a4992020-03-13 18:57:35 +09004088func TestVersioningMacro(t *testing.T) {
4089 for _, tc := range []struct{ moduleName, expected string }{
4090 {"libc", "__LIBC_API__"},
4091 {"libfoo", "__LIBFOO_API__"},
4092 {"libfoo@1", "__LIBFOO_1_API__"},
4093 {"libfoo-v1", "__LIBFOO_V1_API__"},
4094 {"libfoo.v1", "__LIBFOO_V1_API__"},
4095 } {
4096 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
4097 }
4098}
4099
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004100func TestStaticExecutable(t *testing.T) {
4101 ctx := testCc(t, `
4102 cc_binary {
4103 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01004104 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004105 static_executable: true,
4106 }`)
4107
Colin Cross7113d202019-11-20 16:39:12 -08004108 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004109 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
4110 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07004111 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004112 for _, lib := range systemStaticLibs {
4113 if !strings.Contains(libFlags, lib) {
4114 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
4115 }
4116 }
4117 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
4118 for _, lib := range systemSharedLibs {
4119 if strings.Contains(libFlags, lib) {
4120 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
4121 }
4122 }
4123}
Jiyong Parke4bb9862019-02-01 00:31:10 +09004124
4125func TestStaticDepsOrderWithStubs(t *testing.T) {
4126 ctx := testCc(t, `
4127 cc_binary {
4128 name: "mybin",
4129 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07004130 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09004131 static_executable: true,
4132 stl: "none",
4133 }
4134
4135 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08004136 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09004137 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08004138 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09004139 stl: "none",
4140 }
4141
4142 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08004143 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09004144 srcs: ["foo.c"],
4145 stl: "none",
4146 stubs: {
4147 versions: ["1"],
4148 },
4149 }`)
4150
Colin Cross0de8a1e2020-09-18 14:15:30 -07004151 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
4152 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08004153 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09004154
4155 if !reflect.DeepEqual(actual, expected) {
4156 t.Errorf("staticDeps orderings were not propagated correctly"+
4157 "\nactual: %v"+
4158 "\nexpected: %v",
4159 actual,
4160 expected,
4161 )
4162 }
4163}
Jooyung Han38002912019-05-16 04:01:54 +09004164
Jooyung Hand48f3c32019-08-23 11:18:57 +09004165func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
4166 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
4167 cc_library {
4168 name: "libA",
4169 srcs: ["foo.c"],
4170 shared_libs: ["libB"],
4171 stl: "none",
4172 }
4173
4174 cc_library {
4175 name: "libB",
4176 srcs: ["foo.c"],
4177 enabled: false,
4178 stl: "none",
4179 }
4180 `)
4181}
4182
Mitch Phillipsda9a4632019-07-15 09:34:09 -07004183// Simple smoke test for the cc_fuzz target that ensures the rule compiles
4184// correctly.
4185func TestFuzzTarget(t *testing.T) {
4186 ctx := testCc(t, `
4187 cc_fuzz {
4188 name: "fuzz_smoke_test",
4189 srcs: ["foo.c"],
4190 }`)
4191
Paul Duffin075c4172019-12-19 19:06:13 +00004192 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07004193 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
4194}
4195
Jiyong Park29074592019-07-07 16:27:47 +09004196func TestAidl(t *testing.T) {
4197}
4198
Jooyung Han38002912019-05-16 04:01:54 +09004199func assertString(t *testing.T, got, expected string) {
4200 t.Helper()
4201 if got != expected {
4202 t.Errorf("expected %q got %q", expected, got)
4203 }
4204}
4205
4206func assertArrayString(t *testing.T, got, expected []string) {
4207 t.Helper()
4208 if len(got) != len(expected) {
4209 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
4210 return
4211 }
4212 for i := range got {
4213 if got[i] != expected[i] {
4214 t.Errorf("expected %d-th %q (%q) got %q (%q)",
4215 i, expected[i], expected, got[i], got)
4216 return
4217 }
4218 }
4219}
Colin Crosse1bb5d02019-09-24 14:55:04 -07004220
Jooyung Han0302a842019-10-30 18:43:49 +09004221func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
4222 t.Helper()
4223 assertArrayString(t, android.SortedStringKeys(m), expected)
4224}
4225
Colin Crosse1bb5d02019-09-24 14:55:04 -07004226func TestDefaults(t *testing.T) {
4227 ctx := testCc(t, `
4228 cc_defaults {
4229 name: "defaults",
4230 srcs: ["foo.c"],
4231 static: {
4232 srcs: ["bar.c"],
4233 },
4234 shared: {
4235 srcs: ["baz.c"],
4236 },
4237 }
4238
4239 cc_library_static {
4240 name: "libstatic",
4241 defaults: ["defaults"],
4242 }
4243
4244 cc_library_shared {
4245 name: "libshared",
4246 defaults: ["defaults"],
4247 }
4248
4249 cc_library {
4250 name: "libboth",
4251 defaults: ["defaults"],
4252 }
4253
4254 cc_binary {
4255 name: "binary",
4256 defaults: ["defaults"],
4257 }`)
4258
4259 pathsToBase := func(paths android.Paths) []string {
4260 var ret []string
4261 for _, p := range paths {
4262 ret = append(ret, p.Base())
4263 }
4264 return ret
4265 }
4266
Colin Cross7113d202019-11-20 16:39:12 -08004267 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004268 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4269 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
4270 }
Colin Cross7113d202019-11-20 16:39:12 -08004271 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004272 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4273 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
4274 }
Colin Cross7113d202019-11-20 16:39:12 -08004275 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004276 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
4277 t.Errorf("binary ld rule wanted %q, got %q", w, g)
4278 }
4279
Colin Cross7113d202019-11-20 16:39:12 -08004280 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004281 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4282 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
4283 }
Colin Cross7113d202019-11-20 16:39:12 -08004284 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004285 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4286 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
4287 }
4288}
Colin Crosseabaedd2020-02-06 17:01:55 -08004289
4290func TestProductVariableDefaults(t *testing.T) {
4291 bp := `
4292 cc_defaults {
4293 name: "libfoo_defaults",
4294 srcs: ["foo.c"],
4295 cppflags: ["-DFOO"],
4296 product_variables: {
4297 debuggable: {
4298 cppflags: ["-DBAR"],
4299 },
4300 },
4301 }
4302
4303 cc_library {
4304 name: "libfoo",
4305 defaults: ["libfoo_defaults"],
4306 }
4307 `
4308
4309 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4310 config.TestProductVariables.Debuggable = BoolPtr(true)
4311
Colin Crossae8600b2020-10-29 17:09:13 -07004312 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08004313 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
4314 ctx.BottomUp("variable", android.VariableMutator).Parallel()
4315 })
Colin Crossae8600b2020-10-29 17:09:13 -07004316 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08004317
4318 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4319 android.FailIfErrored(t, errs)
4320 _, errs = ctx.PrepareBuildActions(config)
4321 android.FailIfErrored(t, errs)
4322
4323 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
4324 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
4325 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
4326 }
4327}
Colin Crosse4f6eba2020-09-22 18:11:25 -07004328
4329func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
4330 t.Parallel()
4331 bp := `
4332 cc_library_static {
4333 name: "libfoo",
4334 srcs: ["foo.c"],
4335 whole_static_libs: ["libbar"],
4336 }
4337
4338 cc_library_static {
4339 name: "libbar",
4340 whole_static_libs: ["libmissing"],
4341 }
4342 `
4343
4344 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4345 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
4346
Colin Crossae8600b2020-10-29 17:09:13 -07004347 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07004348 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07004349 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07004350
4351 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4352 android.FailIfErrored(t, errs)
4353 _, errs = ctx.PrepareBuildActions(config)
4354 android.FailIfErrored(t, errs)
4355
4356 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
4357 if g, w := libbar.Rule, android.ErrorRule; g != w {
4358 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
4359 }
4360
4361 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
4362 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
4363 }
4364
4365 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
4366 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
4367 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
4368 }
4369
4370}
Colin Crosse9fe2942020-11-10 18:12:15 -08004371
4372func TestInstallSharedLibs(t *testing.T) {
4373 bp := `
4374 cc_binary {
4375 name: "bin",
4376 host_supported: true,
4377 shared_libs: ["libshared"],
4378 runtime_libs: ["libruntime"],
4379 srcs: [":gen"],
4380 }
4381
4382 cc_library_shared {
4383 name: "libshared",
4384 host_supported: true,
4385 shared_libs: ["libtransitive"],
4386 }
4387
4388 cc_library_shared {
4389 name: "libtransitive",
4390 host_supported: true,
4391 }
4392
4393 cc_library_shared {
4394 name: "libruntime",
4395 host_supported: true,
4396 }
4397
4398 cc_binary_host {
4399 name: "tool",
4400 srcs: ["foo.cpp"],
4401 }
4402
4403 genrule {
4404 name: "gen",
4405 tools: ["tool"],
4406 out: ["gen.cpp"],
4407 cmd: "$(location tool) $(out)",
4408 }
4409 `
4410
4411 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4412 ctx := testCcWithConfig(t, config)
4413
4414 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
4415 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
4416 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
4417 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
4418 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
4419
4420 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
4421 t.Errorf("expected host bin dependency %q, got %q", w, g)
4422 }
4423
4424 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4425 t.Errorf("expected host bin dependency %q, got %q", w, g)
4426 }
4427
4428 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4429 t.Errorf("expected host bin dependency %q, got %q", w, g)
4430 }
4431
4432 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
4433 t.Errorf("expected host bin dependency %q, got %q", w, g)
4434 }
4435
4436 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
4437 t.Errorf("expected no host bin dependency %q, got %q", w, g)
4438 }
4439
4440 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
4441 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
4442 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
4443 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
4444
4445 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
4446 t.Errorf("expected device bin dependency %q, got %q", w, g)
4447 }
4448
4449 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4450 t.Errorf("expected device bin dependency %q, got %q", w, g)
4451 }
4452
4453 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4454 t.Errorf("expected device bin dependency %q, got %q", w, g)
4455 }
4456
4457 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
4458 t.Errorf("expected device bin dependency %q, got %q", w, g)
4459 }
4460
4461 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
4462 t.Errorf("expected no device bin dependency %q, got %q", w, g)
4463 }
4464
4465}
Jiyong Park1ad8e162020-12-01 23:40:09 +09004466
4467func TestStubsLibReexportsHeaders(t *testing.T) {
4468 ctx := testCc(t, `
4469 cc_library_shared {
4470 name: "libclient",
4471 srcs: ["foo.c"],
4472 shared_libs: ["libfoo#1"],
4473 }
4474
4475 cc_library_shared {
4476 name: "libfoo",
4477 srcs: ["foo.c"],
4478 shared_libs: ["libbar"],
4479 export_shared_lib_headers: ["libbar"],
4480 stubs: {
4481 symbol_file: "foo.map.txt",
4482 versions: ["1", "2", "3"],
4483 },
4484 }
4485
4486 cc_library_shared {
4487 name: "libbar",
4488 export_include_dirs: ["include/libbar"],
4489 srcs: ["foo.c"],
4490 }`)
4491
4492 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
4493
4494 if !strings.Contains(cFlags, "-Iinclude/libbar") {
4495 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
4496 }
4497}
Jooyung Hane197d8b2021-01-05 10:33:16 +09004498
4499func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
4500 ctx := testCc(t, `
4501 cc_library {
4502 name: "libfoo",
4503 srcs: ["a/Foo.aidl"],
4504 aidl: { flags: ["-Werror"], },
4505 }
4506 `)
4507
4508 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
4509 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
4510 aidlCommand := manifest.Commands[0].GetCommand()
4511 expectedAidlFlag := "-Werror"
4512 if !strings.Contains(aidlCommand, expectedAidlFlag) {
4513 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
4514 }
4515}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004516
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004517type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004518
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004519const (
4520 None MemtagNoteType = iota + 1
4521 Sync
4522 Async
4523)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004524
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004525func (t MemtagNoteType) str() string {
4526 switch t {
4527 case None:
4528 return "none"
4529 case Sync:
4530 return "sync"
4531 case Async:
4532 return "async"
4533 default:
4534 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004535 }
4536}
4537
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004538func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
4539 note_async := "note_memtag_heap_async"
4540 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004541
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004542 found := None
4543 implicits := m.Rule("ld").Implicits
4544 for _, lib := range implicits {
4545 if strings.Contains(lib.Rel(), note_async) {
4546 found = Async
4547 break
4548 } else if strings.Contains(lib.Rel(), note_sync) {
4549 found = Sync
4550 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004551 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004552 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004553
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004554 if found != expected {
4555 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
4556 }
4557}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004558
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004559func makeMemtagTestConfig(t *testing.T) android.Config {
4560 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004561 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004562 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004563 gtest: false,
4564 }
4565
4566 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004567 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004568 gtest: false,
4569 sanitize: { memtag_heap: false },
4570 }
4571
4572 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004573 name: "%[1]s_test_true",
4574 gtest: false,
4575 sanitize: { memtag_heap: true },
4576 }
4577
4578 cc_test {
4579 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004580 gtest: false,
4581 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
4582 }
4583
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004584 cc_test {
4585 name: "%[1]s_test_true_diag",
4586 gtest: false,
4587 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
4588 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004589
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004590 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004591 name: "%[1]s_binary",
4592 }
4593
4594 cc_binary {
4595 name: "%[1]s_binary_false",
4596 sanitize: { memtag_heap: false },
4597 }
4598
4599 cc_binary {
4600 name: "%[1]s_binary_true",
4601 sanitize: { memtag_heap: true },
4602 }
4603
4604 cc_binary {
4605 name: "%[1]s_binary_true_nodiag",
4606 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
4607 }
4608
4609 cc_binary {
4610 name: "%[1]s_binary_true_diag",
4611 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004612 }
4613 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004614 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
4615 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
4616 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
4617 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004618
4619 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004620 "subdir_default/Android.bp": []byte(subdirDefaultBp),
4621 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
4622 "subdir_sync/Android.bp": []byte(subdirSyncBp),
4623 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004624 }
4625
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004626 return TestConfig(buildDir, android.Android, nil, "", mockFS)
4627}
4628
4629func TestSanitizeMemtagHeap(t *testing.T) {
4630 variant := "android_arm64_armv8-a"
4631
4632 config := makeMemtagTestConfig(t)
4633 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004634 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004635 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004636 ctx := CreateTestContext(config)
4637 ctx.Register()
4638
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004639 _, 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 -08004640 android.FailIfErrored(t, errs)
4641 _, errs = ctx.PrepareBuildActions(config)
4642 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004643
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004644 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4645 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4646 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
4647 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4648 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
4649
4650 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
4651 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4652 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
4653 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4654 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4655
4656 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4657 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4658 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
4659 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4660 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4661
4662 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4663 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4664 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
4665 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4666 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4667
4668 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4669 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4670 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
4671 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4672 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4673
4674 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
4675 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4676 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
4677 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4678 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4679
4680 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4681 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4682 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4683 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4684 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4685
4686 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4687 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4688 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4689 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4690 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
4691}
4692
4693func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004694 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004695
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004696 config := makeMemtagTestConfig(t)
4697 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
4698 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
4699 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
4700 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
4701 ctx := CreateTestContext(config)
4702 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004703
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004704 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
4705 android.FailIfErrored(t, errs)
4706 _, errs = ctx.PrepareBuildActions(config)
4707 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004708
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004709 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4710 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4711 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
4712 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4713 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004714
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004715 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
4716 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4717 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
4718 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4719 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4720
4721 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4722 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4723 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
4724 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4725 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4726
4727 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4728 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4729 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
4730 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4731 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4732
4733 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4734 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4735 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
4736 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4737 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4738
4739 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
4740 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4741 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
4742 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4743 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4744
4745 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4746 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4747 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4748 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4749 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4750
4751 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4752 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4753 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4754 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4755 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
4756}
4757
4758func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
4759 variant := "android_arm64_armv8-a"
4760
4761 config := makeMemtagTestConfig(t)
4762 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
4763 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
4764 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
4765 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
4766 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
4767 ctx := CreateTestContext(config)
4768 ctx.Register()
4769
4770 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
4771 android.FailIfErrored(t, errs)
4772 _, errs = ctx.PrepareBuildActions(config)
4773 android.FailIfErrored(t, errs)
4774
4775 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4776 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4777 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
4778 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4779 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
4780
4781 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
4782 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4783 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
4784 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4785 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4786
4787 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4788 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4789 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
4790 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4791 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4792
4793 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4794 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4795 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
4796 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4797 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4798
4799 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4800 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4801 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
4802 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4803 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4804
4805 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
4806 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4807 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
4808 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4809 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4810
4811 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4812 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4813 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4814 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4815 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4816
4817 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4818 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4819 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4820 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4821 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004822}