blob: 56b36df57b1e876bcaf53344aa9dd30cc1cacb79 [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 "sort"
24 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070025 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070026
27 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070028)
29
Jiyong Park6a43f042017-10-12 23:05:00 +090030var buildDir string
31
32func setUp() {
33 var err error
34 buildDir, err = ioutil.TempDir("", "soong_cc_test")
35 if err != nil {
36 panic(err)
37 }
38}
39
40func tearDown() {
41 os.RemoveAll(buildDir)
42}
43
44func TestMain(m *testing.M) {
45 run := func() int {
46 setUp()
47 defer tearDown()
48
49 return m.Run()
50 }
51
52 os.Exit(run())
53}
54
Colin Cross98be1bb2019-12-13 20:41:13 -080055func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070056 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080057 ctx := CreateTestContext()
58 ctx.Register(config)
Logan Chienf3511742017-10-31 18:04:35 +080059
Jeff Gastond3e141d2017-08-08 17:46:01 -070060 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +080061 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090062 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +080063 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090064
65 return ctx
66}
67
Logan Chienf3511742017-10-31 18:04:35 +080068func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080069 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080070 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070071 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
72 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 Yun5f7f7e82019-11-18 19:52:14 +090085func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +080086 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080087
Colin Cross98be1bb2019-12-13 20:41:13 -080088 ctx := CreateTestContext()
89 ctx.Register(config)
Logan Chienf3511742017-10-31 18:04:35 +080090
91 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
92 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +080093 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +080094 return
95 }
96
97 _, errs = ctx.PrepareBuildActions(config)
98 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +080099 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800100 return
101 }
102
103 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
104}
105
Justin Yun5f7f7e82019-11-18 19:52:14 +0900106func testCcError(t *testing.T, pattern string, bp string) {
107 config := TestConfig(buildDir, android.Android, nil, bp, nil)
108 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
109 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
110 testCcErrorWithConfig(t, pattern, config)
111 return
112}
113
114func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
115 config := TestConfig(buildDir, android.Android, nil, bp, nil)
116 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
117 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
118 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
119 testCcErrorWithConfig(t, pattern, config)
120 return
121}
122
Logan Chienf3511742017-10-31 18:04:35 +0800123const (
Colin Cross7113d202019-11-20 16:39:12 -0800124 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800125 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900126 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800127 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800128)
129
Doug Hornc32c6b02019-01-17 14:44:05 -0800130func TestFuchsiaDeps(t *testing.T) {
131 t.Helper()
132
133 bp := `
134 cc_library {
135 name: "libTest",
136 srcs: ["foo.c"],
137 target: {
138 fuchsia: {
139 srcs: ["bar.c"],
140 },
141 },
142 }`
143
Colin Cross98be1bb2019-12-13 20:41:13 -0800144 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
145 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800146
147 rt := false
148 fb := false
149
150 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
151 implicits := ld.Implicits
152 for _, lib := range implicits {
153 if strings.Contains(lib.Rel(), "libcompiler_rt") {
154 rt = true
155 }
156
157 if strings.Contains(lib.Rel(), "libbioniccompat") {
158 fb = true
159 }
160 }
161
162 if !rt || !fb {
163 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
164 }
165}
166
167func TestFuchsiaTargetDecl(t *testing.T) {
168 t.Helper()
169
170 bp := `
171 cc_library {
172 name: "libTest",
173 srcs: ["foo.c"],
174 target: {
175 fuchsia: {
176 srcs: ["bar.c"],
177 },
178 },
179 }`
180
Colin Cross98be1bb2019-12-13 20:41:13 -0800181 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
182 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800183 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
184 var objs []string
185 for _, o := range ld.Inputs {
186 objs = append(objs, o.Base())
187 }
188 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
189 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
190 }
191}
192
Jiyong Park6a43f042017-10-12 23:05:00 +0900193func TestVendorSrc(t *testing.T) {
194 ctx := testCc(t, `
195 cc_library {
196 name: "libTest",
197 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700198 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800199 nocrt: true,
200 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900201 vendor_available: true,
202 target: {
203 vendor: {
204 srcs: ["bar.c"],
205 },
206 },
207 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900208 `)
209
Logan Chienf3511742017-10-31 18:04:35 +0800210 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900211 var objs []string
212 for _, o := range ld.Inputs {
213 objs = append(objs, o.Base())
214 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800215 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900216 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
217 }
218}
219
Logan Chienf3511742017-10-31 18:04:35 +0800220func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900221 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800222
Logan Chiend3c59a22018-03-29 14:08:15 +0800223 t.Helper()
224
Justin Yun0ecf0b22020-02-28 15:07:59 +0900225 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Ivan Lozano52767be2019-10-18 14:49:46 -0700226 if !mod.HasVendorVariant() {
Justin Yun0ecf0b22020-02-28 15:07:59 +0900227 t.Errorf("%q must have variant %q", name, variant)
Logan Chienf3511742017-10-31 18:04:35 +0800228 }
229
230 // Check library properties.
231 lib, ok := mod.compiler.(*libraryDecorator)
232 if !ok {
233 t.Errorf("%q must have libraryDecorator", name)
234 } else if lib.baseInstaller.subDir != subDir {
235 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
236 lib.baseInstaller.subDir)
237 }
238
239 // Check VNDK properties.
240 if mod.vndkdep == nil {
241 t.Fatalf("%q must have `vndkdep`", name)
242 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700243 if !mod.IsVndk() {
244 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800245 }
246 if mod.isVndkSp() != isVndkSp {
247 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
248 }
249
250 // Check VNDK extension properties.
251 isVndkExt := extends != ""
252 if mod.isVndkExt() != isVndkExt {
253 t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt)
254 }
255
256 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
257 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
258 }
259}
260
Inseob Kim8471cda2019-11-15 09:59:12 +0900261func checkSnapshot(t *testing.T, ctx *android.TestContext, singletonName, moduleName, snapshotFilename, subDir, variant string) {
262 snapshotSingleton := ctx.SingletonForTests(singletonName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900263
Jooyung Han39edb6c2019-11-06 16:53:07 +0900264 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
265 if !ok {
266 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900267 return
268 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900269 outputFiles, err := mod.OutputFiles("")
270 if err != nil || len(outputFiles) != 1 {
271 t.Errorf("%q must have single output\n", moduleName)
272 return
273 }
274 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900275
Inseob Kim8471cda2019-11-15 09:59:12 +0900276 out := snapshotSingleton.Output(snapshotPath)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900277 if out.Input.String() != outputFiles[0].String() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900278 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
Inseob Kim1f086e22019-05-09 13:29:15 +0900279 }
280}
281
Jooyung Han2216fb12019-11-06 16:46:15 +0900282func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
283 t.Helper()
284 assertString(t, params.Rule.String(), android.WriteFile.String())
285 actual := strings.FieldsFunc(strings.ReplaceAll(params.Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' })
286 assertArrayString(t, actual, expected)
287}
288
Jooyung Han097087b2019-10-22 19:32:18 +0900289func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
290 t.Helper()
291 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900292 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
293}
294
295func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
296 t.Helper()
297 vndkLibraries := ctx.ModuleForTests(module, "")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900298
299 var output string
300 if module != "vndkcorevariant.libraries.txt" {
301 output = insertVndkVersion(module, "VER")
302 } else {
303 output = module
304 }
305
Jooyung Han2216fb12019-11-06 16:46:15 +0900306 checkWriteFileOutput(t, vndkLibraries.Output(output), expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900307}
308
Logan Chienf3511742017-10-31 18:04:35 +0800309func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800310 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800311 cc_library {
312 name: "libvndk",
313 vendor_available: true,
314 vndk: {
315 enabled: true,
316 },
317 nocrt: true,
318 }
319
320 cc_library {
321 name: "libvndk_private",
322 vendor_available: false,
323 vndk: {
324 enabled: true,
325 },
326 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900327 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800328 }
329
330 cc_library {
331 name: "libvndk_sp",
332 vendor_available: true,
333 vndk: {
334 enabled: true,
335 support_system_process: true,
336 },
337 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900338 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800339 }
340
341 cc_library {
342 name: "libvndk_sp_private",
343 vendor_available: false,
344 vndk: {
345 enabled: true,
346 support_system_process: true,
347 },
348 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900349 target: {
350 vendor: {
351 suffix: "-x",
352 },
353 },
Logan Chienf3511742017-10-31 18:04:35 +0800354 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900355 vndk_libraries_txt {
356 name: "llndk.libraries.txt",
357 }
358 vndk_libraries_txt {
359 name: "vndkcore.libraries.txt",
360 }
361 vndk_libraries_txt {
362 name: "vndksp.libraries.txt",
363 }
364 vndk_libraries_txt {
365 name: "vndkprivate.libraries.txt",
366 }
367 vndk_libraries_txt {
368 name: "vndkcorevariant.libraries.txt",
369 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800370 `
371
372 config := TestConfig(buildDir, android.Android, nil, bp, nil)
373 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
374 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
375
376 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800377
Justin Yun0ecf0b22020-02-28 15:07:59 +0900378 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "", vendorVariant)
379 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "", vendorVariant)
380 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "", vendorVariant)
381 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900382
383 // Check VNDK snapshot output.
384
385 snapshotDir := "vndk-snapshot"
386 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
387
388 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
389 "arm64", "armv8-a"))
390 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
391 "arm", "armv7-a-neon"))
392
393 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
394 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
395 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
396 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
397
Colin Crossfb0c16e2019-11-20 17:12:35 -0800398 variant := "android_vendor.VER_arm64_armv8-a_shared"
399 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900400
Inseob Kim8471cda2019-11-15 09:59:12 +0900401 checkSnapshot(t, ctx, "vndk-snapshot", "libvndk", "libvndk.so", vndkCoreLibPath, variant)
402 checkSnapshot(t, ctx, "vndk-snapshot", "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
403 checkSnapshot(t, ctx, "vndk-snapshot", "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
404 checkSnapshot(t, ctx, "vndk-snapshot", "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900405
Jooyung Han39edb6c2019-11-06 16:53:07 +0900406 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim8471cda2019-11-15 09:59:12 +0900407 checkSnapshot(t, ctx, "vndk-snapshot", "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
408 checkSnapshot(t, ctx, "vndk-snapshot", "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
409 checkSnapshot(t, ctx, "vndk-snapshot", "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
410 checkSnapshot(t, ctx, "vndk-snapshot", "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900411
Jooyung Han097087b2019-10-22 19:32:18 +0900412 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
413 "LLNDK: libc.so",
414 "LLNDK: libdl.so",
415 "LLNDK: libft2.so",
416 "LLNDK: libm.so",
417 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900418 "VNDK-SP: libvndk_sp-x.so",
419 "VNDK-SP: libvndk_sp_private-x.so",
420 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900421 "VNDK-core: libvndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900422 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900423 "VNDK-private: libvndk-private.so",
424 "VNDK-private: libvndk_sp_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900425 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900426 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
427 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
428 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
429 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
430 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
431}
432
433func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800434 bp := `
Jooyung Han2216fb12019-11-06 16:46:15 +0900435 vndk_libraries_txt {
436 name: "llndk.libraries.txt",
Colin Cross98be1bb2019-12-13 20:41:13 -0800437 }`
438 config := TestConfig(buildDir, android.Android, nil, bp, nil)
439 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
440 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
441 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900442
443 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900444 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900445 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900446}
447
448func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800449 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900450 cc_library {
451 name: "libvndk",
452 vendor_available: true,
453 vndk: {
454 enabled: true,
455 },
456 nocrt: true,
457 }
458
459 cc_library {
460 name: "libvndk_sp",
461 vendor_available: true,
462 vndk: {
463 enabled: true,
464 support_system_process: true,
465 },
466 nocrt: true,
467 }
468
469 cc_library {
470 name: "libvndk2",
471 vendor_available: false,
472 vndk: {
473 enabled: true,
474 },
475 nocrt: true,
476 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900477
478 vndk_libraries_txt {
479 name: "vndkcorevariant.libraries.txt",
480 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800481 `
482
483 config := TestConfig(buildDir, android.Android, nil, bp, nil)
484 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
485 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
486 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
487
488 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
489
490 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900491
Jooyung Han2216fb12019-11-06 16:46:15 +0900492 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900493}
494
495func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900496 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900497 cc_library {
498 name: "libvndk",
499 vendor_available: true,
500 vndk: {
501 enabled: true,
502 },
503 nocrt: true,
504 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900505 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900506
507 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
508 "LLNDK: libc.so",
509 "LLNDK: libdl.so",
510 "LLNDK: libft2.so",
511 "LLNDK: libm.so",
512 "VNDK-SP: libc++.so",
513 "VNDK-core: libvndk.so",
514 "VNDK-private: libft2.so",
515 })
Logan Chienf3511742017-10-31 18:04:35 +0800516}
517
Logan Chiend3c59a22018-03-29 14:08:15 +0800518func TestVndkDepError(t *testing.T) {
519 // Check whether an error is emitted when a VNDK lib depends on a system lib.
520 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
521 cc_library {
522 name: "libvndk",
523 vendor_available: true,
524 vndk: {
525 enabled: true,
526 },
527 shared_libs: ["libfwk"], // Cause error
528 nocrt: true,
529 }
530
531 cc_library {
532 name: "libfwk",
533 nocrt: true,
534 }
535 `)
536
537 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
538 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
539 cc_library {
540 name: "libvndk",
541 vendor_available: true,
542 vndk: {
543 enabled: true,
544 },
545 shared_libs: ["libvendor"], // Cause error
546 nocrt: true,
547 }
548
549 cc_library {
550 name: "libvendor",
551 vendor: true,
552 nocrt: true,
553 }
554 `)
555
556 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
557 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
558 cc_library {
559 name: "libvndk_sp",
560 vendor_available: true,
561 vndk: {
562 enabled: true,
563 support_system_process: true,
564 },
565 shared_libs: ["libfwk"], // Cause error
566 nocrt: true,
567 }
568
569 cc_library {
570 name: "libfwk",
571 nocrt: true,
572 }
573 `)
574
575 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
576 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
577 cc_library {
578 name: "libvndk_sp",
579 vendor_available: true,
580 vndk: {
581 enabled: true,
582 support_system_process: true,
583 },
584 shared_libs: ["libvendor"], // Cause error
585 nocrt: true,
586 }
587
588 cc_library {
589 name: "libvendor",
590 vendor: true,
591 nocrt: true,
592 }
593 `)
594
595 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
596 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
597 cc_library {
598 name: "libvndk_sp",
599 vendor_available: true,
600 vndk: {
601 enabled: true,
602 support_system_process: true,
603 },
604 shared_libs: ["libvndk"], // Cause error
605 nocrt: true,
606 }
607
608 cc_library {
609 name: "libvndk",
610 vendor_available: true,
611 vndk: {
612 enabled: true,
613 },
614 nocrt: true,
615 }
616 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900617
618 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
619 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
620 cc_library {
621 name: "libvndk",
622 vendor_available: true,
623 vndk: {
624 enabled: true,
625 },
626 shared_libs: ["libnonvndk"],
627 nocrt: true,
628 }
629
630 cc_library {
631 name: "libnonvndk",
632 vendor_available: true,
633 nocrt: true,
634 }
635 `)
636
637 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
638 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
639 cc_library {
640 name: "libvndkprivate",
641 vendor_available: false,
642 vndk: {
643 enabled: true,
644 },
645 shared_libs: ["libnonvndk"],
646 nocrt: true,
647 }
648
649 cc_library {
650 name: "libnonvndk",
651 vendor_available: true,
652 nocrt: true,
653 }
654 `)
655
656 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
657 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
658 cc_library {
659 name: "libvndksp",
660 vendor_available: true,
661 vndk: {
662 enabled: true,
663 support_system_process: true,
664 },
665 shared_libs: ["libnonvndk"],
666 nocrt: true,
667 }
668
669 cc_library {
670 name: "libnonvndk",
671 vendor_available: true,
672 nocrt: true,
673 }
674 `)
675
676 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
677 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
678 cc_library {
679 name: "libvndkspprivate",
680 vendor_available: false,
681 vndk: {
682 enabled: true,
683 support_system_process: true,
684 },
685 shared_libs: ["libnonvndk"],
686 nocrt: true,
687 }
688
689 cc_library {
690 name: "libnonvndk",
691 vendor_available: true,
692 nocrt: true,
693 }
694 `)
695}
696
697func TestDoubleLoadbleDep(t *testing.T) {
698 // okay to link : LLNDK -> double_loadable VNDK
699 testCc(t, `
700 cc_library {
701 name: "libllndk",
702 shared_libs: ["libdoubleloadable"],
703 }
704
705 llndk_library {
706 name: "libllndk",
707 symbol_file: "",
708 }
709
710 cc_library {
711 name: "libdoubleloadable",
712 vendor_available: true,
713 vndk: {
714 enabled: true,
715 },
716 double_loadable: true,
717 }
718 `)
719 // okay to link : LLNDK -> VNDK-SP
720 testCc(t, `
721 cc_library {
722 name: "libllndk",
723 shared_libs: ["libvndksp"],
724 }
725
726 llndk_library {
727 name: "libllndk",
728 symbol_file: "",
729 }
730
731 cc_library {
732 name: "libvndksp",
733 vendor_available: true,
734 vndk: {
735 enabled: true,
736 support_system_process: true,
737 },
738 }
739 `)
740 // okay to link : double_loadable -> double_loadable
741 testCc(t, `
742 cc_library {
743 name: "libdoubleloadable1",
744 shared_libs: ["libdoubleloadable2"],
745 vendor_available: true,
746 double_loadable: true,
747 }
748
749 cc_library {
750 name: "libdoubleloadable2",
751 vendor_available: true,
752 double_loadable: true,
753 }
754 `)
755 // okay to link : double_loadable VNDK -> double_loadable VNDK private
756 testCc(t, `
757 cc_library {
758 name: "libdoubleloadable",
759 vendor_available: true,
760 vndk: {
761 enabled: true,
762 },
763 double_loadable: true,
764 shared_libs: ["libnondoubleloadable"],
765 }
766
767 cc_library {
768 name: "libnondoubleloadable",
769 vendor_available: false,
770 vndk: {
771 enabled: true,
772 },
773 double_loadable: true,
774 }
775 `)
776 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
777 testCc(t, `
778 cc_library {
779 name: "libllndk",
780 shared_libs: ["libcoreonly"],
781 }
782
783 llndk_library {
784 name: "libllndk",
785 symbol_file: "",
786 }
787
788 cc_library {
789 name: "libcoreonly",
790 shared_libs: ["libvendoravailable"],
791 }
792
793 // indirect dependency of LLNDK
794 cc_library {
795 name: "libvendoravailable",
796 vendor_available: true,
797 double_loadable: true,
798 }
799 `)
800}
801
Inseob Kim8471cda2019-11-15 09:59:12 +0900802func TestVendorSnapshot(t *testing.T) {
803 bp := `
804 cc_library {
805 name: "libvndk",
806 vendor_available: true,
807 vndk: {
808 enabled: true,
809 },
810 nocrt: true,
811 }
812
813 cc_library {
814 name: "libvendor",
815 vendor: true,
816 nocrt: true,
817 }
818
819 cc_library {
820 name: "libvendor_available",
821 vendor_available: true,
822 nocrt: true,
823 }
824
825 cc_library_headers {
826 name: "libvendor_headers",
827 vendor_available: true,
828 nocrt: true,
829 }
830
831 cc_binary {
832 name: "vendor_bin",
833 vendor: true,
834 nocrt: true,
835 }
836
837 cc_binary {
838 name: "vendor_available_bin",
839 vendor_available: true,
840 nocrt: true,
841 }
842`
843 config := TestConfig(buildDir, android.Android, nil, bp, nil)
844 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
845 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
846 ctx := testCcWithConfig(t, config)
847
848 // Check Vendor snapshot output.
849
850 snapshotDir := "vendor-snapshot"
851 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
852
853 for _, arch := range [][]string{
854 []string{"arm64", "armv8-a"},
855 []string{"arm", "armv7-a-neon"},
856 } {
857 archType := arch[0]
858 archVariant := arch[1]
859 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
860
861 // For shared libraries, only non-VNDK vendor_available modules are captured
862 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
863 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
864 checkSnapshot(t, ctx, "vendor-snapshot", "libvendor", "libvendor.so", sharedDir, sharedVariant)
865 checkSnapshot(t, ctx, "vendor-snapshot", "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
866
867 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
868 staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
869 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
870 checkSnapshot(t, ctx, "vendor-snapshot", "libvndk", "libvndk.a", staticDir, staticVariant)
871 checkSnapshot(t, ctx, "vendor-snapshot", "libvendor", "libvendor.a", staticDir, staticVariant)
872 checkSnapshot(t, ctx, "vendor-snapshot", "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
873
874 // For binary libraries, all vendor:true and vendor_available modules are captured.
875 if archType == "arm64" {
876 binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
877 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
878 checkSnapshot(t, ctx, "vendor-snapshot", "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
879 checkSnapshot(t, ctx, "vendor-snapshot", "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
880 }
881 }
882}
883
Jooyung Hana70f0672019-01-18 15:20:43 +0900884func TestDoubleLoadableDepError(t *testing.T) {
885 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
886 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
887 cc_library {
888 name: "libllndk",
889 shared_libs: ["libnondoubleloadable"],
890 }
891
892 llndk_library {
893 name: "libllndk",
894 symbol_file: "",
895 }
896
897 cc_library {
898 name: "libnondoubleloadable",
899 vendor_available: true,
900 vndk: {
901 enabled: true,
902 },
903 }
904 `)
905
906 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
907 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
908 cc_library {
909 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -0700910 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900911 shared_libs: ["libnondoubleloadable"],
912 }
913
914 llndk_library {
915 name: "libllndk",
916 symbol_file: "",
917 }
918
919 cc_library {
920 name: "libnondoubleloadable",
921 vendor_available: true,
922 }
923 `)
924
925 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
926 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
927 cc_library {
928 name: "libdoubleloadable",
929 vendor_available: true,
930 double_loadable: true,
931 shared_libs: ["libnondoubleloadable"],
932 }
933
934 cc_library {
935 name: "libnondoubleloadable",
936 vendor_available: true,
937 }
938 `)
939
940 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
941 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
942 cc_library {
943 name: "libdoubleloadable",
944 vendor_available: true,
945 double_loadable: true,
946 shared_libs: ["libnondoubleloadable"],
947 }
948
949 cc_library {
950 name: "libnondoubleloadable",
951 vendor_available: true,
952 vndk: {
953 enabled: true,
954 },
955 }
956 `)
957
958 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
959 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
960 cc_library {
961 name: "libdoubleloadable",
962 vendor_available: true,
963 vndk: {
964 enabled: true,
965 },
966 double_loadable: true,
967 shared_libs: ["libnondoubleloadable"],
968 }
969
970 cc_library {
971 name: "libnondoubleloadable",
972 vendor_available: false,
973 vndk: {
974 enabled: true,
975 },
976 }
977 `)
978
979 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
980 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
981 cc_library {
982 name: "libllndk",
983 shared_libs: ["libcoreonly"],
984 }
985
986 llndk_library {
987 name: "libllndk",
988 symbol_file: "",
989 }
990
991 cc_library {
992 name: "libcoreonly",
993 shared_libs: ["libvendoravailable"],
994 }
995
996 // indirect dependency of LLNDK
997 cc_library {
998 name: "libvendoravailable",
999 vendor_available: true,
1000 }
1001 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001002}
1003
Logan Chienf3511742017-10-31 18:04:35 +08001004func TestVndkExt(t *testing.T) {
1005 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001006 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001007 cc_library {
1008 name: "libvndk",
1009 vendor_available: true,
1010 vndk: {
1011 enabled: true,
1012 },
1013 nocrt: true,
1014 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001015 cc_library {
1016 name: "libvndk2",
1017 vendor_available: true,
1018 vndk: {
1019 enabled: true,
1020 },
1021 target: {
1022 vendor: {
1023 suffix: "-suffix",
1024 },
1025 },
1026 nocrt: true,
1027 }
Logan Chienf3511742017-10-31 18:04:35 +08001028
1029 cc_library {
1030 name: "libvndk_ext",
1031 vendor: true,
1032 vndk: {
1033 enabled: true,
1034 extends: "libvndk",
1035 },
1036 nocrt: true,
1037 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001038
1039 cc_library {
1040 name: "libvndk2_ext",
1041 vendor: true,
1042 vndk: {
1043 enabled: true,
1044 extends: "libvndk2",
1045 },
1046 nocrt: true,
1047 }
Logan Chienf3511742017-10-31 18:04:35 +08001048
Justin Yun0ecf0b22020-02-28 15:07:59 +09001049 cc_library {
1050 name: "libvndk_ext_product",
1051 product_specific: true,
1052 vndk: {
1053 enabled: true,
1054 extends: "libvndk",
1055 },
1056 nocrt: true,
1057 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001058
Justin Yun0ecf0b22020-02-28 15:07:59 +09001059 cc_library {
1060 name: "libvndk2_ext_product",
1061 product_specific: true,
1062 vndk: {
1063 enabled: true,
1064 extends: "libvndk2",
1065 },
1066 nocrt: true,
1067 }
1068 `
1069 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1070 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1071 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1072 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1073
1074 ctx := testCcWithConfig(t, config)
1075
1076 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1077 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1078
1079 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1080 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1081
1082 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1083 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001084}
1085
Logan Chiend3c59a22018-03-29 14:08:15 +08001086func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001087 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1088 ctx := testCcNoVndk(t, `
1089 cc_library {
1090 name: "libvndk",
1091 vendor_available: true,
1092 vndk: {
1093 enabled: true,
1094 },
1095 nocrt: true,
1096 }
1097
1098 cc_library {
1099 name: "libvndk_ext",
1100 vendor: true,
1101 vndk: {
1102 enabled: true,
1103 extends: "libvndk",
1104 },
1105 nocrt: true,
1106 }
1107 `)
1108
1109 // Ensures that the core variant of "libvndk_ext" can be found.
1110 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1111 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1112 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1113 }
1114}
1115
Justin Yun0ecf0b22020-02-28 15:07:59 +09001116func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1117 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
1118 ctx := testCc(t, `
1119 cc_library {
1120 name: "libvndk",
1121 vendor_available: true,
1122 vndk: {
1123 enabled: true,
1124 },
1125 nocrt: true,
1126 }
1127
1128 cc_library {
1129 name: "libvndk_ext_product",
1130 product_specific: true,
1131 vndk: {
1132 enabled: true,
1133 extends: "libvndk",
1134 },
1135 nocrt: true,
1136 }
1137 `)
1138
1139 // Ensures that the core variant of "libvndk_ext_product" can be found.
1140 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1141 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1142 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1143 }
1144}
1145
Logan Chienf3511742017-10-31 18:04:35 +08001146func TestVndkExtError(t *testing.T) {
1147 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001148 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001149 cc_library {
1150 name: "libvndk",
1151 vendor_available: true,
1152 vndk: {
1153 enabled: true,
1154 },
1155 nocrt: true,
1156 }
1157
1158 cc_library {
1159 name: "libvndk_ext",
1160 vndk: {
1161 enabled: true,
1162 extends: "libvndk",
1163 },
1164 nocrt: true,
1165 }
1166 `)
1167
1168 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1169 cc_library {
1170 name: "libvndk",
1171 vendor_available: true,
1172 vndk: {
1173 enabled: true,
1174 },
1175 nocrt: true,
1176 }
1177
1178 cc_library {
1179 name: "libvndk_ext",
1180 vendor: true,
1181 vndk: {
1182 enabled: true,
1183 },
1184 nocrt: true,
1185 }
1186 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001187
1188 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1189 cc_library {
1190 name: "libvndk",
1191 vendor_available: true,
1192 vndk: {
1193 enabled: true,
1194 },
1195 nocrt: true,
1196 }
1197
1198 cc_library {
1199 name: "libvndk_ext_product",
1200 product_specific: true,
1201 vndk: {
1202 enabled: true,
1203 },
1204 nocrt: true,
1205 }
1206 `)
1207
1208 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1209 cc_library {
1210 name: "libvndk",
1211 vendor_available: true,
1212 vndk: {
1213 enabled: true,
1214 },
1215 nocrt: true,
1216 }
1217
1218 cc_library {
1219 name: "libvndk_ext_product",
1220 product_specific: true,
1221 vendor_available: true,
1222 vndk: {
1223 enabled: true,
1224 extends: "libvndk",
1225 },
1226 nocrt: true,
1227 }
1228 `)
Logan Chienf3511742017-10-31 18:04:35 +08001229}
1230
1231func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1232 // This test ensures an error is emitted for inconsistent support_system_process.
1233 testCcError(t, "module \".*\" with mismatched support_system_process", `
1234 cc_library {
1235 name: "libvndk",
1236 vendor_available: true,
1237 vndk: {
1238 enabled: true,
1239 },
1240 nocrt: true,
1241 }
1242
1243 cc_library {
1244 name: "libvndk_sp_ext",
1245 vendor: true,
1246 vndk: {
1247 enabled: true,
1248 extends: "libvndk",
1249 support_system_process: true,
1250 },
1251 nocrt: true,
1252 }
1253 `)
1254
1255 testCcError(t, "module \".*\" with mismatched support_system_process", `
1256 cc_library {
1257 name: "libvndk_sp",
1258 vendor_available: true,
1259 vndk: {
1260 enabled: true,
1261 support_system_process: true,
1262 },
1263 nocrt: true,
1264 }
1265
1266 cc_library {
1267 name: "libvndk_ext",
1268 vendor: true,
1269 vndk: {
1270 enabled: true,
1271 extends: "libvndk_sp",
1272 },
1273 nocrt: true,
1274 }
1275 `)
1276}
1277
1278func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001279 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +08001280 // with `vendor_available: false`.
1281 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
1282 cc_library {
1283 name: "libvndk",
1284 vendor_available: false,
1285 vndk: {
1286 enabled: true,
1287 },
1288 nocrt: true,
1289 }
1290
1291 cc_library {
1292 name: "libvndk_ext",
1293 vendor: true,
1294 vndk: {
1295 enabled: true,
1296 extends: "libvndk",
1297 },
1298 nocrt: true,
1299 }
1300 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001301
1302 testCcErrorProductVndk(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
1303 cc_library {
1304 name: "libvndk",
1305 vendor_available: false,
1306 vndk: {
1307 enabled: true,
1308 },
1309 nocrt: true,
1310 }
1311
1312 cc_library {
1313 name: "libvndk_ext_product",
1314 product_specific: true,
1315 vndk: {
1316 enabled: true,
1317 extends: "libvndk",
1318 },
1319 nocrt: true,
1320 }
1321 `)
Logan Chienf3511742017-10-31 18:04:35 +08001322}
1323
Logan Chiend3c59a22018-03-29 14:08:15 +08001324func TestVendorModuleUseVndkExt(t *testing.T) {
1325 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001326 testCc(t, `
1327 cc_library {
1328 name: "libvndk",
1329 vendor_available: true,
1330 vndk: {
1331 enabled: true,
1332 },
1333 nocrt: true,
1334 }
1335
1336 cc_library {
1337 name: "libvndk_ext",
1338 vendor: true,
1339 vndk: {
1340 enabled: true,
1341 extends: "libvndk",
1342 },
1343 nocrt: true,
1344 }
1345
1346 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001347 name: "libvndk_sp",
1348 vendor_available: true,
1349 vndk: {
1350 enabled: true,
1351 support_system_process: true,
1352 },
1353 nocrt: true,
1354 }
1355
1356 cc_library {
1357 name: "libvndk_sp_ext",
1358 vendor: true,
1359 vndk: {
1360 enabled: true,
1361 extends: "libvndk_sp",
1362 support_system_process: true,
1363 },
1364 nocrt: true,
1365 }
1366
1367 cc_library {
1368 name: "libvendor",
1369 vendor: true,
1370 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1371 nocrt: true,
1372 }
1373 `)
1374}
1375
Logan Chiend3c59a22018-03-29 14:08:15 +08001376func TestVndkExtUseVendorLib(t *testing.T) {
1377 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001378 testCc(t, `
1379 cc_library {
1380 name: "libvndk",
1381 vendor_available: true,
1382 vndk: {
1383 enabled: true,
1384 },
1385 nocrt: true,
1386 }
1387
1388 cc_library {
1389 name: "libvndk_ext",
1390 vendor: true,
1391 vndk: {
1392 enabled: true,
1393 extends: "libvndk",
1394 },
1395 shared_libs: ["libvendor"],
1396 nocrt: true,
1397 }
1398
1399 cc_library {
1400 name: "libvendor",
1401 vendor: true,
1402 nocrt: true,
1403 }
1404 `)
Logan Chienf3511742017-10-31 18:04:35 +08001405
Logan Chiend3c59a22018-03-29 14:08:15 +08001406 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1407 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001408 cc_library {
1409 name: "libvndk_sp",
1410 vendor_available: true,
1411 vndk: {
1412 enabled: true,
1413 support_system_process: true,
1414 },
1415 nocrt: true,
1416 }
1417
1418 cc_library {
1419 name: "libvndk_sp_ext",
1420 vendor: true,
1421 vndk: {
1422 enabled: true,
1423 extends: "libvndk_sp",
1424 support_system_process: true,
1425 },
1426 shared_libs: ["libvendor"], // Cause an error
1427 nocrt: true,
1428 }
1429
1430 cc_library {
1431 name: "libvendor",
1432 vendor: true,
1433 nocrt: true,
1434 }
1435 `)
1436}
1437
Justin Yun0ecf0b22020-02-28 15:07:59 +09001438func TestProductVndkExtDependency(t *testing.T) {
1439 bp := `
1440 cc_library {
1441 name: "libvndk",
1442 vendor_available: true,
1443 vndk: {
1444 enabled: true,
1445 },
1446 nocrt: true,
1447 }
1448
1449 cc_library {
1450 name: "libvndk_ext_product",
1451 product_specific: true,
1452 vndk: {
1453 enabled: true,
1454 extends: "libvndk",
1455 },
1456 shared_libs: ["libproduct_for_vndklibs"],
1457 nocrt: true,
1458 }
1459
1460 cc_library {
1461 name: "libvndk_sp",
1462 vendor_available: true,
1463 vndk: {
1464 enabled: true,
1465 support_system_process: true,
1466 },
1467 nocrt: true,
1468 }
1469
1470 cc_library {
1471 name: "libvndk_sp_ext_product",
1472 product_specific: true,
1473 vndk: {
1474 enabled: true,
1475 extends: "libvndk_sp",
1476 support_system_process: true,
1477 },
1478 shared_libs: ["libproduct_for_vndklibs"],
1479 nocrt: true,
1480 }
1481
1482 cc_library {
1483 name: "libproduct",
1484 product_specific: true,
1485 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1486 nocrt: true,
1487 }
1488
1489 cc_library {
1490 name: "libproduct_for_vndklibs",
1491 product_specific: true,
1492 nocrt: true,
1493 }
1494 `
1495 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1496 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1497 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1498 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1499
1500 testCcWithConfig(t, config)
1501}
1502
Logan Chiend3c59a22018-03-29 14:08:15 +08001503func TestVndkSpExtUseVndkError(t *testing.T) {
1504 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1505 // library.
1506 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1507 cc_library {
1508 name: "libvndk",
1509 vendor_available: true,
1510 vndk: {
1511 enabled: true,
1512 },
1513 nocrt: true,
1514 }
1515
1516 cc_library {
1517 name: "libvndk_sp",
1518 vendor_available: true,
1519 vndk: {
1520 enabled: true,
1521 support_system_process: true,
1522 },
1523 nocrt: true,
1524 }
1525
1526 cc_library {
1527 name: "libvndk_sp_ext",
1528 vendor: true,
1529 vndk: {
1530 enabled: true,
1531 extends: "libvndk_sp",
1532 support_system_process: true,
1533 },
1534 shared_libs: ["libvndk"], // Cause an error
1535 nocrt: true,
1536 }
1537 `)
1538
1539 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1540 // library.
1541 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1542 cc_library {
1543 name: "libvndk",
1544 vendor_available: true,
1545 vndk: {
1546 enabled: true,
1547 },
1548 nocrt: true,
1549 }
1550
1551 cc_library {
1552 name: "libvndk_ext",
1553 vendor: true,
1554 vndk: {
1555 enabled: true,
1556 extends: "libvndk",
1557 },
1558 nocrt: true,
1559 }
1560
1561 cc_library {
1562 name: "libvndk_sp",
1563 vendor_available: true,
1564 vndk: {
1565 enabled: true,
1566 support_system_process: true,
1567 },
1568 nocrt: true,
1569 }
1570
1571 cc_library {
1572 name: "libvndk_sp_ext",
1573 vendor: true,
1574 vndk: {
1575 enabled: true,
1576 extends: "libvndk_sp",
1577 support_system_process: true,
1578 },
1579 shared_libs: ["libvndk_ext"], // Cause an error
1580 nocrt: true,
1581 }
1582 `)
1583}
1584
1585func TestVndkUseVndkExtError(t *testing.T) {
1586 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1587 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001588 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1589 cc_library {
1590 name: "libvndk",
1591 vendor_available: true,
1592 vndk: {
1593 enabled: true,
1594 },
1595 nocrt: true,
1596 }
1597
1598 cc_library {
1599 name: "libvndk_ext",
1600 vendor: true,
1601 vndk: {
1602 enabled: true,
1603 extends: "libvndk",
1604 },
1605 nocrt: true,
1606 }
1607
1608 cc_library {
1609 name: "libvndk2",
1610 vendor_available: true,
1611 vndk: {
1612 enabled: true,
1613 },
1614 shared_libs: ["libvndk_ext"],
1615 nocrt: true,
1616 }
1617 `)
1618
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001619 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001620 cc_library {
1621 name: "libvndk",
1622 vendor_available: true,
1623 vndk: {
1624 enabled: true,
1625 },
1626 nocrt: true,
1627 }
1628
1629 cc_library {
1630 name: "libvndk_ext",
1631 vendor: true,
1632 vndk: {
1633 enabled: true,
1634 extends: "libvndk",
1635 },
1636 nocrt: true,
1637 }
1638
1639 cc_library {
1640 name: "libvndk2",
1641 vendor_available: true,
1642 vndk: {
1643 enabled: true,
1644 },
1645 target: {
1646 vendor: {
1647 shared_libs: ["libvndk_ext"],
1648 },
1649 },
1650 nocrt: true,
1651 }
1652 `)
1653
1654 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1655 cc_library {
1656 name: "libvndk_sp",
1657 vendor_available: true,
1658 vndk: {
1659 enabled: true,
1660 support_system_process: true,
1661 },
1662 nocrt: true,
1663 }
1664
1665 cc_library {
1666 name: "libvndk_sp_ext",
1667 vendor: true,
1668 vndk: {
1669 enabled: true,
1670 extends: "libvndk_sp",
1671 support_system_process: true,
1672 },
1673 nocrt: true,
1674 }
1675
1676 cc_library {
1677 name: "libvndk_sp_2",
1678 vendor_available: true,
1679 vndk: {
1680 enabled: true,
1681 support_system_process: true,
1682 },
1683 shared_libs: ["libvndk_sp_ext"],
1684 nocrt: true,
1685 }
1686 `)
1687
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001688 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001689 cc_library {
1690 name: "libvndk_sp",
1691 vendor_available: true,
1692 vndk: {
1693 enabled: true,
1694 },
1695 nocrt: true,
1696 }
1697
1698 cc_library {
1699 name: "libvndk_sp_ext",
1700 vendor: true,
1701 vndk: {
1702 enabled: true,
1703 extends: "libvndk_sp",
1704 },
1705 nocrt: true,
1706 }
1707
1708 cc_library {
1709 name: "libvndk_sp2",
1710 vendor_available: true,
1711 vndk: {
1712 enabled: true,
1713 },
1714 target: {
1715 vendor: {
1716 shared_libs: ["libvndk_sp_ext"],
1717 },
1718 },
1719 nocrt: true,
1720 }
1721 `)
1722}
1723
Justin Yun5f7f7e82019-11-18 19:52:14 +09001724func TestEnforceProductVndkVersion(t *testing.T) {
1725 bp := `
1726 cc_library {
1727 name: "libllndk",
1728 }
1729 llndk_library {
1730 name: "libllndk",
1731 symbol_file: "",
1732 }
1733 cc_library {
1734 name: "libvndk",
1735 vendor_available: true,
1736 vndk: {
1737 enabled: true,
1738 },
1739 nocrt: true,
1740 }
1741 cc_library {
1742 name: "libvndk_sp",
1743 vendor_available: true,
1744 vndk: {
1745 enabled: true,
1746 support_system_process: true,
1747 },
1748 nocrt: true,
1749 }
1750 cc_library {
1751 name: "libva",
1752 vendor_available: true,
1753 nocrt: true,
1754 }
1755 cc_library {
1756 name: "libproduct_va",
1757 product_specific: true,
1758 vendor_available: true,
1759 nocrt: true,
1760 }
1761 cc_library {
1762 name: "libprod",
1763 product_specific: true,
1764 shared_libs: [
1765 "libllndk",
1766 "libvndk",
1767 "libvndk_sp",
1768 "libva",
1769 "libproduct_va",
1770 ],
1771 nocrt: true,
1772 }
1773 cc_library {
1774 name: "libvendor",
1775 vendor: true,
1776 shared_libs: [
1777 "libllndk",
1778 "libvndk",
1779 "libvndk_sp",
1780 "libva",
1781 "libproduct_va",
1782 ],
1783 nocrt: true,
1784 }
1785 `
1786
1787 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1788 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1789 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1790 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1791
1792 ctx := testCcWithConfig(t, config)
1793
Justin Yun0ecf0b22020-02-28 15:07:59 +09001794 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "", productVariant)
1795 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "", productVariant)
Justin Yun5f7f7e82019-11-18 19:52:14 +09001796}
1797
1798func TestEnforceProductVndkVersionErrors(t *testing.T) {
1799 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
1800 cc_library {
1801 name: "libprod",
1802 product_specific: true,
1803 shared_libs: [
1804 "libvendor",
1805 ],
1806 nocrt: true,
1807 }
1808 cc_library {
1809 name: "libvendor",
1810 vendor: true,
1811 nocrt: true,
1812 }
1813 `)
1814 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
1815 cc_library {
1816 name: "libprod",
1817 product_specific: true,
1818 shared_libs: [
1819 "libsystem",
1820 ],
1821 nocrt: true,
1822 }
1823 cc_library {
1824 name: "libsystem",
1825 nocrt: true,
1826 }
1827 `)
1828 testCcErrorProductVndk(t, "Vendor module that is not VNDK should not link to \".*\" which is marked as `vendor_available: false`", `
1829 cc_library {
1830 name: "libprod",
1831 product_specific: true,
1832 shared_libs: [
1833 "libvndk_private",
1834 ],
1835 nocrt: true,
1836 }
1837 cc_library {
1838 name: "libvndk_private",
1839 vendor_available: false,
1840 vndk: {
1841 enabled: true,
1842 },
1843 nocrt: true,
1844 }
1845 `)
1846 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
1847 cc_library {
1848 name: "libprod",
1849 product_specific: true,
1850 shared_libs: [
1851 "libsystem_ext",
1852 ],
1853 nocrt: true,
1854 }
1855 cc_library {
1856 name: "libsystem_ext",
1857 system_ext_specific: true,
1858 nocrt: true,
1859 }
1860 `)
1861 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
1862 cc_library {
1863 name: "libsystem",
1864 shared_libs: [
1865 "libproduct_va",
1866 ],
1867 nocrt: true,
1868 }
1869 cc_library {
1870 name: "libproduct_va",
1871 product_specific: true,
1872 vendor_available: true,
1873 nocrt: true,
1874 }
1875 `)
1876}
1877
Jooyung Han38002912019-05-16 04:01:54 +09001878func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08001879 bp := `
1880 cc_library {
1881 name: "libvndk",
1882 vendor_available: true,
1883 vndk: {
1884 enabled: true,
1885 },
1886 }
1887 cc_library {
1888 name: "libvndksp",
1889 vendor_available: true,
1890 vndk: {
1891 enabled: true,
1892 support_system_process: true,
1893 },
1894 }
1895 cc_library {
1896 name: "libvndkprivate",
1897 vendor_available: false,
1898 vndk: {
1899 enabled: true,
1900 },
1901 }
1902 cc_library {
1903 name: "libvendor",
1904 vendor: true,
1905 }
1906 cc_library {
1907 name: "libvndkext",
1908 vendor: true,
1909 vndk: {
1910 enabled: true,
1911 extends: "libvndk",
1912 },
1913 }
1914 vndk_prebuilt_shared {
1915 name: "prevndk",
1916 version: "27",
1917 target_arch: "arm",
1918 binder32bit: true,
1919 vendor_available: true,
1920 vndk: {
1921 enabled: true,
1922 },
1923 arch: {
1924 arm: {
1925 srcs: ["liba.so"],
1926 },
1927 },
1928 }
1929 cc_library {
1930 name: "libllndk",
1931 }
1932 llndk_library {
1933 name: "libllndk",
1934 symbol_file: "",
1935 }
1936 cc_library {
1937 name: "libllndkprivate",
1938 }
1939 llndk_library {
1940 name: "libllndkprivate",
1941 vendor_available: false,
1942 symbol_file: "",
1943 }`
1944
1945 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09001946 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1947 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1948 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08001949 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09001950
Jooyung Han0302a842019-10-30 18:43:49 +09001951 assertMapKeys(t, vndkCoreLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001952 []string{"libvndk", "libvndkprivate"})
Jooyung Han0302a842019-10-30 18:43:49 +09001953 assertMapKeys(t, vndkSpLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001954 []string{"libc++", "libvndksp"})
Jooyung Han0302a842019-10-30 18:43:49 +09001955 assertMapKeys(t, llndkLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001956 []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"})
Jooyung Han0302a842019-10-30 18:43:49 +09001957 assertMapKeys(t, vndkPrivateLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001958 []string{"libft2", "libllndkprivate", "libvndkprivate"})
Jooyung Han38002912019-05-16 04:01:54 +09001959
Colin Crossfb0c16e2019-11-20 17:12:35 -08001960 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09001961
Jooyung Han38002912019-05-16 04:01:54 +09001962 tests := []struct {
1963 variant string
1964 name string
1965 expected string
1966 }{
1967 {vendorVariant, "libvndk", "native:vndk"},
1968 {vendorVariant, "libvndksp", "native:vndk"},
1969 {vendorVariant, "libvndkprivate", "native:vndk_private"},
1970 {vendorVariant, "libvendor", "native:vendor"},
1971 {vendorVariant, "libvndkext", "native:vendor"},
Jooyung Han38002912019-05-16 04:01:54 +09001972 {vendorVariant, "libllndk.llndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09001973 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09001974 {coreVariant, "libvndk", "native:platform"},
1975 {coreVariant, "libvndkprivate", "native:platform"},
1976 {coreVariant, "libllndk", "native:platform"},
1977 }
1978 for _, test := range tests {
1979 t.Run(test.name, func(t *testing.T) {
1980 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
1981 assertString(t, module.makeLinkType, test.expected)
1982 })
1983 }
1984}
1985
Colin Cross0af4b842015-04-30 16:36:18 -07001986var (
1987 str11 = "01234567891"
1988 str10 = str11[:10]
1989 str9 = str11[:9]
1990 str5 = str11[:5]
1991 str4 = str11[:4]
1992)
1993
1994var splitListForSizeTestCases = []struct {
1995 in []string
1996 out [][]string
1997 size int
1998}{
1999 {
2000 in: []string{str10},
2001 out: [][]string{{str10}},
2002 size: 10,
2003 },
2004 {
2005 in: []string{str9},
2006 out: [][]string{{str9}},
2007 size: 10,
2008 },
2009 {
2010 in: []string{str5},
2011 out: [][]string{{str5}},
2012 size: 10,
2013 },
2014 {
2015 in: []string{str11},
2016 out: nil,
2017 size: 10,
2018 },
2019 {
2020 in: []string{str10, str10},
2021 out: [][]string{{str10}, {str10}},
2022 size: 10,
2023 },
2024 {
2025 in: []string{str9, str10},
2026 out: [][]string{{str9}, {str10}},
2027 size: 10,
2028 },
2029 {
2030 in: []string{str10, str9},
2031 out: [][]string{{str10}, {str9}},
2032 size: 10,
2033 },
2034 {
2035 in: []string{str5, str4},
2036 out: [][]string{{str5, str4}},
2037 size: 10,
2038 },
2039 {
2040 in: []string{str5, str4, str5},
2041 out: [][]string{{str5, str4}, {str5}},
2042 size: 10,
2043 },
2044 {
2045 in: []string{str5, str4, str5, str4},
2046 out: [][]string{{str5, str4}, {str5, str4}},
2047 size: 10,
2048 },
2049 {
2050 in: []string{str5, str4, str5, str5},
2051 out: [][]string{{str5, str4}, {str5}, {str5}},
2052 size: 10,
2053 },
2054 {
2055 in: []string{str5, str5, str5, str4},
2056 out: [][]string{{str5}, {str5}, {str5, str4}},
2057 size: 10,
2058 },
2059 {
2060 in: []string{str9, str11},
2061 out: nil,
2062 size: 10,
2063 },
2064 {
2065 in: []string{str11, str9},
2066 out: nil,
2067 size: 10,
2068 },
2069}
2070
2071func TestSplitListForSize(t *testing.T) {
2072 for _, testCase := range splitListForSizeTestCases {
Colin Cross40e33732019-02-15 11:08:35 -08002073 out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size)
Colin Cross5b529592017-05-09 13:34:34 -07002074
2075 var outStrings [][]string
2076
2077 if len(out) > 0 {
2078 outStrings = make([][]string, len(out))
2079 for i, o := range out {
2080 outStrings[i] = o.Strings()
2081 }
2082 }
2083
2084 if !reflect.DeepEqual(outStrings, testCase.out) {
Colin Cross0af4b842015-04-30 16:36:18 -07002085 t.Errorf("incorrect output:")
2086 t.Errorf(" input: %#v", testCase.in)
2087 t.Errorf(" size: %d", testCase.size)
2088 t.Errorf(" expected: %#v", testCase.out)
Colin Cross5b529592017-05-09 13:34:34 -07002089 t.Errorf(" got: %#v", outStrings)
Colin Cross0af4b842015-04-30 16:36:18 -07002090 }
2091 }
2092}
Jeff Gaston294356f2017-09-27 17:05:30 -07002093
2094var staticLinkDepOrderTestCases = []struct {
2095 // This is a string representation of a map[moduleName][]moduleDependency .
2096 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002097 inStatic string
2098
2099 // This is a string representation of a map[moduleName][]moduleDependency .
2100 // It models the dependencies declared in an Android.bp file.
2101 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002102
2103 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2104 // The keys of allOrdered specify which modules we would like to check.
2105 // The values of allOrdered specify the expected result (of the transitive closure of all
2106 // dependencies) for each module to test
2107 allOrdered string
2108
2109 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2110 // The keys of outOrdered specify which modules we would like to check.
2111 // The values of outOrdered specify the expected result (of the ordered linker command line)
2112 // for each module to test.
2113 outOrdered string
2114}{
2115 // Simple tests
2116 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002117 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002118 outOrdered: "",
2119 },
2120 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002121 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002122 outOrdered: "a:",
2123 },
2124 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002125 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002126 outOrdered: "a:b; b:",
2127 },
2128 // Tests of reordering
2129 {
2130 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002131 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002132 outOrdered: "a:b,c,d; b:d; c:d; d:",
2133 },
2134 {
2135 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002136 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002137 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2138 },
2139 {
2140 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002141 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002142 outOrdered: "a:d,b,e,c; d:b; e:c",
2143 },
2144 {
2145 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002146 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002147 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2148 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2149 },
2150 {
2151 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002152 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 -07002153 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2154 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2155 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002156 // shared dependencies
2157 {
2158 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2159 // So, we don't actually have to check that a shared dependency of c will change the order
2160 // of a library that depends statically on b and on c. We only need to check that if c has
2161 // a shared dependency on b, that that shows up in allOrdered.
2162 inShared: "c:b",
2163 allOrdered: "c:b",
2164 outOrdered: "c:",
2165 },
2166 {
2167 // This test doesn't actually include any shared dependencies but it's a reminder of what
2168 // the second phase of the above test would look like
2169 inStatic: "a:b,c; c:b",
2170 allOrdered: "a:c,b; c:b",
2171 outOrdered: "a:c,b; c:b",
2172 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002173 // tiebreakers for when two modules specifying different orderings and there is no dependency
2174 // to dictate an order
2175 {
2176 // 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 -08002177 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002178 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2179 },
2180 {
2181 // 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 -08002182 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 -07002183 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2184 },
2185 // Tests involving duplicate dependencies
2186 {
2187 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002188 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002189 outOrdered: "a:c,b",
2190 },
2191 {
2192 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002193 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002194 outOrdered: "a:d,c,b",
2195 },
2196 // Tests to confirm the nonexistence of infinite loops.
2197 // These cases should never happen, so as long as the test terminates and the
2198 // result is deterministic then that should be fine.
2199 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002200 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002201 outOrdered: "a:a",
2202 },
2203 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002204 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002205 allOrdered: "a:b,c; b:c,a; c:a,b",
2206 outOrdered: "a:b; b:c; c:a",
2207 },
2208 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002209 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002210 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2211 outOrdered: "a:c,b; b:a,c; c:b,a",
2212 },
2213}
2214
2215// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2216func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2217 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2218 strippedText := strings.Replace(text, " ", "", -1)
2219 if len(strippedText) < 1 {
2220 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2221 }
2222 allDeps = make(map[android.Path][]android.Path, 0)
2223
2224 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2225 moduleTexts := strings.Split(strippedText, ";")
2226
2227 outputForModuleName := func(moduleName string) android.Path {
2228 return android.PathForTesting(moduleName)
2229 }
2230
2231 for _, moduleText := range moduleTexts {
2232 // convert from "a:b,c" to ["a", "b,c"]
2233 components := strings.Split(moduleText, ":")
2234 if len(components) != 2 {
2235 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2236 }
2237 moduleName := components[0]
2238 moduleOutput := outputForModuleName(moduleName)
2239 modulesInOrder = append(modulesInOrder, moduleOutput)
2240
2241 depString := components[1]
2242 // convert from "b,c" to ["b", "c"]
2243 depNames := strings.Split(depString, ",")
2244 if len(depString) < 1 {
2245 depNames = []string{}
2246 }
2247 var deps []android.Path
2248 for _, depName := range depNames {
2249 deps = append(deps, outputForModuleName(depName))
2250 }
2251 allDeps[moduleOutput] = deps
2252 }
2253 return modulesInOrder, allDeps
2254}
2255
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002256func TestLinkReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002257 for _, testCase := range staticLinkDepOrderTestCases {
2258 errs := []string{}
2259
2260 // parse testcase
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002261 _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic)
Jeff Gaston294356f2017-09-27 17:05:30 -07002262 expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered)
2263 if testCase.allOrdered == "" {
2264 // allow the test case to skip specifying allOrdered
2265 testCase.allOrdered = testCase.outOrdered
2266 }
2267 _, expectedAllDeps := parseModuleDeps(testCase.allOrdered)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002268 _, givenAllSharedDeps := parseModuleDeps(testCase.inShared)
Jeff Gaston294356f2017-09-27 17:05:30 -07002269
2270 // For each module whose post-reordered dependencies were specified, validate that
2271 // reordering the inputs produces the expected outputs.
2272 for _, moduleName := range expectedModuleNames {
2273 moduleDeps := givenTransitiveDeps[moduleName]
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002274 givenSharedDeps := givenAllSharedDeps[moduleName]
2275 orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07002276
2277 correctAllOrdered := expectedAllDeps[moduleName]
2278 if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) {
2279 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002280 "\nin static:%q"+
2281 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07002282 "\nmodule: %v"+
2283 "\nexpected: %s"+
2284 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002285 testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07002286 }
2287
2288 correctOutputDeps := expectedTransitiveDeps[moduleName]
2289 if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) {
2290 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002291 "\nin static:%q"+
2292 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07002293 "\nmodule: %v"+
2294 "\nexpected: %s"+
2295 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002296 testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07002297 }
2298 }
2299
2300 if len(errs) > 0 {
2301 sort.Strings(errs)
2302 for _, err := range errs {
2303 t.Error(err)
2304 }
2305 }
2306 }
2307}
Logan Chienf3511742017-10-31 18:04:35 +08002308
Jeff Gaston294356f2017-09-27 17:05:30 -07002309func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2310 for _, moduleName := range moduleNames {
2311 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2312 output := module.outputFile.Path()
2313 paths = append(paths, output)
2314 }
2315 return paths
2316}
2317
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002318func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002319 ctx := testCc(t, `
2320 cc_library {
2321 name: "a",
2322 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002323 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002324 }
2325 cc_library {
2326 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002327 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002328 }
2329 cc_library {
2330 name: "c",
2331 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002332 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002333 }
2334 cc_library {
2335 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002336 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002337 }
2338
2339 `)
2340
Colin Cross7113d202019-11-20 16:39:12 -08002341 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002342 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002343 actual := moduleA.depsInLinkOrder
Jeff Gaston294356f2017-09-27 17:05:30 -07002344 expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"})
2345
2346 if !reflect.DeepEqual(actual, expected) {
2347 t.Errorf("staticDeps orderings were not propagated correctly"+
2348 "\nactual: %v"+
2349 "\nexpected: %v",
2350 actual,
2351 expected,
2352 )
2353 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002354}
Jeff Gaston294356f2017-09-27 17:05:30 -07002355
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002356func TestStaticLibDepReorderingWithShared(t *testing.T) {
2357 ctx := testCc(t, `
2358 cc_library {
2359 name: "a",
2360 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002361 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002362 }
2363 cc_library {
2364 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002365 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002366 }
2367 cc_library {
2368 name: "c",
2369 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002370 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002371 }
2372
2373 `)
2374
Colin Cross7113d202019-11-20 16:39:12 -08002375 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002376 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
2377 actual := moduleA.depsInLinkOrder
2378 expected := getOutputPaths(ctx, variant, []string{"c", "b"})
2379
2380 if !reflect.DeepEqual(actual, expected) {
2381 t.Errorf("staticDeps orderings did not account for shared libs"+
2382 "\nactual: %v"+
2383 "\nexpected: %v",
2384 actual,
2385 expected,
2386 )
2387 }
2388}
2389
Jiyong Parka46a4d52017-12-14 19:54:34 +09002390func TestLlndkHeaders(t *testing.T) {
2391 ctx := testCc(t, `
2392 llndk_headers {
2393 name: "libllndk_headers",
2394 export_include_dirs: ["my_include"],
2395 }
2396 llndk_library {
2397 name: "libllndk",
2398 export_llndk_headers: ["libllndk_headers"],
2399 }
2400 cc_library {
2401 name: "libvendor",
2402 shared_libs: ["libllndk"],
2403 vendor: true,
2404 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002405 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002406 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002407 }
2408 `)
2409
2410 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002411 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002412 cflags := cc.Args["cFlags"]
2413 if !strings.Contains(cflags, "-Imy_include") {
2414 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2415 }
2416}
2417
Logan Chien43d34c32017-12-20 01:17:32 +08002418func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2419 actual := module.Properties.AndroidMkRuntimeLibs
2420 if !reflect.DeepEqual(actual, expected) {
2421 t.Errorf("incorrect runtime_libs for shared libs"+
2422 "\nactual: %v"+
2423 "\nexpected: %v",
2424 actual,
2425 expected,
2426 )
2427 }
2428}
2429
2430const runtimeLibAndroidBp = `
2431 cc_library {
2432 name: "libvendor_available1",
2433 vendor_available: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002434 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002435 nocrt : true,
2436 system_shared_libs : [],
2437 }
2438 cc_library {
2439 name: "libvendor_available2",
2440 vendor_available: true,
2441 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002442 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002443 nocrt : true,
2444 system_shared_libs : [],
2445 }
2446 cc_library {
2447 name: "libvendor_available3",
2448 vendor_available: true,
2449 runtime_libs: ["libvendor_available1"],
2450 target: {
2451 vendor: {
2452 exclude_runtime_libs: ["libvendor_available1"],
2453 }
2454 },
Yi Konge7fe9912019-06-02 00:53:50 -07002455 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002456 nocrt : true,
2457 system_shared_libs : [],
2458 }
2459 cc_library {
2460 name: "libcore",
2461 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002462 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002463 nocrt : true,
2464 system_shared_libs : [],
2465 }
2466 cc_library {
2467 name: "libvendor1",
2468 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002469 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002470 nocrt : true,
2471 system_shared_libs : [],
2472 }
2473 cc_library {
2474 name: "libvendor2",
2475 vendor: true,
2476 runtime_libs: ["libvendor_available1", "libvendor1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002477 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002478 nocrt : true,
2479 system_shared_libs : [],
2480 }
2481`
2482
2483func TestRuntimeLibs(t *testing.T) {
2484 ctx := testCc(t, runtimeLibAndroidBp)
2485
2486 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002487 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002488
2489 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2490 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2491
2492 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
2493 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2494
2495 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2496 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002497 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002498
2499 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2500 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
2501
2502 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2503 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
2504}
2505
2506func TestExcludeRuntimeLibs(t *testing.T) {
2507 ctx := testCc(t, runtimeLibAndroidBp)
2508
Colin Cross7113d202019-11-20 16:39:12 -08002509 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002510 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2511 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2512
Colin Crossfb0c16e2019-11-20 17:12:35 -08002513 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002514 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2515 checkRuntimeLibs(t, nil, module)
2516}
2517
2518func TestRuntimeLibsNoVndk(t *testing.T) {
2519 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2520
2521 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2522
Colin Cross7113d202019-11-20 16:39:12 -08002523 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002524
2525 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2526 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2527
2528 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2529 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
2530}
2531
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002532func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002533 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002534 actual := module.Properties.AndroidMkStaticLibs
2535 if !reflect.DeepEqual(actual, expected) {
2536 t.Errorf("incorrect static_libs"+
2537 "\nactual: %v"+
2538 "\nexpected: %v",
2539 actual,
2540 expected,
2541 )
2542 }
2543}
2544
2545const staticLibAndroidBp = `
2546 cc_library {
2547 name: "lib1",
2548 }
2549 cc_library {
2550 name: "lib2",
2551 static_libs: ["lib1"],
2552 }
2553`
2554
2555func TestStaticLibDepExport(t *testing.T) {
2556 ctx := testCc(t, staticLibAndroidBp)
2557
2558 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002559 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002560 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002561 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002562
2563 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002564 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002565 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2566 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002567 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002568}
2569
Jiyong Parkd08b6972017-09-26 10:50:54 +09002570var compilerFlagsTestCases = []struct {
2571 in string
2572 out bool
2573}{
2574 {
2575 in: "a",
2576 out: false,
2577 },
2578 {
2579 in: "-a",
2580 out: true,
2581 },
2582 {
2583 in: "-Ipath/to/something",
2584 out: false,
2585 },
2586 {
2587 in: "-isystempath/to/something",
2588 out: false,
2589 },
2590 {
2591 in: "--coverage",
2592 out: false,
2593 },
2594 {
2595 in: "-include a/b",
2596 out: true,
2597 },
2598 {
2599 in: "-include a/b c/d",
2600 out: false,
2601 },
2602 {
2603 in: "-DMACRO",
2604 out: true,
2605 },
2606 {
2607 in: "-DMAC RO",
2608 out: false,
2609 },
2610 {
2611 in: "-a -b",
2612 out: false,
2613 },
2614 {
2615 in: "-DMACRO=definition",
2616 out: true,
2617 },
2618 {
2619 in: "-DMACRO=defi nition",
2620 out: true, // TODO(jiyong): this should be false
2621 },
2622 {
2623 in: "-DMACRO(x)=x + 1",
2624 out: true,
2625 },
2626 {
2627 in: "-DMACRO=\"defi nition\"",
2628 out: true,
2629 },
2630}
2631
2632type mockContext struct {
2633 BaseModuleContext
2634 result bool
2635}
2636
2637func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2638 // CheckBadCompilerFlags calls this function when the flag should be rejected
2639 ctx.result = false
2640}
2641
2642func TestCompilerFlags(t *testing.T) {
2643 for _, testCase := range compilerFlagsTestCases {
2644 ctx := &mockContext{result: true}
2645 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2646 if ctx.result != testCase.out {
2647 t.Errorf("incorrect output:")
2648 t.Errorf(" input: %#v", testCase.in)
2649 t.Errorf(" expected: %#v", testCase.out)
2650 t.Errorf(" got: %#v", ctx.result)
2651 }
2652 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002653}
Jiyong Park374510b2018-03-19 18:23:01 +09002654
2655func TestVendorPublicLibraries(t *testing.T) {
2656 ctx := testCc(t, `
2657 cc_library_headers {
2658 name: "libvendorpublic_headers",
2659 export_include_dirs: ["my_include"],
2660 }
2661 vendor_public_library {
2662 name: "libvendorpublic",
2663 symbol_file: "",
2664 export_public_headers: ["libvendorpublic_headers"],
2665 }
2666 cc_library {
2667 name: "libvendorpublic",
2668 srcs: ["foo.c"],
2669 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002670 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002671 nocrt: true,
2672 }
2673
2674 cc_library {
2675 name: "libsystem",
2676 shared_libs: ["libvendorpublic"],
2677 vendor: false,
2678 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002679 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002680 nocrt: true,
2681 }
2682 cc_library {
2683 name: "libvendor",
2684 shared_libs: ["libvendorpublic"],
2685 vendor: true,
2686 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002687 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002688 nocrt: true,
2689 }
2690 `)
2691
Colin Cross7113d202019-11-20 16:39:12 -08002692 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08002693 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09002694
2695 // test if header search paths are correctly added
2696 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08002697 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09002698 cflags := cc.Args["cFlags"]
2699 if !strings.Contains(cflags, "-Imy_include") {
2700 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
2701 }
2702
2703 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08002704 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09002705 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08002706 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09002707 if !strings.Contains(libflags, stubPaths[0].String()) {
2708 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
2709 }
2710
2711 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08002712 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09002713 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08002714 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09002715 if !strings.Contains(libflags, stubPaths[0].String()) {
2716 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
2717 }
2718
2719}
Jiyong Park37b25202018-07-11 10:49:27 +09002720
2721func TestRecovery(t *testing.T) {
2722 ctx := testCc(t, `
2723 cc_library_shared {
2724 name: "librecovery",
2725 recovery: true,
2726 }
2727 cc_library_shared {
2728 name: "librecovery32",
2729 recovery: true,
2730 compile_multilib:"32",
2731 }
Jiyong Park5baac542018-08-28 09:55:37 +09002732 cc_library_shared {
2733 name: "libHalInRecovery",
2734 recovery_available: true,
2735 vendor: true,
2736 }
Jiyong Park37b25202018-07-11 10:49:27 +09002737 `)
2738
2739 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08002740 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09002741 if len(variants) != 1 || !android.InList(arm64, variants) {
2742 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
2743 }
2744
2745 variants = ctx.ModuleVariantsForTests("librecovery32")
2746 if android.InList(arm64, variants) {
2747 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
2748 }
Jiyong Park5baac542018-08-28 09:55:37 +09002749
2750 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
2751 if !recoveryModule.Platform() {
2752 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
2753 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002754}
Jiyong Park5baac542018-08-28 09:55:37 +09002755
Jiyong Park7ed9de32018-10-15 22:25:07 +09002756func TestVersionedStubs(t *testing.T) {
2757 ctx := testCc(t, `
2758 cc_library_shared {
2759 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002760 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002761 stubs: {
2762 symbol_file: "foo.map.txt",
2763 versions: ["1", "2", "3"],
2764 },
2765 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002766
Jiyong Park7ed9de32018-10-15 22:25:07 +09002767 cc_library_shared {
2768 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002769 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002770 shared_libs: ["libFoo#1"],
2771 }`)
2772
2773 variants := ctx.ModuleVariantsForTests("libFoo")
2774 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08002775 "android_arm64_armv8-a_shared",
2776 "android_arm64_armv8-a_shared_1",
2777 "android_arm64_armv8-a_shared_2",
2778 "android_arm64_armv8-a_shared_3",
2779 "android_arm_armv7-a-neon_shared",
2780 "android_arm_armv7-a-neon_shared_1",
2781 "android_arm_armv7-a-neon_shared_2",
2782 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09002783 }
2784 variantsMismatch := false
2785 if len(variants) != len(expectedVariants) {
2786 variantsMismatch = true
2787 } else {
2788 for _, v := range expectedVariants {
2789 if !inList(v, variants) {
2790 variantsMismatch = false
2791 }
2792 }
2793 }
2794 if variantsMismatch {
2795 t.Errorf("variants of libFoo expected:\n")
2796 for _, v := range expectedVariants {
2797 t.Errorf("%q\n", v)
2798 }
2799 t.Errorf(", but got:\n")
2800 for _, v := range variants {
2801 t.Errorf("%q\n", v)
2802 }
2803 }
2804
Colin Cross7113d202019-11-20 16:39:12 -08002805 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002806 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08002807 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09002808 if !strings.Contains(libFlags, libFoo1StubPath) {
2809 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
2810 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002811
Colin Cross7113d202019-11-20 16:39:12 -08002812 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09002813 cFlags := libBarCompileRule.Args["cFlags"]
2814 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
2815 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
2816 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
2817 }
Jiyong Park37b25202018-07-11 10:49:27 +09002818}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002819
2820func TestStaticExecutable(t *testing.T) {
2821 ctx := testCc(t, `
2822 cc_binary {
2823 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01002824 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002825 static_executable: true,
2826 }`)
2827
Colin Cross7113d202019-11-20 16:39:12 -08002828 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002829 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
2830 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07002831 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002832 for _, lib := range systemStaticLibs {
2833 if !strings.Contains(libFlags, lib) {
2834 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
2835 }
2836 }
2837 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
2838 for _, lib := range systemSharedLibs {
2839 if strings.Contains(libFlags, lib) {
2840 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
2841 }
2842 }
2843}
Jiyong Parke4bb9862019-02-01 00:31:10 +09002844
2845func TestStaticDepsOrderWithStubs(t *testing.T) {
2846 ctx := testCc(t, `
2847 cc_binary {
2848 name: "mybin",
2849 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08002850 static_libs: ["libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09002851 static_executable: true,
2852 stl: "none",
2853 }
2854
2855 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08002856 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09002857 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08002858 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09002859 stl: "none",
2860 }
2861
2862 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08002863 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09002864 srcs: ["foo.c"],
2865 stl: "none",
2866 stubs: {
2867 versions: ["1"],
2868 },
2869 }`)
2870
Colin Cross7113d202019-11-20 16:39:12 -08002871 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Module().(*Module)
Jiyong Parke4bb9862019-02-01 00:31:10 +09002872 actual := mybin.depsInLinkOrder
Colin Crossf9aabd72020-02-15 11:29:50 -08002873 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09002874
2875 if !reflect.DeepEqual(actual, expected) {
2876 t.Errorf("staticDeps orderings were not propagated correctly"+
2877 "\nactual: %v"+
2878 "\nexpected: %v",
2879 actual,
2880 expected,
2881 )
2882 }
2883}
Jooyung Han38002912019-05-16 04:01:54 +09002884
Jooyung Hand48f3c32019-08-23 11:18:57 +09002885func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
2886 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
2887 cc_library {
2888 name: "libA",
2889 srcs: ["foo.c"],
2890 shared_libs: ["libB"],
2891 stl: "none",
2892 }
2893
2894 cc_library {
2895 name: "libB",
2896 srcs: ["foo.c"],
2897 enabled: false,
2898 stl: "none",
2899 }
2900 `)
2901}
2902
Mitch Phillipsda9a4632019-07-15 09:34:09 -07002903// Simple smoke test for the cc_fuzz target that ensures the rule compiles
2904// correctly.
2905func TestFuzzTarget(t *testing.T) {
2906 ctx := testCc(t, `
2907 cc_fuzz {
2908 name: "fuzz_smoke_test",
2909 srcs: ["foo.c"],
2910 }`)
2911
Paul Duffin075c4172019-12-19 19:06:13 +00002912 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07002913 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
2914}
2915
Jiyong Park29074592019-07-07 16:27:47 +09002916func TestAidl(t *testing.T) {
2917}
2918
Jooyung Han38002912019-05-16 04:01:54 +09002919func assertString(t *testing.T, got, expected string) {
2920 t.Helper()
2921 if got != expected {
2922 t.Errorf("expected %q got %q", expected, got)
2923 }
2924}
2925
2926func assertArrayString(t *testing.T, got, expected []string) {
2927 t.Helper()
2928 if len(got) != len(expected) {
2929 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
2930 return
2931 }
2932 for i := range got {
2933 if got[i] != expected[i] {
2934 t.Errorf("expected %d-th %q (%q) got %q (%q)",
2935 i, expected[i], expected, got[i], got)
2936 return
2937 }
2938 }
2939}
Colin Crosse1bb5d02019-09-24 14:55:04 -07002940
Jooyung Han0302a842019-10-30 18:43:49 +09002941func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
2942 t.Helper()
2943 assertArrayString(t, android.SortedStringKeys(m), expected)
2944}
2945
Colin Crosse1bb5d02019-09-24 14:55:04 -07002946func TestDefaults(t *testing.T) {
2947 ctx := testCc(t, `
2948 cc_defaults {
2949 name: "defaults",
2950 srcs: ["foo.c"],
2951 static: {
2952 srcs: ["bar.c"],
2953 },
2954 shared: {
2955 srcs: ["baz.c"],
2956 },
2957 }
2958
2959 cc_library_static {
2960 name: "libstatic",
2961 defaults: ["defaults"],
2962 }
2963
2964 cc_library_shared {
2965 name: "libshared",
2966 defaults: ["defaults"],
2967 }
2968
2969 cc_library {
2970 name: "libboth",
2971 defaults: ["defaults"],
2972 }
2973
2974 cc_binary {
2975 name: "binary",
2976 defaults: ["defaults"],
2977 }`)
2978
2979 pathsToBase := func(paths android.Paths) []string {
2980 var ret []string
2981 for _, p := range paths {
2982 ret = append(ret, p.Base())
2983 }
2984 return ret
2985 }
2986
Colin Cross7113d202019-11-20 16:39:12 -08002987 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07002988 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2989 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
2990 }
Colin Cross7113d202019-11-20 16:39:12 -08002991 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07002992 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2993 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
2994 }
Colin Cross7113d202019-11-20 16:39:12 -08002995 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07002996 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
2997 t.Errorf("binary ld rule wanted %q, got %q", w, g)
2998 }
2999
Colin Cross7113d202019-11-20 16:39:12 -08003000 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003001 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3002 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3003 }
Colin Cross7113d202019-11-20 16:39:12 -08003004 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003005 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3006 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3007 }
3008}
Colin Crosseabaedd2020-02-06 17:01:55 -08003009
3010func TestProductVariableDefaults(t *testing.T) {
3011 bp := `
3012 cc_defaults {
3013 name: "libfoo_defaults",
3014 srcs: ["foo.c"],
3015 cppflags: ["-DFOO"],
3016 product_variables: {
3017 debuggable: {
3018 cppflags: ["-DBAR"],
3019 },
3020 },
3021 }
3022
3023 cc_library {
3024 name: "libfoo",
3025 defaults: ["libfoo_defaults"],
3026 }
3027 `
3028
3029 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3030 config.TestProductVariables.Debuggable = BoolPtr(true)
3031
3032 ctx := CreateTestContext()
3033 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3034 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3035 })
3036 ctx.Register(config)
3037
3038 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3039 android.FailIfErrored(t, errs)
3040 _, errs = ctx.PrepareBuildActions(config)
3041 android.FailIfErrored(t, errs)
3042
3043 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3044 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3045 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3046 }
3047}