blob: f378f710b034f81b2cb0ea89cac36f6fd590c7d0 [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
Logan Chienf3511742017-10-31 18:04:35 +080055func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070056 t.Helper()
Doug Hornc32c6b02019-01-17 14:44:05 -080057 return testCcWithConfigForOs(t, bp, config, android.Android)
58}
59
60func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080061 t.Helper()
Colin Cross9a942872019-05-14 15:44:26 -070062 ctx := CreateTestContext(bp, nil, os)
Colin Cross33b2fb72019-05-14 14:07:01 -070063 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080064
Jeff Gastond3e141d2017-08-08 17:46:01 -070065 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +080066 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090067 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +080068 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090069
70 return ctx
71}
72
Logan Chienf3511742017-10-31 18:04:35 +080073func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080074 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080075 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070076 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
77 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080078
79 return testCcWithConfig(t, bp, config)
80}
81
82func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080083 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080084 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070085 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080086
87 return testCcWithConfig(t, bp, config)
88}
89
90func testCcError(t *testing.T, pattern string, bp string) {
Logan Chiend3c59a22018-03-29 14:08:15 +080091 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080092 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070093 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
94 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080095
Colin Cross9a942872019-05-14 15:44:26 -070096 ctx := CreateTestContext(bp, nil, android.Android)
Colin Cross33b2fb72019-05-14 14:07:01 -070097 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080098
99 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
100 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800101 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800102 return
103 }
104
105 _, errs = ctx.PrepareBuildActions(config)
106 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800107 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800108 return
109 }
110
111 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
112}
113
114const (
Jiyong Park5baac542018-08-28 09:55:37 +0900115 coreVariant = "android_arm64_armv8-a_core_shared"
Inseob Kim64c43952019-08-26 16:52:35 +0900116 vendorVariant = "android_arm64_armv8-a_vendor.VER_shared"
Jiyong Park5baac542018-08-28 09:55:37 +0900117 recoveryVariant = "android_arm64_armv8-a_recovery_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800118)
119
Doug Hornc32c6b02019-01-17 14:44:05 -0800120func TestFuchsiaDeps(t *testing.T) {
121 t.Helper()
122
123 bp := `
124 cc_library {
125 name: "libTest",
126 srcs: ["foo.c"],
127 target: {
128 fuchsia: {
129 srcs: ["bar.c"],
130 },
131 },
132 }`
133
134 config := android.TestArchConfigFuchsia(buildDir, nil)
135 ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
136
137 rt := false
138 fb := false
139
140 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
141 implicits := ld.Implicits
142 for _, lib := range implicits {
143 if strings.Contains(lib.Rel(), "libcompiler_rt") {
144 rt = true
145 }
146
147 if strings.Contains(lib.Rel(), "libbioniccompat") {
148 fb = true
149 }
150 }
151
152 if !rt || !fb {
153 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
154 }
155}
156
157func TestFuchsiaTargetDecl(t *testing.T) {
158 t.Helper()
159
160 bp := `
161 cc_library {
162 name: "libTest",
163 srcs: ["foo.c"],
164 target: {
165 fuchsia: {
166 srcs: ["bar.c"],
167 },
168 },
169 }`
170
171 config := android.TestArchConfigFuchsia(buildDir, nil)
172 ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
173 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
174 var objs []string
175 for _, o := range ld.Inputs {
176 objs = append(objs, o.Base())
177 }
178 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
179 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
180 }
181}
182
Jiyong Park6a43f042017-10-12 23:05:00 +0900183func TestVendorSrc(t *testing.T) {
184 ctx := testCc(t, `
185 cc_library {
186 name: "libTest",
187 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700188 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800189 nocrt: true,
190 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900191 vendor_available: true,
192 target: {
193 vendor: {
194 srcs: ["bar.c"],
195 },
196 },
197 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900198 `)
199
Logan Chienf3511742017-10-31 18:04:35 +0800200 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900201 var objs []string
202 for _, o := range ld.Inputs {
203 objs = append(objs, o.Base())
204 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800205 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900206 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
207 }
208}
209
Logan Chienf3511742017-10-31 18:04:35 +0800210func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
211 isVndkSp bool, extends string) {
212
Logan Chiend3c59a22018-03-29 14:08:15 +0800213 t.Helper()
214
Logan Chienf3511742017-10-31 18:04:35 +0800215 mod := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
Ivan Lozano52767be2019-10-18 14:49:46 -0700216 if !mod.HasVendorVariant() {
Colin Crossf46e37f2018-03-21 16:25:58 -0700217 t.Errorf("%q must have vendor variant", name)
Logan Chienf3511742017-10-31 18:04:35 +0800218 }
219
220 // Check library properties.
221 lib, ok := mod.compiler.(*libraryDecorator)
222 if !ok {
223 t.Errorf("%q must have libraryDecorator", name)
224 } else if lib.baseInstaller.subDir != subDir {
225 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
226 lib.baseInstaller.subDir)
227 }
228
229 // Check VNDK properties.
230 if mod.vndkdep == nil {
231 t.Fatalf("%q must have `vndkdep`", name)
232 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700233 if !mod.IsVndk() {
234 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800235 }
236 if mod.isVndkSp() != isVndkSp {
237 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
238 }
239
240 // Check VNDK extension properties.
241 isVndkExt := extends != ""
242 if mod.isVndkExt() != isVndkExt {
243 t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt)
244 }
245
246 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
247 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
248 }
249}
250
Jooyung Han39edb6c2019-11-06 16:53:07 +0900251func checkVndkSnapshot(t *testing.T, ctx *android.TestContext, moduleName, snapshotFilename, subDir, variant string) {
Inseob Kim1f086e22019-05-09 13:29:15 +0900252 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
253
Jooyung Han39edb6c2019-11-06 16:53:07 +0900254 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
255 if !ok {
256 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900257 return
258 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900259 outputFiles, err := mod.OutputFiles("")
260 if err != nil || len(outputFiles) != 1 {
261 t.Errorf("%q must have single output\n", moduleName)
262 return
263 }
264 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900265
266 out := vndkSnapshot.Output(snapshotPath)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900267 if out.Input.String() != outputFiles[0].String() {
268 t.Errorf("The input of VNDK snapshot must be %q, but %q", out.Input.String(), outputFiles[0])
Inseob Kim1f086e22019-05-09 13:29:15 +0900269 }
270}
271
Jooyung Han2216fb12019-11-06 16:46:15 +0900272func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
273 t.Helper()
274 assertString(t, params.Rule.String(), android.WriteFile.String())
275 actual := strings.FieldsFunc(strings.ReplaceAll(params.Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' })
276 assertArrayString(t, actual, expected)
277}
278
Jooyung Han097087b2019-10-22 19:32:18 +0900279func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
280 t.Helper()
281 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900282 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
283}
284
285func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
286 t.Helper()
287 vndkLibraries := ctx.ModuleForTests(module, "")
288 output := insertVndkVersion(module, "VER")
289 checkWriteFileOutput(t, vndkLibraries.Output(output), expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900290}
291
Logan Chienf3511742017-10-31 18:04:35 +0800292func TestVndk(t *testing.T) {
Inseob Kim1f086e22019-05-09 13:29:15 +0900293 config := android.TestArchConfig(buildDir, nil)
294 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
295 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
296
297 ctx := testCcWithConfig(t, `
Logan Chienf3511742017-10-31 18:04:35 +0800298 cc_library {
299 name: "libvndk",
300 vendor_available: true,
301 vndk: {
302 enabled: true,
303 },
304 nocrt: true,
305 }
306
307 cc_library {
308 name: "libvndk_private",
309 vendor_available: false,
310 vndk: {
311 enabled: true,
312 },
313 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900314 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800315 }
316
317 cc_library {
318 name: "libvndk_sp",
319 vendor_available: true,
320 vndk: {
321 enabled: true,
322 support_system_process: true,
323 },
324 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900325 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800326 }
327
328 cc_library {
329 name: "libvndk_sp_private",
330 vendor_available: false,
331 vndk: {
332 enabled: true,
333 support_system_process: true,
334 },
335 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900336 target: {
337 vendor: {
338 suffix: "-x",
339 },
340 },
Logan Chienf3511742017-10-31 18:04:35 +0800341 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900342 vndk_libraries_txt {
343 name: "llndk.libraries.txt",
344 }
345 vndk_libraries_txt {
346 name: "vndkcore.libraries.txt",
347 }
348 vndk_libraries_txt {
349 name: "vndksp.libraries.txt",
350 }
351 vndk_libraries_txt {
352 name: "vndkprivate.libraries.txt",
353 }
354 vndk_libraries_txt {
355 name: "vndkcorevariant.libraries.txt",
356 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900357 `, config)
Logan Chienf3511742017-10-31 18:04:35 +0800358
359 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
360 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "")
361 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "")
362 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "")
Inseob Kim1f086e22019-05-09 13:29:15 +0900363
364 // Check VNDK snapshot output.
365
366 snapshotDir := "vndk-snapshot"
367 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
368
369 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
370 "arm64", "armv8-a"))
371 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
372 "arm", "armv7-a-neon"))
373
374 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
375 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
376 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
377 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
378
Inseob Kim64c43952019-08-26 16:52:35 +0900379 variant := "android_arm64_armv8-a_vendor.VER_shared"
380 variant2nd := "android_arm_armv7-a-neon_vendor.VER_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900381
Jooyung Han39edb6c2019-11-06 16:53:07 +0900382 checkVndkSnapshot(t, ctx, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
383 checkVndkSnapshot(t, ctx, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
384 checkVndkSnapshot(t, ctx, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
385 checkVndkSnapshot(t, ctx, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900386
Jooyung Han39edb6c2019-11-06 16:53:07 +0900387 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
388 checkVndkSnapshot(t, ctx, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
389 checkVndkSnapshot(t, ctx, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
390 checkVndkSnapshot(t, ctx, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
391 checkVndkSnapshot(t, ctx, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
392
Jooyung Han097087b2019-10-22 19:32:18 +0900393 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
394 "LLNDK: libc.so",
395 "LLNDK: libdl.so",
396 "LLNDK: libft2.so",
397 "LLNDK: libm.so",
398 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900399 "VNDK-SP: libvndk_sp-x.so",
400 "VNDK-SP: libvndk_sp_private-x.so",
401 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900402 "VNDK-core: libvndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900403 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900404 "VNDK-private: libvndk-private.so",
405 "VNDK-private: libvndk_sp_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900406 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900407 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
408 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
409 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
410 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
411 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
412}
413
414func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
415 config := android.TestArchConfig(buildDir, nil)
416 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
417 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
418 ctx := testCcWithConfig(t, `
419 vndk_libraries_txt {
420 name: "llndk.libraries.txt",
421 }`, config)
422
423 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900424 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900425 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900426}
427
428func TestVndkUsingCoreVariant(t *testing.T) {
429 config := android.TestArchConfig(buildDir, nil)
430 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
431 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
432 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
433
434 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
435
436 ctx := testCcWithConfig(t, `
437 cc_library {
438 name: "libvndk",
439 vendor_available: true,
440 vndk: {
441 enabled: true,
442 },
443 nocrt: true,
444 }
445
446 cc_library {
447 name: "libvndk_sp",
448 vendor_available: true,
449 vndk: {
450 enabled: true,
451 support_system_process: true,
452 },
453 nocrt: true,
454 }
455
456 cc_library {
457 name: "libvndk2",
458 vendor_available: false,
459 vndk: {
460 enabled: true,
461 },
462 nocrt: true,
463 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900464
465 vndk_libraries_txt {
466 name: "vndkcorevariant.libraries.txt",
467 }
Jooyung Han097087b2019-10-22 19:32:18 +0900468 `, config)
469
Jooyung Han2216fb12019-11-06 16:46:15 +0900470 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900471}
472
473func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900474 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900475 cc_library {
476 name: "libvndk",
477 vendor_available: true,
478 vndk: {
479 enabled: true,
480 },
481 nocrt: true,
482 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900483 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900484
485 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
486 "LLNDK: libc.so",
487 "LLNDK: libdl.so",
488 "LLNDK: libft2.so",
489 "LLNDK: libm.so",
490 "VNDK-SP: libc++.so",
491 "VNDK-core: libvndk.so",
492 "VNDK-private: libft2.so",
493 })
Logan Chienf3511742017-10-31 18:04:35 +0800494}
495
Logan Chiend3c59a22018-03-29 14:08:15 +0800496func TestVndkDepError(t *testing.T) {
497 // Check whether an error is emitted when a VNDK lib depends on a system lib.
498 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
499 cc_library {
500 name: "libvndk",
501 vendor_available: true,
502 vndk: {
503 enabled: true,
504 },
505 shared_libs: ["libfwk"], // Cause error
506 nocrt: true,
507 }
508
509 cc_library {
510 name: "libfwk",
511 nocrt: true,
512 }
513 `)
514
515 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
516 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
517 cc_library {
518 name: "libvndk",
519 vendor_available: true,
520 vndk: {
521 enabled: true,
522 },
523 shared_libs: ["libvendor"], // Cause error
524 nocrt: true,
525 }
526
527 cc_library {
528 name: "libvendor",
529 vendor: true,
530 nocrt: true,
531 }
532 `)
533
534 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
535 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
536 cc_library {
537 name: "libvndk_sp",
538 vendor_available: true,
539 vndk: {
540 enabled: true,
541 support_system_process: true,
542 },
543 shared_libs: ["libfwk"], // Cause error
544 nocrt: true,
545 }
546
547 cc_library {
548 name: "libfwk",
549 nocrt: true,
550 }
551 `)
552
553 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
554 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
555 cc_library {
556 name: "libvndk_sp",
557 vendor_available: true,
558 vndk: {
559 enabled: true,
560 support_system_process: true,
561 },
562 shared_libs: ["libvendor"], // Cause error
563 nocrt: true,
564 }
565
566 cc_library {
567 name: "libvendor",
568 vendor: true,
569 nocrt: true,
570 }
571 `)
572
573 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
574 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
575 cc_library {
576 name: "libvndk_sp",
577 vendor_available: true,
578 vndk: {
579 enabled: true,
580 support_system_process: true,
581 },
582 shared_libs: ["libvndk"], // Cause error
583 nocrt: true,
584 }
585
586 cc_library {
587 name: "libvndk",
588 vendor_available: true,
589 vndk: {
590 enabled: true,
591 },
592 nocrt: true,
593 }
594 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900595
596 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
597 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
598 cc_library {
599 name: "libvndk",
600 vendor_available: true,
601 vndk: {
602 enabled: true,
603 },
604 shared_libs: ["libnonvndk"],
605 nocrt: true,
606 }
607
608 cc_library {
609 name: "libnonvndk",
610 vendor_available: true,
611 nocrt: true,
612 }
613 `)
614
615 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
616 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
617 cc_library {
618 name: "libvndkprivate",
619 vendor_available: false,
620 vndk: {
621 enabled: true,
622 },
623 shared_libs: ["libnonvndk"],
624 nocrt: true,
625 }
626
627 cc_library {
628 name: "libnonvndk",
629 vendor_available: true,
630 nocrt: true,
631 }
632 `)
633
634 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
635 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
636 cc_library {
637 name: "libvndksp",
638 vendor_available: true,
639 vndk: {
640 enabled: true,
641 support_system_process: true,
642 },
643 shared_libs: ["libnonvndk"],
644 nocrt: true,
645 }
646
647 cc_library {
648 name: "libnonvndk",
649 vendor_available: true,
650 nocrt: true,
651 }
652 `)
653
654 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
655 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
656 cc_library {
657 name: "libvndkspprivate",
658 vendor_available: false,
659 vndk: {
660 enabled: true,
661 support_system_process: true,
662 },
663 shared_libs: ["libnonvndk"],
664 nocrt: true,
665 }
666
667 cc_library {
668 name: "libnonvndk",
669 vendor_available: true,
670 nocrt: true,
671 }
672 `)
673}
674
675func TestDoubleLoadbleDep(t *testing.T) {
676 // okay to link : LLNDK -> double_loadable VNDK
677 testCc(t, `
678 cc_library {
679 name: "libllndk",
680 shared_libs: ["libdoubleloadable"],
681 }
682
683 llndk_library {
684 name: "libllndk",
685 symbol_file: "",
686 }
687
688 cc_library {
689 name: "libdoubleloadable",
690 vendor_available: true,
691 vndk: {
692 enabled: true,
693 },
694 double_loadable: true,
695 }
696 `)
697 // okay to link : LLNDK -> VNDK-SP
698 testCc(t, `
699 cc_library {
700 name: "libllndk",
701 shared_libs: ["libvndksp"],
702 }
703
704 llndk_library {
705 name: "libllndk",
706 symbol_file: "",
707 }
708
709 cc_library {
710 name: "libvndksp",
711 vendor_available: true,
712 vndk: {
713 enabled: true,
714 support_system_process: true,
715 },
716 }
717 `)
718 // okay to link : double_loadable -> double_loadable
719 testCc(t, `
720 cc_library {
721 name: "libdoubleloadable1",
722 shared_libs: ["libdoubleloadable2"],
723 vendor_available: true,
724 double_loadable: true,
725 }
726
727 cc_library {
728 name: "libdoubleloadable2",
729 vendor_available: true,
730 double_loadable: true,
731 }
732 `)
733 // okay to link : double_loadable VNDK -> double_loadable VNDK private
734 testCc(t, `
735 cc_library {
736 name: "libdoubleloadable",
737 vendor_available: true,
738 vndk: {
739 enabled: true,
740 },
741 double_loadable: true,
742 shared_libs: ["libnondoubleloadable"],
743 }
744
745 cc_library {
746 name: "libnondoubleloadable",
747 vendor_available: false,
748 vndk: {
749 enabled: true,
750 },
751 double_loadable: true,
752 }
753 `)
754 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
755 testCc(t, `
756 cc_library {
757 name: "libllndk",
758 shared_libs: ["libcoreonly"],
759 }
760
761 llndk_library {
762 name: "libllndk",
763 symbol_file: "",
764 }
765
766 cc_library {
767 name: "libcoreonly",
768 shared_libs: ["libvendoravailable"],
769 }
770
771 // indirect dependency of LLNDK
772 cc_library {
773 name: "libvendoravailable",
774 vendor_available: true,
775 double_loadable: true,
776 }
777 `)
778}
779
780func TestDoubleLoadableDepError(t *testing.T) {
781 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
782 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
783 cc_library {
784 name: "libllndk",
785 shared_libs: ["libnondoubleloadable"],
786 }
787
788 llndk_library {
789 name: "libllndk",
790 symbol_file: "",
791 }
792
793 cc_library {
794 name: "libnondoubleloadable",
795 vendor_available: true,
796 vndk: {
797 enabled: true,
798 },
799 }
800 `)
801
802 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
803 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
804 cc_library {
805 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -0700806 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900807 shared_libs: ["libnondoubleloadable"],
808 }
809
810 llndk_library {
811 name: "libllndk",
812 symbol_file: "",
813 }
814
815 cc_library {
816 name: "libnondoubleloadable",
817 vendor_available: true,
818 }
819 `)
820
821 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
822 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
823 cc_library {
824 name: "libdoubleloadable",
825 vendor_available: true,
826 double_loadable: true,
827 shared_libs: ["libnondoubleloadable"],
828 }
829
830 cc_library {
831 name: "libnondoubleloadable",
832 vendor_available: true,
833 }
834 `)
835
836 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
837 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
838 cc_library {
839 name: "libdoubleloadable",
840 vendor_available: true,
841 double_loadable: true,
842 shared_libs: ["libnondoubleloadable"],
843 }
844
845 cc_library {
846 name: "libnondoubleloadable",
847 vendor_available: true,
848 vndk: {
849 enabled: true,
850 },
851 }
852 `)
853
854 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
855 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
856 cc_library {
857 name: "libdoubleloadable",
858 vendor_available: true,
859 vndk: {
860 enabled: true,
861 },
862 double_loadable: true,
863 shared_libs: ["libnondoubleloadable"],
864 }
865
866 cc_library {
867 name: "libnondoubleloadable",
868 vendor_available: false,
869 vndk: {
870 enabled: true,
871 },
872 }
873 `)
874
875 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
876 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
877 cc_library {
878 name: "libllndk",
879 shared_libs: ["libcoreonly"],
880 }
881
882 llndk_library {
883 name: "libllndk",
884 symbol_file: "",
885 }
886
887 cc_library {
888 name: "libcoreonly",
889 shared_libs: ["libvendoravailable"],
890 }
891
892 // indirect dependency of LLNDK
893 cc_library {
894 name: "libvendoravailable",
895 vendor_available: true,
896 }
897 `)
Logan Chiend3c59a22018-03-29 14:08:15 +0800898}
899
Justin Yun9357f4a2018-11-28 15:14:47 +0900900func TestVndkMustNotBeProductSpecific(t *testing.T) {
901 // Check whether an error is emitted when a vndk lib has 'product_specific: true'.
902 testCcError(t, "product_specific must not be true when `vndk: {enabled: true}`", `
903 cc_library {
904 name: "libvndk",
905 product_specific: true, // Cause error
906 vendor_available: true,
907 vndk: {
908 enabled: true,
909 },
910 nocrt: true,
911 }
912 `)
913}
914
Logan Chienf3511742017-10-31 18:04:35 +0800915func TestVndkExt(t *testing.T) {
916 // This test checks the VNDK-Ext properties.
917 ctx := testCc(t, `
918 cc_library {
919 name: "libvndk",
920 vendor_available: true,
921 vndk: {
922 enabled: true,
923 },
924 nocrt: true,
925 }
Jooyung Han4c2b9422019-10-22 19:53:47 +0900926 cc_library {
927 name: "libvndk2",
928 vendor_available: true,
929 vndk: {
930 enabled: true,
931 },
932 target: {
933 vendor: {
934 suffix: "-suffix",
935 },
936 },
937 nocrt: true,
938 }
Logan Chienf3511742017-10-31 18:04:35 +0800939
940 cc_library {
941 name: "libvndk_ext",
942 vendor: true,
943 vndk: {
944 enabled: true,
945 extends: "libvndk",
946 },
947 nocrt: true,
948 }
Jooyung Han4c2b9422019-10-22 19:53:47 +0900949
950 cc_library {
951 name: "libvndk2_ext",
952 vendor: true,
953 vndk: {
954 enabled: true,
955 extends: "libvndk2",
956 },
957 nocrt: true,
958 }
Logan Chienf3511742017-10-31 18:04:35 +0800959 `)
960
961 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk")
Jooyung Han4c2b9422019-10-22 19:53:47 +0900962
963 mod := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
964 assertString(t, mod.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +0800965}
966
Logan Chiend3c59a22018-03-29 14:08:15 +0800967func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +0800968 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
969 ctx := testCcNoVndk(t, `
970 cc_library {
971 name: "libvndk",
972 vendor_available: true,
973 vndk: {
974 enabled: true,
975 },
976 nocrt: true,
977 }
978
979 cc_library {
980 name: "libvndk_ext",
981 vendor: true,
982 vndk: {
983 enabled: true,
984 extends: "libvndk",
985 },
986 nocrt: true,
987 }
988 `)
989
990 // Ensures that the core variant of "libvndk_ext" can be found.
991 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
992 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
993 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
994 }
995}
996
997func TestVndkExtError(t *testing.T) {
998 // This test ensures an error is emitted in ill-formed vndk-ext definition.
999 testCcError(t, "must set `vendor: true` to set `extends: \".*\"`", `
1000 cc_library {
1001 name: "libvndk",
1002 vendor_available: true,
1003 vndk: {
1004 enabled: true,
1005 },
1006 nocrt: true,
1007 }
1008
1009 cc_library {
1010 name: "libvndk_ext",
1011 vndk: {
1012 enabled: true,
1013 extends: "libvndk",
1014 },
1015 nocrt: true,
1016 }
1017 `)
1018
1019 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1020 cc_library {
1021 name: "libvndk",
1022 vendor_available: true,
1023 vndk: {
1024 enabled: true,
1025 },
1026 nocrt: true,
1027 }
1028
1029 cc_library {
1030 name: "libvndk_ext",
1031 vendor: true,
1032 vndk: {
1033 enabled: true,
1034 },
1035 nocrt: true,
1036 }
1037 `)
1038}
1039
1040func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1041 // This test ensures an error is emitted for inconsistent support_system_process.
1042 testCcError(t, "module \".*\" with mismatched support_system_process", `
1043 cc_library {
1044 name: "libvndk",
1045 vendor_available: true,
1046 vndk: {
1047 enabled: true,
1048 },
1049 nocrt: true,
1050 }
1051
1052 cc_library {
1053 name: "libvndk_sp_ext",
1054 vendor: true,
1055 vndk: {
1056 enabled: true,
1057 extends: "libvndk",
1058 support_system_process: true,
1059 },
1060 nocrt: true,
1061 }
1062 `)
1063
1064 testCcError(t, "module \".*\" with mismatched support_system_process", `
1065 cc_library {
1066 name: "libvndk_sp",
1067 vendor_available: true,
1068 vndk: {
1069 enabled: true,
1070 support_system_process: true,
1071 },
1072 nocrt: true,
1073 }
1074
1075 cc_library {
1076 name: "libvndk_ext",
1077 vendor: true,
1078 vndk: {
1079 enabled: true,
1080 extends: "libvndk_sp",
1081 },
1082 nocrt: true,
1083 }
1084 `)
1085}
1086
1087func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001088 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +08001089 // with `vendor_available: false`.
1090 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
1091 cc_library {
1092 name: "libvndk",
1093 vendor_available: false,
1094 vndk: {
1095 enabled: true,
1096 },
1097 nocrt: true,
1098 }
1099
1100 cc_library {
1101 name: "libvndk_ext",
1102 vendor: true,
1103 vndk: {
1104 enabled: true,
1105 extends: "libvndk",
1106 },
1107 nocrt: true,
1108 }
1109 `)
1110}
1111
Logan Chiend3c59a22018-03-29 14:08:15 +08001112func TestVendorModuleUseVndkExt(t *testing.T) {
1113 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001114 testCc(t, `
1115 cc_library {
1116 name: "libvndk",
1117 vendor_available: true,
1118 vndk: {
1119 enabled: true,
1120 },
1121 nocrt: true,
1122 }
1123
1124 cc_library {
1125 name: "libvndk_ext",
1126 vendor: true,
1127 vndk: {
1128 enabled: true,
1129 extends: "libvndk",
1130 },
1131 nocrt: true,
1132 }
1133
1134 cc_library {
1135
1136 name: "libvndk_sp",
1137 vendor_available: true,
1138 vndk: {
1139 enabled: true,
1140 support_system_process: true,
1141 },
1142 nocrt: true,
1143 }
1144
1145 cc_library {
1146 name: "libvndk_sp_ext",
1147 vendor: true,
1148 vndk: {
1149 enabled: true,
1150 extends: "libvndk_sp",
1151 support_system_process: true,
1152 },
1153 nocrt: true,
1154 }
1155
1156 cc_library {
1157 name: "libvendor",
1158 vendor: true,
1159 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1160 nocrt: true,
1161 }
1162 `)
1163}
1164
Logan Chiend3c59a22018-03-29 14:08:15 +08001165func TestVndkExtUseVendorLib(t *testing.T) {
1166 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001167 testCc(t, `
1168 cc_library {
1169 name: "libvndk",
1170 vendor_available: true,
1171 vndk: {
1172 enabled: true,
1173 },
1174 nocrt: true,
1175 }
1176
1177 cc_library {
1178 name: "libvndk_ext",
1179 vendor: true,
1180 vndk: {
1181 enabled: true,
1182 extends: "libvndk",
1183 },
1184 shared_libs: ["libvendor"],
1185 nocrt: true,
1186 }
1187
1188 cc_library {
1189 name: "libvendor",
1190 vendor: true,
1191 nocrt: true,
1192 }
1193 `)
Logan Chienf3511742017-10-31 18:04:35 +08001194
Logan Chiend3c59a22018-03-29 14:08:15 +08001195 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1196 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001197 cc_library {
1198 name: "libvndk_sp",
1199 vendor_available: true,
1200 vndk: {
1201 enabled: true,
1202 support_system_process: true,
1203 },
1204 nocrt: true,
1205 }
1206
1207 cc_library {
1208 name: "libvndk_sp_ext",
1209 vendor: true,
1210 vndk: {
1211 enabled: true,
1212 extends: "libvndk_sp",
1213 support_system_process: true,
1214 },
1215 shared_libs: ["libvendor"], // Cause an error
1216 nocrt: true,
1217 }
1218
1219 cc_library {
1220 name: "libvendor",
1221 vendor: true,
1222 nocrt: true,
1223 }
1224 `)
1225}
1226
Logan Chiend3c59a22018-03-29 14:08:15 +08001227func TestVndkSpExtUseVndkError(t *testing.T) {
1228 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1229 // library.
1230 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1231 cc_library {
1232 name: "libvndk",
1233 vendor_available: true,
1234 vndk: {
1235 enabled: true,
1236 },
1237 nocrt: true,
1238 }
1239
1240 cc_library {
1241 name: "libvndk_sp",
1242 vendor_available: true,
1243 vndk: {
1244 enabled: true,
1245 support_system_process: true,
1246 },
1247 nocrt: true,
1248 }
1249
1250 cc_library {
1251 name: "libvndk_sp_ext",
1252 vendor: true,
1253 vndk: {
1254 enabled: true,
1255 extends: "libvndk_sp",
1256 support_system_process: true,
1257 },
1258 shared_libs: ["libvndk"], // Cause an error
1259 nocrt: true,
1260 }
1261 `)
1262
1263 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1264 // library.
1265 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1266 cc_library {
1267 name: "libvndk",
1268 vendor_available: true,
1269 vndk: {
1270 enabled: true,
1271 },
1272 nocrt: true,
1273 }
1274
1275 cc_library {
1276 name: "libvndk_ext",
1277 vendor: true,
1278 vndk: {
1279 enabled: true,
1280 extends: "libvndk",
1281 },
1282 nocrt: true,
1283 }
1284
1285 cc_library {
1286 name: "libvndk_sp",
1287 vendor_available: true,
1288 vndk: {
1289 enabled: true,
1290 support_system_process: true,
1291 },
1292 nocrt: true,
1293 }
1294
1295 cc_library {
1296 name: "libvndk_sp_ext",
1297 vendor: true,
1298 vndk: {
1299 enabled: true,
1300 extends: "libvndk_sp",
1301 support_system_process: true,
1302 },
1303 shared_libs: ["libvndk_ext"], // Cause an error
1304 nocrt: true,
1305 }
1306 `)
1307}
1308
1309func TestVndkUseVndkExtError(t *testing.T) {
1310 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1311 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001312 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1313 cc_library {
1314 name: "libvndk",
1315 vendor_available: true,
1316 vndk: {
1317 enabled: true,
1318 },
1319 nocrt: true,
1320 }
1321
1322 cc_library {
1323 name: "libvndk_ext",
1324 vendor: true,
1325 vndk: {
1326 enabled: true,
1327 extends: "libvndk",
1328 },
1329 nocrt: true,
1330 }
1331
1332 cc_library {
1333 name: "libvndk2",
1334 vendor_available: true,
1335 vndk: {
1336 enabled: true,
1337 },
1338 shared_libs: ["libvndk_ext"],
1339 nocrt: true,
1340 }
1341 `)
1342
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001343 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001344 cc_library {
1345 name: "libvndk",
1346 vendor_available: true,
1347 vndk: {
1348 enabled: true,
1349 },
1350 nocrt: true,
1351 }
1352
1353 cc_library {
1354 name: "libvndk_ext",
1355 vendor: true,
1356 vndk: {
1357 enabled: true,
1358 extends: "libvndk",
1359 },
1360 nocrt: true,
1361 }
1362
1363 cc_library {
1364 name: "libvndk2",
1365 vendor_available: true,
1366 vndk: {
1367 enabled: true,
1368 },
1369 target: {
1370 vendor: {
1371 shared_libs: ["libvndk_ext"],
1372 },
1373 },
1374 nocrt: true,
1375 }
1376 `)
1377
1378 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1379 cc_library {
1380 name: "libvndk_sp",
1381 vendor_available: true,
1382 vndk: {
1383 enabled: true,
1384 support_system_process: true,
1385 },
1386 nocrt: true,
1387 }
1388
1389 cc_library {
1390 name: "libvndk_sp_ext",
1391 vendor: true,
1392 vndk: {
1393 enabled: true,
1394 extends: "libvndk_sp",
1395 support_system_process: true,
1396 },
1397 nocrt: true,
1398 }
1399
1400 cc_library {
1401 name: "libvndk_sp_2",
1402 vendor_available: true,
1403 vndk: {
1404 enabled: true,
1405 support_system_process: true,
1406 },
1407 shared_libs: ["libvndk_sp_ext"],
1408 nocrt: true,
1409 }
1410 `)
1411
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001412 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001413 cc_library {
1414 name: "libvndk_sp",
1415 vendor_available: true,
1416 vndk: {
1417 enabled: true,
1418 },
1419 nocrt: true,
1420 }
1421
1422 cc_library {
1423 name: "libvndk_sp_ext",
1424 vendor: true,
1425 vndk: {
1426 enabled: true,
1427 extends: "libvndk_sp",
1428 },
1429 nocrt: true,
1430 }
1431
1432 cc_library {
1433 name: "libvndk_sp2",
1434 vendor_available: true,
1435 vndk: {
1436 enabled: true,
1437 },
1438 target: {
1439 vendor: {
1440 shared_libs: ["libvndk_sp_ext"],
1441 },
1442 },
1443 nocrt: true,
1444 }
1445 `)
1446}
1447
Jooyung Han38002912019-05-16 04:01:54 +09001448func TestMakeLinkType(t *testing.T) {
1449 config := android.TestArchConfig(buildDir, nil)
1450 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1451 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1452 // native:vndk
1453 ctx := testCcWithConfig(t, `
1454 cc_library {
1455 name: "libvndk",
1456 vendor_available: true,
1457 vndk: {
1458 enabled: true,
1459 },
1460 }
1461 cc_library {
1462 name: "libvndksp",
1463 vendor_available: true,
1464 vndk: {
1465 enabled: true,
1466 support_system_process: true,
1467 },
1468 }
1469 cc_library {
1470 name: "libvndkprivate",
1471 vendor_available: false,
1472 vndk: {
1473 enabled: true,
1474 },
1475 }
1476 cc_library {
1477 name: "libvendor",
1478 vendor: true,
1479 }
1480 cc_library {
1481 name: "libvndkext",
1482 vendor: true,
1483 vndk: {
1484 enabled: true,
1485 extends: "libvndk",
1486 },
1487 }
1488 vndk_prebuilt_shared {
1489 name: "prevndk",
1490 version: "27",
1491 target_arch: "arm",
1492 binder32bit: true,
1493 vendor_available: true,
1494 vndk: {
1495 enabled: true,
1496 },
1497 arch: {
1498 arm: {
1499 srcs: ["liba.so"],
1500 },
1501 },
1502 }
1503 cc_library {
1504 name: "libllndk",
1505 }
1506 llndk_library {
1507 name: "libllndk",
1508 symbol_file: "",
1509 }
1510 cc_library {
1511 name: "libllndkprivate",
1512 }
1513 llndk_library {
1514 name: "libllndkprivate",
1515 vendor_available: false,
1516 symbol_file: "",
1517 }`, config)
1518
Jooyung Han0302a842019-10-30 18:43:49 +09001519 assertMapKeys(t, vndkCoreLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001520 []string{"libvndk", "libvndkprivate"})
Jooyung Han0302a842019-10-30 18:43:49 +09001521 assertMapKeys(t, vndkSpLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001522 []string{"libc++", "libvndksp"})
Jooyung Han0302a842019-10-30 18:43:49 +09001523 assertMapKeys(t, llndkLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001524 []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"})
Jooyung Han0302a842019-10-30 18:43:49 +09001525 assertMapKeys(t, vndkPrivateLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001526 []string{"libft2", "libllndkprivate", "libvndkprivate"})
Jooyung Han38002912019-05-16 04:01:54 +09001527
Inseob Kim64c43952019-08-26 16:52:35 +09001528 vendorVariant27 := "android_arm64_armv8-a_vendor.27_shared"
1529
Jooyung Han38002912019-05-16 04:01:54 +09001530 tests := []struct {
1531 variant string
1532 name string
1533 expected string
1534 }{
1535 {vendorVariant, "libvndk", "native:vndk"},
1536 {vendorVariant, "libvndksp", "native:vndk"},
1537 {vendorVariant, "libvndkprivate", "native:vndk_private"},
1538 {vendorVariant, "libvendor", "native:vendor"},
1539 {vendorVariant, "libvndkext", "native:vendor"},
Jooyung Han38002912019-05-16 04:01:54 +09001540 {vendorVariant, "libllndk.llndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09001541 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09001542 {coreVariant, "libvndk", "native:platform"},
1543 {coreVariant, "libvndkprivate", "native:platform"},
1544 {coreVariant, "libllndk", "native:platform"},
1545 }
1546 for _, test := range tests {
1547 t.Run(test.name, func(t *testing.T) {
1548 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
1549 assertString(t, module.makeLinkType, test.expected)
1550 })
1551 }
1552}
1553
Colin Cross0af4b842015-04-30 16:36:18 -07001554var (
1555 str11 = "01234567891"
1556 str10 = str11[:10]
1557 str9 = str11[:9]
1558 str5 = str11[:5]
1559 str4 = str11[:4]
1560)
1561
1562var splitListForSizeTestCases = []struct {
1563 in []string
1564 out [][]string
1565 size int
1566}{
1567 {
1568 in: []string{str10},
1569 out: [][]string{{str10}},
1570 size: 10,
1571 },
1572 {
1573 in: []string{str9},
1574 out: [][]string{{str9}},
1575 size: 10,
1576 },
1577 {
1578 in: []string{str5},
1579 out: [][]string{{str5}},
1580 size: 10,
1581 },
1582 {
1583 in: []string{str11},
1584 out: nil,
1585 size: 10,
1586 },
1587 {
1588 in: []string{str10, str10},
1589 out: [][]string{{str10}, {str10}},
1590 size: 10,
1591 },
1592 {
1593 in: []string{str9, str10},
1594 out: [][]string{{str9}, {str10}},
1595 size: 10,
1596 },
1597 {
1598 in: []string{str10, str9},
1599 out: [][]string{{str10}, {str9}},
1600 size: 10,
1601 },
1602 {
1603 in: []string{str5, str4},
1604 out: [][]string{{str5, str4}},
1605 size: 10,
1606 },
1607 {
1608 in: []string{str5, str4, str5},
1609 out: [][]string{{str5, str4}, {str5}},
1610 size: 10,
1611 },
1612 {
1613 in: []string{str5, str4, str5, str4},
1614 out: [][]string{{str5, str4}, {str5, str4}},
1615 size: 10,
1616 },
1617 {
1618 in: []string{str5, str4, str5, str5},
1619 out: [][]string{{str5, str4}, {str5}, {str5}},
1620 size: 10,
1621 },
1622 {
1623 in: []string{str5, str5, str5, str4},
1624 out: [][]string{{str5}, {str5}, {str5, str4}},
1625 size: 10,
1626 },
1627 {
1628 in: []string{str9, str11},
1629 out: nil,
1630 size: 10,
1631 },
1632 {
1633 in: []string{str11, str9},
1634 out: nil,
1635 size: 10,
1636 },
1637}
1638
1639func TestSplitListForSize(t *testing.T) {
1640 for _, testCase := range splitListForSizeTestCases {
Colin Cross40e33732019-02-15 11:08:35 -08001641 out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size)
Colin Cross5b529592017-05-09 13:34:34 -07001642
1643 var outStrings [][]string
1644
1645 if len(out) > 0 {
1646 outStrings = make([][]string, len(out))
1647 for i, o := range out {
1648 outStrings[i] = o.Strings()
1649 }
1650 }
1651
1652 if !reflect.DeepEqual(outStrings, testCase.out) {
Colin Cross0af4b842015-04-30 16:36:18 -07001653 t.Errorf("incorrect output:")
1654 t.Errorf(" input: %#v", testCase.in)
1655 t.Errorf(" size: %d", testCase.size)
1656 t.Errorf(" expected: %#v", testCase.out)
Colin Cross5b529592017-05-09 13:34:34 -07001657 t.Errorf(" got: %#v", outStrings)
Colin Cross0af4b842015-04-30 16:36:18 -07001658 }
1659 }
1660}
Jeff Gaston294356f2017-09-27 17:05:30 -07001661
1662var staticLinkDepOrderTestCases = []struct {
1663 // This is a string representation of a map[moduleName][]moduleDependency .
1664 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001665 inStatic string
1666
1667 // This is a string representation of a map[moduleName][]moduleDependency .
1668 // It models the dependencies declared in an Android.bp file.
1669 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07001670
1671 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
1672 // The keys of allOrdered specify which modules we would like to check.
1673 // The values of allOrdered specify the expected result (of the transitive closure of all
1674 // dependencies) for each module to test
1675 allOrdered string
1676
1677 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
1678 // The keys of outOrdered specify which modules we would like to check.
1679 // The values of outOrdered specify the expected result (of the ordered linker command line)
1680 // for each module to test.
1681 outOrdered string
1682}{
1683 // Simple tests
1684 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001685 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07001686 outOrdered: "",
1687 },
1688 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001689 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001690 outOrdered: "a:",
1691 },
1692 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001693 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001694 outOrdered: "a:b; b:",
1695 },
1696 // Tests of reordering
1697 {
1698 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001699 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001700 outOrdered: "a:b,c,d; b:d; c:d; d:",
1701 },
1702 {
1703 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001704 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001705 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
1706 },
1707 {
1708 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001709 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07001710 outOrdered: "a:d,b,e,c; d:b; e:c",
1711 },
1712 {
1713 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001714 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07001715 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
1716 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
1717 },
1718 {
1719 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001720 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 -07001721 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1722 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1723 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001724 // shared dependencies
1725 {
1726 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
1727 // So, we don't actually have to check that a shared dependency of c will change the order
1728 // of a library that depends statically on b and on c. We only need to check that if c has
1729 // a shared dependency on b, that that shows up in allOrdered.
1730 inShared: "c:b",
1731 allOrdered: "c:b",
1732 outOrdered: "c:",
1733 },
1734 {
1735 // This test doesn't actually include any shared dependencies but it's a reminder of what
1736 // the second phase of the above test would look like
1737 inStatic: "a:b,c; c:b",
1738 allOrdered: "a:c,b; c:b",
1739 outOrdered: "a:c,b; c:b",
1740 },
Jeff Gaston294356f2017-09-27 17:05:30 -07001741 // tiebreakers for when two modules specifying different orderings and there is no dependency
1742 // to dictate an order
1743 {
1744 // 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 -08001745 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07001746 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
1747 },
1748 {
1749 // 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 -08001750 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 -07001751 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
1752 },
1753 // Tests involving duplicate dependencies
1754 {
1755 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001756 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001757 outOrdered: "a:c,b",
1758 },
1759 {
1760 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001761 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001762 outOrdered: "a:d,c,b",
1763 },
1764 // Tests to confirm the nonexistence of infinite loops.
1765 // These cases should never happen, so as long as the test terminates and the
1766 // result is deterministic then that should be fine.
1767 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001768 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001769 outOrdered: "a:a",
1770 },
1771 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001772 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001773 allOrdered: "a:b,c; b:c,a; c:a,b",
1774 outOrdered: "a:b; b:c; c:a",
1775 },
1776 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001777 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001778 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
1779 outOrdered: "a:c,b; b:a,c; c:b,a",
1780 },
1781}
1782
1783// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
1784func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
1785 // convert from "a:b,c; d:e" to "a:b,c;d:e"
1786 strippedText := strings.Replace(text, " ", "", -1)
1787 if len(strippedText) < 1 {
1788 return []android.Path{}, make(map[android.Path][]android.Path, 0)
1789 }
1790 allDeps = make(map[android.Path][]android.Path, 0)
1791
1792 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
1793 moduleTexts := strings.Split(strippedText, ";")
1794
1795 outputForModuleName := func(moduleName string) android.Path {
1796 return android.PathForTesting(moduleName)
1797 }
1798
1799 for _, moduleText := range moduleTexts {
1800 // convert from "a:b,c" to ["a", "b,c"]
1801 components := strings.Split(moduleText, ":")
1802 if len(components) != 2 {
1803 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
1804 }
1805 moduleName := components[0]
1806 moduleOutput := outputForModuleName(moduleName)
1807 modulesInOrder = append(modulesInOrder, moduleOutput)
1808
1809 depString := components[1]
1810 // convert from "b,c" to ["b", "c"]
1811 depNames := strings.Split(depString, ",")
1812 if len(depString) < 1 {
1813 depNames = []string{}
1814 }
1815 var deps []android.Path
1816 for _, depName := range depNames {
1817 deps = append(deps, outputForModuleName(depName))
1818 }
1819 allDeps[moduleOutput] = deps
1820 }
1821 return modulesInOrder, allDeps
1822}
1823
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001824func TestLinkReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001825 for _, testCase := range staticLinkDepOrderTestCases {
1826 errs := []string{}
1827
1828 // parse testcase
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001829 _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic)
Jeff Gaston294356f2017-09-27 17:05:30 -07001830 expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered)
1831 if testCase.allOrdered == "" {
1832 // allow the test case to skip specifying allOrdered
1833 testCase.allOrdered = testCase.outOrdered
1834 }
1835 _, expectedAllDeps := parseModuleDeps(testCase.allOrdered)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001836 _, givenAllSharedDeps := parseModuleDeps(testCase.inShared)
Jeff Gaston294356f2017-09-27 17:05:30 -07001837
1838 // For each module whose post-reordered dependencies were specified, validate that
1839 // reordering the inputs produces the expected outputs.
1840 for _, moduleName := range expectedModuleNames {
1841 moduleDeps := givenTransitiveDeps[moduleName]
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001842 givenSharedDeps := givenAllSharedDeps[moduleName]
1843 orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001844
1845 correctAllOrdered := expectedAllDeps[moduleName]
1846 if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) {
1847 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001848 "\nin static:%q"+
1849 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001850 "\nmodule: %v"+
1851 "\nexpected: %s"+
1852 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001853 testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001854 }
1855
1856 correctOutputDeps := expectedTransitiveDeps[moduleName]
1857 if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) {
1858 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001859 "\nin static:%q"+
1860 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001861 "\nmodule: %v"+
1862 "\nexpected: %s"+
1863 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001864 testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001865 }
1866 }
1867
1868 if len(errs) > 0 {
1869 sort.Strings(errs)
1870 for _, err := range errs {
1871 t.Error(err)
1872 }
1873 }
1874 }
1875}
Logan Chienf3511742017-10-31 18:04:35 +08001876
Jeff Gaston294356f2017-09-27 17:05:30 -07001877func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
1878 for _, moduleName := range moduleNames {
1879 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
1880 output := module.outputFile.Path()
1881 paths = append(paths, output)
1882 }
1883 return paths
1884}
1885
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001886func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001887 ctx := testCc(t, `
1888 cc_library {
1889 name: "a",
1890 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09001891 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001892 }
1893 cc_library {
1894 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001895 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001896 }
1897 cc_library {
1898 name: "c",
1899 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001900 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001901 }
1902 cc_library {
1903 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09001904 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001905 }
1906
1907 `)
1908
1909 variant := "android_arm64_armv8-a_core_static"
1910 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001911 actual := moduleA.depsInLinkOrder
Jeff Gaston294356f2017-09-27 17:05:30 -07001912 expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"})
1913
1914 if !reflect.DeepEqual(actual, expected) {
1915 t.Errorf("staticDeps orderings were not propagated correctly"+
1916 "\nactual: %v"+
1917 "\nexpected: %v",
1918 actual,
1919 expected,
1920 )
1921 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09001922}
Jeff Gaston294356f2017-09-27 17:05:30 -07001923
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001924func TestStaticLibDepReorderingWithShared(t *testing.T) {
1925 ctx := testCc(t, `
1926 cc_library {
1927 name: "a",
1928 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09001929 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001930 }
1931 cc_library {
1932 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001933 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001934 }
1935 cc_library {
1936 name: "c",
1937 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001938 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001939 }
1940
1941 `)
1942
1943 variant := "android_arm64_armv8-a_core_static"
1944 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
1945 actual := moduleA.depsInLinkOrder
1946 expected := getOutputPaths(ctx, variant, []string{"c", "b"})
1947
1948 if !reflect.DeepEqual(actual, expected) {
1949 t.Errorf("staticDeps orderings did not account for shared libs"+
1950 "\nactual: %v"+
1951 "\nexpected: %v",
1952 actual,
1953 expected,
1954 )
1955 }
1956}
1957
Jiyong Parka46a4d52017-12-14 19:54:34 +09001958func TestLlndkHeaders(t *testing.T) {
1959 ctx := testCc(t, `
1960 llndk_headers {
1961 name: "libllndk_headers",
1962 export_include_dirs: ["my_include"],
1963 }
1964 llndk_library {
1965 name: "libllndk",
1966 export_llndk_headers: ["libllndk_headers"],
1967 }
1968 cc_library {
1969 name: "libvendor",
1970 shared_libs: ["libllndk"],
1971 vendor: true,
1972 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07001973 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08001974 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09001975 }
1976 `)
1977
1978 // _static variant is used since _shared reuses *.o from the static variant
Inseob Kim64c43952019-08-26 16:52:35 +09001979 cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor.VER_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09001980 cflags := cc.Args["cFlags"]
1981 if !strings.Contains(cflags, "-Imy_include") {
1982 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
1983 }
1984}
1985
Logan Chien43d34c32017-12-20 01:17:32 +08001986func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
1987 actual := module.Properties.AndroidMkRuntimeLibs
1988 if !reflect.DeepEqual(actual, expected) {
1989 t.Errorf("incorrect runtime_libs for shared libs"+
1990 "\nactual: %v"+
1991 "\nexpected: %v",
1992 actual,
1993 expected,
1994 )
1995 }
1996}
1997
1998const runtimeLibAndroidBp = `
1999 cc_library {
2000 name: "libvendor_available1",
2001 vendor_available: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002002 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002003 nocrt : true,
2004 system_shared_libs : [],
2005 }
2006 cc_library {
2007 name: "libvendor_available2",
2008 vendor_available: true,
2009 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002010 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002011 nocrt : true,
2012 system_shared_libs : [],
2013 }
2014 cc_library {
2015 name: "libvendor_available3",
2016 vendor_available: true,
2017 runtime_libs: ["libvendor_available1"],
2018 target: {
2019 vendor: {
2020 exclude_runtime_libs: ["libvendor_available1"],
2021 }
2022 },
Yi Konge7fe9912019-06-02 00:53:50 -07002023 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002024 nocrt : true,
2025 system_shared_libs : [],
2026 }
2027 cc_library {
2028 name: "libcore",
2029 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002030 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002031 nocrt : true,
2032 system_shared_libs : [],
2033 }
2034 cc_library {
2035 name: "libvendor1",
2036 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002037 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002038 nocrt : true,
2039 system_shared_libs : [],
2040 }
2041 cc_library {
2042 name: "libvendor2",
2043 vendor: true,
2044 runtime_libs: ["libvendor_available1", "libvendor1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002045 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002046 nocrt : true,
2047 system_shared_libs : [],
2048 }
2049`
2050
2051func TestRuntimeLibs(t *testing.T) {
2052 ctx := testCc(t, runtimeLibAndroidBp)
2053
2054 // runtime_libs for core variants use the module names without suffixes.
2055 variant := "android_arm64_armv8-a_core_shared"
2056
2057 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2058 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2059
2060 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
2061 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2062
2063 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2064 // and vendor variants.
Inseob Kim64c43952019-08-26 16:52:35 +09002065 variant = "android_arm64_armv8-a_vendor.VER_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002066
2067 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2068 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
2069
2070 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2071 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
2072}
2073
2074func TestExcludeRuntimeLibs(t *testing.T) {
2075 ctx := testCc(t, runtimeLibAndroidBp)
2076
2077 variant := "android_arm64_armv8-a_core_shared"
2078 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2079 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2080
Inseob Kim64c43952019-08-26 16:52:35 +09002081 variant = "android_arm64_armv8-a_vendor.VER_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002082 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2083 checkRuntimeLibs(t, nil, module)
2084}
2085
2086func TestRuntimeLibsNoVndk(t *testing.T) {
2087 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2088
2089 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2090
2091 variant := "android_arm64_armv8-a_core_shared"
2092
2093 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2094 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2095
2096 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2097 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
2098}
2099
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002100func checkStaticLibs(t *testing.T, expected []string, module *Module) {
2101 actual := module.Properties.AndroidMkStaticLibs
2102 if !reflect.DeepEqual(actual, expected) {
2103 t.Errorf("incorrect static_libs"+
2104 "\nactual: %v"+
2105 "\nexpected: %v",
2106 actual,
2107 expected,
2108 )
2109 }
2110}
2111
2112const staticLibAndroidBp = `
2113 cc_library {
2114 name: "lib1",
2115 }
2116 cc_library {
2117 name: "lib2",
2118 static_libs: ["lib1"],
2119 }
2120`
2121
2122func TestStaticLibDepExport(t *testing.T) {
2123 ctx := testCc(t, staticLibAndroidBp)
2124
2125 // Check the shared version of lib2.
2126 variant := "android_arm64_armv8-a_core_shared"
2127 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Dan Albert2da19cb2019-07-24 12:17:40 -07002128 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002129
2130 // Check the static version of lib2.
2131 variant = "android_arm64_armv8-a_core_static"
2132 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2133 // libc++_static is linked additionally.
Dan Albert2da19cb2019-07-24 12:17:40 -07002134 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002135}
2136
Jiyong Parkd08b6972017-09-26 10:50:54 +09002137var compilerFlagsTestCases = []struct {
2138 in string
2139 out bool
2140}{
2141 {
2142 in: "a",
2143 out: false,
2144 },
2145 {
2146 in: "-a",
2147 out: true,
2148 },
2149 {
2150 in: "-Ipath/to/something",
2151 out: false,
2152 },
2153 {
2154 in: "-isystempath/to/something",
2155 out: false,
2156 },
2157 {
2158 in: "--coverage",
2159 out: false,
2160 },
2161 {
2162 in: "-include a/b",
2163 out: true,
2164 },
2165 {
2166 in: "-include a/b c/d",
2167 out: false,
2168 },
2169 {
2170 in: "-DMACRO",
2171 out: true,
2172 },
2173 {
2174 in: "-DMAC RO",
2175 out: false,
2176 },
2177 {
2178 in: "-a -b",
2179 out: false,
2180 },
2181 {
2182 in: "-DMACRO=definition",
2183 out: true,
2184 },
2185 {
2186 in: "-DMACRO=defi nition",
2187 out: true, // TODO(jiyong): this should be false
2188 },
2189 {
2190 in: "-DMACRO(x)=x + 1",
2191 out: true,
2192 },
2193 {
2194 in: "-DMACRO=\"defi nition\"",
2195 out: true,
2196 },
2197}
2198
2199type mockContext struct {
2200 BaseModuleContext
2201 result bool
2202}
2203
2204func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2205 // CheckBadCompilerFlags calls this function when the flag should be rejected
2206 ctx.result = false
2207}
2208
2209func TestCompilerFlags(t *testing.T) {
2210 for _, testCase := range compilerFlagsTestCases {
2211 ctx := &mockContext{result: true}
2212 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2213 if ctx.result != testCase.out {
2214 t.Errorf("incorrect output:")
2215 t.Errorf(" input: %#v", testCase.in)
2216 t.Errorf(" expected: %#v", testCase.out)
2217 t.Errorf(" got: %#v", ctx.result)
2218 }
2219 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002220}
Jiyong Park374510b2018-03-19 18:23:01 +09002221
2222func TestVendorPublicLibraries(t *testing.T) {
2223 ctx := testCc(t, `
2224 cc_library_headers {
2225 name: "libvendorpublic_headers",
2226 export_include_dirs: ["my_include"],
2227 }
2228 vendor_public_library {
2229 name: "libvendorpublic",
2230 symbol_file: "",
2231 export_public_headers: ["libvendorpublic_headers"],
2232 }
2233 cc_library {
2234 name: "libvendorpublic",
2235 srcs: ["foo.c"],
2236 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002237 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002238 nocrt: true,
2239 }
2240
2241 cc_library {
2242 name: "libsystem",
2243 shared_libs: ["libvendorpublic"],
2244 vendor: false,
2245 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002246 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002247 nocrt: true,
2248 }
2249 cc_library {
2250 name: "libvendor",
2251 shared_libs: ["libvendorpublic"],
2252 vendor: true,
2253 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002254 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002255 nocrt: true,
2256 }
2257 `)
2258
2259 variant := "android_arm64_armv8-a_core_shared"
2260
2261 // test if header search paths are correctly added
2262 // _static variant is used since _shared reuses *.o from the static variant
2263 cc := ctx.ModuleForTests("libsystem", strings.Replace(variant, "_shared", "_static", 1)).Rule("cc")
2264 cflags := cc.Args["cFlags"]
2265 if !strings.Contains(cflags, "-Imy_include") {
2266 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
2267 }
2268
2269 // test if libsystem is linked to the stub
2270 ld := ctx.ModuleForTests("libsystem", variant).Rule("ld")
2271 libflags := ld.Args["libFlags"]
2272 stubPaths := getOutputPaths(ctx, variant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
2273 if !strings.Contains(libflags, stubPaths[0].String()) {
2274 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
2275 }
2276
2277 // test if libvendor is linked to the real shared lib
Inseob Kim64c43952019-08-26 16:52:35 +09002278 ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor.VER", 1)).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09002279 libflags = ld.Args["libFlags"]
Inseob Kim64c43952019-08-26 16:52:35 +09002280 stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor.VER", 1), []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09002281 if !strings.Contains(libflags, stubPaths[0].String()) {
2282 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
2283 }
2284
2285}
Jiyong Park37b25202018-07-11 10:49:27 +09002286
2287func TestRecovery(t *testing.T) {
2288 ctx := testCc(t, `
2289 cc_library_shared {
2290 name: "librecovery",
2291 recovery: true,
2292 }
2293 cc_library_shared {
2294 name: "librecovery32",
2295 recovery: true,
2296 compile_multilib:"32",
2297 }
Jiyong Park5baac542018-08-28 09:55:37 +09002298 cc_library_shared {
2299 name: "libHalInRecovery",
2300 recovery_available: true,
2301 vendor: true,
2302 }
Jiyong Park37b25202018-07-11 10:49:27 +09002303 `)
2304
2305 variants := ctx.ModuleVariantsForTests("librecovery")
2306 const arm64 = "android_arm64_armv8-a_recovery_shared"
2307 if len(variants) != 1 || !android.InList(arm64, variants) {
2308 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
2309 }
2310
2311 variants = ctx.ModuleVariantsForTests("librecovery32")
2312 if android.InList(arm64, variants) {
2313 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
2314 }
Jiyong Park5baac542018-08-28 09:55:37 +09002315
2316 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
2317 if !recoveryModule.Platform() {
2318 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
2319 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002320}
Jiyong Park5baac542018-08-28 09:55:37 +09002321
Jiyong Park7ed9de32018-10-15 22:25:07 +09002322func TestVersionedStubs(t *testing.T) {
2323 ctx := testCc(t, `
2324 cc_library_shared {
2325 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002326 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002327 stubs: {
2328 symbol_file: "foo.map.txt",
2329 versions: ["1", "2", "3"],
2330 },
2331 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002332
Jiyong Park7ed9de32018-10-15 22:25:07 +09002333 cc_library_shared {
2334 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002335 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002336 shared_libs: ["libFoo#1"],
2337 }`)
2338
2339 variants := ctx.ModuleVariantsForTests("libFoo")
2340 expectedVariants := []string{
2341 "android_arm64_armv8-a_core_shared",
2342 "android_arm64_armv8-a_core_shared_1",
2343 "android_arm64_armv8-a_core_shared_2",
2344 "android_arm64_armv8-a_core_shared_3",
2345 "android_arm_armv7-a-neon_core_shared",
2346 "android_arm_armv7-a-neon_core_shared_1",
2347 "android_arm_armv7-a-neon_core_shared_2",
2348 "android_arm_armv7-a-neon_core_shared_3",
2349 }
2350 variantsMismatch := false
2351 if len(variants) != len(expectedVariants) {
2352 variantsMismatch = true
2353 } else {
2354 for _, v := range expectedVariants {
2355 if !inList(v, variants) {
2356 variantsMismatch = false
2357 }
2358 }
2359 }
2360 if variantsMismatch {
2361 t.Errorf("variants of libFoo expected:\n")
2362 for _, v := range expectedVariants {
2363 t.Errorf("%q\n", v)
2364 }
2365 t.Errorf(", but got:\n")
2366 for _, v := range variants {
2367 t.Errorf("%q\n", v)
2368 }
2369 }
2370
2371 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("ld")
2372 libFlags := libBarLinkRule.Args["libFlags"]
2373 libFoo1StubPath := "libFoo/android_arm64_armv8-a_core_shared_1/libFoo.so"
2374 if !strings.Contains(libFlags, libFoo1StubPath) {
2375 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
2376 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002377
2378 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc")
2379 cFlags := libBarCompileRule.Args["cFlags"]
2380 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
2381 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
2382 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
2383 }
Jiyong Park37b25202018-07-11 10:49:27 +09002384}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002385
2386func TestStaticExecutable(t *testing.T) {
2387 ctx := testCc(t, `
2388 cc_binary {
2389 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01002390 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002391 static_executable: true,
2392 }`)
2393
2394 variant := "android_arm64_armv8-a_core"
2395 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
2396 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07002397 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002398 for _, lib := range systemStaticLibs {
2399 if !strings.Contains(libFlags, lib) {
2400 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
2401 }
2402 }
2403 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
2404 for _, lib := range systemSharedLibs {
2405 if strings.Contains(libFlags, lib) {
2406 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
2407 }
2408 }
2409}
Jiyong Parke4bb9862019-02-01 00:31:10 +09002410
2411func TestStaticDepsOrderWithStubs(t *testing.T) {
2412 ctx := testCc(t, `
2413 cc_binary {
2414 name: "mybin",
2415 srcs: ["foo.c"],
2416 static_libs: ["libB"],
2417 static_executable: true,
2418 stl: "none",
2419 }
2420
2421 cc_library {
2422 name: "libB",
2423 srcs: ["foo.c"],
2424 shared_libs: ["libC"],
2425 stl: "none",
2426 }
2427
2428 cc_library {
2429 name: "libC",
2430 srcs: ["foo.c"],
2431 stl: "none",
2432 stubs: {
2433 versions: ["1"],
2434 },
2435 }`)
2436
2437 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a_core").Module().(*Module)
2438 actual := mybin.depsInLinkOrder
2439 expected := getOutputPaths(ctx, "android_arm64_armv8-a_core_static", []string{"libB", "libC"})
2440
2441 if !reflect.DeepEqual(actual, expected) {
2442 t.Errorf("staticDeps orderings were not propagated correctly"+
2443 "\nactual: %v"+
2444 "\nexpected: %v",
2445 actual,
2446 expected,
2447 )
2448 }
2449}
Jooyung Han38002912019-05-16 04:01:54 +09002450
Jooyung Hand48f3c32019-08-23 11:18:57 +09002451func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
2452 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
2453 cc_library {
2454 name: "libA",
2455 srcs: ["foo.c"],
2456 shared_libs: ["libB"],
2457 stl: "none",
2458 }
2459
2460 cc_library {
2461 name: "libB",
2462 srcs: ["foo.c"],
2463 enabled: false,
2464 stl: "none",
2465 }
2466 `)
2467}
2468
Mitch Phillipsda9a4632019-07-15 09:34:09 -07002469// Simple smoke test for the cc_fuzz target that ensures the rule compiles
2470// correctly.
2471func TestFuzzTarget(t *testing.T) {
2472 ctx := testCc(t, `
2473 cc_fuzz {
2474 name: "fuzz_smoke_test",
2475 srcs: ["foo.c"],
2476 }`)
2477
2478 variant := "android_arm64_armv8-a_core"
2479 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
2480}
2481
Jiyong Park29074592019-07-07 16:27:47 +09002482func TestAidl(t *testing.T) {
2483}
2484
Jooyung Han38002912019-05-16 04:01:54 +09002485func assertString(t *testing.T, got, expected string) {
2486 t.Helper()
2487 if got != expected {
2488 t.Errorf("expected %q got %q", expected, got)
2489 }
2490}
2491
2492func assertArrayString(t *testing.T, got, expected []string) {
2493 t.Helper()
2494 if len(got) != len(expected) {
2495 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
2496 return
2497 }
2498 for i := range got {
2499 if got[i] != expected[i] {
2500 t.Errorf("expected %d-th %q (%q) got %q (%q)",
2501 i, expected[i], expected, got[i], got)
2502 return
2503 }
2504 }
2505}
Colin Crosse1bb5d02019-09-24 14:55:04 -07002506
Jooyung Han0302a842019-10-30 18:43:49 +09002507func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
2508 t.Helper()
2509 assertArrayString(t, android.SortedStringKeys(m), expected)
2510}
2511
Colin Crosse1bb5d02019-09-24 14:55:04 -07002512func TestDefaults(t *testing.T) {
2513 ctx := testCc(t, `
2514 cc_defaults {
2515 name: "defaults",
2516 srcs: ["foo.c"],
2517 static: {
2518 srcs: ["bar.c"],
2519 },
2520 shared: {
2521 srcs: ["baz.c"],
2522 },
2523 }
2524
2525 cc_library_static {
2526 name: "libstatic",
2527 defaults: ["defaults"],
2528 }
2529
2530 cc_library_shared {
2531 name: "libshared",
2532 defaults: ["defaults"],
2533 }
2534
2535 cc_library {
2536 name: "libboth",
2537 defaults: ["defaults"],
2538 }
2539
2540 cc_binary {
2541 name: "binary",
2542 defaults: ["defaults"],
2543 }`)
2544
2545 pathsToBase := func(paths android.Paths) []string {
2546 var ret []string
2547 for _, p := range paths {
2548 ret = append(ret, p.Base())
2549 }
2550 return ret
2551 }
2552
2553 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_core_shared").Rule("ld")
2554 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2555 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
2556 }
2557 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_shared").Rule("ld")
2558 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2559 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
2560 }
2561 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a_core").Rule("ld")
2562 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
2563 t.Errorf("binary ld rule wanted %q, got %q", w, g)
2564 }
2565
2566 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_core_static").Rule("ar")
2567 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
2568 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
2569 }
2570 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_static").Rule("ar")
2571 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
2572 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
2573 }
2574}