blob: 2d02a6a6d631a4d3f178fbaa29a3d9ade0f9f7a0 [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)
Ivan Lozano52767be2019-10-18 14:49:46 -0700237 if !mod.HasVendorVariant() {
Justin Yun0ecf0b22020-02-28 15:07:59 +0900238 t.Errorf("%q must have variant %q", name, variant)
Logan Chienf3511742017-10-31 18:04:35 +0800239 }
240
241 // Check library properties.
242 lib, ok := mod.compiler.(*libraryDecorator)
243 if !ok {
244 t.Errorf("%q must have libraryDecorator", name)
245 } else if lib.baseInstaller.subDir != subDir {
246 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
247 lib.baseInstaller.subDir)
248 }
249
250 // Check VNDK properties.
251 if mod.vndkdep == nil {
252 t.Fatalf("%q must have `vndkdep`", name)
253 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700254 if !mod.IsVndk() {
255 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800256 }
257 if mod.isVndkSp() != isVndkSp {
258 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
259 }
260
261 // Check VNDK extension properties.
262 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500263 if mod.IsVndkExt() != isVndkExt {
264 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800265 }
266
267 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
268 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
269 }
270}
271
Bill Peckham945441c2020-08-31 16:07:58 -0700272func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool) {
273 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900274 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
275 if !ok {
276 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900277 return
278 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900279 outputFiles, err := mod.OutputFiles("")
280 if err != nil || len(outputFiles) != 1 {
281 t.Errorf("%q must have single output\n", moduleName)
282 return
283 }
284 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900285
Bill Peckham945441c2020-08-31 16:07:58 -0700286 if include {
287 out := singleton.Output(snapshotPath)
288 if out.Input.String() != outputFiles[0].String() {
289 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
290 }
291 } else {
292 out := singleton.MaybeOutput(snapshotPath)
293 if out.Rule != nil {
294 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
295 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900296 }
297}
298
Bill Peckham945441c2020-08-31 16:07:58 -0700299func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
300 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true)
301}
302
303func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
304 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false)
305}
306
Jooyung Han2216fb12019-11-06 16:46:15 +0900307func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
308 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800309 content := android.ContentFromFileRuleForTests(t, params)
310 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900311 assertArrayString(t, actual, expected)
312}
313
Jooyung Han097087b2019-10-22 19:32:18 +0900314func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
315 t.Helper()
316 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900317 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
318}
319
320func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
321 t.Helper()
322 vndkLibraries := ctx.ModuleForTests(module, "")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900323
324 var output string
325 if module != "vndkcorevariant.libraries.txt" {
326 output = insertVndkVersion(module, "VER")
327 } else {
328 output = module
329 }
330
Jooyung Han2216fb12019-11-06 16:46:15 +0900331 checkWriteFileOutput(t, vndkLibraries.Output(output), expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900332}
333
Logan Chienf3511742017-10-31 18:04:35 +0800334func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800335 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800336 cc_library {
337 name: "libvndk",
338 vendor_available: true,
339 vndk: {
340 enabled: true,
341 },
342 nocrt: true,
343 }
344
345 cc_library {
346 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900347 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800348 vndk: {
349 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900350 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800351 },
352 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900353 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800354 }
355
356 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900357 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800358 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900359 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800360 vndk: {
361 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900362 },
363 nocrt: true,
364 target: {
365 vendor: {
366 cflags: ["-DTEST"],
367 },
368 product: {
369 cflags: ["-DTEST"],
370 },
371 },
372 }
373
374 cc_library {
375 name: "libvndk_sp",
376 vendor_available: true,
377 vndk: {
378 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800379 support_system_process: true,
380 },
381 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900382 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800383 }
384
385 cc_library {
386 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900387 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800388 vndk: {
389 enabled: true,
390 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900391 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800392 },
393 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900394 target: {
395 vendor: {
396 suffix: "-x",
397 },
398 },
Logan Chienf3511742017-10-31 18:04:35 +0800399 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900400
401 cc_library {
402 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900403 vendor_available: true,
404 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900405 vndk: {
406 enabled: true,
407 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900408 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900409 },
410 nocrt: true,
411 target: {
412 vendor: {
413 suffix: "-x",
414 },
415 product: {
416 suffix: "-x",
417 },
418 },
419 }
420
Jooyung Han2216fb12019-11-06 16:46:15 +0900421 vndk_libraries_txt {
422 name: "llndk.libraries.txt",
423 }
424 vndk_libraries_txt {
425 name: "vndkcore.libraries.txt",
426 }
427 vndk_libraries_txt {
428 name: "vndksp.libraries.txt",
429 }
430 vndk_libraries_txt {
431 name: "vndkprivate.libraries.txt",
432 }
433 vndk_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900434 name: "vndkproduct.libraries.txt",
435 }
436 vndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900437 name: "vndkcorevariant.libraries.txt",
438 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800439 `
440
441 config := TestConfig(buildDir, android.Android, nil, bp, nil)
442 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900443 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800444 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
445
446 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800447
Jooyung Han261e1582020-10-20 18:54:21 +0900448 // subdir == "" because VNDK libs are not supposed to be installed separately.
449 // They are installed as part of VNDK APEX instead.
450 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
451 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900452 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900453 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
454 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900455 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900456
Justin Yun6977e8a2020-10-29 18:24:11 +0900457 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
458 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900459
Inseob Kim1f086e22019-05-09 13:29:15 +0900460 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900461 snapshotDir := "vndk-snapshot"
462 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
463
464 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
465 "arm64", "armv8-a"))
466 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
467 "arm", "armv7-a-neon"))
468
469 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
470 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
471 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
472 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
473
Colin Crossfb0c16e2019-11-20 17:12:35 -0800474 variant := "android_vendor.VER_arm64_armv8-a_shared"
475 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900476
Inseob Kim7f283f42020-06-01 21:53:49 +0900477 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
478
479 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
480 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900481 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
482 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900483 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
484 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900485
Jooyung Han39edb6c2019-11-06 16:53:07 +0900486 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900487 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
488 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
489 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
490 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900491 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900492
Jooyung Han097087b2019-10-22 19:32:18 +0900493 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
494 "LLNDK: libc.so",
495 "LLNDK: libdl.so",
496 "LLNDK: libft2.so",
497 "LLNDK: libm.so",
498 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900499 "VNDK-SP: libvndk_sp-x.so",
500 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900501 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900502 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900503 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900504 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900505 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900506 "VNDK-private: libvndk-private.so",
507 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900508 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900509 "VNDK-product: libc++.so",
510 "VNDK-product: libvndk_product.so",
511 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900512 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900513 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900514 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
515 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
516 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
Justin Yun8a2600c2020-12-07 12:44:03 +0900517 checkVndkLibrariesOutput(t, ctx, "vndkproduct.libraries.txt", []string{"libc++.so", "libvndk_product.so", "libvndk_sp_product_private-x.so"})
Jooyung Han2216fb12019-11-06 16:46:15 +0900518 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
519}
520
Yo Chiangbba545e2020-06-09 16:15:37 +0800521func TestVndkWithHostSupported(t *testing.T) {
522 ctx := testCc(t, `
523 cc_library {
524 name: "libvndk_host_supported",
525 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900526 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800527 vndk: {
528 enabled: true,
529 },
530 host_supported: true,
531 }
532
533 cc_library {
534 name: "libvndk_host_supported_but_disabled_on_device",
535 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900536 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800537 vndk: {
538 enabled: true,
539 },
540 host_supported: true,
541 enabled: false,
542 target: {
543 host: {
544 enabled: true,
545 }
546 }
547 }
548
549 vndk_libraries_txt {
550 name: "vndkcore.libraries.txt",
551 }
552 `)
553
554 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
555}
556
Jooyung Han2216fb12019-11-06 16:46:15 +0900557func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800558 bp := `
Jooyung Han2216fb12019-11-06 16:46:15 +0900559 vndk_libraries_txt {
560 name: "llndk.libraries.txt",
Colin Cross98be1bb2019-12-13 20:41:13 -0800561 }`
562 config := TestConfig(buildDir, android.Android, nil, bp, nil)
563 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
564 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
565 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900566
567 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900568 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900569 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900570}
571
572func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800573 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900574 cc_library {
575 name: "libvndk",
576 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900577 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900578 vndk: {
579 enabled: true,
580 },
581 nocrt: true,
582 }
583
584 cc_library {
585 name: "libvndk_sp",
586 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900587 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900588 vndk: {
589 enabled: true,
590 support_system_process: true,
591 },
592 nocrt: true,
593 }
594
595 cc_library {
596 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900597 vendor_available: true,
598 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900599 vndk: {
600 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900601 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900602 },
603 nocrt: true,
604 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900605
606 vndk_libraries_txt {
607 name: "vndkcorevariant.libraries.txt",
608 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800609 `
610
611 config := TestConfig(buildDir, android.Android, nil, bp, nil)
612 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
613 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
614 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
615
616 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
617
618 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900619
Jooyung Han2216fb12019-11-06 16:46:15 +0900620 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900621}
622
Chris Parsons79d66a52020-06-05 17:26:16 -0400623func TestDataLibs(t *testing.T) {
624 bp := `
625 cc_test_library {
626 name: "test_lib",
627 srcs: ["test_lib.cpp"],
628 gtest: false,
629 }
630
631 cc_test {
632 name: "main_test",
633 data_libs: ["test_lib"],
634 gtest: false,
635 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400636 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400637
638 config := TestConfig(buildDir, android.Android, nil, bp, nil)
639 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
640 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
641 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
642
643 ctx := testCcWithConfig(t, config)
644 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
645 testBinary := module.(*Module).linker.(*testBinary)
646 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
647 if err != nil {
648 t.Errorf("Expected cc_test to produce output files, error: %s", err)
649 return
650 }
651 if len(outputFiles) != 1 {
652 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
653 return
654 }
655 if len(testBinary.dataPaths()) != 1 {
656 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
657 return
658 }
659
660 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400661 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400662
663 if !strings.HasSuffix(outputPath, "/main_test") {
664 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
665 return
666 }
667 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
668 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
669 return
670 }
671}
672
Chris Parsons216e10a2020-07-09 17:12:52 -0400673func TestDataLibsRelativeInstallPath(t *testing.T) {
674 bp := `
675 cc_test_library {
676 name: "test_lib",
677 srcs: ["test_lib.cpp"],
678 relative_install_path: "foo/bar/baz",
679 gtest: false,
680 }
681
682 cc_test {
683 name: "main_test",
684 data_libs: ["test_lib"],
685 gtest: false,
686 }
687 `
688
689 config := TestConfig(buildDir, android.Android, nil, bp, nil)
690 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
691 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
692 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
693
694 ctx := testCcWithConfig(t, config)
695 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
696 testBinary := module.(*Module).linker.(*testBinary)
697 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
698 if err != nil {
699 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
700 }
701 if len(outputFiles) != 1 {
702 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
703 }
704 if len(testBinary.dataPaths()) != 1 {
705 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
706 }
707
708 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400709
710 if !strings.HasSuffix(outputPath, "/main_test") {
711 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
712 }
713 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
714 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
715 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400716 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400717 }
718}
719
Jooyung Han0302a842019-10-30 18:43:49 +0900720func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900721 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900722 cc_library {
723 name: "libvndk",
724 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900725 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900726 vndk: {
727 enabled: true,
728 },
729 nocrt: true,
730 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900731 cc_library {
732 name: "libvndk-private",
733 vendor_available: false,
734 product_available: false,
735 vndk: {
736 enabled: true,
737 },
738 nocrt: true,
739 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900740 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900741
742 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
743 "LLNDK: libc.so",
744 "LLNDK: libdl.so",
745 "LLNDK: libft2.so",
746 "LLNDK: libm.so",
747 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900748 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900749 "VNDK-core: libvndk.so",
750 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900751 "VNDK-private: libvndk-private.so",
752 "VNDK-product: libc++.so",
753 "VNDK-product: libvndk-private.so",
754 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900755 })
Logan Chienf3511742017-10-31 18:04:35 +0800756}
757
Justin Yun63e9ec72020-10-29 16:49:43 +0900758func TestVndkModuleError(t *testing.T) {
759 // Check the error message for vendor_available and product_available properties.
Justin Yun6977e8a2020-10-29 18:24:11 +0900760 testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", `
761 cc_library {
762 name: "libvndk",
763 vndk: {
764 enabled: true,
765 },
766 nocrt: true,
767 }
768 `)
769
770 testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", `
771 cc_library {
772 name: "libvndk",
773 product_available: true,
774 vndk: {
775 enabled: true,
776 },
777 nocrt: true,
778 }
779 `)
780
Justin Yun6977e8a2020-10-29 18:24:11 +0900781 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
782 cc_library {
783 name: "libvndkprop",
784 vendor_available: true,
785 product_available: true,
786 vndk: {
787 enabled: true,
788 },
789 nocrt: true,
790 target: {
791 vendor: {
792 cflags: ["-DTEST",],
793 },
794 },
795 }
796 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900797}
798
Logan Chiend3c59a22018-03-29 14:08:15 +0800799func TestVndkDepError(t *testing.T) {
800 // Check whether an error is emitted when a VNDK lib depends on a system lib.
801 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
802 cc_library {
803 name: "libvndk",
804 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900805 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800806 vndk: {
807 enabled: true,
808 },
809 shared_libs: ["libfwk"], // Cause error
810 nocrt: true,
811 }
812
813 cc_library {
814 name: "libfwk",
815 nocrt: true,
816 }
817 `)
818
819 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
820 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
821 cc_library {
822 name: "libvndk",
823 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900824 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800825 vndk: {
826 enabled: true,
827 },
828 shared_libs: ["libvendor"], // Cause error
829 nocrt: true,
830 }
831
832 cc_library {
833 name: "libvendor",
834 vendor: true,
835 nocrt: true,
836 }
837 `)
838
839 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
840 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
841 cc_library {
842 name: "libvndk_sp",
843 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900844 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800845 vndk: {
846 enabled: true,
847 support_system_process: true,
848 },
849 shared_libs: ["libfwk"], // Cause error
850 nocrt: true,
851 }
852
853 cc_library {
854 name: "libfwk",
855 nocrt: true,
856 }
857 `)
858
859 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
860 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
861 cc_library {
862 name: "libvndk_sp",
863 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900864 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800865 vndk: {
866 enabled: true,
867 support_system_process: true,
868 },
869 shared_libs: ["libvendor"], // Cause error
870 nocrt: true,
871 }
872
873 cc_library {
874 name: "libvendor",
875 vendor: true,
876 nocrt: true,
877 }
878 `)
879
880 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
881 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
882 cc_library {
883 name: "libvndk_sp",
884 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900885 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800886 vndk: {
887 enabled: true,
888 support_system_process: true,
889 },
890 shared_libs: ["libvndk"], // Cause error
891 nocrt: true,
892 }
893
894 cc_library {
895 name: "libvndk",
896 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900897 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800898 vndk: {
899 enabled: true,
900 },
901 nocrt: true,
902 }
903 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900904
905 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
906 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
907 cc_library {
908 name: "libvndk",
909 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900910 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900911 vndk: {
912 enabled: true,
913 },
914 shared_libs: ["libnonvndk"],
915 nocrt: true,
916 }
917
918 cc_library {
919 name: "libnonvndk",
920 vendor_available: true,
921 nocrt: true,
922 }
923 `)
924
925 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
926 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
927 cc_library {
928 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900929 vendor_available: true,
930 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900931 vndk: {
932 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900933 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900934 },
935 shared_libs: ["libnonvndk"],
936 nocrt: true,
937 }
938
939 cc_library {
940 name: "libnonvndk",
941 vendor_available: true,
942 nocrt: true,
943 }
944 `)
945
946 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
947 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
948 cc_library {
949 name: "libvndksp",
950 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900951 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900952 vndk: {
953 enabled: true,
954 support_system_process: true,
955 },
956 shared_libs: ["libnonvndk"],
957 nocrt: true,
958 }
959
960 cc_library {
961 name: "libnonvndk",
962 vendor_available: true,
963 nocrt: true,
964 }
965 `)
966
967 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
968 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
969 cc_library {
970 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900971 vendor_available: true,
972 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900973 vndk: {
974 enabled: true,
975 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900976 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900977 },
978 shared_libs: ["libnonvndk"],
979 nocrt: true,
980 }
981
982 cc_library {
983 name: "libnonvndk",
984 vendor_available: true,
985 nocrt: true,
986 }
987 `)
988}
989
990func TestDoubleLoadbleDep(t *testing.T) {
991 // okay to link : LLNDK -> double_loadable VNDK
992 testCc(t, `
993 cc_library {
994 name: "libllndk",
995 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -0700996 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900997 }
998
999 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001000 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001001 symbol_file: "",
1002 }
1003
1004 cc_library {
1005 name: "libdoubleloadable",
1006 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001007 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001008 vndk: {
1009 enabled: true,
1010 },
1011 double_loadable: true,
1012 }
1013 `)
1014 // okay to link : LLNDK -> VNDK-SP
1015 testCc(t, `
1016 cc_library {
1017 name: "libllndk",
1018 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -07001019 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001020 }
1021
1022 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001023 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001024 symbol_file: "",
1025 }
1026
1027 cc_library {
1028 name: "libvndksp",
1029 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001030 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001031 vndk: {
1032 enabled: true,
1033 support_system_process: true,
1034 },
1035 }
1036 `)
1037 // okay to link : double_loadable -> double_loadable
1038 testCc(t, `
1039 cc_library {
1040 name: "libdoubleloadable1",
1041 shared_libs: ["libdoubleloadable2"],
1042 vendor_available: true,
1043 double_loadable: true,
1044 }
1045
1046 cc_library {
1047 name: "libdoubleloadable2",
1048 vendor_available: true,
1049 double_loadable: true,
1050 }
1051 `)
1052 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1053 testCc(t, `
1054 cc_library {
1055 name: "libdoubleloadable",
1056 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001057 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001058 vndk: {
1059 enabled: true,
1060 },
1061 double_loadable: true,
1062 shared_libs: ["libnondoubleloadable"],
1063 }
1064
1065 cc_library {
1066 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001067 vendor_available: true,
1068 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001069 vndk: {
1070 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001071 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001072 },
1073 double_loadable: true,
1074 }
1075 `)
1076 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1077 testCc(t, `
1078 cc_library {
1079 name: "libllndk",
1080 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001081 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001082 }
1083
1084 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001085 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001086 symbol_file: "",
1087 }
1088
1089 cc_library {
1090 name: "libcoreonly",
1091 shared_libs: ["libvendoravailable"],
1092 }
1093
1094 // indirect dependency of LLNDK
1095 cc_library {
1096 name: "libvendoravailable",
1097 vendor_available: true,
1098 double_loadable: true,
1099 }
1100 `)
1101}
1102
Inseob Kim5f58ff72020-09-07 19:53:31 +09001103func TestVendorSnapshotCapture(t *testing.T) {
Inseob Kim8471cda2019-11-15 09:59:12 +09001104 bp := `
1105 cc_library {
1106 name: "libvndk",
1107 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001108 product_available: true,
Inseob Kim8471cda2019-11-15 09:59:12 +09001109 vndk: {
1110 enabled: true,
1111 },
1112 nocrt: true,
1113 }
1114
1115 cc_library {
1116 name: "libvendor",
1117 vendor: true,
1118 nocrt: true,
1119 }
1120
1121 cc_library {
1122 name: "libvendor_available",
1123 vendor_available: true,
1124 nocrt: true,
1125 }
1126
1127 cc_library_headers {
1128 name: "libvendor_headers",
1129 vendor_available: true,
1130 nocrt: true,
1131 }
1132
1133 cc_binary {
1134 name: "vendor_bin",
1135 vendor: true,
1136 nocrt: true,
1137 }
1138
1139 cc_binary {
1140 name: "vendor_available_bin",
1141 vendor_available: true,
1142 nocrt: true,
1143 }
Inseob Kim7f283f42020-06-01 21:53:49 +09001144
1145 toolchain_library {
1146 name: "libb",
1147 vendor_available: true,
1148 src: "libb.a",
1149 }
Inseob Kim1042d292020-06-01 23:23:05 +09001150
1151 cc_object {
1152 name: "obj",
1153 vendor_available: true,
1154 }
Colin Cross127bb8b2020-12-16 16:46:01 -08001155
1156 cc_library {
1157 name: "libllndk",
1158 llndk_stubs: "libllndk.llndk",
1159 }
1160
1161 llndk_library {
1162 name: "libllndk.llndk",
1163 symbol_file: "",
1164 }
Inseob Kim8471cda2019-11-15 09:59:12 +09001165`
1166 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1167 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1168 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1169 ctx := testCcWithConfig(t, config)
1170
1171 // Check Vendor snapshot output.
1172
1173 snapshotDir := "vendor-snapshot"
1174 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
Inseob Kim7f283f42020-06-01 21:53:49 +09001175 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1176
1177 var jsonFiles []string
Inseob Kim8471cda2019-11-15 09:59:12 +09001178
1179 for _, arch := range [][]string{
1180 []string{"arm64", "armv8-a"},
1181 []string{"arm", "armv7-a-neon"},
1182 } {
1183 archType := arch[0]
1184 archVariant := arch[1]
1185 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1186
1187 // For shared libraries, only non-VNDK vendor_available modules are captured
1188 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1189 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Inseob Kim7f283f42020-06-01 21:53:49 +09001190 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1191 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1192 jsonFiles = append(jsonFiles,
1193 filepath.Join(sharedDir, "libvendor.so.json"),
1194 filepath.Join(sharedDir, "libvendor_available.so.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001195
Colin Cross127bb8b2020-12-16 16:46:01 -08001196 // LLNDK modules are not captured
1197 checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
1198
Inseob Kim8471cda2019-11-15 09:59:12 +09001199 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
Inseob Kimc42f2f22020-07-29 20:32:10 +09001200 // Also cfi variants are captured, except for prebuilts like toolchain_library
Inseob Kim8471cda2019-11-15 09:59:12 +09001201 staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001202 staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant)
Inseob Kim8471cda2019-11-15 09:59:12 +09001203 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Inseob Kim7f283f42020-06-01 21:53:49 +09001204 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1205 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001206 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001207 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001208 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001209 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001210 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001211 jsonFiles = append(jsonFiles,
1212 filepath.Join(staticDir, "libb.a.json"),
1213 filepath.Join(staticDir, "libvndk.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001214 filepath.Join(staticDir, "libvndk.cfi.a.json"),
Inseob Kim7f283f42020-06-01 21:53:49 +09001215 filepath.Join(staticDir, "libvendor.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001216 filepath.Join(staticDir, "libvendor.cfi.a.json"),
1217 filepath.Join(staticDir, "libvendor_available.a.json"),
1218 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001219
Inseob Kim7f283f42020-06-01 21:53:49 +09001220 // For binary executables, all vendor:true and vendor_available modules are captured.
Inseob Kim8471cda2019-11-15 09:59:12 +09001221 if archType == "arm64" {
1222 binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1223 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Inseob Kim7f283f42020-06-01 21:53:49 +09001224 checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
1225 checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
1226 jsonFiles = append(jsonFiles,
1227 filepath.Join(binaryDir, "vendor_bin.json"),
1228 filepath.Join(binaryDir, "vendor_available_bin.json"))
1229 }
1230
1231 // For header libraries, all vendor:true and vendor_available modules are captured.
1232 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1233 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
Inseob Kim1042d292020-06-01 23:23:05 +09001234
1235 // For object modules, all vendor:true and vendor_available modules are captured.
1236 objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1237 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1238 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1239 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
Inseob Kim7f283f42020-06-01 21:53:49 +09001240 }
1241
1242 for _, jsonFile := range jsonFiles {
1243 // verify all json files exist
1244 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1245 t.Errorf("%q expected but not found", jsonFile)
Inseob Kim8471cda2019-11-15 09:59:12 +09001246 }
1247 }
1248}
1249
Inseob Kim5f58ff72020-09-07 19:53:31 +09001250func TestVendorSnapshotUse(t *testing.T) {
1251 frameworkBp := `
1252 cc_library {
1253 name: "libvndk",
1254 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001255 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001256 vndk: {
1257 enabled: true,
1258 },
1259 nocrt: true,
1260 compile_multilib: "64",
1261 }
1262
1263 cc_library {
1264 name: "libvendor",
1265 vendor: true,
1266 nocrt: true,
1267 no_libcrt: true,
1268 stl: "none",
1269 system_shared_libs: [],
1270 compile_multilib: "64",
1271 }
1272
1273 cc_binary {
1274 name: "bin",
1275 vendor: true,
1276 nocrt: true,
1277 no_libcrt: true,
1278 stl: "none",
1279 system_shared_libs: [],
1280 compile_multilib: "64",
1281 }
1282`
1283
1284 vndkBp := `
1285 vndk_prebuilt_shared {
1286 name: "libvndk",
1287 version: "BOARD",
1288 target_arch: "arm64",
1289 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001290 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001291 vndk: {
1292 enabled: true,
1293 },
1294 arch: {
1295 arm64: {
1296 srcs: ["libvndk.so"],
Inseob Kim67be7322020-10-19 10:15:28 +09001297 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001298 },
1299 },
1300 }
1301`
1302
1303 vendorProprietaryBp := `
1304 cc_library {
1305 name: "libvendor_without_snapshot",
1306 vendor: true,
1307 nocrt: true,
1308 no_libcrt: true,
1309 stl: "none",
1310 system_shared_libs: [],
1311 compile_multilib: "64",
1312 }
1313
1314 cc_library_shared {
1315 name: "libclient",
1316 vendor: true,
1317 nocrt: true,
1318 no_libcrt: true,
1319 stl: "none",
1320 system_shared_libs: [],
1321 shared_libs: ["libvndk"],
1322 static_libs: ["libvendor", "libvendor_without_snapshot"],
1323 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001324 srcs: ["client.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001325 }
1326
1327 cc_binary {
1328 name: "bin_without_snapshot",
1329 vendor: true,
1330 nocrt: true,
1331 no_libcrt: true,
1332 stl: "none",
1333 system_shared_libs: [],
1334 static_libs: ["libvndk"],
1335 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001336 srcs: ["bin.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001337 }
1338
1339 vendor_snapshot_static {
1340 name: "libvndk",
1341 version: "BOARD",
1342 target_arch: "arm64",
1343 vendor: true,
1344 arch: {
1345 arm64: {
1346 src: "libvndk.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001347 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001348 },
1349 },
1350 }
1351
1352 vendor_snapshot_shared {
1353 name: "libvendor",
1354 version: "BOARD",
1355 target_arch: "arm64",
1356 vendor: true,
1357 arch: {
1358 arm64: {
1359 src: "libvendor.so",
Inseob Kim67be7322020-10-19 10:15:28 +09001360 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001361 },
1362 },
1363 }
1364
1365 vendor_snapshot_static {
1366 name: "libvendor",
1367 version: "BOARD",
1368 target_arch: "arm64",
1369 vendor: true,
1370 arch: {
1371 arm64: {
1372 src: "libvendor.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001373 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001374 },
1375 },
1376 }
1377
1378 vendor_snapshot_binary {
1379 name: "bin",
1380 version: "BOARD",
1381 target_arch: "arm64",
1382 vendor: true,
1383 arch: {
1384 arm64: {
1385 src: "bin",
1386 },
1387 },
1388 }
1389`
1390 depsBp := GatherRequiredDepsForTest(android.Android)
1391
1392 mockFS := map[string][]byte{
Inseob Kim67be7322020-10-19 10:15:28 +09001393 "deps/Android.bp": []byte(depsBp),
1394 "framework/Android.bp": []byte(frameworkBp),
1395 "vendor/Android.bp": []byte(vendorProprietaryBp),
1396 "vendor/bin": nil,
1397 "vendor/bin.cpp": nil,
1398 "vendor/client.cpp": nil,
1399 "vendor/include/libvndk/a.h": nil,
1400 "vendor/include/libvendor/b.h": nil,
1401 "vendor/libvndk.a": nil,
1402 "vendor/libvendor.a": nil,
1403 "vendor/libvendor.so": nil,
1404 "vndk/Android.bp": []byte(vndkBp),
1405 "vndk/include/libvndk/a.h": nil,
1406 "vndk/libvndk.so": nil,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001407 }
1408
1409 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1410 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1411 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001412 ctx := CreateTestContext(config)
1413 ctx.Register()
Inseob Kim5f58ff72020-09-07 19:53:31 +09001414
1415 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
1416 android.FailIfErrored(t, errs)
1417 _, errs = ctx.PrepareBuildActions(config)
1418 android.FailIfErrored(t, errs)
1419
1420 sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared"
1421 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1422 binaryVariant := "android_vendor.BOARD_arm64_armv8-a"
1423
1424 // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot
Inseob Kim67be7322020-10-19 10:15:28 +09001425 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
1426 for _, includeFlags := range []string{
1427 "-Ivndk/include/libvndk", // libvndk
1428 "-Ivendor/include/libvendor", // libvendor
1429 } {
1430 if !strings.Contains(libclientCcFlags, includeFlags) {
1431 t.Errorf("flags for libclient must contain %#v, but was %#v.",
1432 includeFlags, libclientCcFlags)
1433 }
1434 }
Inseob Kim5f58ff72020-09-07 19:53:31 +09001435
Inseob Kim67be7322020-10-19 10:15:28 +09001436 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001437 for _, input := range [][]string{
1438 []string{sharedVariant, "libvndk.vndk.BOARD.arm64"},
1439 []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"},
1440 []string{staticVariant, "libvendor_without_snapshot"},
1441 } {
1442 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Inseob Kim67be7322020-10-19 10:15:28 +09001443 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
1444 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001445 }
1446 }
1447
1448 // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64
Inseob Kim67be7322020-10-19 10:15:28 +09001449 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
1450 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
1451 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
1452 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
1453 }
1454
1455 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001456 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"})
Inseob Kim67be7322020-10-19 10:15:28 +09001457 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
Inseob Kim5f58ff72020-09-07 19:53:31 +09001458 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
Inseob Kim67be7322020-10-19 10:15:28 +09001459 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001460 }
1461
1462 // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64
1463 ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so")
1464
1465 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
1466 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
1467
1468 // bin is installed by bin.vendor_binary.BOARD.arm64
1469 ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin")
1470
1471 // bin_without_snapshot is installed by bin_without_snapshot
1472 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1473
1474 // libvendor and bin don't have vendor.BOARD variant
1475 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1476 if inList(sharedVariant, libvendorVariants) {
1477 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1478 }
1479
1480 binVariants := ctx.ModuleVariantsForTests("bin")
1481 if inList(binaryVariant, binVariants) {
1482 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1483 }
1484}
1485
Inseob Kimc42f2f22020-07-29 20:32:10 +09001486func TestVendorSnapshotSanitizer(t *testing.T) {
1487 bp := `
1488 vendor_snapshot_static {
1489 name: "libsnapshot",
1490 vendor: true,
1491 target_arch: "arm64",
1492 version: "BOARD",
1493 arch: {
1494 arm64: {
1495 src: "libsnapshot.a",
1496 cfi: {
1497 src: "libsnapshot.cfi.a",
1498 }
1499 },
1500 },
1501 }
1502`
1503 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1504 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1505 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1506 ctx := testCcWithConfig(t, config)
1507
1508 // Check non-cfi and cfi variant.
1509 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1510 staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi"
1511
1512 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module)
1513 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1514
1515 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module)
1516 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1517}
1518
Bill Peckham945441c2020-08-31 16:07:58 -07001519func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) {
1520 t.Helper()
1521 if c.ExcludeFromVendorSnapshot() != expected {
1522 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected)
1523 }
1524}
1525
Jose Galmes6f843bc2020-12-11 13:36:29 -08001526func assertExcludeFromRecoverySnapshotIs(t *testing.T, c *Module, expected bool) {
1527 t.Helper()
1528 if c.ExcludeFromRecoverySnapshot() != expected {
1529 t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", c.String(), expected)
1530 }
1531}
1532
Bill Peckham945441c2020-08-31 16:07:58 -07001533func TestVendorSnapshotExclude(t *testing.T) {
1534
1535 // This test verifies that the exclude_from_vendor_snapshot property
1536 // makes its way from the Android.bp source file into the module data
1537 // structure. It also verifies that modules are correctly included or
1538 // excluded in the vendor snapshot based on their path (framework or
1539 // vendor) and the exclude_from_vendor_snapshot property.
1540
1541 frameworkBp := `
1542 cc_library_shared {
1543 name: "libinclude",
1544 srcs: ["src/include.cpp"],
1545 vendor_available: true,
1546 }
1547 cc_library_shared {
1548 name: "libexclude",
1549 srcs: ["src/exclude.cpp"],
1550 vendor: true,
1551 exclude_from_vendor_snapshot: true,
1552 }
1553 `
1554
1555 vendorProprietaryBp := `
1556 cc_library_shared {
1557 name: "libvendor",
1558 srcs: ["vendor.cpp"],
1559 vendor: true,
1560 }
1561 `
1562
1563 depsBp := GatherRequiredDepsForTest(android.Android)
1564
1565 mockFS := map[string][]byte{
1566 "deps/Android.bp": []byte(depsBp),
1567 "framework/Android.bp": []byte(frameworkBp),
1568 "framework/include.cpp": nil,
1569 "framework/exclude.cpp": nil,
1570 "device/Android.bp": []byte(vendorProprietaryBp),
1571 "device/vendor.cpp": nil,
1572 }
1573
1574 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1575 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1576 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001577 ctx := CreateTestContext(config)
1578 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001579
1580 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1581 android.FailIfErrored(t, errs)
1582 _, errs = ctx.PrepareBuildActions(config)
1583 android.FailIfErrored(t, errs)
1584
1585 // Test an include and exclude framework module.
1586 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
1587 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false)
1588 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true)
1589
1590 // A vendor module is excluded, but by its path, not the
1591 // exclude_from_vendor_snapshot property.
1592 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false)
1593
1594 // Verify the content of the vendor snapshot.
1595
1596 snapshotDir := "vendor-snapshot"
1597 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1598 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1599
1600 var includeJsonFiles []string
1601 var excludeJsonFiles []string
1602
1603 for _, arch := range [][]string{
1604 []string{"arm64", "armv8-a"},
1605 []string{"arm", "armv7-a-neon"},
1606 } {
1607 archType := arch[0]
1608 archVariant := arch[1]
1609 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1610
1611 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1612 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1613
1614 // Included modules
1615 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1616 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1617
1618 // Excluded modules
1619 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1620 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1621 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1622 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1623 }
1624
1625 // Verify that each json file for an included module has a rule.
1626 for _, jsonFile := range includeJsonFiles {
1627 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1628 t.Errorf("include json file %q not found", jsonFile)
1629 }
1630 }
1631
1632 // Verify that each json file for an excluded module has no rule.
1633 for _, jsonFile := range excludeJsonFiles {
1634 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1635 t.Errorf("exclude json file %q found", jsonFile)
1636 }
1637 }
1638}
1639
1640func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1641
1642 // This test verifies that using the exclude_from_vendor_snapshot
1643 // property on a module in a vendor proprietary path generates an
1644 // error. These modules are already excluded, so we prohibit using the
1645 // property in this way, which could add to confusion.
1646
1647 vendorProprietaryBp := `
1648 cc_library_shared {
1649 name: "libvendor",
1650 srcs: ["vendor.cpp"],
1651 vendor: true,
1652 exclude_from_vendor_snapshot: true,
1653 }
1654 `
1655
1656 depsBp := GatherRequiredDepsForTest(android.Android)
1657
1658 mockFS := map[string][]byte{
1659 "deps/Android.bp": []byte(depsBp),
1660 "device/Android.bp": []byte(vendorProprietaryBp),
1661 "device/vendor.cpp": nil,
1662 }
1663
1664 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1665 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1666 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001667 ctx := CreateTestContext(config)
1668 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001669
1670 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1671 android.FailIfErrored(t, errs)
1672
1673 _, errs = ctx.PrepareBuildActions(config)
1674 android.CheckErrorsAgainstExpectations(t, errs, []string{
1675 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1676 `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 -08001677 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1678 `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 -07001679 })
1680}
1681
1682func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) {
1683
1684 // This test verifies that using the exclude_from_vendor_snapshot
1685 // property on a module that is vendor available generates an error. A
1686 // vendor available module must be captured in the vendor snapshot and
1687 // must not built from source when building the vendor image against
1688 // the vendor snapshot.
1689
1690 frameworkBp := `
1691 cc_library_shared {
1692 name: "libinclude",
1693 srcs: ["src/include.cpp"],
1694 vendor_available: true,
1695 exclude_from_vendor_snapshot: true,
1696 }
1697 `
1698
1699 depsBp := GatherRequiredDepsForTest(android.Android)
1700
1701 mockFS := map[string][]byte{
1702 "deps/Android.bp": []byte(depsBp),
1703 "framework/Android.bp": []byte(frameworkBp),
1704 "framework/include.cpp": nil,
1705 }
1706
1707 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1708 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1709 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001710 ctx := CreateTestContext(config)
1711 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001712
1713 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"})
1714 android.FailIfErrored(t, errs)
1715
1716 _, errs = ctx.PrepareBuildActions(config)
1717 android.CheckErrorsAgainstExpectations(t, errs, []string{
1718 `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1719 `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1720 `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1721 `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1722 })
1723}
1724
Jose Galmesf7294582020-11-13 12:07:36 -08001725func TestRecoverySnapshotCapture(t *testing.T) {
1726 bp := `
1727 cc_library {
1728 name: "libvndk",
1729 vendor_available: true,
1730 recovery_available: true,
1731 product_available: true,
1732 vndk: {
1733 enabled: true,
1734 },
1735 nocrt: true,
1736 }
1737
1738 cc_library {
1739 name: "librecovery",
1740 recovery: true,
1741 nocrt: true,
1742 }
1743
1744 cc_library {
1745 name: "librecovery_available",
1746 recovery_available: true,
1747 nocrt: true,
1748 }
1749
1750 cc_library_headers {
1751 name: "librecovery_headers",
1752 recovery_available: true,
1753 nocrt: true,
1754 }
1755
1756 cc_binary {
1757 name: "recovery_bin",
1758 recovery: true,
1759 nocrt: true,
1760 }
1761
1762 cc_binary {
1763 name: "recovery_available_bin",
1764 recovery_available: true,
1765 nocrt: true,
1766 }
1767
1768 toolchain_library {
1769 name: "libb",
1770 recovery_available: true,
1771 src: "libb.a",
1772 }
1773
1774 cc_object {
1775 name: "obj",
1776 recovery_available: true,
1777 }
1778`
1779 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001780 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
Jose Galmesf7294582020-11-13 12:07:36 -08001781 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1782 ctx := testCcWithConfig(t, config)
1783
1784 // Check Recovery snapshot output.
1785
1786 snapshotDir := "recovery-snapshot"
1787 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1788 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1789
1790 var jsonFiles []string
1791
1792 for _, arch := range [][]string{
1793 []string{"arm64", "armv8-a"},
1794 } {
1795 archType := arch[0]
1796 archVariant := arch[1]
1797 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1798
1799 // For shared libraries, only recovery_available modules are captured.
1800 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1801 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1802 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1803 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1804 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1805 jsonFiles = append(jsonFiles,
1806 filepath.Join(sharedDir, "libvndk.so.json"),
1807 filepath.Join(sharedDir, "librecovery.so.json"),
1808 filepath.Join(sharedDir, "librecovery_available.so.json"))
1809
1810 // For static libraries, all recovery:true and recovery_available modules are captured.
1811 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1812 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1813 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1814 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1815 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1816 jsonFiles = append(jsonFiles,
1817 filepath.Join(staticDir, "libb.a.json"),
1818 filepath.Join(staticDir, "librecovery.a.json"),
1819 filepath.Join(staticDir, "librecovery_available.a.json"))
1820
1821 // For binary executables, all recovery:true and recovery_available modules are captured.
1822 if archType == "arm64" {
1823 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1824 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1825 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1826 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1827 jsonFiles = append(jsonFiles,
1828 filepath.Join(binaryDir, "recovery_bin.json"),
1829 filepath.Join(binaryDir, "recovery_available_bin.json"))
1830 }
1831
1832 // For header libraries, all vendor:true and vendor_available modules are captured.
1833 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1834 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1835
1836 // For object modules, all vendor:true and vendor_available modules are captured.
1837 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1838 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1839 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1840 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1841 }
1842
1843 for _, jsonFile := range jsonFiles {
1844 // verify all json files exist
1845 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1846 t.Errorf("%q expected but not found", jsonFile)
1847 }
1848 }
1849}
1850
Jose Galmes6f843bc2020-12-11 13:36:29 -08001851func TestRecoverySnapshotExclude(t *testing.T) {
1852 // This test verifies that the exclude_from_recovery_snapshot property
1853 // makes its way from the Android.bp source file into the module data
1854 // structure. It also verifies that modules are correctly included or
1855 // excluded in the recovery snapshot based on their path (framework or
1856 // vendor) and the exclude_from_recovery_snapshot property.
1857
1858 frameworkBp := `
1859 cc_library_shared {
1860 name: "libinclude",
1861 srcs: ["src/include.cpp"],
1862 recovery_available: true,
1863 }
1864 cc_library_shared {
1865 name: "libexclude",
1866 srcs: ["src/exclude.cpp"],
1867 recovery: true,
1868 exclude_from_recovery_snapshot: true,
1869 }
1870 `
1871
1872 vendorProprietaryBp := `
1873 cc_library_shared {
1874 name: "libvendor",
1875 srcs: ["vendor.cpp"],
1876 recovery: true,
1877 }
1878 `
1879
1880 depsBp := GatherRequiredDepsForTest(android.Android)
1881
1882 mockFS := map[string][]byte{
1883 "deps/Android.bp": []byte(depsBp),
1884 "framework/Android.bp": []byte(frameworkBp),
1885 "framework/include.cpp": nil,
1886 "framework/exclude.cpp": nil,
1887 "device/Android.bp": []byte(vendorProprietaryBp),
1888 "device/vendor.cpp": nil,
1889 }
1890
1891 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1892 config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
1893 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1894 ctx := CreateTestContext(config)
1895 ctx.Register()
1896
1897 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1898 android.FailIfErrored(t, errs)
1899 _, errs = ctx.PrepareBuildActions(config)
1900 android.FailIfErrored(t, errs)
1901
1902 // Test an include and exclude framework module.
1903 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
1904 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", recoveryVariant).Module().(*Module), false)
1905 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libexclude", recoveryVariant).Module().(*Module), true)
1906
1907 // A vendor module is excluded, but by its path, not the
1908 // exclude_from_recovery_snapshot property.
1909 assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libvendor", recoveryVariant).Module().(*Module), false)
1910
1911 // Verify the content of the recovery snapshot.
1912
1913 snapshotDir := "recovery-snapshot"
1914 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1915 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1916
1917 var includeJsonFiles []string
1918 var excludeJsonFiles []string
1919
1920 for _, arch := range [][]string{
1921 []string{"arm64", "armv8-a"},
1922 } {
1923 archType := arch[0]
1924 archVariant := arch[1]
1925 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1926
1927 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1928 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1929
1930 // Included modules
1931 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1932 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1933
1934 // Excluded modules
1935 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1936 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1937 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1938 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1939 }
1940
1941 // Verify that each json file for an included module has a rule.
1942 for _, jsonFile := range includeJsonFiles {
1943 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1944 t.Errorf("include json file %q not found", jsonFile)
1945 }
1946 }
1947
1948 // Verify that each json file for an excluded module has no rule.
1949 for _, jsonFile := range excludeJsonFiles {
1950 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1951 t.Errorf("exclude json file %q found", jsonFile)
1952 }
1953 }
1954}
1955
Jooyung Hana70f0672019-01-18 15:20:43 +09001956func TestDoubleLoadableDepError(t *testing.T) {
1957 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1958 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1959 cc_library {
1960 name: "libllndk",
1961 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001962 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001963 }
1964
1965 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001966 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001967 symbol_file: "",
1968 }
1969
1970 cc_library {
1971 name: "libnondoubleloadable",
1972 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001973 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001974 vndk: {
1975 enabled: true,
1976 },
1977 }
1978 `)
1979
1980 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1981 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1982 cc_library {
1983 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001984 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001985 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001986 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001987 }
1988
1989 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001990 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001991 symbol_file: "",
1992 }
1993
1994 cc_library {
1995 name: "libnondoubleloadable",
1996 vendor_available: true,
1997 }
1998 `)
1999
2000 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
2001 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2002 cc_library {
2003 name: "libdoubleloadable",
2004 vendor_available: true,
2005 double_loadable: true,
2006 shared_libs: ["libnondoubleloadable"],
2007 }
2008
2009 cc_library {
2010 name: "libnondoubleloadable",
2011 vendor_available: true,
2012 }
2013 `)
2014
2015 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
2016 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2017 cc_library {
2018 name: "libdoubleloadable",
2019 vendor_available: true,
2020 double_loadable: true,
2021 shared_libs: ["libnondoubleloadable"],
2022 }
2023
2024 cc_library {
2025 name: "libnondoubleloadable",
2026 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002027 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002028 vndk: {
2029 enabled: true,
2030 },
2031 }
2032 `)
2033
2034 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
2035 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2036 cc_library {
2037 name: "libdoubleloadable",
2038 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002039 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002040 vndk: {
2041 enabled: true,
2042 },
2043 double_loadable: true,
2044 shared_libs: ["libnondoubleloadable"],
2045 }
2046
2047 cc_library {
2048 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09002049 vendor_available: true,
2050 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002051 vndk: {
2052 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002053 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09002054 },
2055 }
2056 `)
2057
2058 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
2059 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
2060 cc_library {
2061 name: "libllndk",
2062 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07002063 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002064 }
2065
2066 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002067 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09002068 symbol_file: "",
2069 }
2070
2071 cc_library {
2072 name: "libcoreonly",
2073 shared_libs: ["libvendoravailable"],
2074 }
2075
2076 // indirect dependency of LLNDK
2077 cc_library {
2078 name: "libvendoravailable",
2079 vendor_available: true,
2080 }
2081 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08002082}
2083
Jooyung Han479ca172020-10-19 18:51:07 +09002084func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
2085 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
2086 cc_library {
2087 name: "libvndksp",
2088 shared_libs: ["libanothervndksp"],
2089 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002090 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09002091 vndk: {
2092 enabled: true,
2093 support_system_process: true,
2094 }
2095 }
2096
2097 cc_library {
2098 name: "libllndk",
2099 shared_libs: ["libanothervndksp"],
2100 }
2101
2102 llndk_library {
2103 name: "libllndk",
2104 symbol_file: "",
2105 }
2106
2107 cc_library {
2108 name: "libanothervndksp",
2109 vendor_available: true,
2110 }
2111 `)
2112}
2113
Logan Chienf3511742017-10-31 18:04:35 +08002114func TestVndkExt(t *testing.T) {
2115 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002116 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08002117 cc_library {
2118 name: "libvndk",
2119 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002120 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002121 vndk: {
2122 enabled: true,
2123 },
2124 nocrt: true,
2125 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002126 cc_library {
2127 name: "libvndk2",
2128 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002129 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09002130 vndk: {
2131 enabled: true,
2132 },
2133 target: {
2134 vendor: {
2135 suffix: "-suffix",
2136 },
Justin Yun63e9ec72020-10-29 16:49:43 +09002137 product: {
2138 suffix: "-suffix",
2139 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09002140 },
2141 nocrt: true,
2142 }
Logan Chienf3511742017-10-31 18:04:35 +08002143
2144 cc_library {
2145 name: "libvndk_ext",
2146 vendor: true,
2147 vndk: {
2148 enabled: true,
2149 extends: "libvndk",
2150 },
2151 nocrt: true,
2152 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002153
2154 cc_library {
2155 name: "libvndk2_ext",
2156 vendor: true,
2157 vndk: {
2158 enabled: true,
2159 extends: "libvndk2",
2160 },
2161 nocrt: true,
2162 }
Logan Chienf3511742017-10-31 18:04:35 +08002163
Justin Yun0ecf0b22020-02-28 15:07:59 +09002164 cc_library {
2165 name: "libvndk_ext_product",
2166 product_specific: true,
2167 vndk: {
2168 enabled: true,
2169 extends: "libvndk",
2170 },
2171 nocrt: true,
2172 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09002173
Justin Yun0ecf0b22020-02-28 15:07:59 +09002174 cc_library {
2175 name: "libvndk2_ext_product",
2176 product_specific: true,
2177 vndk: {
2178 enabled: true,
2179 extends: "libvndk2",
2180 },
2181 nocrt: true,
2182 }
2183 `
2184 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2185 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2186 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2187 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2188
2189 ctx := testCcWithConfig(t, config)
2190
2191 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
2192 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
2193
2194 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
2195 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
2196
2197 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
2198 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08002199}
2200
Logan Chiend3c59a22018-03-29 14:08:15 +08002201func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08002202 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
2203 ctx := testCcNoVndk(t, `
2204 cc_library {
2205 name: "libvndk",
2206 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002207 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002208 vndk: {
2209 enabled: true,
2210 },
2211 nocrt: true,
2212 }
2213
2214 cc_library {
2215 name: "libvndk_ext",
2216 vendor: true,
2217 vndk: {
2218 enabled: true,
2219 extends: "libvndk",
2220 },
2221 nocrt: true,
2222 }
2223 `)
2224
2225 // Ensures that the core variant of "libvndk_ext" can be found.
2226 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
2227 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2228 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
2229 }
2230}
2231
Justin Yun0ecf0b22020-02-28 15:07:59 +09002232func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
2233 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09002234 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002235 cc_library {
2236 name: "libvndk",
2237 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002238 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002239 vndk: {
2240 enabled: true,
2241 },
2242 nocrt: true,
2243 }
2244
2245 cc_library {
2246 name: "libvndk_ext_product",
2247 product_specific: true,
2248 vndk: {
2249 enabled: true,
2250 extends: "libvndk",
2251 },
2252 nocrt: true,
2253 }
2254 `)
2255
2256 // Ensures that the core variant of "libvndk_ext_product" can be found.
2257 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
2258 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2259 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
2260 }
2261}
2262
Logan Chienf3511742017-10-31 18:04:35 +08002263func TestVndkExtError(t *testing.T) {
2264 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002265 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08002266 cc_library {
2267 name: "libvndk",
2268 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002269 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002270 vndk: {
2271 enabled: true,
2272 },
2273 nocrt: true,
2274 }
2275
2276 cc_library {
2277 name: "libvndk_ext",
2278 vndk: {
2279 enabled: true,
2280 extends: "libvndk",
2281 },
2282 nocrt: true,
2283 }
2284 `)
2285
2286 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2287 cc_library {
2288 name: "libvndk",
2289 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002290 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002291 vndk: {
2292 enabled: true,
2293 },
2294 nocrt: true,
2295 }
2296
2297 cc_library {
2298 name: "libvndk_ext",
2299 vendor: true,
2300 vndk: {
2301 enabled: true,
2302 },
2303 nocrt: true,
2304 }
2305 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002306
2307 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2308 cc_library {
2309 name: "libvndk",
2310 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002311 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002312 vndk: {
2313 enabled: true,
2314 },
2315 nocrt: true,
2316 }
2317
2318 cc_library {
2319 name: "libvndk_ext_product",
2320 product_specific: true,
2321 vndk: {
2322 enabled: true,
2323 },
2324 nocrt: true,
2325 }
2326 `)
2327
2328 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
2329 cc_library {
2330 name: "libvndk",
2331 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002332 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002333 vndk: {
2334 enabled: true,
2335 },
2336 nocrt: true,
2337 }
2338
2339 cc_library {
2340 name: "libvndk_ext_product",
2341 product_specific: true,
2342 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002343 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002344 vndk: {
2345 enabled: true,
2346 extends: "libvndk",
2347 },
2348 nocrt: true,
2349 }
2350 `)
Logan Chienf3511742017-10-31 18:04:35 +08002351}
2352
2353func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
2354 // This test ensures an error is emitted for inconsistent support_system_process.
2355 testCcError(t, "module \".*\" with mismatched support_system_process", `
2356 cc_library {
2357 name: "libvndk",
2358 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002359 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002360 vndk: {
2361 enabled: true,
2362 },
2363 nocrt: true,
2364 }
2365
2366 cc_library {
2367 name: "libvndk_sp_ext",
2368 vendor: true,
2369 vndk: {
2370 enabled: true,
2371 extends: "libvndk",
2372 support_system_process: true,
2373 },
2374 nocrt: true,
2375 }
2376 `)
2377
2378 testCcError(t, "module \".*\" with mismatched support_system_process", `
2379 cc_library {
2380 name: "libvndk_sp",
2381 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002382 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002383 vndk: {
2384 enabled: true,
2385 support_system_process: true,
2386 },
2387 nocrt: true,
2388 }
2389
2390 cc_library {
2391 name: "libvndk_ext",
2392 vendor: true,
2393 vndk: {
2394 enabled: true,
2395 extends: "libvndk_sp",
2396 },
2397 nocrt: true,
2398 }
2399 `)
2400}
2401
2402func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08002403 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09002404 // with `private: true`.
2405 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08002406 cc_library {
2407 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002408 vendor_available: true,
2409 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002410 vndk: {
2411 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002412 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08002413 },
2414 nocrt: true,
2415 }
2416
2417 cc_library {
2418 name: "libvndk_ext",
2419 vendor: true,
2420 vndk: {
2421 enabled: true,
2422 extends: "libvndk",
2423 },
2424 nocrt: true,
2425 }
2426 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002427
Justin Yunfd9e8042020-12-23 18:23:14 +09002428 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09002429 cc_library {
2430 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09002431 vendor_available: true,
2432 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002433 vndk: {
2434 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002435 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002436 },
2437 nocrt: true,
2438 }
2439
2440 cc_library {
2441 name: "libvndk_ext_product",
2442 product_specific: true,
2443 vndk: {
2444 enabled: true,
2445 extends: "libvndk",
2446 },
2447 nocrt: true,
2448 }
2449 `)
Logan Chienf3511742017-10-31 18:04:35 +08002450}
2451
Logan Chiend3c59a22018-03-29 14:08:15 +08002452func TestVendorModuleUseVndkExt(t *testing.T) {
2453 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002454 testCc(t, `
2455 cc_library {
2456 name: "libvndk",
2457 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002458 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002459 vndk: {
2460 enabled: true,
2461 },
2462 nocrt: true,
2463 }
2464
2465 cc_library {
2466 name: "libvndk_ext",
2467 vendor: true,
2468 vndk: {
2469 enabled: true,
2470 extends: "libvndk",
2471 },
2472 nocrt: true,
2473 }
2474
2475 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08002476 name: "libvndk_sp",
2477 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002478 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002479 vndk: {
2480 enabled: true,
2481 support_system_process: true,
2482 },
2483 nocrt: true,
2484 }
2485
2486 cc_library {
2487 name: "libvndk_sp_ext",
2488 vendor: true,
2489 vndk: {
2490 enabled: true,
2491 extends: "libvndk_sp",
2492 support_system_process: true,
2493 },
2494 nocrt: true,
2495 }
2496
2497 cc_library {
2498 name: "libvendor",
2499 vendor: true,
2500 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
2501 nocrt: true,
2502 }
2503 `)
2504}
2505
Logan Chiend3c59a22018-03-29 14:08:15 +08002506func TestVndkExtUseVendorLib(t *testing.T) {
2507 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08002508 testCc(t, `
2509 cc_library {
2510 name: "libvndk",
2511 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002512 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002513 vndk: {
2514 enabled: true,
2515 },
2516 nocrt: true,
2517 }
2518
2519 cc_library {
2520 name: "libvndk_ext",
2521 vendor: true,
2522 vndk: {
2523 enabled: true,
2524 extends: "libvndk",
2525 },
2526 shared_libs: ["libvendor"],
2527 nocrt: true,
2528 }
2529
2530 cc_library {
2531 name: "libvendor",
2532 vendor: true,
2533 nocrt: true,
2534 }
2535 `)
Logan Chienf3511742017-10-31 18:04:35 +08002536
Logan Chiend3c59a22018-03-29 14:08:15 +08002537 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
2538 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08002539 cc_library {
2540 name: "libvndk_sp",
2541 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002542 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002543 vndk: {
2544 enabled: true,
2545 support_system_process: true,
2546 },
2547 nocrt: true,
2548 }
2549
2550 cc_library {
2551 name: "libvndk_sp_ext",
2552 vendor: true,
2553 vndk: {
2554 enabled: true,
2555 extends: "libvndk_sp",
2556 support_system_process: true,
2557 },
2558 shared_libs: ["libvendor"], // Cause an error
2559 nocrt: true,
2560 }
2561
2562 cc_library {
2563 name: "libvendor",
2564 vendor: true,
2565 nocrt: true,
2566 }
2567 `)
2568}
2569
Justin Yun0ecf0b22020-02-28 15:07:59 +09002570func TestProductVndkExtDependency(t *testing.T) {
2571 bp := `
2572 cc_library {
2573 name: "libvndk",
2574 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002575 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002576 vndk: {
2577 enabled: true,
2578 },
2579 nocrt: true,
2580 }
2581
2582 cc_library {
2583 name: "libvndk_ext_product",
2584 product_specific: true,
2585 vndk: {
2586 enabled: true,
2587 extends: "libvndk",
2588 },
2589 shared_libs: ["libproduct_for_vndklibs"],
2590 nocrt: true,
2591 }
2592
2593 cc_library {
2594 name: "libvndk_sp",
2595 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002596 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002597 vndk: {
2598 enabled: true,
2599 support_system_process: true,
2600 },
2601 nocrt: true,
2602 }
2603
2604 cc_library {
2605 name: "libvndk_sp_ext_product",
2606 product_specific: true,
2607 vndk: {
2608 enabled: true,
2609 extends: "libvndk_sp",
2610 support_system_process: true,
2611 },
2612 shared_libs: ["libproduct_for_vndklibs"],
2613 nocrt: true,
2614 }
2615
2616 cc_library {
2617 name: "libproduct",
2618 product_specific: true,
2619 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
2620 nocrt: true,
2621 }
2622
2623 cc_library {
2624 name: "libproduct_for_vndklibs",
2625 product_specific: true,
2626 nocrt: true,
2627 }
2628 `
2629 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2630 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2631 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2632 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2633
2634 testCcWithConfig(t, config)
2635}
2636
Logan Chiend3c59a22018-03-29 14:08:15 +08002637func TestVndkSpExtUseVndkError(t *testing.T) {
2638 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
2639 // library.
2640 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2641 cc_library {
2642 name: "libvndk",
2643 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002644 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002645 vndk: {
2646 enabled: true,
2647 },
2648 nocrt: true,
2649 }
2650
2651 cc_library {
2652 name: "libvndk_sp",
2653 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002654 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002655 vndk: {
2656 enabled: true,
2657 support_system_process: true,
2658 },
2659 nocrt: true,
2660 }
2661
2662 cc_library {
2663 name: "libvndk_sp_ext",
2664 vendor: true,
2665 vndk: {
2666 enabled: true,
2667 extends: "libvndk_sp",
2668 support_system_process: true,
2669 },
2670 shared_libs: ["libvndk"], // Cause an error
2671 nocrt: true,
2672 }
2673 `)
2674
2675 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
2676 // library.
2677 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2678 cc_library {
2679 name: "libvndk",
2680 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002681 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002682 vndk: {
2683 enabled: true,
2684 },
2685 nocrt: true,
2686 }
2687
2688 cc_library {
2689 name: "libvndk_ext",
2690 vendor: true,
2691 vndk: {
2692 enabled: true,
2693 extends: "libvndk",
2694 },
2695 nocrt: true,
2696 }
2697
2698 cc_library {
2699 name: "libvndk_sp",
2700 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002701 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002702 vndk: {
2703 enabled: true,
2704 support_system_process: true,
2705 },
2706 nocrt: true,
2707 }
2708
2709 cc_library {
2710 name: "libvndk_sp_ext",
2711 vendor: true,
2712 vndk: {
2713 enabled: true,
2714 extends: "libvndk_sp",
2715 support_system_process: true,
2716 },
2717 shared_libs: ["libvndk_ext"], // Cause an error
2718 nocrt: true,
2719 }
2720 `)
2721}
2722
2723func TestVndkUseVndkExtError(t *testing.T) {
2724 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
2725 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002726 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2727 cc_library {
2728 name: "libvndk",
2729 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002730 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002731 vndk: {
2732 enabled: true,
2733 },
2734 nocrt: true,
2735 }
2736
2737 cc_library {
2738 name: "libvndk_ext",
2739 vendor: true,
2740 vndk: {
2741 enabled: true,
2742 extends: "libvndk",
2743 },
2744 nocrt: true,
2745 }
2746
2747 cc_library {
2748 name: "libvndk2",
2749 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002750 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002751 vndk: {
2752 enabled: true,
2753 },
2754 shared_libs: ["libvndk_ext"],
2755 nocrt: true,
2756 }
2757 `)
2758
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002759 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002760 cc_library {
2761 name: "libvndk",
2762 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002763 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002764 vndk: {
2765 enabled: true,
2766 },
2767 nocrt: true,
2768 }
2769
2770 cc_library {
2771 name: "libvndk_ext",
2772 vendor: true,
2773 vndk: {
2774 enabled: true,
2775 extends: "libvndk",
2776 },
2777 nocrt: true,
2778 }
2779
2780 cc_library {
2781 name: "libvndk2",
2782 vendor_available: true,
2783 vndk: {
2784 enabled: true,
2785 },
2786 target: {
2787 vendor: {
2788 shared_libs: ["libvndk_ext"],
2789 },
2790 },
2791 nocrt: true,
2792 }
2793 `)
2794
2795 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2796 cc_library {
2797 name: "libvndk_sp",
2798 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002799 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002800 vndk: {
2801 enabled: true,
2802 support_system_process: true,
2803 },
2804 nocrt: true,
2805 }
2806
2807 cc_library {
2808 name: "libvndk_sp_ext",
2809 vendor: true,
2810 vndk: {
2811 enabled: true,
2812 extends: "libvndk_sp",
2813 support_system_process: true,
2814 },
2815 nocrt: true,
2816 }
2817
2818 cc_library {
2819 name: "libvndk_sp_2",
2820 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002821 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002822 vndk: {
2823 enabled: true,
2824 support_system_process: true,
2825 },
2826 shared_libs: ["libvndk_sp_ext"],
2827 nocrt: true,
2828 }
2829 `)
2830
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002831 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002832 cc_library {
2833 name: "libvndk_sp",
2834 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002835 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002836 vndk: {
2837 enabled: true,
2838 },
2839 nocrt: true,
2840 }
2841
2842 cc_library {
2843 name: "libvndk_sp_ext",
2844 vendor: true,
2845 vndk: {
2846 enabled: true,
2847 extends: "libvndk_sp",
2848 },
2849 nocrt: true,
2850 }
2851
2852 cc_library {
2853 name: "libvndk_sp2",
2854 vendor_available: true,
2855 vndk: {
2856 enabled: true,
2857 },
2858 target: {
2859 vendor: {
2860 shared_libs: ["libvndk_sp_ext"],
2861 },
2862 },
2863 nocrt: true,
2864 }
2865 `)
2866}
2867
Justin Yun5f7f7e82019-11-18 19:52:14 +09002868func TestEnforceProductVndkVersion(t *testing.T) {
2869 bp := `
2870 cc_library {
2871 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002872 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002873 }
2874 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002875 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002876 symbol_file: "",
2877 }
2878 cc_library {
2879 name: "libvndk",
2880 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002881 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002882 vndk: {
2883 enabled: true,
2884 },
2885 nocrt: true,
2886 }
2887 cc_library {
2888 name: "libvndk_sp",
2889 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002890 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002891 vndk: {
2892 enabled: true,
2893 support_system_process: true,
2894 },
2895 nocrt: true,
2896 }
2897 cc_library {
2898 name: "libva",
2899 vendor_available: true,
2900 nocrt: true,
2901 }
2902 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002903 name: "libpa",
2904 product_available: true,
2905 nocrt: true,
2906 }
2907 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002908 name: "libboth_available",
2909 vendor_available: true,
2910 product_available: true,
2911 nocrt: true,
2912 target: {
2913 vendor: {
2914 suffix: "-vendor",
2915 },
2916 product: {
2917 suffix: "-product",
2918 },
2919 }
2920 }
2921 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002922 name: "libproduct_va",
2923 product_specific: true,
2924 vendor_available: true,
2925 nocrt: true,
2926 }
2927 cc_library {
2928 name: "libprod",
2929 product_specific: true,
2930 shared_libs: [
2931 "libllndk",
2932 "libvndk",
2933 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002934 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002935 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002936 "libproduct_va",
2937 ],
2938 nocrt: true,
2939 }
2940 cc_library {
2941 name: "libvendor",
2942 vendor: true,
2943 shared_libs: [
2944 "libllndk",
2945 "libvndk",
2946 "libvndk_sp",
2947 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002948 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002949 "libproduct_va",
2950 ],
2951 nocrt: true,
2952 }
2953 `
2954
2955 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2956 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2957 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2958 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2959
2960 ctx := testCcWithConfig(t, config)
2961
Jooyung Han261e1582020-10-20 18:54:21 +09002962 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2963 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002964
2965 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2966 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2967
2968 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2969 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002970}
2971
2972func TestEnforceProductVndkVersionErrors(t *testing.T) {
2973 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2974 cc_library {
2975 name: "libprod",
2976 product_specific: true,
2977 shared_libs: [
2978 "libvendor",
2979 ],
2980 nocrt: true,
2981 }
2982 cc_library {
2983 name: "libvendor",
2984 vendor: true,
2985 nocrt: true,
2986 }
2987 `)
2988 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2989 cc_library {
2990 name: "libprod",
2991 product_specific: true,
2992 shared_libs: [
2993 "libsystem",
2994 ],
2995 nocrt: true,
2996 }
2997 cc_library {
2998 name: "libsystem",
2999 nocrt: true,
3000 }
3001 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09003002 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3003 cc_library {
3004 name: "libprod",
3005 product_specific: true,
3006 shared_libs: [
3007 "libva",
3008 ],
3009 nocrt: true,
3010 }
3011 cc_library {
3012 name: "libva",
3013 vendor_available: true,
3014 nocrt: true,
3015 }
3016 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09003017 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09003018 cc_library {
3019 name: "libprod",
3020 product_specific: true,
3021 shared_libs: [
3022 "libvndk_private",
3023 ],
3024 nocrt: true,
3025 }
3026 cc_library {
3027 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09003028 vendor_available: true,
3029 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003030 vndk: {
3031 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09003032 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003033 },
3034 nocrt: true,
3035 }
3036 `)
3037 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
3038 cc_library {
3039 name: "libprod",
3040 product_specific: true,
3041 shared_libs: [
3042 "libsystem_ext",
3043 ],
3044 nocrt: true,
3045 }
3046 cc_library {
3047 name: "libsystem_ext",
3048 system_ext_specific: true,
3049 nocrt: true,
3050 }
3051 `)
3052 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
3053 cc_library {
3054 name: "libsystem",
3055 shared_libs: [
3056 "libproduct_va",
3057 ],
3058 nocrt: true,
3059 }
3060 cc_library {
3061 name: "libproduct_va",
3062 product_specific: true,
3063 vendor_available: true,
3064 nocrt: true,
3065 }
3066 `)
3067}
3068
Jooyung Han38002912019-05-16 04:01:54 +09003069func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08003070 bp := `
3071 cc_library {
3072 name: "libvndk",
3073 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003074 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003075 vndk: {
3076 enabled: true,
3077 },
3078 }
3079 cc_library {
3080 name: "libvndksp",
3081 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003082 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003083 vndk: {
3084 enabled: true,
3085 support_system_process: true,
3086 },
3087 }
3088 cc_library {
3089 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09003090 vendor_available: true,
3091 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003092 vndk: {
3093 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09003094 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003095 },
3096 }
3097 cc_library {
3098 name: "libvendor",
3099 vendor: true,
3100 }
3101 cc_library {
3102 name: "libvndkext",
3103 vendor: true,
3104 vndk: {
3105 enabled: true,
3106 extends: "libvndk",
3107 },
3108 }
3109 vndk_prebuilt_shared {
3110 name: "prevndk",
3111 version: "27",
3112 target_arch: "arm",
3113 binder32bit: true,
3114 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09003115 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08003116 vndk: {
3117 enabled: true,
3118 },
3119 arch: {
3120 arm: {
3121 srcs: ["liba.so"],
3122 },
3123 },
3124 }
3125 cc_library {
3126 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07003127 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003128 }
3129 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003130 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003131 symbol_file: "",
3132 }
3133 cc_library {
3134 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07003135 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003136 }
3137 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003138 name: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08003139 vendor_available: false,
3140 symbol_file: "",
3141 }`
3142
3143 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09003144 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3145 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3146 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08003147 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09003148
Jooyung Han0302a842019-10-30 18:43:49 +09003149 assertMapKeys(t, vndkCoreLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09003150 []string{"libvndk", "libvndkprivate"})
Jooyung Han0302a842019-10-30 18:43:49 +09003151 assertMapKeys(t, vndkSpLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09003152 []string{"libc++", "libvndksp"})
Jooyung Han0302a842019-10-30 18:43:49 +09003153 assertMapKeys(t, llndkLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09003154 []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"})
Jooyung Han0302a842019-10-30 18:43:49 +09003155 assertMapKeys(t, vndkPrivateLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09003156 []string{"libft2", "libllndkprivate", "libvndkprivate"})
Jooyung Han38002912019-05-16 04:01:54 +09003157
Colin Crossfb0c16e2019-11-20 17:12:35 -08003158 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09003159
Jooyung Han38002912019-05-16 04:01:54 +09003160 tests := []struct {
3161 variant string
3162 name string
3163 expected string
3164 }{
3165 {vendorVariant, "libvndk", "native:vndk"},
3166 {vendorVariant, "libvndksp", "native:vndk"},
3167 {vendorVariant, "libvndkprivate", "native:vndk_private"},
3168 {vendorVariant, "libvendor", "native:vendor"},
3169 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08003170 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09003171 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09003172 {coreVariant, "libvndk", "native:platform"},
3173 {coreVariant, "libvndkprivate", "native:platform"},
3174 {coreVariant, "libllndk", "native:platform"},
3175 }
3176 for _, test := range tests {
3177 t.Run(test.name, func(t *testing.T) {
3178 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
3179 assertString(t, module.makeLinkType, test.expected)
3180 })
3181 }
3182}
3183
Jeff Gaston294356f2017-09-27 17:05:30 -07003184var staticLinkDepOrderTestCases = []struct {
3185 // This is a string representation of a map[moduleName][]moduleDependency .
3186 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003187 inStatic string
3188
3189 // This is a string representation of a map[moduleName][]moduleDependency .
3190 // It models the dependencies declared in an Android.bp file.
3191 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07003192
3193 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
3194 // The keys of allOrdered specify which modules we would like to check.
3195 // The values of allOrdered specify the expected result (of the transitive closure of all
3196 // dependencies) for each module to test
3197 allOrdered string
3198
3199 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
3200 // The keys of outOrdered specify which modules we would like to check.
3201 // The values of outOrdered specify the expected result (of the ordered linker command line)
3202 // for each module to test.
3203 outOrdered string
3204}{
3205 // Simple tests
3206 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003207 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07003208 outOrdered: "",
3209 },
3210 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003211 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003212 outOrdered: "a:",
3213 },
3214 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003215 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003216 outOrdered: "a:b; b:",
3217 },
3218 // Tests of reordering
3219 {
3220 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003221 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07003222 outOrdered: "a:b,c,d; b:d; c:d; d:",
3223 },
3224 {
3225 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003226 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003227 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
3228 },
3229 {
3230 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003231 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07003232 outOrdered: "a:d,b,e,c; d:b; e:c",
3233 },
3234 {
3235 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003236 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07003237 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
3238 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
3239 },
3240 {
3241 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003242 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 -07003243 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3244 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
3245 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003246 // shared dependencies
3247 {
3248 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
3249 // So, we don't actually have to check that a shared dependency of c will change the order
3250 // of a library that depends statically on b and on c. We only need to check that if c has
3251 // a shared dependency on b, that that shows up in allOrdered.
3252 inShared: "c:b",
3253 allOrdered: "c:b",
3254 outOrdered: "c:",
3255 },
3256 {
3257 // This test doesn't actually include any shared dependencies but it's a reminder of what
3258 // the second phase of the above test would look like
3259 inStatic: "a:b,c; c:b",
3260 allOrdered: "a:c,b; c:b",
3261 outOrdered: "a:c,b; c:b",
3262 },
Jeff Gaston294356f2017-09-27 17:05:30 -07003263 // tiebreakers for when two modules specifying different orderings and there is no dependency
3264 // to dictate an order
3265 {
3266 // 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 -08003267 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07003268 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
3269 },
3270 {
3271 // 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 -08003272 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 -07003273 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
3274 },
3275 // Tests involving duplicate dependencies
3276 {
3277 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003278 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003279 outOrdered: "a:c,b",
3280 },
3281 {
3282 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003283 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003284 outOrdered: "a:d,c,b",
3285 },
3286 // Tests to confirm the nonexistence of infinite loops.
3287 // These cases should never happen, so as long as the test terminates and the
3288 // result is deterministic then that should be fine.
3289 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003290 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003291 outOrdered: "a:a",
3292 },
3293 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003294 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003295 allOrdered: "a:b,c; b:c,a; c:a,b",
3296 outOrdered: "a:b; b:c; c:a",
3297 },
3298 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003299 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003300 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
3301 outOrdered: "a:c,b; b:a,c; c:b,a",
3302 },
3303}
3304
3305// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
3306func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
3307 // convert from "a:b,c; d:e" to "a:b,c;d:e"
3308 strippedText := strings.Replace(text, " ", "", -1)
3309 if len(strippedText) < 1 {
3310 return []android.Path{}, make(map[android.Path][]android.Path, 0)
3311 }
3312 allDeps = make(map[android.Path][]android.Path, 0)
3313
3314 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
3315 moduleTexts := strings.Split(strippedText, ";")
3316
3317 outputForModuleName := func(moduleName string) android.Path {
3318 return android.PathForTesting(moduleName)
3319 }
3320
3321 for _, moduleText := range moduleTexts {
3322 // convert from "a:b,c" to ["a", "b,c"]
3323 components := strings.Split(moduleText, ":")
3324 if len(components) != 2 {
3325 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
3326 }
3327 moduleName := components[0]
3328 moduleOutput := outputForModuleName(moduleName)
3329 modulesInOrder = append(modulesInOrder, moduleOutput)
3330
3331 depString := components[1]
3332 // convert from "b,c" to ["b", "c"]
3333 depNames := strings.Split(depString, ",")
3334 if len(depString) < 1 {
3335 depNames = []string{}
3336 }
3337 var deps []android.Path
3338 for _, depName := range depNames {
3339 deps = append(deps, outputForModuleName(depName))
3340 }
3341 allDeps[moduleOutput] = deps
3342 }
3343 return modulesInOrder, allDeps
3344}
3345
Jeff Gaston294356f2017-09-27 17:05:30 -07003346func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
3347 for _, moduleName := range moduleNames {
3348 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
3349 output := module.outputFile.Path()
3350 paths = append(paths, output)
3351 }
3352 return paths
3353}
3354
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003355func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07003356 ctx := testCc(t, `
3357 cc_library {
3358 name: "a",
3359 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09003360 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003361 }
3362 cc_library {
3363 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003364 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003365 }
3366 cc_library {
3367 name: "c",
3368 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003369 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003370 }
3371 cc_library {
3372 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09003373 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003374 }
3375
3376 `)
3377
Colin Cross7113d202019-11-20 16:39:12 -08003378 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07003379 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003380 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3381 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07003382
3383 if !reflect.DeepEqual(actual, expected) {
3384 t.Errorf("staticDeps orderings were not propagated correctly"+
3385 "\nactual: %v"+
3386 "\nexpected: %v",
3387 actual,
3388 expected,
3389 )
3390 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09003391}
Jeff Gaston294356f2017-09-27 17:05:30 -07003392
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003393func TestStaticLibDepReorderingWithShared(t *testing.T) {
3394 ctx := testCc(t, `
3395 cc_library {
3396 name: "a",
3397 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09003398 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003399 }
3400 cc_library {
3401 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003402 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003403 }
3404 cc_library {
3405 name: "c",
3406 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003407 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003408 }
3409
3410 `)
3411
Colin Cross7113d202019-11-20 16:39:12 -08003412 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003413 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003414 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3415 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003416
3417 if !reflect.DeepEqual(actual, expected) {
3418 t.Errorf("staticDeps orderings did not account for shared libs"+
3419 "\nactual: %v"+
3420 "\nexpected: %v",
3421 actual,
3422 expected,
3423 )
3424 }
3425}
3426
Jooyung Hanb04a4992020-03-13 18:57:35 +09003427func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07003428 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09003429 if !reflect.DeepEqual(actual, expected) {
3430 t.Errorf(message+
3431 "\nactual: %v"+
3432 "\nexpected: %v",
3433 actual,
3434 expected,
3435 )
3436 }
3437}
3438
Jooyung Han61b66e92020-03-21 14:21:46 +00003439func TestLlndkLibrary(t *testing.T) {
3440 ctx := testCc(t, `
3441 cc_library {
3442 name: "libllndk",
3443 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07003444 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003445 }
3446 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003447 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003448 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003449
3450 cc_prebuilt_library_shared {
3451 name: "libllndkprebuilt",
3452 stubs: { versions: ["1", "2"] },
3453 llndk_stubs: "libllndkprebuilt.llndk",
3454 }
3455 llndk_library {
3456 name: "libllndkprebuilt.llndk",
3457 }
3458
3459 cc_library {
3460 name: "libllndk_with_external_headers",
3461 stubs: { versions: ["1", "2"] },
3462 llndk_stubs: "libllndk_with_external_headers.llndk",
3463 header_libs: ["libexternal_headers"],
3464 export_header_lib_headers: ["libexternal_headers"],
3465 }
3466 llndk_library {
3467 name: "libllndk_with_external_headers.llndk",
3468 }
3469 cc_library_headers {
3470 name: "libexternal_headers",
3471 export_include_dirs: ["include"],
3472 vendor_available: true,
3473 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003474 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08003475 actual := ctx.ModuleVariantsForTests("libllndk")
3476 for i := 0; i < len(actual); i++ {
3477 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
3478 actual = append(actual[:i], actual[i+1:]...)
3479 i--
3480 }
3481 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003482 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00003483 "android_vendor.VER_arm64_armv8-a_shared_1",
3484 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003485 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003486 "android_vendor.VER_arm_armv7-a-neon_shared_1",
3487 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003488 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003489 }
3490 checkEquals(t, "variants for llndk stubs", expected, actual)
3491
Colin Cross127bb8b2020-12-16 16:46:01 -08003492 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003493 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
3494
Colin Cross127bb8b2020-12-16 16:46:01 -08003495 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003496 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
3497}
3498
Jiyong Parka46a4d52017-12-14 19:54:34 +09003499func TestLlndkHeaders(t *testing.T) {
3500 ctx := testCc(t, `
3501 llndk_headers {
3502 name: "libllndk_headers",
3503 export_include_dirs: ["my_include"],
3504 }
3505 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003506 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09003507 export_llndk_headers: ["libllndk_headers"],
3508 }
3509 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07003510 name: "libllndk",
3511 llndk_stubs: "libllndk.llndk",
3512 }
3513
3514 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09003515 name: "libvendor",
3516 shared_libs: ["libllndk"],
3517 vendor: true,
3518 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003519 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08003520 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09003521 }
3522 `)
3523
3524 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08003525 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09003526 cflags := cc.Args["cFlags"]
3527 if !strings.Contains(cflags, "-Imy_include") {
3528 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
3529 }
3530}
3531
Logan Chien43d34c32017-12-20 01:17:32 +08003532func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
3533 actual := module.Properties.AndroidMkRuntimeLibs
3534 if !reflect.DeepEqual(actual, expected) {
3535 t.Errorf("incorrect runtime_libs for shared libs"+
3536 "\nactual: %v"+
3537 "\nexpected: %v",
3538 actual,
3539 expected,
3540 )
3541 }
3542}
3543
3544const runtimeLibAndroidBp = `
3545 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09003546 name: "liball_available",
3547 vendor_available: true,
3548 product_available: true,
3549 no_libcrt : true,
3550 nocrt : true,
3551 system_shared_libs : [],
3552 }
3553 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08003554 name: "libvendor_available1",
3555 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003556 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07003557 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003558 nocrt : true,
3559 system_shared_libs : [],
3560 }
3561 cc_library {
3562 name: "libvendor_available2",
3563 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003564 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08003565 target: {
3566 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09003567 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08003568 }
3569 },
Yi Konge7fe9912019-06-02 00:53:50 -07003570 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003571 nocrt : true,
3572 system_shared_libs : [],
3573 }
3574 cc_library {
3575 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09003576 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07003577 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003578 nocrt : true,
3579 system_shared_libs : [],
3580 }
3581 cc_library {
3582 name: "libvendor1",
3583 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003584 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003585 nocrt : true,
3586 system_shared_libs : [],
3587 }
3588 cc_library {
3589 name: "libvendor2",
3590 vendor: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09003591 runtime_libs: ["liball_available", "libvendor1"],
3592 no_libcrt : true,
3593 nocrt : true,
3594 system_shared_libs : [],
3595 }
3596 cc_library {
3597 name: "libproduct_available1",
3598 product_available: true,
3599 runtime_libs: ["liball_available"],
3600 no_libcrt : true,
3601 nocrt : true,
3602 system_shared_libs : [],
3603 }
3604 cc_library {
3605 name: "libproduct1",
3606 product_specific: true,
3607 no_libcrt : true,
3608 nocrt : true,
3609 system_shared_libs : [],
3610 }
3611 cc_library {
3612 name: "libproduct2",
3613 product_specific: true,
3614 runtime_libs: ["liball_available", "libproduct1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003615 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003616 nocrt : true,
3617 system_shared_libs : [],
3618 }
3619`
3620
3621func TestRuntimeLibs(t *testing.T) {
3622 ctx := testCc(t, runtimeLibAndroidBp)
3623
3624 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08003625 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003626
Justin Yun8a2600c2020-12-07 12:44:03 +09003627 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3628 checkRuntimeLibs(t, []string{"liball_available"}, module)
3629
3630 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3631 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003632
3633 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003634 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003635
3636 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
3637 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08003638 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003639
Justin Yun8a2600c2020-12-07 12:44:03 +09003640 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3641 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003642
3643 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003644 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1"}, module)
3645
3646 // runtime_libs for product variants have '.product' suffixes if the modules have both core
3647 // and product variants.
3648 variant = "android_product.VER_arm64_armv8-a_shared"
3649
3650 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3651 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
3652
3653 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
3654 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003655}
3656
3657func TestExcludeRuntimeLibs(t *testing.T) {
3658 ctx := testCc(t, runtimeLibAndroidBp)
3659
Colin Cross7113d202019-11-20 16:39:12 -08003660 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003661 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3662 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003663
Colin Crossfb0c16e2019-11-20 17:12:35 -08003664 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003665 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08003666 checkRuntimeLibs(t, nil, module)
3667}
3668
3669func TestRuntimeLibsNoVndk(t *testing.T) {
3670 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
3671
3672 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
3673
Colin Cross7113d202019-11-20 16:39:12 -08003674 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003675
Justin Yun8a2600c2020-12-07 12:44:03 +09003676 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3677 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003678
3679 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003680 checkRuntimeLibs(t, []string{"liball_available", "libvendor1"}, module)
3681
3682 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
3683 checkRuntimeLibs(t, []string{"liball_available", "libproduct1"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003684}
3685
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003686func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09003687 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003688 actual := module.Properties.AndroidMkStaticLibs
3689 if !reflect.DeepEqual(actual, expected) {
3690 t.Errorf("incorrect static_libs"+
3691 "\nactual: %v"+
3692 "\nexpected: %v",
3693 actual,
3694 expected,
3695 )
3696 }
3697}
3698
3699const staticLibAndroidBp = `
3700 cc_library {
3701 name: "lib1",
3702 }
3703 cc_library {
3704 name: "lib2",
3705 static_libs: ["lib1"],
3706 }
3707`
3708
3709func TestStaticLibDepExport(t *testing.T) {
3710 ctx := testCc(t, staticLibAndroidBp)
3711
3712 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003713 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003714 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003715 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003716
3717 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003718 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003719 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
3720 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003721 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003722}
3723
Jiyong Parkd08b6972017-09-26 10:50:54 +09003724var compilerFlagsTestCases = []struct {
3725 in string
3726 out bool
3727}{
3728 {
3729 in: "a",
3730 out: false,
3731 },
3732 {
3733 in: "-a",
3734 out: true,
3735 },
3736 {
3737 in: "-Ipath/to/something",
3738 out: false,
3739 },
3740 {
3741 in: "-isystempath/to/something",
3742 out: false,
3743 },
3744 {
3745 in: "--coverage",
3746 out: false,
3747 },
3748 {
3749 in: "-include a/b",
3750 out: true,
3751 },
3752 {
3753 in: "-include a/b c/d",
3754 out: false,
3755 },
3756 {
3757 in: "-DMACRO",
3758 out: true,
3759 },
3760 {
3761 in: "-DMAC RO",
3762 out: false,
3763 },
3764 {
3765 in: "-a -b",
3766 out: false,
3767 },
3768 {
3769 in: "-DMACRO=definition",
3770 out: true,
3771 },
3772 {
3773 in: "-DMACRO=defi nition",
3774 out: true, // TODO(jiyong): this should be false
3775 },
3776 {
3777 in: "-DMACRO(x)=x + 1",
3778 out: true,
3779 },
3780 {
3781 in: "-DMACRO=\"defi nition\"",
3782 out: true,
3783 },
3784}
3785
3786type mockContext struct {
3787 BaseModuleContext
3788 result bool
3789}
3790
3791func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3792 // CheckBadCompilerFlags calls this function when the flag should be rejected
3793 ctx.result = false
3794}
3795
3796func TestCompilerFlags(t *testing.T) {
3797 for _, testCase := range compilerFlagsTestCases {
3798 ctx := &mockContext{result: true}
3799 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3800 if ctx.result != testCase.out {
3801 t.Errorf("incorrect output:")
3802 t.Errorf(" input: %#v", testCase.in)
3803 t.Errorf(" expected: %#v", testCase.out)
3804 t.Errorf(" got: %#v", ctx.result)
3805 }
3806 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003807}
Jiyong Park374510b2018-03-19 18:23:01 +09003808
3809func TestVendorPublicLibraries(t *testing.T) {
3810 ctx := testCc(t, `
3811 cc_library_headers {
3812 name: "libvendorpublic_headers",
3813 export_include_dirs: ["my_include"],
3814 }
3815 vendor_public_library {
3816 name: "libvendorpublic",
3817 symbol_file: "",
3818 export_public_headers: ["libvendorpublic_headers"],
3819 }
3820 cc_library {
3821 name: "libvendorpublic",
3822 srcs: ["foo.c"],
3823 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003824 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003825 nocrt: true,
3826 }
3827
3828 cc_library {
3829 name: "libsystem",
3830 shared_libs: ["libvendorpublic"],
3831 vendor: false,
3832 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003833 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003834 nocrt: true,
3835 }
3836 cc_library {
3837 name: "libvendor",
3838 shared_libs: ["libvendorpublic"],
3839 vendor: true,
3840 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003841 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003842 nocrt: true,
3843 }
3844 `)
3845
Colin Cross7113d202019-11-20 16:39:12 -08003846 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003847 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003848
3849 // test if header search paths are correctly added
3850 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003851 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003852 cflags := cc.Args["cFlags"]
3853 if !strings.Contains(cflags, "-Imy_include") {
3854 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3855 }
3856
3857 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003858 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003859 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003860 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003861 if !strings.Contains(libflags, stubPaths[0].String()) {
3862 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3863 }
3864
3865 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003866 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003867 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003868 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003869 if !strings.Contains(libflags, stubPaths[0].String()) {
3870 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3871 }
3872
3873}
Jiyong Park37b25202018-07-11 10:49:27 +09003874
3875func TestRecovery(t *testing.T) {
3876 ctx := testCc(t, `
3877 cc_library_shared {
3878 name: "librecovery",
3879 recovery: true,
3880 }
3881 cc_library_shared {
3882 name: "librecovery32",
3883 recovery: true,
3884 compile_multilib:"32",
3885 }
Jiyong Park5baac542018-08-28 09:55:37 +09003886 cc_library_shared {
3887 name: "libHalInRecovery",
3888 recovery_available: true,
3889 vendor: true,
3890 }
Jiyong Park37b25202018-07-11 10:49:27 +09003891 `)
3892
3893 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003894 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003895 if len(variants) != 1 || !android.InList(arm64, variants) {
3896 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3897 }
3898
3899 variants = ctx.ModuleVariantsForTests("librecovery32")
3900 if android.InList(arm64, variants) {
3901 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3902 }
Jiyong Park5baac542018-08-28 09:55:37 +09003903
3904 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3905 if !recoveryModule.Platform() {
3906 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3907 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003908}
Jiyong Park5baac542018-08-28 09:55:37 +09003909
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003910func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3911 bp := `
3912 cc_prebuilt_test_library_shared {
3913 name: "test_lib",
3914 relative_install_path: "foo/bar/baz",
3915 srcs: ["srcpath/dontusethispath/baz.so"],
3916 }
3917
3918 cc_test {
3919 name: "main_test",
3920 data_libs: ["test_lib"],
3921 gtest: false,
3922 }
3923 `
3924
3925 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3926 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3927 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3928 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3929
3930 ctx := testCcWithConfig(t, config)
3931 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3932 testBinary := module.(*Module).linker.(*testBinary)
3933 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3934 if err != nil {
3935 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3936 }
3937 if len(outputFiles) != 1 {
3938 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3939 }
3940 if len(testBinary.dataPaths()) != 1 {
3941 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3942 }
3943
3944 outputPath := outputFiles[0].String()
3945
3946 if !strings.HasSuffix(outputPath, "/main_test") {
3947 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3948 }
3949 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3950 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3951 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3952 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3953 }
3954}
3955
Jiyong Park7ed9de32018-10-15 22:25:07 +09003956func TestVersionedStubs(t *testing.T) {
3957 ctx := testCc(t, `
3958 cc_library_shared {
3959 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003960 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003961 stubs: {
3962 symbol_file: "foo.map.txt",
3963 versions: ["1", "2", "3"],
3964 },
3965 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003966
Jiyong Park7ed9de32018-10-15 22:25:07 +09003967 cc_library_shared {
3968 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003969 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003970 shared_libs: ["libFoo#1"],
3971 }`)
3972
3973 variants := ctx.ModuleVariantsForTests("libFoo")
3974 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003975 "android_arm64_armv8-a_shared",
3976 "android_arm64_armv8-a_shared_1",
3977 "android_arm64_armv8-a_shared_2",
3978 "android_arm64_armv8-a_shared_3",
3979 "android_arm_armv7-a-neon_shared",
3980 "android_arm_armv7-a-neon_shared_1",
3981 "android_arm_armv7-a-neon_shared_2",
3982 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003983 }
3984 variantsMismatch := false
3985 if len(variants) != len(expectedVariants) {
3986 variantsMismatch = true
3987 } else {
3988 for _, v := range expectedVariants {
3989 if !inList(v, variants) {
3990 variantsMismatch = false
3991 }
3992 }
3993 }
3994 if variantsMismatch {
3995 t.Errorf("variants of libFoo expected:\n")
3996 for _, v := range expectedVariants {
3997 t.Errorf("%q\n", v)
3998 }
3999 t.Errorf(", but got:\n")
4000 for _, v := range variants {
4001 t.Errorf("%q\n", v)
4002 }
4003 }
4004
Colin Cross7113d202019-11-20 16:39:12 -08004005 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09004006 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08004007 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09004008 if !strings.Contains(libFlags, libFoo1StubPath) {
4009 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
4010 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09004011
Colin Cross7113d202019-11-20 16:39:12 -08004012 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09004013 cFlags := libBarCompileRule.Args["cFlags"]
4014 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
4015 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
4016 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
4017 }
Jiyong Park37b25202018-07-11 10:49:27 +09004018}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004019
Jooyung Hanb04a4992020-03-13 18:57:35 +09004020func TestVersioningMacro(t *testing.T) {
4021 for _, tc := range []struct{ moduleName, expected string }{
4022 {"libc", "__LIBC_API__"},
4023 {"libfoo", "__LIBFOO_API__"},
4024 {"libfoo@1", "__LIBFOO_1_API__"},
4025 {"libfoo-v1", "__LIBFOO_V1_API__"},
4026 {"libfoo.v1", "__LIBFOO_V1_API__"},
4027 } {
4028 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
4029 }
4030}
4031
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004032func TestStaticExecutable(t *testing.T) {
4033 ctx := testCc(t, `
4034 cc_binary {
4035 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01004036 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004037 static_executable: true,
4038 }`)
4039
Colin Cross7113d202019-11-20 16:39:12 -08004040 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004041 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
4042 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07004043 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08004044 for _, lib := range systemStaticLibs {
4045 if !strings.Contains(libFlags, lib) {
4046 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
4047 }
4048 }
4049 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
4050 for _, lib := range systemSharedLibs {
4051 if strings.Contains(libFlags, lib) {
4052 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
4053 }
4054 }
4055}
Jiyong Parke4bb9862019-02-01 00:31:10 +09004056
4057func TestStaticDepsOrderWithStubs(t *testing.T) {
4058 ctx := testCc(t, `
4059 cc_binary {
4060 name: "mybin",
4061 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07004062 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09004063 static_executable: true,
4064 stl: "none",
4065 }
4066
4067 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08004068 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09004069 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08004070 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09004071 stl: "none",
4072 }
4073
4074 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08004075 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09004076 srcs: ["foo.c"],
4077 stl: "none",
4078 stubs: {
4079 versions: ["1"],
4080 },
4081 }`)
4082
Colin Cross0de8a1e2020-09-18 14:15:30 -07004083 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
4084 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08004085 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09004086
4087 if !reflect.DeepEqual(actual, expected) {
4088 t.Errorf("staticDeps orderings were not propagated correctly"+
4089 "\nactual: %v"+
4090 "\nexpected: %v",
4091 actual,
4092 expected,
4093 )
4094 }
4095}
Jooyung Han38002912019-05-16 04:01:54 +09004096
Jooyung Hand48f3c32019-08-23 11:18:57 +09004097func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
4098 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
4099 cc_library {
4100 name: "libA",
4101 srcs: ["foo.c"],
4102 shared_libs: ["libB"],
4103 stl: "none",
4104 }
4105
4106 cc_library {
4107 name: "libB",
4108 srcs: ["foo.c"],
4109 enabled: false,
4110 stl: "none",
4111 }
4112 `)
4113}
4114
Mitch Phillipsda9a4632019-07-15 09:34:09 -07004115// Simple smoke test for the cc_fuzz target that ensures the rule compiles
4116// correctly.
4117func TestFuzzTarget(t *testing.T) {
4118 ctx := testCc(t, `
4119 cc_fuzz {
4120 name: "fuzz_smoke_test",
4121 srcs: ["foo.c"],
4122 }`)
4123
Paul Duffin075c4172019-12-19 19:06:13 +00004124 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07004125 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
4126}
4127
Jiyong Park29074592019-07-07 16:27:47 +09004128func TestAidl(t *testing.T) {
4129}
4130
Jooyung Han38002912019-05-16 04:01:54 +09004131func assertString(t *testing.T, got, expected string) {
4132 t.Helper()
4133 if got != expected {
4134 t.Errorf("expected %q got %q", expected, got)
4135 }
4136}
4137
4138func assertArrayString(t *testing.T, got, expected []string) {
4139 t.Helper()
4140 if len(got) != len(expected) {
4141 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
4142 return
4143 }
4144 for i := range got {
4145 if got[i] != expected[i] {
4146 t.Errorf("expected %d-th %q (%q) got %q (%q)",
4147 i, expected[i], expected, got[i], got)
4148 return
4149 }
4150 }
4151}
Colin Crosse1bb5d02019-09-24 14:55:04 -07004152
Jooyung Han0302a842019-10-30 18:43:49 +09004153func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
4154 t.Helper()
4155 assertArrayString(t, android.SortedStringKeys(m), expected)
4156}
4157
Colin Crosse1bb5d02019-09-24 14:55:04 -07004158func TestDefaults(t *testing.T) {
4159 ctx := testCc(t, `
4160 cc_defaults {
4161 name: "defaults",
4162 srcs: ["foo.c"],
4163 static: {
4164 srcs: ["bar.c"],
4165 },
4166 shared: {
4167 srcs: ["baz.c"],
4168 },
4169 }
4170
4171 cc_library_static {
4172 name: "libstatic",
4173 defaults: ["defaults"],
4174 }
4175
4176 cc_library_shared {
4177 name: "libshared",
4178 defaults: ["defaults"],
4179 }
4180
4181 cc_library {
4182 name: "libboth",
4183 defaults: ["defaults"],
4184 }
4185
4186 cc_binary {
4187 name: "binary",
4188 defaults: ["defaults"],
4189 }`)
4190
4191 pathsToBase := func(paths android.Paths) []string {
4192 var ret []string
4193 for _, p := range paths {
4194 ret = append(ret, p.Base())
4195 }
4196 return ret
4197 }
4198
Colin Cross7113d202019-11-20 16:39:12 -08004199 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004200 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4201 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
4202 }
Colin Cross7113d202019-11-20 16:39:12 -08004203 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004204 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
4205 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
4206 }
Colin Cross7113d202019-11-20 16:39:12 -08004207 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004208 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
4209 t.Errorf("binary ld rule wanted %q, got %q", w, g)
4210 }
4211
Colin Cross7113d202019-11-20 16:39:12 -08004212 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004213 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4214 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
4215 }
Colin Cross7113d202019-11-20 16:39:12 -08004216 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07004217 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
4218 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
4219 }
4220}
Colin Crosseabaedd2020-02-06 17:01:55 -08004221
4222func TestProductVariableDefaults(t *testing.T) {
4223 bp := `
4224 cc_defaults {
4225 name: "libfoo_defaults",
4226 srcs: ["foo.c"],
4227 cppflags: ["-DFOO"],
4228 product_variables: {
4229 debuggable: {
4230 cppflags: ["-DBAR"],
4231 },
4232 },
4233 }
4234
4235 cc_library {
4236 name: "libfoo",
4237 defaults: ["libfoo_defaults"],
4238 }
4239 `
4240
4241 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4242 config.TestProductVariables.Debuggable = BoolPtr(true)
4243
Colin Crossae8600b2020-10-29 17:09:13 -07004244 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08004245 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
4246 ctx.BottomUp("variable", android.VariableMutator).Parallel()
4247 })
Colin Crossae8600b2020-10-29 17:09:13 -07004248 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08004249
4250 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4251 android.FailIfErrored(t, errs)
4252 _, errs = ctx.PrepareBuildActions(config)
4253 android.FailIfErrored(t, errs)
4254
4255 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
4256 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
4257 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
4258 }
4259}
Colin Crosse4f6eba2020-09-22 18:11:25 -07004260
4261func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
4262 t.Parallel()
4263 bp := `
4264 cc_library_static {
4265 name: "libfoo",
4266 srcs: ["foo.c"],
4267 whole_static_libs: ["libbar"],
4268 }
4269
4270 cc_library_static {
4271 name: "libbar",
4272 whole_static_libs: ["libmissing"],
4273 }
4274 `
4275
4276 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4277 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
4278
Colin Crossae8600b2020-10-29 17:09:13 -07004279 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07004280 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07004281 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07004282
4283 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
4284 android.FailIfErrored(t, errs)
4285 _, errs = ctx.PrepareBuildActions(config)
4286 android.FailIfErrored(t, errs)
4287
4288 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
4289 if g, w := libbar.Rule, android.ErrorRule; g != w {
4290 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
4291 }
4292
4293 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
4294 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
4295 }
4296
4297 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
4298 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
4299 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
4300 }
4301
4302}
Colin Crosse9fe2942020-11-10 18:12:15 -08004303
4304func TestInstallSharedLibs(t *testing.T) {
4305 bp := `
4306 cc_binary {
4307 name: "bin",
4308 host_supported: true,
4309 shared_libs: ["libshared"],
4310 runtime_libs: ["libruntime"],
4311 srcs: [":gen"],
4312 }
4313
4314 cc_library_shared {
4315 name: "libshared",
4316 host_supported: true,
4317 shared_libs: ["libtransitive"],
4318 }
4319
4320 cc_library_shared {
4321 name: "libtransitive",
4322 host_supported: true,
4323 }
4324
4325 cc_library_shared {
4326 name: "libruntime",
4327 host_supported: true,
4328 }
4329
4330 cc_binary_host {
4331 name: "tool",
4332 srcs: ["foo.cpp"],
4333 }
4334
4335 genrule {
4336 name: "gen",
4337 tools: ["tool"],
4338 out: ["gen.cpp"],
4339 cmd: "$(location tool) $(out)",
4340 }
4341 `
4342
4343 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4344 ctx := testCcWithConfig(t, config)
4345
4346 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
4347 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
4348 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
4349 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
4350 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
4351
4352 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
4353 t.Errorf("expected host bin dependency %q, got %q", w, g)
4354 }
4355
4356 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4357 t.Errorf("expected host bin dependency %q, got %q", w, g)
4358 }
4359
4360 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4361 t.Errorf("expected host bin dependency %q, got %q", w, g)
4362 }
4363
4364 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
4365 t.Errorf("expected host bin dependency %q, got %q", w, g)
4366 }
4367
4368 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
4369 t.Errorf("expected no host bin dependency %q, got %q", w, g)
4370 }
4371
4372 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
4373 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
4374 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
4375 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
4376
4377 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
4378 t.Errorf("expected device bin dependency %q, got %q", w, g)
4379 }
4380
4381 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4382 t.Errorf("expected device bin dependency %q, got %q", w, g)
4383 }
4384
4385 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4386 t.Errorf("expected device bin dependency %q, got %q", w, g)
4387 }
4388
4389 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
4390 t.Errorf("expected device bin dependency %q, got %q", w, g)
4391 }
4392
4393 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
4394 t.Errorf("expected no device bin dependency %q, got %q", w, g)
4395 }
4396
4397}
Jiyong Park1ad8e162020-12-01 23:40:09 +09004398
4399func TestStubsLibReexportsHeaders(t *testing.T) {
4400 ctx := testCc(t, `
4401 cc_library_shared {
4402 name: "libclient",
4403 srcs: ["foo.c"],
4404 shared_libs: ["libfoo#1"],
4405 }
4406
4407 cc_library_shared {
4408 name: "libfoo",
4409 srcs: ["foo.c"],
4410 shared_libs: ["libbar"],
4411 export_shared_lib_headers: ["libbar"],
4412 stubs: {
4413 symbol_file: "foo.map.txt",
4414 versions: ["1", "2", "3"],
4415 },
4416 }
4417
4418 cc_library_shared {
4419 name: "libbar",
4420 export_include_dirs: ["include/libbar"],
4421 srcs: ["foo.c"],
4422 }`)
4423
4424 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
4425
4426 if !strings.Contains(cFlags, "-Iinclude/libbar") {
4427 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
4428 }
4429}
Jooyung Hane197d8b2021-01-05 10:33:16 +09004430
4431func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
4432 ctx := testCc(t, `
4433 cc_library {
4434 name: "libfoo",
4435 srcs: ["a/Foo.aidl"],
4436 aidl: { flags: ["-Werror"], },
4437 }
4438 `)
4439
4440 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
4441 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
4442 aidlCommand := manifest.Commands[0].GetCommand()
4443 expectedAidlFlag := "-Werror"
4444 if !strings.Contains(aidlCommand, expectedAidlFlag) {
4445 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
4446 }
4447}