blob: 0cd83a75fff90e7a1a7945403eff4fe1ec47d1f1 [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
Bill Peckham945441c2020-08-31 16:07:58 -07001627func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) {
1628 t.Helper()
1629 if c.ExcludeFromVendorSnapshot() != expected {
1630 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected)
1631 }
1632}
1633
Jose Galmes6f843bc2020-12-11 13:36:29 -08001634func assertExcludeFromRecoverySnapshotIs(t *testing.T, c *Module, expected bool) {
1635 t.Helper()
1636 if c.ExcludeFromRecoverySnapshot() != expected {
1637 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", c.String(), expected)
1638 }
1639}
1640
Bill Peckham945441c2020-08-31 16:07:58 -07001641func TestVendorSnapshotExclude(t *testing.T) {
1642
1643 // This test verifies that the exclude_from_vendor_snapshot property
1644 // makes its way from the Android.bp source file into the module data
1645 // structure. It also verifies that modules are correctly included or
1646 // excluded in the vendor snapshot based on their path (framework or
1647 // vendor) and the exclude_from_vendor_snapshot property.
1648
1649 frameworkBp := `
1650 cc_library_shared {
1651 name: "libinclude",
1652 srcs: ["src/include.cpp"],
1653 vendor_available: true,
1654 }
1655 cc_library_shared {
1656 name: "libexclude",
1657 srcs: ["src/exclude.cpp"],
1658 vendor: true,
1659 exclude_from_vendor_snapshot: true,
1660 }
1661 `
1662
1663 vendorProprietaryBp := `
1664 cc_library_shared {
1665 name: "libvendor",
1666 srcs: ["vendor.cpp"],
1667 vendor: true,
1668 }
1669 `
1670
1671 depsBp := GatherRequiredDepsForTest(android.Android)
1672
1673 mockFS := map[string][]byte{
1674 "deps/Android.bp": []byte(depsBp),
1675 "framework/Android.bp": []byte(frameworkBp),
1676 "framework/include.cpp": nil,
1677 "framework/exclude.cpp": nil,
1678 "device/Android.bp": []byte(vendorProprietaryBp),
1679 "device/vendor.cpp": nil,
1680 }
1681
1682 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1683 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1684 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001685 ctx := CreateTestContext(config)
1686 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001687
1688 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1689 android.FailIfErrored(t, errs)
1690 _, errs = ctx.PrepareBuildActions(config)
1691 android.FailIfErrored(t, errs)
1692
1693 // Test an include and exclude framework module.
1694 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
1695 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false)
1696 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true)
1697
1698 // A vendor module is excluded, but by its path, not the
1699 // exclude_from_vendor_snapshot property.
1700 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false)
1701
1702 // Verify the content of the vendor snapshot.
1703
1704 snapshotDir := "vendor-snapshot"
1705 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1706 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1707
1708 var includeJsonFiles []string
1709 var excludeJsonFiles []string
1710
1711 for _, arch := range [][]string{
1712 []string{"arm64", "armv8-a"},
1713 []string{"arm", "armv7-a-neon"},
1714 } {
1715 archType := arch[0]
1716 archVariant := arch[1]
1717 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1718
1719 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1720 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1721
1722 // Included modules
1723 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1724 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1725
1726 // Excluded modules
1727 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1728 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1729 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1730 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1731 }
1732
1733 // Verify that each json file for an included module has a rule.
1734 for _, jsonFile := range includeJsonFiles {
1735 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1736 t.Errorf("include json file %q not found", jsonFile)
1737 }
1738 }
1739
1740 // Verify that each json file for an excluded module has no rule.
1741 for _, jsonFile := range excludeJsonFiles {
1742 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1743 t.Errorf("exclude json file %q found", jsonFile)
1744 }
1745 }
1746}
1747
1748func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1749
1750 // This test verifies that using the exclude_from_vendor_snapshot
1751 // property on a module in a vendor proprietary path generates an
1752 // error. These modules are already excluded, so we prohibit using the
1753 // property in this way, which could add to confusion.
1754
1755 vendorProprietaryBp := `
1756 cc_library_shared {
1757 name: "libvendor",
1758 srcs: ["vendor.cpp"],
1759 vendor: true,
1760 exclude_from_vendor_snapshot: true,
1761 }
1762 `
1763
1764 depsBp := GatherRequiredDepsForTest(android.Android)
1765
1766 mockFS := map[string][]byte{
1767 "deps/Android.bp": []byte(depsBp),
1768 "device/Android.bp": []byte(vendorProprietaryBp),
1769 "device/vendor.cpp": nil,
1770 }
1771
1772 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1773 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1774 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001775 ctx := CreateTestContext(config)
1776 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001777
1778 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1779 android.FailIfErrored(t, errs)
1780
1781 _, errs = ctx.PrepareBuildActions(config)
1782 android.CheckErrorsAgainstExpectations(t, errs, []string{
1783 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1784 `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 -08001785 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1786 `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 +09001787 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1788 `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 -07001789 })
1790}
1791
1792func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) {
1793
1794 // This test verifies that using the exclude_from_vendor_snapshot
1795 // property on a module that is vendor available generates an error. A
1796 // vendor available module must be captured in the vendor snapshot and
1797 // must not built from source when building the vendor image against
1798 // the vendor snapshot.
1799
1800 frameworkBp := `
1801 cc_library_shared {
1802 name: "libinclude",
1803 srcs: ["src/include.cpp"],
1804 vendor_available: true,
1805 exclude_from_vendor_snapshot: true,
1806 }
1807 `
1808
1809 depsBp := GatherRequiredDepsForTest(android.Android)
1810
1811 mockFS := map[string][]byte{
1812 "deps/Android.bp": []byte(depsBp),
1813 "framework/Android.bp": []byte(frameworkBp),
1814 "framework/include.cpp": nil,
1815 }
1816
1817 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1818 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1819 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001820 ctx := CreateTestContext(config)
1821 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001822
1823 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"})
1824 android.FailIfErrored(t, errs)
1825
1826 _, errs = ctx.PrepareBuildActions(config)
1827 android.CheckErrorsAgainstExpectations(t, errs, []string{
1828 `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1829 `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1830 `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1831 `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
Inseob Kime9aec6a2021-01-05 20:03:22 +09001832 `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1833 `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1834 `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1835 `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
Bill Peckham945441c2020-08-31 16:07:58 -07001836 })
1837}
1838
Jose Galmesf7294582020-11-13 12:07:36 -08001839func TestRecoverySnapshotCapture(t *testing.T) {
1840 bp := `
1841 cc_library {
1842 name: "libvndk",
1843 vendor_available: true,
1844 recovery_available: true,
1845 product_available: true,
1846 vndk: {
1847 enabled: true,
1848 },
1849 nocrt: true,
1850 }
1851
1852 cc_library {
1853 name: "librecovery",
1854 recovery: true,
1855 nocrt: true,
1856 }
1857
1858 cc_library {
1859 name: "librecovery_available",
1860 recovery_available: true,
1861 nocrt: true,
1862 }
1863
1864 cc_library_headers {
1865 name: "librecovery_headers",
1866 recovery_available: true,
1867 nocrt: true,
1868 }
1869
1870 cc_binary {
1871 name: "recovery_bin",
1872 recovery: true,
1873 nocrt: true,
1874 }
1875
1876 cc_binary {
1877 name: "recovery_available_bin",
1878 recovery_available: true,
1879 nocrt: true,
1880 }
1881
1882 toolchain_library {
1883 name: "libb",
1884 recovery_available: true,
1885 src: "libb.a",
1886 }
1887
1888 cc_object {
1889 name: "obj",
1890 recovery_available: true,
1891 }
1892`
1893 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001894 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jose Galmesf7294582020-11-13 12:07:36 -08001895 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1896 ctx := testCcWithConfig(t, config)
1897
1898 // Check Recovery snapshot output.
1899
1900 snapshotDir := "recovery-snapshot"
1901 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1902 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1903
1904 var jsonFiles []string
1905
1906 for _, arch := range [][]string{
1907 []string{"arm64", "armv8-a"},
1908 } {
1909 archType := arch[0]
1910 archVariant := arch[1]
1911 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1912
1913 // For shared libraries, only recovery_available modules are captured.
1914 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1915 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1916 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1917 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1918 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1919 jsonFiles = append(jsonFiles,
1920 filepath.Join(sharedDir, "libvndk.so.json"),
1921 filepath.Join(sharedDir, "librecovery.so.json"),
1922 filepath.Join(sharedDir, "librecovery_available.so.json"))
1923
1924 // For static libraries, all recovery:true and recovery_available modules are captured.
1925 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1926 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1927 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1928 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1929 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1930 jsonFiles = append(jsonFiles,
1931 filepath.Join(staticDir, "libb.a.json"),
1932 filepath.Join(staticDir, "librecovery.a.json"),
1933 filepath.Join(staticDir, "librecovery_available.a.json"))
1934
1935 // For binary executables, all recovery:true and recovery_available modules are captured.
1936 if archType == "arm64" {
1937 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1938 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1939 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1940 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1941 jsonFiles = append(jsonFiles,
1942 filepath.Join(binaryDir, "recovery_bin.json"),
1943 filepath.Join(binaryDir, "recovery_available_bin.json"))
1944 }
1945
1946 // For header libraries, all vendor:true and vendor_available modules are captured.
1947 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1948 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1949
1950 // For object modules, all vendor:true and vendor_available modules are captured.
1951 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1952 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1953 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1954 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1955 }
1956
1957 for _, jsonFile := range jsonFiles {
1958 // verify all json files exist
1959 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1960 t.Errorf("%q expected but not found", jsonFile)
1961 }
1962 }
1963}
1964
Jose Galmes6f843bc2020-12-11 13:36:29 -08001965func TestRecoverySnapshotExclude(t *testing.T) {
1966 // This test verifies that the exclude_from_recovery_snapshot property
1967 // makes its way from the Android.bp source file into the module data
1968 // structure. It also verifies that modules are correctly included or
1969 // excluded in the recovery snapshot based on their path (framework or
1970 // vendor) and the exclude_from_recovery_snapshot property.
1971
1972 frameworkBp := `
1973 cc_library_shared {
1974 name: "libinclude",
1975 srcs: ["src/include.cpp"],
1976 recovery_available: true,
1977 }
1978 cc_library_shared {
1979 name: "libexclude",
1980 srcs: ["src/exclude.cpp"],
1981 recovery: true,
1982 exclude_from_recovery_snapshot: true,
1983 }
1984 `
1985
1986 vendorProprietaryBp := `
1987 cc_library_shared {
1988 name: "libvendor",
1989 srcs: ["vendor.cpp"],
1990 recovery: true,
1991 }
1992 `
1993
1994 depsBp := GatherRequiredDepsForTest(android.Android)
1995
1996 mockFS := map[string][]byte{
1997 "deps/Android.bp": []byte(depsBp),
1998 "framework/Android.bp": []byte(frameworkBp),
1999 "framework/include.cpp": nil,
2000 "framework/exclude.cpp": nil,
2001 "device/Android.bp": []byte(vendorProprietaryBp),
2002 "device/vendor.cpp": nil,
2003 }
2004
2005 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
2006 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
2007 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2008 ctx := CreateTestContext(config)
2009 ctx.Register()
2010
2011 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
2012 android.FailIfErrored(t, errs)
2013 _, errs = ctx.PrepareBuildActions(config)
2014 android.FailIfErrored(t, errs)
2015
2016 // Test an include and exclude framework module.
2017 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
2018 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", recoveryVariant).Module().(*Module), false)
2019 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libexclude", recoveryVariant).Module().(*Module), true)
2020
2021 // A vendor module is excluded, but by its path, not the
2022 // exclude_from_recovery_snapshot property.
2023 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libvendor", recoveryVariant).Module().(*Module), false)
2024
2025 // Verify the content of the recovery snapshot.
2026
2027 snapshotDir := "recovery-snapshot"
2028 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
2029 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
2030
2031 var includeJsonFiles []string
2032 var excludeJsonFiles []string
2033
2034 for _, arch := range [][]string{
2035 []string{"arm64", "armv8-a"},
2036 } {
2037 archType := arch[0]
2038 archVariant := arch[1]
2039 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
2040
2041 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
2042 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
2043
2044 // Included modules
2045 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
2046 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
2047
2048 // Excluded modules
2049 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
2050 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
2051 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
2052 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
2053 }
2054
2055 // Verify that each json file for an included module has a rule.
2056 for _, jsonFile := range includeJsonFiles {
2057 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
2058 t.Errorf("include json file %q not found", jsonFile)
2059 }
2060 }
2061
2062 // Verify that each json file for an excluded module has no rule.
2063 for _, jsonFile := range excludeJsonFiles {
2064 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
2065 t.Errorf("exclude json file %q found", jsonFile)
2066 }
2067 }
2068}
2069
Jooyung Hana70f0672019-01-18 15:20:43 +09002070func TestDoubleLoadableDepError(t *testing.T) {
2071 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
2072 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2073 cc_library {
2074 name: "libllndk",
2075 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07002076 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002077 }
2078
2079 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002080 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002081 symbol_file: "",
2082 }
2083
2084 cc_library {
2085 name: "libnondoubleloadable",
2086 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002087 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002088 vndk: {
2089 enabled: true,
2090 },
2091 }
2092 `)
2093
2094 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
2095 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2096 cc_library {
2097 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07002098 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002099 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07002100 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002101 }
2102
2103 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002104 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002105 symbol_file: "",
2106 }
2107
2108 cc_library {
2109 name: "libnondoubleloadable",
2110 vendor_available: true,
2111 }
2112 `)
2113
Jooyung Hana70f0672019-01-18 15:20:43 +09002114 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
2115 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2116 cc_library {
2117 name: "libllndk",
2118 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07002119 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002120 }
2121
2122 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002123 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002124 symbol_file: "",
2125 }
2126
2127 cc_library {
2128 name: "libcoreonly",
2129 shared_libs: ["libvendoravailable"],
2130 }
2131
2132 // indirect dependency of LLNDK
2133 cc_library {
2134 name: "libvendoravailable",
2135 vendor_available: true,
2136 }
2137 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09002138
2139 // The error is not from 'client' but from 'libllndk'
2140 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
2141 cc_library {
2142 name: "client",
2143 vendor_available: true,
2144 double_loadable: true,
2145 shared_libs: ["libllndk"],
2146 }
2147 cc_library {
2148 name: "libllndk",
2149 shared_libs: ["libnondoubleloadable"],
2150 llndk_stubs: "libllndk.llndk",
2151 }
2152 llndk_library {
2153 name: "libllndk.llndk",
2154 symbol_file: "",
2155 }
2156 cc_library {
2157 name: "libnondoubleloadable",
2158 vendor_available: true,
2159 }
2160 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08002161}
2162
Jooyung Han479ca172020-10-19 18:51:07 +09002163func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
2164 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
2165 cc_library {
2166 name: "libvndksp",
2167 shared_libs: ["libanothervndksp"],
2168 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002169 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09002170 vndk: {
2171 enabled: true,
2172 support_system_process: true,
2173 }
2174 }
2175
2176 cc_library {
2177 name: "libllndk",
2178 shared_libs: ["libanothervndksp"],
2179 }
2180
2181 llndk_library {
2182 name: "libllndk",
2183 symbol_file: "",
2184 }
2185
2186 cc_library {
2187 name: "libanothervndksp",
2188 vendor_available: true,
2189 }
2190 `)
2191}
2192
Logan Chienf3511742017-10-31 18:04:35 +08002193func TestVndkExt(t *testing.T) {
2194 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002195 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08002196 cc_library {
2197 name: "libvndk",
2198 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002199 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002200 vndk: {
2201 enabled: true,
2202 },
2203 nocrt: true,
2204 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002205 cc_library {
2206 name: "libvndk2",
2207 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002208 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09002209 vndk: {
2210 enabled: true,
2211 },
2212 target: {
2213 vendor: {
2214 suffix: "-suffix",
2215 },
Justin Yun63e9ec72020-10-29 16:49:43 +09002216 product: {
2217 suffix: "-suffix",
2218 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09002219 },
2220 nocrt: true,
2221 }
Logan Chienf3511742017-10-31 18:04:35 +08002222
2223 cc_library {
2224 name: "libvndk_ext",
2225 vendor: true,
2226 vndk: {
2227 enabled: true,
2228 extends: "libvndk",
2229 },
2230 nocrt: true,
2231 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002232
2233 cc_library {
2234 name: "libvndk2_ext",
2235 vendor: true,
2236 vndk: {
2237 enabled: true,
2238 extends: "libvndk2",
2239 },
2240 nocrt: true,
2241 }
Logan Chienf3511742017-10-31 18:04:35 +08002242
Justin Yun0ecf0b22020-02-28 15:07:59 +09002243 cc_library {
2244 name: "libvndk_ext_product",
2245 product_specific: true,
2246 vndk: {
2247 enabled: true,
2248 extends: "libvndk",
2249 },
2250 nocrt: true,
2251 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002252
Justin Yun0ecf0b22020-02-28 15:07:59 +09002253 cc_library {
2254 name: "libvndk2_ext_product",
2255 product_specific: true,
2256 vndk: {
2257 enabled: true,
2258 extends: "libvndk2",
2259 },
2260 nocrt: true,
2261 }
2262 `
2263 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2264 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2265 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2266 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2267
2268 ctx := testCcWithConfig(t, config)
2269
2270 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
2271 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
2272
2273 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
2274 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
2275
2276 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
2277 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08002278}
2279
Logan Chiend3c59a22018-03-29 14:08:15 +08002280func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08002281 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
2282 ctx := testCcNoVndk(t, `
2283 cc_library {
2284 name: "libvndk",
2285 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002286 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002287 vndk: {
2288 enabled: true,
2289 },
2290 nocrt: true,
2291 }
2292
2293 cc_library {
2294 name: "libvndk_ext",
2295 vendor: true,
2296 vndk: {
2297 enabled: true,
2298 extends: "libvndk",
2299 },
2300 nocrt: true,
2301 }
2302 `)
2303
2304 // Ensures that the core variant of "libvndk_ext" can be found.
2305 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
2306 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2307 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
2308 }
2309}
2310
Justin Yun0ecf0b22020-02-28 15:07:59 +09002311func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
2312 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09002313 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002314 cc_library {
2315 name: "libvndk",
2316 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002317 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002318 vndk: {
2319 enabled: true,
2320 },
2321 nocrt: true,
2322 }
2323
2324 cc_library {
2325 name: "libvndk_ext_product",
2326 product_specific: true,
2327 vndk: {
2328 enabled: true,
2329 extends: "libvndk",
2330 },
2331 nocrt: true,
2332 }
2333 `)
2334
2335 // Ensures that the core variant of "libvndk_ext_product" can be found.
2336 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
2337 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2338 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
2339 }
2340}
2341
Logan Chienf3511742017-10-31 18:04:35 +08002342func TestVndkExtError(t *testing.T) {
2343 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002344 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08002345 cc_library {
2346 name: "libvndk",
2347 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002348 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002349 vndk: {
2350 enabled: true,
2351 },
2352 nocrt: true,
2353 }
2354
2355 cc_library {
2356 name: "libvndk_ext",
2357 vndk: {
2358 enabled: true,
2359 extends: "libvndk",
2360 },
2361 nocrt: true,
2362 }
2363 `)
2364
2365 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2366 cc_library {
2367 name: "libvndk",
2368 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002369 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002370 vndk: {
2371 enabled: true,
2372 },
2373 nocrt: true,
2374 }
2375
2376 cc_library {
2377 name: "libvndk_ext",
2378 vendor: true,
2379 vndk: {
2380 enabled: true,
2381 },
2382 nocrt: true,
2383 }
2384 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002385
2386 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2387 cc_library {
2388 name: "libvndk",
2389 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002390 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002391 vndk: {
2392 enabled: true,
2393 },
2394 nocrt: true,
2395 }
2396
2397 cc_library {
2398 name: "libvndk_ext_product",
2399 product_specific: true,
2400 vndk: {
2401 enabled: true,
2402 },
2403 nocrt: true,
2404 }
2405 `)
2406
2407 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
2408 cc_library {
2409 name: "libvndk",
2410 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002411 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002412 vndk: {
2413 enabled: true,
2414 },
2415 nocrt: true,
2416 }
2417
2418 cc_library {
2419 name: "libvndk_ext_product",
2420 product_specific: true,
2421 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002422 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002423 vndk: {
2424 enabled: true,
2425 extends: "libvndk",
2426 },
2427 nocrt: true,
2428 }
2429 `)
Logan Chienf3511742017-10-31 18:04:35 +08002430}
2431
2432func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
2433 // This test ensures an error is emitted for inconsistent support_system_process.
2434 testCcError(t, "module \".*\" with mismatched support_system_process", `
2435 cc_library {
2436 name: "libvndk",
2437 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002438 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002439 vndk: {
2440 enabled: true,
2441 },
2442 nocrt: true,
2443 }
2444
2445 cc_library {
2446 name: "libvndk_sp_ext",
2447 vendor: true,
2448 vndk: {
2449 enabled: true,
2450 extends: "libvndk",
2451 support_system_process: true,
2452 },
2453 nocrt: true,
2454 }
2455 `)
2456
2457 testCcError(t, "module \".*\" with mismatched support_system_process", `
2458 cc_library {
2459 name: "libvndk_sp",
2460 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002461 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002462 vndk: {
2463 enabled: true,
2464 support_system_process: true,
2465 },
2466 nocrt: true,
2467 }
2468
2469 cc_library {
2470 name: "libvndk_ext",
2471 vendor: true,
2472 vndk: {
2473 enabled: true,
2474 extends: "libvndk_sp",
2475 },
2476 nocrt: true,
2477 }
2478 `)
2479}
2480
2481func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08002482 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09002483 // with `private: true`.
2484 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08002485 cc_library {
2486 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002487 vendor_available: true,
2488 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002489 vndk: {
2490 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002491 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08002492 },
2493 nocrt: true,
2494 }
2495
2496 cc_library {
2497 name: "libvndk_ext",
2498 vendor: true,
2499 vndk: {
2500 enabled: true,
2501 extends: "libvndk",
2502 },
2503 nocrt: true,
2504 }
2505 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002506
Justin Yunfd9e8042020-12-23 18:23:14 +09002507 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002508 cc_library {
2509 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002510 vendor_available: true,
2511 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002512 vndk: {
2513 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002514 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002515 },
2516 nocrt: true,
2517 }
2518
2519 cc_library {
2520 name: "libvndk_ext_product",
2521 product_specific: true,
2522 vndk: {
2523 enabled: true,
2524 extends: "libvndk",
2525 },
2526 nocrt: true,
2527 }
2528 `)
Logan Chienf3511742017-10-31 18:04:35 +08002529}
2530
Logan Chiend3c59a22018-03-29 14:08:15 +08002531func TestVendorModuleUseVndkExt(t *testing.T) {
2532 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002533 testCc(t, `
2534 cc_library {
2535 name: "libvndk",
2536 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002537 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002538 vndk: {
2539 enabled: true,
2540 },
2541 nocrt: true,
2542 }
2543
2544 cc_library {
2545 name: "libvndk_ext",
2546 vendor: true,
2547 vndk: {
2548 enabled: true,
2549 extends: "libvndk",
2550 },
2551 nocrt: true,
2552 }
2553
2554 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08002555 name: "libvndk_sp",
2556 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002557 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002558 vndk: {
2559 enabled: true,
2560 support_system_process: true,
2561 },
2562 nocrt: true,
2563 }
2564
2565 cc_library {
2566 name: "libvndk_sp_ext",
2567 vendor: true,
2568 vndk: {
2569 enabled: true,
2570 extends: "libvndk_sp",
2571 support_system_process: true,
2572 },
2573 nocrt: true,
2574 }
2575
2576 cc_library {
2577 name: "libvendor",
2578 vendor: true,
2579 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
2580 nocrt: true,
2581 }
2582 `)
2583}
2584
Logan Chiend3c59a22018-03-29 14:08:15 +08002585func TestVndkExtUseVendorLib(t *testing.T) {
2586 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08002587 testCc(t, `
2588 cc_library {
2589 name: "libvndk",
2590 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002591 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002592 vndk: {
2593 enabled: true,
2594 },
2595 nocrt: true,
2596 }
2597
2598 cc_library {
2599 name: "libvndk_ext",
2600 vendor: true,
2601 vndk: {
2602 enabled: true,
2603 extends: "libvndk",
2604 },
2605 shared_libs: ["libvendor"],
2606 nocrt: true,
2607 }
2608
2609 cc_library {
2610 name: "libvendor",
2611 vendor: true,
2612 nocrt: true,
2613 }
2614 `)
Logan Chienf3511742017-10-31 18:04:35 +08002615
Logan Chiend3c59a22018-03-29 14:08:15 +08002616 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
2617 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08002618 cc_library {
2619 name: "libvndk_sp",
2620 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002621 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002622 vndk: {
2623 enabled: true,
2624 support_system_process: true,
2625 },
2626 nocrt: true,
2627 }
2628
2629 cc_library {
2630 name: "libvndk_sp_ext",
2631 vendor: true,
2632 vndk: {
2633 enabled: true,
2634 extends: "libvndk_sp",
2635 support_system_process: true,
2636 },
2637 shared_libs: ["libvendor"], // Cause an error
2638 nocrt: true,
2639 }
2640
2641 cc_library {
2642 name: "libvendor",
2643 vendor: true,
2644 nocrt: true,
2645 }
2646 `)
2647}
2648
Justin Yun0ecf0b22020-02-28 15:07:59 +09002649func TestProductVndkExtDependency(t *testing.T) {
2650 bp := `
2651 cc_library {
2652 name: "libvndk",
2653 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002654 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002655 vndk: {
2656 enabled: true,
2657 },
2658 nocrt: true,
2659 }
2660
2661 cc_library {
2662 name: "libvndk_ext_product",
2663 product_specific: true,
2664 vndk: {
2665 enabled: true,
2666 extends: "libvndk",
2667 },
2668 shared_libs: ["libproduct_for_vndklibs"],
2669 nocrt: true,
2670 }
2671
2672 cc_library {
2673 name: "libvndk_sp",
2674 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002675 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002676 vndk: {
2677 enabled: true,
2678 support_system_process: true,
2679 },
2680 nocrt: true,
2681 }
2682
2683 cc_library {
2684 name: "libvndk_sp_ext_product",
2685 product_specific: true,
2686 vndk: {
2687 enabled: true,
2688 extends: "libvndk_sp",
2689 support_system_process: true,
2690 },
2691 shared_libs: ["libproduct_for_vndklibs"],
2692 nocrt: true,
2693 }
2694
2695 cc_library {
2696 name: "libproduct",
2697 product_specific: true,
2698 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
2699 nocrt: true,
2700 }
2701
2702 cc_library {
2703 name: "libproduct_for_vndklibs",
2704 product_specific: true,
2705 nocrt: true,
2706 }
2707 `
2708 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2709 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2710 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2711 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2712
2713 testCcWithConfig(t, config)
2714}
2715
Logan Chiend3c59a22018-03-29 14:08:15 +08002716func TestVndkSpExtUseVndkError(t *testing.T) {
2717 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
2718 // library.
2719 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2720 cc_library {
2721 name: "libvndk",
2722 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002723 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002724 vndk: {
2725 enabled: true,
2726 },
2727 nocrt: true,
2728 }
2729
2730 cc_library {
2731 name: "libvndk_sp",
2732 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002733 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002734 vndk: {
2735 enabled: true,
2736 support_system_process: true,
2737 },
2738 nocrt: true,
2739 }
2740
2741 cc_library {
2742 name: "libvndk_sp_ext",
2743 vendor: true,
2744 vndk: {
2745 enabled: true,
2746 extends: "libvndk_sp",
2747 support_system_process: true,
2748 },
2749 shared_libs: ["libvndk"], // Cause an error
2750 nocrt: true,
2751 }
2752 `)
2753
2754 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
2755 // library.
2756 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2757 cc_library {
2758 name: "libvndk",
2759 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002760 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002761 vndk: {
2762 enabled: true,
2763 },
2764 nocrt: true,
2765 }
2766
2767 cc_library {
2768 name: "libvndk_ext",
2769 vendor: true,
2770 vndk: {
2771 enabled: true,
2772 extends: "libvndk",
2773 },
2774 nocrt: true,
2775 }
2776
2777 cc_library {
2778 name: "libvndk_sp",
2779 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002780 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002781 vndk: {
2782 enabled: true,
2783 support_system_process: true,
2784 },
2785 nocrt: true,
2786 }
2787
2788 cc_library {
2789 name: "libvndk_sp_ext",
2790 vendor: true,
2791 vndk: {
2792 enabled: true,
2793 extends: "libvndk_sp",
2794 support_system_process: true,
2795 },
2796 shared_libs: ["libvndk_ext"], // Cause an error
2797 nocrt: true,
2798 }
2799 `)
2800}
2801
2802func TestVndkUseVndkExtError(t *testing.T) {
2803 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
2804 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002805 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2806 cc_library {
2807 name: "libvndk",
2808 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002809 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002810 vndk: {
2811 enabled: true,
2812 },
2813 nocrt: true,
2814 }
2815
2816 cc_library {
2817 name: "libvndk_ext",
2818 vendor: true,
2819 vndk: {
2820 enabled: true,
2821 extends: "libvndk",
2822 },
2823 nocrt: true,
2824 }
2825
2826 cc_library {
2827 name: "libvndk2",
2828 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002829 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002830 vndk: {
2831 enabled: true,
2832 },
2833 shared_libs: ["libvndk_ext"],
2834 nocrt: true,
2835 }
2836 `)
2837
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002838 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002839 cc_library {
2840 name: "libvndk",
2841 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002842 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002843 vndk: {
2844 enabled: true,
2845 },
2846 nocrt: true,
2847 }
2848
2849 cc_library {
2850 name: "libvndk_ext",
2851 vendor: true,
2852 vndk: {
2853 enabled: true,
2854 extends: "libvndk",
2855 },
2856 nocrt: true,
2857 }
2858
2859 cc_library {
2860 name: "libvndk2",
2861 vendor_available: true,
2862 vndk: {
2863 enabled: true,
2864 },
2865 target: {
2866 vendor: {
2867 shared_libs: ["libvndk_ext"],
2868 },
2869 },
2870 nocrt: true,
2871 }
2872 `)
2873
2874 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2875 cc_library {
2876 name: "libvndk_sp",
2877 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002878 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002879 vndk: {
2880 enabled: true,
2881 support_system_process: true,
2882 },
2883 nocrt: true,
2884 }
2885
2886 cc_library {
2887 name: "libvndk_sp_ext",
2888 vendor: true,
2889 vndk: {
2890 enabled: true,
2891 extends: "libvndk_sp",
2892 support_system_process: true,
2893 },
2894 nocrt: true,
2895 }
2896
2897 cc_library {
2898 name: "libvndk_sp_2",
2899 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002900 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002901 vndk: {
2902 enabled: true,
2903 support_system_process: true,
2904 },
2905 shared_libs: ["libvndk_sp_ext"],
2906 nocrt: true,
2907 }
2908 `)
2909
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002910 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002911 cc_library {
2912 name: "libvndk_sp",
2913 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002914 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002915 vndk: {
2916 enabled: true,
2917 },
2918 nocrt: true,
2919 }
2920
2921 cc_library {
2922 name: "libvndk_sp_ext",
2923 vendor: true,
2924 vndk: {
2925 enabled: true,
2926 extends: "libvndk_sp",
2927 },
2928 nocrt: true,
2929 }
2930
2931 cc_library {
2932 name: "libvndk_sp2",
2933 vendor_available: true,
2934 vndk: {
2935 enabled: true,
2936 },
2937 target: {
2938 vendor: {
2939 shared_libs: ["libvndk_sp_ext"],
2940 },
2941 },
2942 nocrt: true,
2943 }
2944 `)
2945}
2946
Justin Yun5f7f7e82019-11-18 19:52:14 +09002947func TestEnforceProductVndkVersion(t *testing.T) {
2948 bp := `
2949 cc_library {
2950 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002951 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002952 }
2953 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002954 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002955 symbol_file: "",
2956 }
2957 cc_library {
2958 name: "libvndk",
2959 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002960 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002961 vndk: {
2962 enabled: true,
2963 },
2964 nocrt: true,
2965 }
2966 cc_library {
2967 name: "libvndk_sp",
2968 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002969 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002970 vndk: {
2971 enabled: true,
2972 support_system_process: true,
2973 },
2974 nocrt: true,
2975 }
2976 cc_library {
2977 name: "libva",
2978 vendor_available: true,
2979 nocrt: true,
2980 }
2981 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002982 name: "libpa",
2983 product_available: true,
2984 nocrt: true,
2985 }
2986 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002987 name: "libboth_available",
2988 vendor_available: true,
2989 product_available: true,
2990 nocrt: true,
2991 target: {
2992 vendor: {
2993 suffix: "-vendor",
2994 },
2995 product: {
2996 suffix: "-product",
2997 },
2998 }
2999 }
3000 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003001 name: "libproduct_va",
3002 product_specific: true,
3003 vendor_available: true,
3004 nocrt: true,
3005 }
3006 cc_library {
3007 name: "libprod",
3008 product_specific: true,
3009 shared_libs: [
3010 "libllndk",
3011 "libvndk",
3012 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09003013 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09003014 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09003015 "libproduct_va",
3016 ],
3017 nocrt: true,
3018 }
3019 cc_library {
3020 name: "libvendor",
3021 vendor: true,
3022 shared_libs: [
3023 "libllndk",
3024 "libvndk",
3025 "libvndk_sp",
3026 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09003027 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09003028 "libproduct_va",
3029 ],
3030 nocrt: true,
3031 }
3032 `
3033
3034 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3035 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3036 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
3037 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3038
3039 ctx := testCcWithConfig(t, config)
3040
Jooyung Han261e1582020-10-20 18:54:21 +09003041 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
3042 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09003043
3044 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
3045 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
3046
3047 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
3048 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09003049}
3050
3051func TestEnforceProductVndkVersionErrors(t *testing.T) {
3052 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3053 cc_library {
3054 name: "libprod",
3055 product_specific: true,
3056 shared_libs: [
3057 "libvendor",
3058 ],
3059 nocrt: true,
3060 }
3061 cc_library {
3062 name: "libvendor",
3063 vendor: true,
3064 nocrt: true,
3065 }
3066 `)
3067 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3068 cc_library {
3069 name: "libprod",
3070 product_specific: true,
3071 shared_libs: [
3072 "libsystem",
3073 ],
3074 nocrt: true,
3075 }
3076 cc_library {
3077 name: "libsystem",
3078 nocrt: true,
3079 }
3080 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09003081 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3082 cc_library {
3083 name: "libprod",
3084 product_specific: true,
3085 shared_libs: [
3086 "libva",
3087 ],
3088 nocrt: true,
3089 }
3090 cc_library {
3091 name: "libva",
3092 vendor_available: true,
3093 nocrt: true,
3094 }
3095 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09003096 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09003097 cc_library {
3098 name: "libprod",
3099 product_specific: true,
3100 shared_libs: [
3101 "libvndk_private",
3102 ],
3103 nocrt: true,
3104 }
3105 cc_library {
3106 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09003107 vendor_available: true,
3108 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003109 vndk: {
3110 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09003111 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003112 },
3113 nocrt: true,
3114 }
3115 `)
3116 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3117 cc_library {
3118 name: "libprod",
3119 product_specific: true,
3120 shared_libs: [
3121 "libsystem_ext",
3122 ],
3123 nocrt: true,
3124 }
3125 cc_library {
3126 name: "libsystem_ext",
3127 system_ext_specific: true,
3128 nocrt: true,
3129 }
3130 `)
3131 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
3132 cc_library {
3133 name: "libsystem",
3134 shared_libs: [
3135 "libproduct_va",
3136 ],
3137 nocrt: true,
3138 }
3139 cc_library {
3140 name: "libproduct_va",
3141 product_specific: true,
3142 vendor_available: true,
3143 nocrt: true,
3144 }
3145 `)
3146}
3147
Jooyung Han38002912019-05-16 04:01:54 +09003148func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08003149 bp := `
3150 cc_library {
3151 name: "libvndk",
3152 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003153 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003154 vndk: {
3155 enabled: true,
3156 },
3157 }
3158 cc_library {
3159 name: "libvndksp",
3160 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003161 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003162 vndk: {
3163 enabled: true,
3164 support_system_process: true,
3165 },
3166 }
3167 cc_library {
3168 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09003169 vendor_available: true,
3170 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003171 vndk: {
3172 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09003173 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003174 },
3175 }
3176 cc_library {
3177 name: "libvendor",
3178 vendor: true,
3179 }
3180 cc_library {
3181 name: "libvndkext",
3182 vendor: true,
3183 vndk: {
3184 enabled: true,
3185 extends: "libvndk",
3186 },
3187 }
3188 vndk_prebuilt_shared {
3189 name: "prevndk",
3190 version: "27",
3191 target_arch: "arm",
3192 binder32bit: true,
3193 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003194 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003195 vndk: {
3196 enabled: true,
3197 },
3198 arch: {
3199 arm: {
3200 srcs: ["liba.so"],
3201 },
3202 },
3203 }
3204 cc_library {
3205 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07003206 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003207 }
3208 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003209 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003210 symbol_file: "",
3211 }
3212 cc_library {
3213 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07003214 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003215 }
3216 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003217 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09003218 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003219 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08003220 }
3221
3222 llndk_libraries_txt {
3223 name: "llndk.libraries.txt",
3224 }
3225 vndkcore_libraries_txt {
3226 name: "vndkcore.libraries.txt",
3227 }
3228 vndksp_libraries_txt {
3229 name: "vndksp.libraries.txt",
3230 }
3231 vndkprivate_libraries_txt {
3232 name: "vndkprivate.libraries.txt",
3233 }
3234 vndkcorevariant_libraries_txt {
3235 name: "vndkcorevariant.libraries.txt",
3236 insert_vndk_version: false,
3237 }
3238 `
Colin Cross98be1bb2019-12-13 20:41:13 -08003239
3240 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09003241 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3242 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3243 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08003244 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09003245
Colin Cross78212242021-01-06 14:51:30 -08003246 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
3247 []string{"libvndk.so", "libvndkprivate.so"})
3248 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
3249 []string{"libc++.so", "libvndksp.so"})
3250 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
3251 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
3252 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
3253 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09003254
Colin Crossfb0c16e2019-11-20 17:12:35 -08003255 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09003256
Jooyung Han38002912019-05-16 04:01:54 +09003257 tests := []struct {
3258 variant string
3259 name string
3260 expected string
3261 }{
3262 {vendorVariant, "libvndk", "native:vndk"},
3263 {vendorVariant, "libvndksp", "native:vndk"},
3264 {vendorVariant, "libvndkprivate", "native:vndk_private"},
3265 {vendorVariant, "libvendor", "native:vendor"},
3266 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08003267 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09003268 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09003269 {coreVariant, "libvndk", "native:platform"},
3270 {coreVariant, "libvndkprivate", "native:platform"},
3271 {coreVariant, "libllndk", "native:platform"},
3272 }
3273 for _, test := range tests {
3274 t.Run(test.name, func(t *testing.T) {
3275 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
3276 assertString(t, module.makeLinkType, test.expected)
3277 })
3278 }
3279}
3280
Jeff Gaston294356f2017-09-27 17:05:30 -07003281var staticLinkDepOrderTestCases = []struct {
3282 // This is a string representation of a map[moduleName][]moduleDependency .
3283 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003284 inStatic string
3285
3286 // This is a string representation of a map[moduleName][]moduleDependency .
3287 // It models the dependencies declared in an Android.bp file.
3288 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07003289
3290 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
3291 // The keys of allOrdered specify which modules we would like to check.
3292 // The values of allOrdered specify the expected result (of the transitive closure of all
3293 // dependencies) for each module to test
3294 allOrdered string
3295
3296 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
3297 // The keys of outOrdered specify which modules we would like to check.
3298 // The values of outOrdered specify the expected result (of the ordered linker command line)
3299 // for each module to test.
3300 outOrdered string
3301}{
3302 // Simple tests
3303 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003304 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07003305 outOrdered: "",
3306 },
3307 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003308 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003309 outOrdered: "a:",
3310 },
3311 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003312 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003313 outOrdered: "a:b; b:",
3314 },
3315 // Tests of reordering
3316 {
3317 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003318 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003319 outOrdered: "a:b,c,d; b:d; c:d; d:",
3320 },
3321 {
3322 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003323 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003324 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
3325 },
3326 {
3327 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003328 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07003329 outOrdered: "a:d,b,e,c; d:b; e:c",
3330 },
3331 {
3332 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003333 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07003334 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
3335 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
3336 },
3337 {
3338 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003339 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 -07003340 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3341 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3342 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003343 // shared dependencies
3344 {
3345 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
3346 // So, we don't actually have to check that a shared dependency of c will change the order
3347 // of a library that depends statically on b and on c. We only need to check that if c has
3348 // a shared dependency on b, that that shows up in allOrdered.
3349 inShared: "c:b",
3350 allOrdered: "c:b",
3351 outOrdered: "c:",
3352 },
3353 {
3354 // This test doesn't actually include any shared dependencies but it's a reminder of what
3355 // the second phase of the above test would look like
3356 inStatic: "a:b,c; c:b",
3357 allOrdered: "a:c,b; c:b",
3358 outOrdered: "a:c,b; c:b",
3359 },
Jeff Gaston294356f2017-09-27 17:05:30 -07003360 // tiebreakers for when two modules specifying different orderings and there is no dependency
3361 // to dictate an order
3362 {
3363 // 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 -08003364 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07003365 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
3366 },
3367 {
3368 // 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 -08003369 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 -07003370 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
3371 },
3372 // Tests involving duplicate dependencies
3373 {
3374 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003375 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003376 outOrdered: "a:c,b",
3377 },
3378 {
3379 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003380 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003381 outOrdered: "a:d,c,b",
3382 },
3383 // Tests to confirm the nonexistence of infinite loops.
3384 // These cases should never happen, so as long as the test terminates and the
3385 // result is deterministic then that should be fine.
3386 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003387 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003388 outOrdered: "a:a",
3389 },
3390 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003391 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003392 allOrdered: "a:b,c; b:c,a; c:a,b",
3393 outOrdered: "a:b; b:c; c:a",
3394 },
3395 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003396 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003397 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
3398 outOrdered: "a:c,b; b:a,c; c:b,a",
3399 },
3400}
3401
3402// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
3403func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
3404 // convert from "a:b,c; d:e" to "a:b,c;d:e"
3405 strippedText := strings.Replace(text, " ", "", -1)
3406 if len(strippedText) < 1 {
3407 return []android.Path{}, make(map[android.Path][]android.Path, 0)
3408 }
3409 allDeps = make(map[android.Path][]android.Path, 0)
3410
3411 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
3412 moduleTexts := strings.Split(strippedText, ";")
3413
3414 outputForModuleName := func(moduleName string) android.Path {
3415 return android.PathForTesting(moduleName)
3416 }
3417
3418 for _, moduleText := range moduleTexts {
3419 // convert from "a:b,c" to ["a", "b,c"]
3420 components := strings.Split(moduleText, ":")
3421 if len(components) != 2 {
3422 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
3423 }
3424 moduleName := components[0]
3425 moduleOutput := outputForModuleName(moduleName)
3426 modulesInOrder = append(modulesInOrder, moduleOutput)
3427
3428 depString := components[1]
3429 // convert from "b,c" to ["b", "c"]
3430 depNames := strings.Split(depString, ",")
3431 if len(depString) < 1 {
3432 depNames = []string{}
3433 }
3434 var deps []android.Path
3435 for _, depName := range depNames {
3436 deps = append(deps, outputForModuleName(depName))
3437 }
3438 allDeps[moduleOutput] = deps
3439 }
3440 return modulesInOrder, allDeps
3441}
3442
Jeff Gaston294356f2017-09-27 17:05:30 -07003443func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
3444 for _, moduleName := range moduleNames {
3445 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
3446 output := module.outputFile.Path()
3447 paths = append(paths, output)
3448 }
3449 return paths
3450}
3451
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003452func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07003453 ctx := testCc(t, `
3454 cc_library {
3455 name: "a",
3456 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09003457 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003458 }
3459 cc_library {
3460 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003461 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003462 }
3463 cc_library {
3464 name: "c",
3465 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003466 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003467 }
3468 cc_library {
3469 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09003470 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003471 }
3472
3473 `)
3474
Colin Cross7113d202019-11-20 16:39:12 -08003475 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07003476 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003477 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3478 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07003479
3480 if !reflect.DeepEqual(actual, expected) {
3481 t.Errorf("staticDeps orderings were not propagated correctly"+
3482 "\nactual: %v"+
3483 "\nexpected: %v",
3484 actual,
3485 expected,
3486 )
3487 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09003488}
Jeff Gaston294356f2017-09-27 17:05:30 -07003489
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003490func TestStaticLibDepReorderingWithShared(t *testing.T) {
3491 ctx := testCc(t, `
3492 cc_library {
3493 name: "a",
3494 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09003495 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003496 }
3497 cc_library {
3498 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003499 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003500 }
3501 cc_library {
3502 name: "c",
3503 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003504 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003505 }
3506
3507 `)
3508
Colin Cross7113d202019-11-20 16:39:12 -08003509 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003510 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003511 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3512 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003513
3514 if !reflect.DeepEqual(actual, expected) {
3515 t.Errorf("staticDeps orderings did not account for shared libs"+
3516 "\nactual: %v"+
3517 "\nexpected: %v",
3518 actual,
3519 expected,
3520 )
3521 }
3522}
3523
Jooyung Hanb04a4992020-03-13 18:57:35 +09003524func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07003525 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09003526 if !reflect.DeepEqual(actual, expected) {
3527 t.Errorf(message+
3528 "\nactual: %v"+
3529 "\nexpected: %v",
3530 actual,
3531 expected,
3532 )
3533 }
3534}
3535
Jooyung Han61b66e92020-03-21 14:21:46 +00003536func TestLlndkLibrary(t *testing.T) {
3537 ctx := testCc(t, `
3538 cc_library {
3539 name: "libllndk",
3540 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07003541 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003542 }
3543 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003544 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003545 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003546
3547 cc_prebuilt_library_shared {
3548 name: "libllndkprebuilt",
3549 stubs: { versions: ["1", "2"] },
3550 llndk_stubs: "libllndkprebuilt.llndk",
3551 }
3552 llndk_library {
3553 name: "libllndkprebuilt.llndk",
3554 }
3555
3556 cc_library {
3557 name: "libllndk_with_external_headers",
3558 stubs: { versions: ["1", "2"] },
3559 llndk_stubs: "libllndk_with_external_headers.llndk",
3560 header_libs: ["libexternal_headers"],
3561 export_header_lib_headers: ["libexternal_headers"],
3562 }
3563 llndk_library {
3564 name: "libllndk_with_external_headers.llndk",
3565 }
3566 cc_library_headers {
3567 name: "libexternal_headers",
3568 export_include_dirs: ["include"],
3569 vendor_available: true,
3570 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003571 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08003572 actual := ctx.ModuleVariantsForTests("libllndk")
3573 for i := 0; i < len(actual); i++ {
3574 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
3575 actual = append(actual[:i], actual[i+1:]...)
3576 i--
3577 }
3578 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003579 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00003580 "android_vendor.VER_arm64_armv8-a_shared_1",
3581 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003582 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003583 "android_vendor.VER_arm_armv7-a-neon_shared_1",
3584 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003585 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003586 }
3587 checkEquals(t, "variants for llndk stubs", expected, actual)
3588
Colin Cross127bb8b2020-12-16 16:46:01 -08003589 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003590 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
3591
Colin Cross127bb8b2020-12-16 16:46:01 -08003592 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003593 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
3594}
3595
Jiyong Parka46a4d52017-12-14 19:54:34 +09003596func TestLlndkHeaders(t *testing.T) {
3597 ctx := testCc(t, `
3598 llndk_headers {
3599 name: "libllndk_headers",
3600 export_include_dirs: ["my_include"],
3601 }
3602 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003603 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09003604 export_llndk_headers: ["libllndk_headers"],
3605 }
3606 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07003607 name: "libllndk",
3608 llndk_stubs: "libllndk.llndk",
3609 }
3610
3611 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09003612 name: "libvendor",
3613 shared_libs: ["libllndk"],
3614 vendor: true,
3615 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003616 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08003617 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09003618 }
3619 `)
3620
3621 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08003622 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09003623 cflags := cc.Args["cFlags"]
3624 if !strings.Contains(cflags, "-Imy_include") {
3625 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
3626 }
3627}
3628
Logan Chien43d34c32017-12-20 01:17:32 +08003629func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
3630 actual := module.Properties.AndroidMkRuntimeLibs
3631 if !reflect.DeepEqual(actual, expected) {
3632 t.Errorf("incorrect runtime_libs for shared libs"+
3633 "\nactual: %v"+
3634 "\nexpected: %v",
3635 actual,
3636 expected,
3637 )
3638 }
3639}
3640
3641const runtimeLibAndroidBp = `
3642 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09003643 name: "liball_available",
3644 vendor_available: true,
3645 product_available: true,
3646 no_libcrt : true,
3647 nocrt : true,
3648 system_shared_libs : [],
3649 }
3650 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08003651 name: "libvendor_available1",
3652 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003653 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07003654 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003655 nocrt : true,
3656 system_shared_libs : [],
3657 }
3658 cc_library {
3659 name: "libvendor_available2",
3660 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003661 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08003662 target: {
3663 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09003664 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08003665 }
3666 },
Yi Konge7fe9912019-06-02 00:53:50 -07003667 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003668 nocrt : true,
3669 system_shared_libs : [],
3670 }
3671 cc_library {
3672 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09003673 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07003674 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003675 nocrt : true,
3676 system_shared_libs : [],
3677 }
3678 cc_library {
3679 name: "libvendor1",
3680 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003681 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003682 nocrt : true,
3683 system_shared_libs : [],
3684 }
3685 cc_library {
3686 name: "libvendor2",
3687 vendor: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003688 runtime_libs: ["liball_available", "libvendor1"],
3689 no_libcrt : true,
3690 nocrt : true,
3691 system_shared_libs : [],
3692 }
3693 cc_library {
3694 name: "libproduct_available1",
3695 product_available: true,
3696 runtime_libs: ["liball_available"],
3697 no_libcrt : true,
3698 nocrt : true,
3699 system_shared_libs : [],
3700 }
3701 cc_library {
3702 name: "libproduct1",
3703 product_specific: true,
3704 no_libcrt : true,
3705 nocrt : true,
3706 system_shared_libs : [],
3707 }
3708 cc_library {
3709 name: "libproduct2",
3710 product_specific: true,
3711 runtime_libs: ["liball_available", "libproduct1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003712 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003713 nocrt : true,
3714 system_shared_libs : [],
3715 }
3716`
3717
3718func TestRuntimeLibs(t *testing.T) {
3719 ctx := testCc(t, runtimeLibAndroidBp)
3720
3721 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08003722 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003723
Justin Yun8a2600c2020-12-07 12:44:03 +09003724 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3725 checkRuntimeLibs(t, []string{"liball_available"}, module)
3726
3727 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3728 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003729
3730 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003731 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003732
3733 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
3734 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08003735 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003736
Justin Yun8a2600c2020-12-07 12:44:03 +09003737 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3738 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003739
3740 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003741 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1"}, module)
3742
3743 // runtime_libs for product variants have '.product' suffixes if the modules have both core
3744 // and product variants.
3745 variant = "android_product.VER_arm64_armv8-a_shared"
3746
3747 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3748 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
3749
3750 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
3751 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003752}
3753
3754func TestExcludeRuntimeLibs(t *testing.T) {
3755 ctx := testCc(t, runtimeLibAndroidBp)
3756
Colin Cross7113d202019-11-20 16:39:12 -08003757 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003758 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3759 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003760
Colin Crossfb0c16e2019-11-20 17:12:35 -08003761 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003762 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08003763 checkRuntimeLibs(t, nil, module)
3764}
3765
3766func TestRuntimeLibsNoVndk(t *testing.T) {
3767 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
3768
3769 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
3770
Colin Cross7113d202019-11-20 16:39:12 -08003771 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003772
Justin Yun8a2600c2020-12-07 12:44:03 +09003773 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3774 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003775
3776 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003777 checkRuntimeLibs(t, []string{"liball_available", "libvendor1"}, module)
3778
3779 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
3780 checkRuntimeLibs(t, []string{"liball_available", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003781}
3782
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003783func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09003784 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003785 actual := module.Properties.AndroidMkStaticLibs
3786 if !reflect.DeepEqual(actual, expected) {
3787 t.Errorf("incorrect static_libs"+
3788 "\nactual: %v"+
3789 "\nexpected: %v",
3790 actual,
3791 expected,
3792 )
3793 }
3794}
3795
3796const staticLibAndroidBp = `
3797 cc_library {
3798 name: "lib1",
3799 }
3800 cc_library {
3801 name: "lib2",
3802 static_libs: ["lib1"],
3803 }
3804`
3805
3806func TestStaticLibDepExport(t *testing.T) {
3807 ctx := testCc(t, staticLibAndroidBp)
3808
3809 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003810 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003811 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003812 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003813
3814 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003815 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003816 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
3817 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003818 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003819}
3820
Jiyong Parkd08b6972017-09-26 10:50:54 +09003821var compilerFlagsTestCases = []struct {
3822 in string
3823 out bool
3824}{
3825 {
3826 in: "a",
3827 out: false,
3828 },
3829 {
3830 in: "-a",
3831 out: true,
3832 },
3833 {
3834 in: "-Ipath/to/something",
3835 out: false,
3836 },
3837 {
3838 in: "-isystempath/to/something",
3839 out: false,
3840 },
3841 {
3842 in: "--coverage",
3843 out: false,
3844 },
3845 {
3846 in: "-include a/b",
3847 out: true,
3848 },
3849 {
3850 in: "-include a/b c/d",
3851 out: false,
3852 },
3853 {
3854 in: "-DMACRO",
3855 out: true,
3856 },
3857 {
3858 in: "-DMAC RO",
3859 out: false,
3860 },
3861 {
3862 in: "-a -b",
3863 out: false,
3864 },
3865 {
3866 in: "-DMACRO=definition",
3867 out: true,
3868 },
3869 {
3870 in: "-DMACRO=defi nition",
3871 out: true, // TODO(jiyong): this should be false
3872 },
3873 {
3874 in: "-DMACRO(x)=x + 1",
3875 out: true,
3876 },
3877 {
3878 in: "-DMACRO=\"defi nition\"",
3879 out: true,
3880 },
3881}
3882
3883type mockContext struct {
3884 BaseModuleContext
3885 result bool
3886}
3887
3888func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3889 // CheckBadCompilerFlags calls this function when the flag should be rejected
3890 ctx.result = false
3891}
3892
3893func TestCompilerFlags(t *testing.T) {
3894 for _, testCase := range compilerFlagsTestCases {
3895 ctx := &mockContext{result: true}
3896 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3897 if ctx.result != testCase.out {
3898 t.Errorf("incorrect output:")
3899 t.Errorf(" input: %#v", testCase.in)
3900 t.Errorf(" expected: %#v", testCase.out)
3901 t.Errorf(" got: %#v", ctx.result)
3902 }
3903 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003904}
Jiyong Park374510b2018-03-19 18:23:01 +09003905
3906func TestVendorPublicLibraries(t *testing.T) {
3907 ctx := testCc(t, `
3908 cc_library_headers {
3909 name: "libvendorpublic_headers",
3910 export_include_dirs: ["my_include"],
3911 }
3912 vendor_public_library {
3913 name: "libvendorpublic",
3914 symbol_file: "",
3915 export_public_headers: ["libvendorpublic_headers"],
3916 }
3917 cc_library {
3918 name: "libvendorpublic",
3919 srcs: ["foo.c"],
3920 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003921 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003922 nocrt: true,
3923 }
3924
3925 cc_library {
3926 name: "libsystem",
3927 shared_libs: ["libvendorpublic"],
3928 vendor: false,
3929 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003930 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003931 nocrt: true,
3932 }
3933 cc_library {
3934 name: "libvendor",
3935 shared_libs: ["libvendorpublic"],
3936 vendor: true,
3937 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003938 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003939 nocrt: true,
3940 }
3941 `)
3942
Colin Cross7113d202019-11-20 16:39:12 -08003943 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003944 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003945
3946 // test if header search paths are correctly added
3947 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003948 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003949 cflags := cc.Args["cFlags"]
3950 if !strings.Contains(cflags, "-Imy_include") {
3951 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3952 }
3953
3954 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003955 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003956 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003957 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003958 if !strings.Contains(libflags, stubPaths[0].String()) {
3959 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3960 }
3961
3962 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003963 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003964 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003965 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003966 if !strings.Contains(libflags, stubPaths[0].String()) {
3967 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3968 }
3969
3970}
Jiyong Park37b25202018-07-11 10:49:27 +09003971
3972func TestRecovery(t *testing.T) {
3973 ctx := testCc(t, `
3974 cc_library_shared {
3975 name: "librecovery",
3976 recovery: true,
3977 }
3978 cc_library_shared {
3979 name: "librecovery32",
3980 recovery: true,
3981 compile_multilib:"32",
3982 }
Jiyong Park5baac542018-08-28 09:55:37 +09003983 cc_library_shared {
3984 name: "libHalInRecovery",
3985 recovery_available: true,
3986 vendor: true,
3987 }
Jiyong Park37b25202018-07-11 10:49:27 +09003988 `)
3989
3990 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003991 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003992 if len(variants) != 1 || !android.InList(arm64, variants) {
3993 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3994 }
3995
3996 variants = ctx.ModuleVariantsForTests("librecovery32")
3997 if android.InList(arm64, variants) {
3998 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3999 }
Jiyong Park5baac542018-08-28 09:55:37 +09004000
4001 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
4002 if !recoveryModule.Platform() {
4003 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
4004 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09004005}
Jiyong Park5baac542018-08-28 09:55:37 +09004006
Chris Parsons1f6d90f2020-06-17 16:10:42 -04004007func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
4008 bp := `
4009 cc_prebuilt_test_library_shared {
4010 name: "test_lib",
4011 relative_install_path: "foo/bar/baz",
4012 srcs: ["srcpath/dontusethispath/baz.so"],
4013 }
4014
4015 cc_test {
4016 name: "main_test",
4017 data_libs: ["test_lib"],
4018 gtest: false,
4019 }
4020 `
4021
4022 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4023 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
4024 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
4025 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
4026
4027 ctx := testCcWithConfig(t, config)
4028 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
4029 testBinary := module.(*Module).linker.(*testBinary)
4030 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
4031 if err != nil {
4032 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
4033 }
4034 if len(outputFiles) != 1 {
4035 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
4036 }
4037 if len(testBinary.dataPaths()) != 1 {
4038 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
4039 }
4040
4041 outputPath := outputFiles[0].String()
4042
4043 if !strings.HasSuffix(outputPath, "/main_test") {
4044 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
4045 }
4046 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
4047 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
4048 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
4049 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
4050 }
4051}
4052
Jiyong Park7ed9de32018-10-15 22:25:07 +09004053func TestVersionedStubs(t *testing.T) {
4054 ctx := testCc(t, `
4055 cc_library_shared {
4056 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09004057 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09004058 stubs: {
4059 symbol_file: "foo.map.txt",
4060 versions: ["1", "2", "3"],
4061 },
4062 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09004063
Jiyong Park7ed9de32018-10-15 22:25:07 +09004064 cc_library_shared {
4065 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09004066 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09004067 shared_libs: ["libFoo#1"],
4068 }`)
4069
4070 variants := ctx.ModuleVariantsForTests("libFoo")
4071 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08004072 "android_arm64_armv8-a_shared",
4073 "android_arm64_armv8-a_shared_1",
4074 "android_arm64_armv8-a_shared_2",
4075 "android_arm64_armv8-a_shared_3",
4076 "android_arm_armv7-a-neon_shared",
4077 "android_arm_armv7-a-neon_shared_1",
4078 "android_arm_armv7-a-neon_shared_2",
4079 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09004080 }
4081 variantsMismatch := false
4082 if len(variants) != len(expectedVariants) {
4083 variantsMismatch = true
4084 } else {
4085 for _, v := range expectedVariants {
4086 if !inList(v, variants) {
4087 variantsMismatch = false
4088 }
4089 }
4090 }
4091 if variantsMismatch {
4092 t.Errorf("variants of libFoo expected:\n")
4093 for _, v := range expectedVariants {
4094 t.Errorf("%q\n", v)
4095 }
4096 t.Errorf(", but got:\n")
4097 for _, v := range variants {
4098 t.Errorf("%q\n", v)
4099 }
4100 }
4101
Colin Cross7113d202019-11-20 16:39:12 -08004102 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09004103 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08004104 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09004105 if !strings.Contains(libFlags, libFoo1StubPath) {
4106 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
4107 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09004108
Colin Cross7113d202019-11-20 16:39:12 -08004109 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09004110 cFlags := libBarCompileRule.Args["cFlags"]
4111 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
4112 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
4113 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
4114 }
Jiyong Park37b25202018-07-11 10:49:27 +09004115}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004116
Jooyung Hanb04a4992020-03-13 18:57:35 +09004117func TestVersioningMacro(t *testing.T) {
4118 for _, tc := range []struct{ moduleName, expected string }{
4119 {"libc", "__LIBC_API__"},
4120 {"libfoo", "__LIBFOO_API__"},
4121 {"libfoo@1", "__LIBFOO_1_API__"},
4122 {"libfoo-v1", "__LIBFOO_V1_API__"},
4123 {"libfoo.v1", "__LIBFOO_V1_API__"},
4124 } {
4125 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
4126 }
4127}
4128
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004129func TestStaticExecutable(t *testing.T) {
4130 ctx := testCc(t, `
4131 cc_binary {
4132 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01004133 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004134 static_executable: true,
4135 }`)
4136
Colin Cross7113d202019-11-20 16:39:12 -08004137 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004138 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
4139 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07004140 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004141 for _, lib := range systemStaticLibs {
4142 if !strings.Contains(libFlags, lib) {
4143 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
4144 }
4145 }
4146 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
4147 for _, lib := range systemSharedLibs {
4148 if strings.Contains(libFlags, lib) {
4149 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
4150 }
4151 }
4152}
Jiyong Parke4bb9862019-02-01 00:31:10 +09004153
4154func TestStaticDepsOrderWithStubs(t *testing.T) {
4155 ctx := testCc(t, `
4156 cc_binary {
4157 name: "mybin",
4158 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07004159 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09004160 static_executable: true,
4161 stl: "none",
4162 }
4163
4164 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08004165 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09004166 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08004167 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09004168 stl: "none",
4169 }
4170
4171 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08004172 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09004173 srcs: ["foo.c"],
4174 stl: "none",
4175 stubs: {
4176 versions: ["1"],
4177 },
4178 }`)
4179
Colin Cross0de8a1e2020-09-18 14:15:30 -07004180 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
4181 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08004182 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09004183
4184 if !reflect.DeepEqual(actual, expected) {
4185 t.Errorf("staticDeps orderings were not propagated correctly"+
4186 "\nactual: %v"+
4187 "\nexpected: %v",
4188 actual,
4189 expected,
4190 )
4191 }
4192}
Jooyung Han38002912019-05-16 04:01:54 +09004193
Jooyung Hand48f3c32019-08-23 11:18:57 +09004194func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
4195 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
4196 cc_library {
4197 name: "libA",
4198 srcs: ["foo.c"],
4199 shared_libs: ["libB"],
4200 stl: "none",
4201 }
4202
4203 cc_library {
4204 name: "libB",
4205 srcs: ["foo.c"],
4206 enabled: false,
4207 stl: "none",
4208 }
4209 `)
4210}
4211
Mitch Phillipsda9a4632019-07-15 09:34:09 -07004212// Simple smoke test for the cc_fuzz target that ensures the rule compiles
4213// correctly.
4214func TestFuzzTarget(t *testing.T) {
4215 ctx := testCc(t, `
4216 cc_fuzz {
4217 name: "fuzz_smoke_test",
4218 srcs: ["foo.c"],
4219 }`)
4220
Paul Duffin075c4172019-12-19 19:06:13 +00004221 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07004222 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
4223}
4224
Jiyong Park29074592019-07-07 16:27:47 +09004225func TestAidl(t *testing.T) {
4226}
4227
Jooyung Han38002912019-05-16 04:01:54 +09004228func assertString(t *testing.T, got, expected string) {
4229 t.Helper()
4230 if got != expected {
4231 t.Errorf("expected %q got %q", expected, got)
4232 }
4233}
4234
4235func assertArrayString(t *testing.T, got, expected []string) {
4236 t.Helper()
4237 if len(got) != len(expected) {
4238 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
4239 return
4240 }
4241 for i := range got {
4242 if got[i] != expected[i] {
4243 t.Errorf("expected %d-th %q (%q) got %q (%q)",
4244 i, expected[i], expected, got[i], got)
4245 return
4246 }
4247 }
4248}
Colin Crosse1bb5d02019-09-24 14:55:04 -07004249
Jooyung Han0302a842019-10-30 18:43:49 +09004250func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
4251 t.Helper()
4252 assertArrayString(t, android.SortedStringKeys(m), expected)
4253}
4254
Colin Crosse1bb5d02019-09-24 14:55:04 -07004255func TestDefaults(t *testing.T) {
4256 ctx := testCc(t, `
4257 cc_defaults {
4258 name: "defaults",
4259 srcs: ["foo.c"],
4260 static: {
4261 srcs: ["bar.c"],
4262 },
4263 shared: {
4264 srcs: ["baz.c"],
4265 },
4266 }
4267
4268 cc_library_static {
4269 name: "libstatic",
4270 defaults: ["defaults"],
4271 }
4272
4273 cc_library_shared {
4274 name: "libshared",
4275 defaults: ["defaults"],
4276 }
4277
4278 cc_library {
4279 name: "libboth",
4280 defaults: ["defaults"],
4281 }
4282
4283 cc_binary {
4284 name: "binary",
4285 defaults: ["defaults"],
4286 }`)
4287
4288 pathsToBase := func(paths android.Paths) []string {
4289 var ret []string
4290 for _, p := range paths {
4291 ret = append(ret, p.Base())
4292 }
4293 return ret
4294 }
4295
Colin Cross7113d202019-11-20 16:39:12 -08004296 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004297 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4298 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
4299 }
Colin Cross7113d202019-11-20 16:39:12 -08004300 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004301 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4302 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
4303 }
Colin Cross7113d202019-11-20 16:39:12 -08004304 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004305 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
4306 t.Errorf("binary ld rule wanted %q, got %q", w, g)
4307 }
4308
Colin Cross7113d202019-11-20 16:39:12 -08004309 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004310 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4311 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
4312 }
Colin Cross7113d202019-11-20 16:39:12 -08004313 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004314 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4315 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
4316 }
4317}
Colin Crosseabaedd2020-02-06 17:01:55 -08004318
4319func TestProductVariableDefaults(t *testing.T) {
4320 bp := `
4321 cc_defaults {
4322 name: "libfoo_defaults",
4323 srcs: ["foo.c"],
4324 cppflags: ["-DFOO"],
4325 product_variables: {
4326 debuggable: {
4327 cppflags: ["-DBAR"],
4328 },
4329 },
4330 }
4331
4332 cc_library {
4333 name: "libfoo",
4334 defaults: ["libfoo_defaults"],
4335 }
4336 `
4337
4338 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4339 config.TestProductVariables.Debuggable = BoolPtr(true)
4340
Colin Crossae8600b2020-10-29 17:09:13 -07004341 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08004342 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
4343 ctx.BottomUp("variable", android.VariableMutator).Parallel()
4344 })
Colin Crossae8600b2020-10-29 17:09:13 -07004345 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08004346
4347 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4348 android.FailIfErrored(t, errs)
4349 _, errs = ctx.PrepareBuildActions(config)
4350 android.FailIfErrored(t, errs)
4351
4352 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
4353 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
4354 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
4355 }
4356}
Colin Crosse4f6eba2020-09-22 18:11:25 -07004357
4358func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
4359 t.Parallel()
4360 bp := `
4361 cc_library_static {
4362 name: "libfoo",
4363 srcs: ["foo.c"],
4364 whole_static_libs: ["libbar"],
4365 }
4366
4367 cc_library_static {
4368 name: "libbar",
4369 whole_static_libs: ["libmissing"],
4370 }
4371 `
4372
4373 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4374 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
4375
Colin Crossae8600b2020-10-29 17:09:13 -07004376 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07004377 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07004378 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07004379
4380 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4381 android.FailIfErrored(t, errs)
4382 _, errs = ctx.PrepareBuildActions(config)
4383 android.FailIfErrored(t, errs)
4384
4385 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
4386 if g, w := libbar.Rule, android.ErrorRule; g != w {
4387 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
4388 }
4389
4390 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
4391 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
4392 }
4393
4394 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
4395 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
4396 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
4397 }
4398
4399}
Colin Crosse9fe2942020-11-10 18:12:15 -08004400
4401func TestInstallSharedLibs(t *testing.T) {
4402 bp := `
4403 cc_binary {
4404 name: "bin",
4405 host_supported: true,
4406 shared_libs: ["libshared"],
4407 runtime_libs: ["libruntime"],
4408 srcs: [":gen"],
4409 }
4410
4411 cc_library_shared {
4412 name: "libshared",
4413 host_supported: true,
4414 shared_libs: ["libtransitive"],
4415 }
4416
4417 cc_library_shared {
4418 name: "libtransitive",
4419 host_supported: true,
4420 }
4421
4422 cc_library_shared {
4423 name: "libruntime",
4424 host_supported: true,
4425 }
4426
4427 cc_binary_host {
4428 name: "tool",
4429 srcs: ["foo.cpp"],
4430 }
4431
4432 genrule {
4433 name: "gen",
4434 tools: ["tool"],
4435 out: ["gen.cpp"],
4436 cmd: "$(location tool) $(out)",
4437 }
4438 `
4439
4440 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4441 ctx := testCcWithConfig(t, config)
4442
4443 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
4444 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
4445 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
4446 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
4447 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
4448
4449 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
4450 t.Errorf("expected host bin dependency %q, got %q", w, g)
4451 }
4452
4453 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4454 t.Errorf("expected host bin dependency %q, got %q", w, g)
4455 }
4456
4457 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4458 t.Errorf("expected host bin dependency %q, got %q", w, g)
4459 }
4460
4461 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
4462 t.Errorf("expected host bin dependency %q, got %q", w, g)
4463 }
4464
4465 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
4466 t.Errorf("expected no host bin dependency %q, got %q", w, g)
4467 }
4468
4469 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
4470 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
4471 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
4472 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
4473
4474 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
4475 t.Errorf("expected device bin dependency %q, got %q", w, g)
4476 }
4477
4478 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4479 t.Errorf("expected device bin dependency %q, got %q", w, g)
4480 }
4481
4482 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4483 t.Errorf("expected device bin dependency %q, got %q", w, g)
4484 }
4485
4486 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
4487 t.Errorf("expected device bin dependency %q, got %q", w, g)
4488 }
4489
4490 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
4491 t.Errorf("expected no device bin dependency %q, got %q", w, g)
4492 }
4493
4494}
Jiyong Park1ad8e162020-12-01 23:40:09 +09004495
4496func TestStubsLibReexportsHeaders(t *testing.T) {
4497 ctx := testCc(t, `
4498 cc_library_shared {
4499 name: "libclient",
4500 srcs: ["foo.c"],
4501 shared_libs: ["libfoo#1"],
4502 }
4503
4504 cc_library_shared {
4505 name: "libfoo",
4506 srcs: ["foo.c"],
4507 shared_libs: ["libbar"],
4508 export_shared_lib_headers: ["libbar"],
4509 stubs: {
4510 symbol_file: "foo.map.txt",
4511 versions: ["1", "2", "3"],
4512 },
4513 }
4514
4515 cc_library_shared {
4516 name: "libbar",
4517 export_include_dirs: ["include/libbar"],
4518 srcs: ["foo.c"],
4519 }`)
4520
4521 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
4522
4523 if !strings.Contains(cFlags, "-Iinclude/libbar") {
4524 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
4525 }
4526}
Jooyung Hane197d8b2021-01-05 10:33:16 +09004527
4528func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
4529 ctx := testCc(t, `
4530 cc_library {
4531 name: "libfoo",
4532 srcs: ["a/Foo.aidl"],
4533 aidl: { flags: ["-Werror"], },
4534 }
4535 `)
4536
4537 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
4538 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
4539 aidlCommand := manifest.Commands[0].GetCommand()
4540 expectedAidlFlag := "-Werror"
4541 if !strings.Contains(aidlCommand, expectedAidlFlag) {
4542 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
4543 }
4544}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004545
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004546type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004547
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004548const (
4549 None MemtagNoteType = iota + 1
4550 Sync
4551 Async
4552)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004553
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004554func (t MemtagNoteType) str() string {
4555 switch t {
4556 case None:
4557 return "none"
4558 case Sync:
4559 return "sync"
4560 case Async:
4561 return "async"
4562 default:
4563 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004564 }
4565}
4566
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004567func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
4568 note_async := "note_memtag_heap_async"
4569 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004570
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004571 found := None
4572 implicits := m.Rule("ld").Implicits
4573 for _, lib := range implicits {
4574 if strings.Contains(lib.Rel(), note_async) {
4575 found = Async
4576 break
4577 } else if strings.Contains(lib.Rel(), note_sync) {
4578 found = Sync
4579 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004580 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004581 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004582
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004583 if found != expected {
4584 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
4585 }
4586}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004587
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004588func makeMemtagTestConfig(t *testing.T) android.Config {
4589 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004590 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004591 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004592 gtest: false,
4593 }
4594
4595 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004596 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004597 gtest: false,
4598 sanitize: { memtag_heap: false },
4599 }
4600
4601 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004602 name: "%[1]s_test_true",
4603 gtest: false,
4604 sanitize: { memtag_heap: true },
4605 }
4606
4607 cc_test {
4608 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004609 gtest: false,
4610 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
4611 }
4612
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004613 cc_test {
4614 name: "%[1]s_test_true_diag",
4615 gtest: false,
4616 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
4617 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004618
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004619 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004620 name: "%[1]s_binary",
4621 }
4622
4623 cc_binary {
4624 name: "%[1]s_binary_false",
4625 sanitize: { memtag_heap: false },
4626 }
4627
4628 cc_binary {
4629 name: "%[1]s_binary_true",
4630 sanitize: { memtag_heap: true },
4631 }
4632
4633 cc_binary {
4634 name: "%[1]s_binary_true_nodiag",
4635 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
4636 }
4637
4638 cc_binary {
4639 name: "%[1]s_binary_true_diag",
4640 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004641 }
4642 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004643 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
4644 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
4645 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
4646 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004647
4648 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004649 "subdir_default/Android.bp": []byte(subdirDefaultBp),
4650 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
4651 "subdir_sync/Android.bp": []byte(subdirSyncBp),
4652 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004653 }
4654
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004655 return TestConfig(buildDir, android.Android, nil, "", mockFS)
4656}
4657
4658func TestSanitizeMemtagHeap(t *testing.T) {
4659 variant := "android_arm64_armv8-a"
4660
4661 config := makeMemtagTestConfig(t)
4662 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004663 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004664 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004665 ctx := CreateTestContext(config)
4666 ctx.Register()
4667
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004668 _, 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 -08004669 android.FailIfErrored(t, errs)
4670 _, errs = ctx.PrepareBuildActions(config)
4671 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004672
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004673 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4674 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4675 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
4676 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4677 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
4678
4679 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
4680 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4681 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
4682 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4683 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4684
4685 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4686 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4687 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
4688 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4689 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4690
4691 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4692 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4693 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
4694 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4695 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4696
4697 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4698 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4699 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
4700 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4701 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4702
4703 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
4704 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4705 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
4706 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4707 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4708
4709 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4710 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4711 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4712 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4713 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4714
4715 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4716 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4717 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4718 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4719 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
4720}
4721
4722func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004723 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004724
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004725 config := makeMemtagTestConfig(t)
4726 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
4727 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
4728 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
4729 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
4730 ctx := CreateTestContext(config)
4731 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004732
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004733 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
4734 android.FailIfErrored(t, errs)
4735 _, errs = ctx.PrepareBuildActions(config)
4736 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004737
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004738 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4739 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4740 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
4741 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4742 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004743
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004744 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
4745 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4746 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
4747 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4748 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4749
4750 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4751 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4752 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
4753 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4754 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4755
4756 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4757 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4758 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
4759 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4760 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4761
4762 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4763 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4764 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
4765 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4766 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4767
4768 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
4769 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4770 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
4771 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4772 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4773
4774 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4775 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4776 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4777 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4778 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4779
4780 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4781 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4782 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4783 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4784 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
4785}
4786
4787func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
4788 variant := "android_arm64_armv8-a"
4789
4790 config := makeMemtagTestConfig(t)
4791 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
4792 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
4793 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
4794 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
4795 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
4796 ctx := CreateTestContext(config)
4797 ctx.Register()
4798
4799 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
4800 android.FailIfErrored(t, errs)
4801 _, errs = ctx.PrepareBuildActions(config)
4802 android.FailIfErrored(t, errs)
4803
4804 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4805 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4806 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
4807 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4808 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
4809
4810 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
4811 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4812 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
4813 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4814 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4815
4816 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4817 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4818 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
4819 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4820 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4821
4822 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4823 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4824 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
4825 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4826 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4827
4828 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4829 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4830 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
4831 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4832 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4833
4834 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
4835 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4836 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
4837 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4838 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4839
4840 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4841 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4842 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4843 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4844 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4845
4846 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4847 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4848 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4849 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4850 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004851}