blob: 80a6361baca730997f576d1d3b875de32aef17ad [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
Inseob Kim1f086e22019-05-09 13:29:15 +0900251func checkVndkSnapshot(t *testing.T, ctx *android.TestContext, name, subDir, variant string) {
252 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
253
Inseob Kim1f086e22019-05-09 13:29:15 +0900254 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
255 if !mod.outputFile.Valid() {
256 t.Errorf("%q must have output\n", name)
257 return
258 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900259 snapshotPath := filepath.Join(subDir, mod.outputFile.Path().Base())
Inseob Kim1f086e22019-05-09 13:29:15 +0900260
261 out := vndkSnapshot.Output(snapshotPath)
262 if out.Input != mod.outputFile.Path() {
263 t.Errorf("The input of VNDK snapshot must be %q, but %q", out.Input.String(), mod.outputFile.String())
264 }
265}
266
Jooyung Han2216fb12019-11-06 16:46:15 +0900267func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
268 t.Helper()
269 assertString(t, params.Rule.String(), android.WriteFile.String())
270 actual := strings.FieldsFunc(strings.ReplaceAll(params.Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' })
271 assertArrayString(t, actual, expected)
272}
273
Jooyung Han097087b2019-10-22 19:32:18 +0900274func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
275 t.Helper()
276 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900277 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
278}
279
280func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
281 t.Helper()
282 vndkLibraries := ctx.ModuleForTests(module, "")
283 output := insertVndkVersion(module, "VER")
284 checkWriteFileOutput(t, vndkLibraries.Output(output), expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900285}
286
Logan Chienf3511742017-10-31 18:04:35 +0800287func TestVndk(t *testing.T) {
Inseob Kim1f086e22019-05-09 13:29:15 +0900288 config := android.TestArchConfig(buildDir, nil)
289 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
290 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
291
292 ctx := testCcWithConfig(t, `
Logan Chienf3511742017-10-31 18:04:35 +0800293 cc_library {
294 name: "libvndk",
295 vendor_available: true,
296 vndk: {
297 enabled: true,
298 },
299 nocrt: true,
300 }
301
302 cc_library {
303 name: "libvndk_private",
304 vendor_available: false,
305 vndk: {
306 enabled: true,
307 },
308 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900309 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800310 }
311
312 cc_library {
313 name: "libvndk_sp",
314 vendor_available: true,
315 vndk: {
316 enabled: true,
317 support_system_process: true,
318 },
319 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900320 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800321 }
322
323 cc_library {
324 name: "libvndk_sp_private",
325 vendor_available: false,
326 vndk: {
327 enabled: true,
328 support_system_process: true,
329 },
330 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900331 target: {
332 vendor: {
333 suffix: "-x",
334 },
335 },
Logan Chienf3511742017-10-31 18:04:35 +0800336 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900337 vndk_libraries_txt {
338 name: "llndk.libraries.txt",
339 }
340 vndk_libraries_txt {
341 name: "vndkcore.libraries.txt",
342 }
343 vndk_libraries_txt {
344 name: "vndksp.libraries.txt",
345 }
346 vndk_libraries_txt {
347 name: "vndkprivate.libraries.txt",
348 }
349 vndk_libraries_txt {
350 name: "vndkcorevariant.libraries.txt",
351 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900352 `, config)
Logan Chienf3511742017-10-31 18:04:35 +0800353
354 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
355 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "")
356 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "")
357 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "")
Inseob Kim1f086e22019-05-09 13:29:15 +0900358
359 // Check VNDK snapshot output.
360
361 snapshotDir := "vndk-snapshot"
362 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
363
364 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
365 "arm64", "armv8-a"))
366 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
367 "arm", "armv7-a-neon"))
368
369 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
370 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
371 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
372 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
373
Inseob Kim64c43952019-08-26 16:52:35 +0900374 variant := "android_arm64_armv8-a_vendor.VER_shared"
375 variant2nd := "android_arm_armv7-a-neon_vendor.VER_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900376
377 checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLibPath, variant)
378 checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLib2ndPath, variant2nd)
379 checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLibPath, variant)
380 checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900381
382 checkVndkOutput(t, ctx, "vndk/llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900383 checkVndkOutput(t, ctx, "vndk/vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
384 checkVndkOutput(t, ctx, "vndk/vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
385 checkVndkOutput(t, ctx, "vndk/vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
Jooyung Han097087b2019-10-22 19:32:18 +0900386 // merged & tagged & filtered-out(libclang_rt)
387 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
388 "LLNDK: libc.so",
389 "LLNDK: libdl.so",
390 "LLNDK: libft2.so",
391 "LLNDK: libm.so",
392 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900393 "VNDK-SP: libvndk_sp-x.so",
394 "VNDK-SP: libvndk_sp_private-x.so",
395 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900396 "VNDK-core: libvndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900397 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900398 "VNDK-private: libvndk-private.so",
399 "VNDK-private: libvndk_sp_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900400 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900401 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
402 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
403 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
404 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
405 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
406}
407
408func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
409 config := android.TestArchConfig(buildDir, nil)
410 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
411 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
412 ctx := testCcWithConfig(t, `
413 vndk_libraries_txt {
414 name: "llndk.libraries.txt",
415 }`, config)
416
417 module := ctx.ModuleForTests("llndk.libraries.txt", "")
418 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())
419 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900420}
421
422func TestVndkUsingCoreVariant(t *testing.T) {
423 config := android.TestArchConfig(buildDir, nil)
424 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
425 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
426 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
427
428 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
429
430 ctx := testCcWithConfig(t, `
431 cc_library {
432 name: "libvndk",
433 vendor_available: true,
434 vndk: {
435 enabled: true,
436 },
437 nocrt: true,
438 }
439
440 cc_library {
441 name: "libvndk_sp",
442 vendor_available: true,
443 vndk: {
444 enabled: true,
445 support_system_process: true,
446 },
447 nocrt: true,
448 }
449
450 cc_library {
451 name: "libvndk2",
452 vendor_available: false,
453 vndk: {
454 enabled: true,
455 },
456 nocrt: true,
457 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900458
459 vndk_libraries_txt {
460 name: "vndkcorevariant.libraries.txt",
461 }
Jooyung Han097087b2019-10-22 19:32:18 +0900462 `, config)
463
Jooyung Han2216fb12019-11-06 16:46:15 +0900464 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900465}
466
467func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900468 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900469 cc_library {
470 name: "libvndk",
471 vendor_available: true,
472 vndk: {
473 enabled: true,
474 },
475 nocrt: true,
476 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900477 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900478
479 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
480 "LLNDK: libc.so",
481 "LLNDK: libdl.so",
482 "LLNDK: libft2.so",
483 "LLNDK: libm.so",
484 "VNDK-SP: libc++.so",
485 "VNDK-core: libvndk.so",
486 "VNDK-private: libft2.so",
487 })
Logan Chienf3511742017-10-31 18:04:35 +0800488}
489
Logan Chiend3c59a22018-03-29 14:08:15 +0800490func TestVndkDepError(t *testing.T) {
491 // Check whether an error is emitted when a VNDK lib depends on a system lib.
492 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
493 cc_library {
494 name: "libvndk",
495 vendor_available: true,
496 vndk: {
497 enabled: true,
498 },
499 shared_libs: ["libfwk"], // Cause error
500 nocrt: true,
501 }
502
503 cc_library {
504 name: "libfwk",
505 nocrt: true,
506 }
507 `)
508
509 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
510 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
511 cc_library {
512 name: "libvndk",
513 vendor_available: true,
514 vndk: {
515 enabled: true,
516 },
517 shared_libs: ["libvendor"], // Cause error
518 nocrt: true,
519 }
520
521 cc_library {
522 name: "libvendor",
523 vendor: true,
524 nocrt: true,
525 }
526 `)
527
528 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
529 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
530 cc_library {
531 name: "libvndk_sp",
532 vendor_available: true,
533 vndk: {
534 enabled: true,
535 support_system_process: true,
536 },
537 shared_libs: ["libfwk"], // Cause error
538 nocrt: true,
539 }
540
541 cc_library {
542 name: "libfwk",
543 nocrt: true,
544 }
545 `)
546
547 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
548 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
549 cc_library {
550 name: "libvndk_sp",
551 vendor_available: true,
552 vndk: {
553 enabled: true,
554 support_system_process: true,
555 },
556 shared_libs: ["libvendor"], // Cause error
557 nocrt: true,
558 }
559
560 cc_library {
561 name: "libvendor",
562 vendor: true,
563 nocrt: true,
564 }
565 `)
566
567 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
568 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
569 cc_library {
570 name: "libvndk_sp",
571 vendor_available: true,
572 vndk: {
573 enabled: true,
574 support_system_process: true,
575 },
576 shared_libs: ["libvndk"], // Cause error
577 nocrt: true,
578 }
579
580 cc_library {
581 name: "libvndk",
582 vendor_available: true,
583 vndk: {
584 enabled: true,
585 },
586 nocrt: true,
587 }
588 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900589
590 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
591 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
592 cc_library {
593 name: "libvndk",
594 vendor_available: true,
595 vndk: {
596 enabled: true,
597 },
598 shared_libs: ["libnonvndk"],
599 nocrt: true,
600 }
601
602 cc_library {
603 name: "libnonvndk",
604 vendor_available: true,
605 nocrt: true,
606 }
607 `)
608
609 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
610 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
611 cc_library {
612 name: "libvndkprivate",
613 vendor_available: false,
614 vndk: {
615 enabled: true,
616 },
617 shared_libs: ["libnonvndk"],
618 nocrt: true,
619 }
620
621 cc_library {
622 name: "libnonvndk",
623 vendor_available: true,
624 nocrt: true,
625 }
626 `)
627
628 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
629 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
630 cc_library {
631 name: "libvndksp",
632 vendor_available: true,
633 vndk: {
634 enabled: true,
635 support_system_process: true,
636 },
637 shared_libs: ["libnonvndk"],
638 nocrt: true,
639 }
640
641 cc_library {
642 name: "libnonvndk",
643 vendor_available: true,
644 nocrt: true,
645 }
646 `)
647
648 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
649 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
650 cc_library {
651 name: "libvndkspprivate",
652 vendor_available: false,
653 vndk: {
654 enabled: true,
655 support_system_process: true,
656 },
657 shared_libs: ["libnonvndk"],
658 nocrt: true,
659 }
660
661 cc_library {
662 name: "libnonvndk",
663 vendor_available: true,
664 nocrt: true,
665 }
666 `)
667}
668
669func TestDoubleLoadbleDep(t *testing.T) {
670 // okay to link : LLNDK -> double_loadable VNDK
671 testCc(t, `
672 cc_library {
673 name: "libllndk",
674 shared_libs: ["libdoubleloadable"],
675 }
676
677 llndk_library {
678 name: "libllndk",
679 symbol_file: "",
680 }
681
682 cc_library {
683 name: "libdoubleloadable",
684 vendor_available: true,
685 vndk: {
686 enabled: true,
687 },
688 double_loadable: true,
689 }
690 `)
691 // okay to link : LLNDK -> VNDK-SP
692 testCc(t, `
693 cc_library {
694 name: "libllndk",
695 shared_libs: ["libvndksp"],
696 }
697
698 llndk_library {
699 name: "libllndk",
700 symbol_file: "",
701 }
702
703 cc_library {
704 name: "libvndksp",
705 vendor_available: true,
706 vndk: {
707 enabled: true,
708 support_system_process: true,
709 },
710 }
711 `)
712 // okay to link : double_loadable -> double_loadable
713 testCc(t, `
714 cc_library {
715 name: "libdoubleloadable1",
716 shared_libs: ["libdoubleloadable2"],
717 vendor_available: true,
718 double_loadable: true,
719 }
720
721 cc_library {
722 name: "libdoubleloadable2",
723 vendor_available: true,
724 double_loadable: true,
725 }
726 `)
727 // okay to link : double_loadable VNDK -> double_loadable VNDK private
728 testCc(t, `
729 cc_library {
730 name: "libdoubleloadable",
731 vendor_available: true,
732 vndk: {
733 enabled: true,
734 },
735 double_loadable: true,
736 shared_libs: ["libnondoubleloadable"],
737 }
738
739 cc_library {
740 name: "libnondoubleloadable",
741 vendor_available: false,
742 vndk: {
743 enabled: true,
744 },
745 double_loadable: true,
746 }
747 `)
748 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
749 testCc(t, `
750 cc_library {
751 name: "libllndk",
752 shared_libs: ["libcoreonly"],
753 }
754
755 llndk_library {
756 name: "libllndk",
757 symbol_file: "",
758 }
759
760 cc_library {
761 name: "libcoreonly",
762 shared_libs: ["libvendoravailable"],
763 }
764
765 // indirect dependency of LLNDK
766 cc_library {
767 name: "libvendoravailable",
768 vendor_available: true,
769 double_loadable: true,
770 }
771 `)
772}
773
774func TestDoubleLoadableDepError(t *testing.T) {
775 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
776 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
777 cc_library {
778 name: "libllndk",
779 shared_libs: ["libnondoubleloadable"],
780 }
781
782 llndk_library {
783 name: "libllndk",
784 symbol_file: "",
785 }
786
787 cc_library {
788 name: "libnondoubleloadable",
789 vendor_available: true,
790 vndk: {
791 enabled: true,
792 },
793 }
794 `)
795
796 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
797 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
798 cc_library {
799 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -0700800 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900801 shared_libs: ["libnondoubleloadable"],
802 }
803
804 llndk_library {
805 name: "libllndk",
806 symbol_file: "",
807 }
808
809 cc_library {
810 name: "libnondoubleloadable",
811 vendor_available: true,
812 }
813 `)
814
815 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
816 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
817 cc_library {
818 name: "libdoubleloadable",
819 vendor_available: true,
820 double_loadable: true,
821 shared_libs: ["libnondoubleloadable"],
822 }
823
824 cc_library {
825 name: "libnondoubleloadable",
826 vendor_available: true,
827 }
828 `)
829
830 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
831 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
832 cc_library {
833 name: "libdoubleloadable",
834 vendor_available: true,
835 double_loadable: true,
836 shared_libs: ["libnondoubleloadable"],
837 }
838
839 cc_library {
840 name: "libnondoubleloadable",
841 vendor_available: true,
842 vndk: {
843 enabled: true,
844 },
845 }
846 `)
847
848 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
849 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
850 cc_library {
851 name: "libdoubleloadable",
852 vendor_available: true,
853 vndk: {
854 enabled: true,
855 },
856 double_loadable: true,
857 shared_libs: ["libnondoubleloadable"],
858 }
859
860 cc_library {
861 name: "libnondoubleloadable",
862 vendor_available: false,
863 vndk: {
864 enabled: true,
865 },
866 }
867 `)
868
869 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
870 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
871 cc_library {
872 name: "libllndk",
873 shared_libs: ["libcoreonly"],
874 }
875
876 llndk_library {
877 name: "libllndk",
878 symbol_file: "",
879 }
880
881 cc_library {
882 name: "libcoreonly",
883 shared_libs: ["libvendoravailable"],
884 }
885
886 // indirect dependency of LLNDK
887 cc_library {
888 name: "libvendoravailable",
889 vendor_available: true,
890 }
891 `)
Logan Chiend3c59a22018-03-29 14:08:15 +0800892}
893
Justin Yun9357f4a2018-11-28 15:14:47 +0900894func TestVndkMustNotBeProductSpecific(t *testing.T) {
895 // Check whether an error is emitted when a vndk lib has 'product_specific: true'.
896 testCcError(t, "product_specific must not be true when `vndk: {enabled: true}`", `
897 cc_library {
898 name: "libvndk",
899 product_specific: true, // Cause error
900 vendor_available: true,
901 vndk: {
902 enabled: true,
903 },
904 nocrt: true,
905 }
906 `)
907}
908
Logan Chienf3511742017-10-31 18:04:35 +0800909func TestVndkExt(t *testing.T) {
910 // This test checks the VNDK-Ext properties.
911 ctx := testCc(t, `
912 cc_library {
913 name: "libvndk",
914 vendor_available: true,
915 vndk: {
916 enabled: true,
917 },
918 nocrt: true,
919 }
Jooyung Han4c2b9422019-10-22 19:53:47 +0900920 cc_library {
921 name: "libvndk2",
922 vendor_available: true,
923 vndk: {
924 enabled: true,
925 },
926 target: {
927 vendor: {
928 suffix: "-suffix",
929 },
930 },
931 nocrt: true,
932 }
Logan Chienf3511742017-10-31 18:04:35 +0800933
934 cc_library {
935 name: "libvndk_ext",
936 vendor: true,
937 vndk: {
938 enabled: true,
939 extends: "libvndk",
940 },
941 nocrt: true,
942 }
Jooyung Han4c2b9422019-10-22 19:53:47 +0900943
944 cc_library {
945 name: "libvndk2_ext",
946 vendor: true,
947 vndk: {
948 enabled: true,
949 extends: "libvndk2",
950 },
951 nocrt: true,
952 }
Logan Chienf3511742017-10-31 18:04:35 +0800953 `)
954
955 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk")
Jooyung Han4c2b9422019-10-22 19:53:47 +0900956
957 mod := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
958 assertString(t, mod.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +0800959}
960
Logan Chiend3c59a22018-03-29 14:08:15 +0800961func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +0800962 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
963 ctx := testCcNoVndk(t, `
964 cc_library {
965 name: "libvndk",
966 vendor_available: true,
967 vndk: {
968 enabled: true,
969 },
970 nocrt: true,
971 }
972
973 cc_library {
974 name: "libvndk_ext",
975 vendor: true,
976 vndk: {
977 enabled: true,
978 extends: "libvndk",
979 },
980 nocrt: true,
981 }
982 `)
983
984 // Ensures that the core variant of "libvndk_ext" can be found.
985 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
986 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
987 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
988 }
989}
990
991func TestVndkExtError(t *testing.T) {
992 // This test ensures an error is emitted in ill-formed vndk-ext definition.
993 testCcError(t, "must set `vendor: true` to set `extends: \".*\"`", `
994 cc_library {
995 name: "libvndk",
996 vendor_available: true,
997 vndk: {
998 enabled: true,
999 },
1000 nocrt: true,
1001 }
1002
1003 cc_library {
1004 name: "libvndk_ext",
1005 vndk: {
1006 enabled: true,
1007 extends: "libvndk",
1008 },
1009 nocrt: true,
1010 }
1011 `)
1012
1013 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1014 cc_library {
1015 name: "libvndk",
1016 vendor_available: true,
1017 vndk: {
1018 enabled: true,
1019 },
1020 nocrt: true,
1021 }
1022
1023 cc_library {
1024 name: "libvndk_ext",
1025 vendor: true,
1026 vndk: {
1027 enabled: true,
1028 },
1029 nocrt: true,
1030 }
1031 `)
1032}
1033
1034func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1035 // This test ensures an error is emitted for inconsistent support_system_process.
1036 testCcError(t, "module \".*\" with mismatched support_system_process", `
1037 cc_library {
1038 name: "libvndk",
1039 vendor_available: true,
1040 vndk: {
1041 enabled: true,
1042 },
1043 nocrt: true,
1044 }
1045
1046 cc_library {
1047 name: "libvndk_sp_ext",
1048 vendor: true,
1049 vndk: {
1050 enabled: true,
1051 extends: "libvndk",
1052 support_system_process: true,
1053 },
1054 nocrt: true,
1055 }
1056 `)
1057
1058 testCcError(t, "module \".*\" with mismatched support_system_process", `
1059 cc_library {
1060 name: "libvndk_sp",
1061 vendor_available: true,
1062 vndk: {
1063 enabled: true,
1064 support_system_process: true,
1065 },
1066 nocrt: true,
1067 }
1068
1069 cc_library {
1070 name: "libvndk_ext",
1071 vendor: true,
1072 vndk: {
1073 enabled: true,
1074 extends: "libvndk_sp",
1075 },
1076 nocrt: true,
1077 }
1078 `)
1079}
1080
1081func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001082 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +08001083 // with `vendor_available: false`.
1084 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
1085 cc_library {
1086 name: "libvndk",
1087 vendor_available: false,
1088 vndk: {
1089 enabled: true,
1090 },
1091 nocrt: true,
1092 }
1093
1094 cc_library {
1095 name: "libvndk_ext",
1096 vendor: true,
1097 vndk: {
1098 enabled: true,
1099 extends: "libvndk",
1100 },
1101 nocrt: true,
1102 }
1103 `)
1104}
1105
Logan Chiend3c59a22018-03-29 14:08:15 +08001106func TestVendorModuleUseVndkExt(t *testing.T) {
1107 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001108 testCc(t, `
1109 cc_library {
1110 name: "libvndk",
1111 vendor_available: true,
1112 vndk: {
1113 enabled: true,
1114 },
1115 nocrt: true,
1116 }
1117
1118 cc_library {
1119 name: "libvndk_ext",
1120 vendor: true,
1121 vndk: {
1122 enabled: true,
1123 extends: "libvndk",
1124 },
1125 nocrt: true,
1126 }
1127
1128 cc_library {
1129
1130 name: "libvndk_sp",
1131 vendor_available: true,
1132 vndk: {
1133 enabled: true,
1134 support_system_process: true,
1135 },
1136 nocrt: true,
1137 }
1138
1139 cc_library {
1140 name: "libvndk_sp_ext",
1141 vendor: true,
1142 vndk: {
1143 enabled: true,
1144 extends: "libvndk_sp",
1145 support_system_process: true,
1146 },
1147 nocrt: true,
1148 }
1149
1150 cc_library {
1151 name: "libvendor",
1152 vendor: true,
1153 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1154 nocrt: true,
1155 }
1156 `)
1157}
1158
Logan Chiend3c59a22018-03-29 14:08:15 +08001159func TestVndkExtUseVendorLib(t *testing.T) {
1160 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001161 testCc(t, `
1162 cc_library {
1163 name: "libvndk",
1164 vendor_available: true,
1165 vndk: {
1166 enabled: true,
1167 },
1168 nocrt: true,
1169 }
1170
1171 cc_library {
1172 name: "libvndk_ext",
1173 vendor: true,
1174 vndk: {
1175 enabled: true,
1176 extends: "libvndk",
1177 },
1178 shared_libs: ["libvendor"],
1179 nocrt: true,
1180 }
1181
1182 cc_library {
1183 name: "libvendor",
1184 vendor: true,
1185 nocrt: true,
1186 }
1187 `)
Logan Chienf3511742017-10-31 18:04:35 +08001188
Logan Chiend3c59a22018-03-29 14:08:15 +08001189 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1190 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001191 cc_library {
1192 name: "libvndk_sp",
1193 vendor_available: true,
1194 vndk: {
1195 enabled: true,
1196 support_system_process: true,
1197 },
1198 nocrt: true,
1199 }
1200
1201 cc_library {
1202 name: "libvndk_sp_ext",
1203 vendor: true,
1204 vndk: {
1205 enabled: true,
1206 extends: "libvndk_sp",
1207 support_system_process: true,
1208 },
1209 shared_libs: ["libvendor"], // Cause an error
1210 nocrt: true,
1211 }
1212
1213 cc_library {
1214 name: "libvendor",
1215 vendor: true,
1216 nocrt: true,
1217 }
1218 `)
1219}
1220
Logan Chiend3c59a22018-03-29 14:08:15 +08001221func TestVndkSpExtUseVndkError(t *testing.T) {
1222 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1223 // library.
1224 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1225 cc_library {
1226 name: "libvndk",
1227 vendor_available: true,
1228 vndk: {
1229 enabled: true,
1230 },
1231 nocrt: true,
1232 }
1233
1234 cc_library {
1235 name: "libvndk_sp",
1236 vendor_available: true,
1237 vndk: {
1238 enabled: true,
1239 support_system_process: true,
1240 },
1241 nocrt: true,
1242 }
1243
1244 cc_library {
1245 name: "libvndk_sp_ext",
1246 vendor: true,
1247 vndk: {
1248 enabled: true,
1249 extends: "libvndk_sp",
1250 support_system_process: true,
1251 },
1252 shared_libs: ["libvndk"], // Cause an error
1253 nocrt: true,
1254 }
1255 `)
1256
1257 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1258 // library.
1259 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1260 cc_library {
1261 name: "libvndk",
1262 vendor_available: true,
1263 vndk: {
1264 enabled: true,
1265 },
1266 nocrt: true,
1267 }
1268
1269 cc_library {
1270 name: "libvndk_ext",
1271 vendor: true,
1272 vndk: {
1273 enabled: true,
1274 extends: "libvndk",
1275 },
1276 nocrt: true,
1277 }
1278
1279 cc_library {
1280 name: "libvndk_sp",
1281 vendor_available: true,
1282 vndk: {
1283 enabled: true,
1284 support_system_process: true,
1285 },
1286 nocrt: true,
1287 }
1288
1289 cc_library {
1290 name: "libvndk_sp_ext",
1291 vendor: true,
1292 vndk: {
1293 enabled: true,
1294 extends: "libvndk_sp",
1295 support_system_process: true,
1296 },
1297 shared_libs: ["libvndk_ext"], // Cause an error
1298 nocrt: true,
1299 }
1300 `)
1301}
1302
1303func TestVndkUseVndkExtError(t *testing.T) {
1304 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1305 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001306 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1307 cc_library {
1308 name: "libvndk",
1309 vendor_available: true,
1310 vndk: {
1311 enabled: true,
1312 },
1313 nocrt: true,
1314 }
1315
1316 cc_library {
1317 name: "libvndk_ext",
1318 vendor: true,
1319 vndk: {
1320 enabled: true,
1321 extends: "libvndk",
1322 },
1323 nocrt: true,
1324 }
1325
1326 cc_library {
1327 name: "libvndk2",
1328 vendor_available: true,
1329 vndk: {
1330 enabled: true,
1331 },
1332 shared_libs: ["libvndk_ext"],
1333 nocrt: true,
1334 }
1335 `)
1336
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001337 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001338 cc_library {
1339 name: "libvndk",
1340 vendor_available: true,
1341 vndk: {
1342 enabled: true,
1343 },
1344 nocrt: true,
1345 }
1346
1347 cc_library {
1348 name: "libvndk_ext",
1349 vendor: true,
1350 vndk: {
1351 enabled: true,
1352 extends: "libvndk",
1353 },
1354 nocrt: true,
1355 }
1356
1357 cc_library {
1358 name: "libvndk2",
1359 vendor_available: true,
1360 vndk: {
1361 enabled: true,
1362 },
1363 target: {
1364 vendor: {
1365 shared_libs: ["libvndk_ext"],
1366 },
1367 },
1368 nocrt: true,
1369 }
1370 `)
1371
1372 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1373 cc_library {
1374 name: "libvndk_sp",
1375 vendor_available: true,
1376 vndk: {
1377 enabled: true,
1378 support_system_process: true,
1379 },
1380 nocrt: true,
1381 }
1382
1383 cc_library {
1384 name: "libvndk_sp_ext",
1385 vendor: true,
1386 vndk: {
1387 enabled: true,
1388 extends: "libvndk_sp",
1389 support_system_process: true,
1390 },
1391 nocrt: true,
1392 }
1393
1394 cc_library {
1395 name: "libvndk_sp_2",
1396 vendor_available: true,
1397 vndk: {
1398 enabled: true,
1399 support_system_process: true,
1400 },
1401 shared_libs: ["libvndk_sp_ext"],
1402 nocrt: true,
1403 }
1404 `)
1405
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001406 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001407 cc_library {
1408 name: "libvndk_sp",
1409 vendor_available: true,
1410 vndk: {
1411 enabled: true,
1412 },
1413 nocrt: true,
1414 }
1415
1416 cc_library {
1417 name: "libvndk_sp_ext",
1418 vendor: true,
1419 vndk: {
1420 enabled: true,
1421 extends: "libvndk_sp",
1422 },
1423 nocrt: true,
1424 }
1425
1426 cc_library {
1427 name: "libvndk_sp2",
1428 vendor_available: true,
1429 vndk: {
1430 enabled: true,
1431 },
1432 target: {
1433 vendor: {
1434 shared_libs: ["libvndk_sp_ext"],
1435 },
1436 },
1437 nocrt: true,
1438 }
1439 `)
1440}
1441
Jooyung Han38002912019-05-16 04:01:54 +09001442func TestMakeLinkType(t *testing.T) {
1443 config := android.TestArchConfig(buildDir, nil)
1444 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1445 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1446 // native:vndk
1447 ctx := testCcWithConfig(t, `
1448 cc_library {
1449 name: "libvndk",
1450 vendor_available: true,
1451 vndk: {
1452 enabled: true,
1453 },
1454 }
1455 cc_library {
1456 name: "libvndksp",
1457 vendor_available: true,
1458 vndk: {
1459 enabled: true,
1460 support_system_process: true,
1461 },
1462 }
1463 cc_library {
1464 name: "libvndkprivate",
1465 vendor_available: false,
1466 vndk: {
1467 enabled: true,
1468 },
1469 }
1470 cc_library {
1471 name: "libvendor",
1472 vendor: true,
1473 }
1474 cc_library {
1475 name: "libvndkext",
1476 vendor: true,
1477 vndk: {
1478 enabled: true,
1479 extends: "libvndk",
1480 },
1481 }
1482 vndk_prebuilt_shared {
1483 name: "prevndk",
1484 version: "27",
1485 target_arch: "arm",
1486 binder32bit: true,
1487 vendor_available: true,
1488 vndk: {
1489 enabled: true,
1490 },
1491 arch: {
1492 arm: {
1493 srcs: ["liba.so"],
1494 },
1495 },
1496 }
1497 cc_library {
1498 name: "libllndk",
1499 }
1500 llndk_library {
1501 name: "libllndk",
1502 symbol_file: "",
1503 }
1504 cc_library {
1505 name: "libllndkprivate",
1506 }
1507 llndk_library {
1508 name: "libllndkprivate",
1509 vendor_available: false,
1510 symbol_file: "",
1511 }`, config)
1512
Jooyung Han0302a842019-10-30 18:43:49 +09001513 assertMapKeys(t, vndkCoreLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001514 []string{"libvndk", "libvndkprivate"})
Jooyung Han0302a842019-10-30 18:43:49 +09001515 assertMapKeys(t, vndkSpLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001516 []string{"libc++", "libvndksp"})
Jooyung Han0302a842019-10-30 18:43:49 +09001517 assertMapKeys(t, llndkLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001518 []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"})
Jooyung Han0302a842019-10-30 18:43:49 +09001519 assertMapKeys(t, vndkPrivateLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001520 []string{"libft2", "libllndkprivate", "libvndkprivate"})
Jooyung Han38002912019-05-16 04:01:54 +09001521
Inseob Kim64c43952019-08-26 16:52:35 +09001522 vendorVariant27 := "android_arm64_armv8-a_vendor.27_shared"
1523
Jooyung Han38002912019-05-16 04:01:54 +09001524 tests := []struct {
1525 variant string
1526 name string
1527 expected string
1528 }{
1529 {vendorVariant, "libvndk", "native:vndk"},
1530 {vendorVariant, "libvndksp", "native:vndk"},
1531 {vendorVariant, "libvndkprivate", "native:vndk_private"},
1532 {vendorVariant, "libvendor", "native:vendor"},
1533 {vendorVariant, "libvndkext", "native:vendor"},
Jooyung Han38002912019-05-16 04:01:54 +09001534 {vendorVariant, "libllndk.llndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09001535 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09001536 {coreVariant, "libvndk", "native:platform"},
1537 {coreVariant, "libvndkprivate", "native:platform"},
1538 {coreVariant, "libllndk", "native:platform"},
1539 }
1540 for _, test := range tests {
1541 t.Run(test.name, func(t *testing.T) {
1542 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
1543 assertString(t, module.makeLinkType, test.expected)
1544 })
1545 }
1546}
1547
Colin Cross0af4b842015-04-30 16:36:18 -07001548var (
1549 str11 = "01234567891"
1550 str10 = str11[:10]
1551 str9 = str11[:9]
1552 str5 = str11[:5]
1553 str4 = str11[:4]
1554)
1555
1556var splitListForSizeTestCases = []struct {
1557 in []string
1558 out [][]string
1559 size int
1560}{
1561 {
1562 in: []string{str10},
1563 out: [][]string{{str10}},
1564 size: 10,
1565 },
1566 {
1567 in: []string{str9},
1568 out: [][]string{{str9}},
1569 size: 10,
1570 },
1571 {
1572 in: []string{str5},
1573 out: [][]string{{str5}},
1574 size: 10,
1575 },
1576 {
1577 in: []string{str11},
1578 out: nil,
1579 size: 10,
1580 },
1581 {
1582 in: []string{str10, str10},
1583 out: [][]string{{str10}, {str10}},
1584 size: 10,
1585 },
1586 {
1587 in: []string{str9, str10},
1588 out: [][]string{{str9}, {str10}},
1589 size: 10,
1590 },
1591 {
1592 in: []string{str10, str9},
1593 out: [][]string{{str10}, {str9}},
1594 size: 10,
1595 },
1596 {
1597 in: []string{str5, str4},
1598 out: [][]string{{str5, str4}},
1599 size: 10,
1600 },
1601 {
1602 in: []string{str5, str4, str5},
1603 out: [][]string{{str5, str4}, {str5}},
1604 size: 10,
1605 },
1606 {
1607 in: []string{str5, str4, str5, str4},
1608 out: [][]string{{str5, str4}, {str5, str4}},
1609 size: 10,
1610 },
1611 {
1612 in: []string{str5, str4, str5, str5},
1613 out: [][]string{{str5, str4}, {str5}, {str5}},
1614 size: 10,
1615 },
1616 {
1617 in: []string{str5, str5, str5, str4},
1618 out: [][]string{{str5}, {str5}, {str5, str4}},
1619 size: 10,
1620 },
1621 {
1622 in: []string{str9, str11},
1623 out: nil,
1624 size: 10,
1625 },
1626 {
1627 in: []string{str11, str9},
1628 out: nil,
1629 size: 10,
1630 },
1631}
1632
1633func TestSplitListForSize(t *testing.T) {
1634 for _, testCase := range splitListForSizeTestCases {
Colin Cross40e33732019-02-15 11:08:35 -08001635 out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size)
Colin Cross5b529592017-05-09 13:34:34 -07001636
1637 var outStrings [][]string
1638
1639 if len(out) > 0 {
1640 outStrings = make([][]string, len(out))
1641 for i, o := range out {
1642 outStrings[i] = o.Strings()
1643 }
1644 }
1645
1646 if !reflect.DeepEqual(outStrings, testCase.out) {
Colin Cross0af4b842015-04-30 16:36:18 -07001647 t.Errorf("incorrect output:")
1648 t.Errorf(" input: %#v", testCase.in)
1649 t.Errorf(" size: %d", testCase.size)
1650 t.Errorf(" expected: %#v", testCase.out)
Colin Cross5b529592017-05-09 13:34:34 -07001651 t.Errorf(" got: %#v", outStrings)
Colin Cross0af4b842015-04-30 16:36:18 -07001652 }
1653 }
1654}
Jeff Gaston294356f2017-09-27 17:05:30 -07001655
1656var staticLinkDepOrderTestCases = []struct {
1657 // This is a string representation of a map[moduleName][]moduleDependency .
1658 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001659 inStatic string
1660
1661 // This is a string representation of a map[moduleName][]moduleDependency .
1662 // It models the dependencies declared in an Android.bp file.
1663 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07001664
1665 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
1666 // The keys of allOrdered specify which modules we would like to check.
1667 // The values of allOrdered specify the expected result (of the transitive closure of all
1668 // dependencies) for each module to test
1669 allOrdered string
1670
1671 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
1672 // The keys of outOrdered specify which modules we would like to check.
1673 // The values of outOrdered specify the expected result (of the ordered linker command line)
1674 // for each module to test.
1675 outOrdered string
1676}{
1677 // Simple tests
1678 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001679 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07001680 outOrdered: "",
1681 },
1682 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001683 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001684 outOrdered: "a:",
1685 },
1686 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001687 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001688 outOrdered: "a:b; b:",
1689 },
1690 // Tests of reordering
1691 {
1692 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001693 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001694 outOrdered: "a:b,c,d; b:d; c:d; d:",
1695 },
1696 {
1697 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001698 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001699 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
1700 },
1701 {
1702 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001703 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07001704 outOrdered: "a:d,b,e,c; d:b; e:c",
1705 },
1706 {
1707 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001708 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07001709 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
1710 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
1711 },
1712 {
1713 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001714 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 -07001715 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1716 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1717 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001718 // shared dependencies
1719 {
1720 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
1721 // So, we don't actually have to check that a shared dependency of c will change the order
1722 // of a library that depends statically on b and on c. We only need to check that if c has
1723 // a shared dependency on b, that that shows up in allOrdered.
1724 inShared: "c:b",
1725 allOrdered: "c:b",
1726 outOrdered: "c:",
1727 },
1728 {
1729 // This test doesn't actually include any shared dependencies but it's a reminder of what
1730 // the second phase of the above test would look like
1731 inStatic: "a:b,c; c:b",
1732 allOrdered: "a:c,b; c:b",
1733 outOrdered: "a:c,b; c:b",
1734 },
Jeff Gaston294356f2017-09-27 17:05:30 -07001735 // tiebreakers for when two modules specifying different orderings and there is no dependency
1736 // to dictate an order
1737 {
1738 // 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 -08001739 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07001740 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
1741 },
1742 {
1743 // 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 -08001744 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 -07001745 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
1746 },
1747 // Tests involving duplicate dependencies
1748 {
1749 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001750 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001751 outOrdered: "a:c,b",
1752 },
1753 {
1754 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001755 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001756 outOrdered: "a:d,c,b",
1757 },
1758 // Tests to confirm the nonexistence of infinite loops.
1759 // These cases should never happen, so as long as the test terminates and the
1760 // result is deterministic then that should be fine.
1761 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001762 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001763 outOrdered: "a:a",
1764 },
1765 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001766 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001767 allOrdered: "a:b,c; b:c,a; c:a,b",
1768 outOrdered: "a:b; b:c; c:a",
1769 },
1770 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001771 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001772 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
1773 outOrdered: "a:c,b; b:a,c; c:b,a",
1774 },
1775}
1776
1777// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
1778func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
1779 // convert from "a:b,c; d:e" to "a:b,c;d:e"
1780 strippedText := strings.Replace(text, " ", "", -1)
1781 if len(strippedText) < 1 {
1782 return []android.Path{}, make(map[android.Path][]android.Path, 0)
1783 }
1784 allDeps = make(map[android.Path][]android.Path, 0)
1785
1786 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
1787 moduleTexts := strings.Split(strippedText, ";")
1788
1789 outputForModuleName := func(moduleName string) android.Path {
1790 return android.PathForTesting(moduleName)
1791 }
1792
1793 for _, moduleText := range moduleTexts {
1794 // convert from "a:b,c" to ["a", "b,c"]
1795 components := strings.Split(moduleText, ":")
1796 if len(components) != 2 {
1797 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
1798 }
1799 moduleName := components[0]
1800 moduleOutput := outputForModuleName(moduleName)
1801 modulesInOrder = append(modulesInOrder, moduleOutput)
1802
1803 depString := components[1]
1804 // convert from "b,c" to ["b", "c"]
1805 depNames := strings.Split(depString, ",")
1806 if len(depString) < 1 {
1807 depNames = []string{}
1808 }
1809 var deps []android.Path
1810 for _, depName := range depNames {
1811 deps = append(deps, outputForModuleName(depName))
1812 }
1813 allDeps[moduleOutput] = deps
1814 }
1815 return modulesInOrder, allDeps
1816}
1817
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001818func TestLinkReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001819 for _, testCase := range staticLinkDepOrderTestCases {
1820 errs := []string{}
1821
1822 // parse testcase
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001823 _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic)
Jeff Gaston294356f2017-09-27 17:05:30 -07001824 expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered)
1825 if testCase.allOrdered == "" {
1826 // allow the test case to skip specifying allOrdered
1827 testCase.allOrdered = testCase.outOrdered
1828 }
1829 _, expectedAllDeps := parseModuleDeps(testCase.allOrdered)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001830 _, givenAllSharedDeps := parseModuleDeps(testCase.inShared)
Jeff Gaston294356f2017-09-27 17:05:30 -07001831
1832 // For each module whose post-reordered dependencies were specified, validate that
1833 // reordering the inputs produces the expected outputs.
1834 for _, moduleName := range expectedModuleNames {
1835 moduleDeps := givenTransitiveDeps[moduleName]
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001836 givenSharedDeps := givenAllSharedDeps[moduleName]
1837 orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001838
1839 correctAllOrdered := expectedAllDeps[moduleName]
1840 if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) {
1841 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001842 "\nin static:%q"+
1843 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001844 "\nmodule: %v"+
1845 "\nexpected: %s"+
1846 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001847 testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001848 }
1849
1850 correctOutputDeps := expectedTransitiveDeps[moduleName]
1851 if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) {
1852 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001853 "\nin static:%q"+
1854 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001855 "\nmodule: %v"+
1856 "\nexpected: %s"+
1857 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001858 testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001859 }
1860 }
1861
1862 if len(errs) > 0 {
1863 sort.Strings(errs)
1864 for _, err := range errs {
1865 t.Error(err)
1866 }
1867 }
1868 }
1869}
Logan Chienf3511742017-10-31 18:04:35 +08001870
Jeff Gaston294356f2017-09-27 17:05:30 -07001871func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
1872 for _, moduleName := range moduleNames {
1873 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
1874 output := module.outputFile.Path()
1875 paths = append(paths, output)
1876 }
1877 return paths
1878}
1879
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001880func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001881 ctx := testCc(t, `
1882 cc_library {
1883 name: "a",
1884 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09001885 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001886 }
1887 cc_library {
1888 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001889 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001890 }
1891 cc_library {
1892 name: "c",
1893 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001894 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001895 }
1896 cc_library {
1897 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09001898 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001899 }
1900
1901 `)
1902
1903 variant := "android_arm64_armv8-a_core_static"
1904 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001905 actual := moduleA.depsInLinkOrder
Jeff Gaston294356f2017-09-27 17:05:30 -07001906 expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"})
1907
1908 if !reflect.DeepEqual(actual, expected) {
1909 t.Errorf("staticDeps orderings were not propagated correctly"+
1910 "\nactual: %v"+
1911 "\nexpected: %v",
1912 actual,
1913 expected,
1914 )
1915 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09001916}
Jeff Gaston294356f2017-09-27 17:05:30 -07001917
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001918func TestStaticLibDepReorderingWithShared(t *testing.T) {
1919 ctx := testCc(t, `
1920 cc_library {
1921 name: "a",
1922 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09001923 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001924 }
1925 cc_library {
1926 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001927 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001928 }
1929 cc_library {
1930 name: "c",
1931 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001932 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001933 }
1934
1935 `)
1936
1937 variant := "android_arm64_armv8-a_core_static"
1938 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
1939 actual := moduleA.depsInLinkOrder
1940 expected := getOutputPaths(ctx, variant, []string{"c", "b"})
1941
1942 if !reflect.DeepEqual(actual, expected) {
1943 t.Errorf("staticDeps orderings did not account for shared libs"+
1944 "\nactual: %v"+
1945 "\nexpected: %v",
1946 actual,
1947 expected,
1948 )
1949 }
1950}
1951
Jiyong Parka46a4d52017-12-14 19:54:34 +09001952func TestLlndkHeaders(t *testing.T) {
1953 ctx := testCc(t, `
1954 llndk_headers {
1955 name: "libllndk_headers",
1956 export_include_dirs: ["my_include"],
1957 }
1958 llndk_library {
1959 name: "libllndk",
1960 export_llndk_headers: ["libllndk_headers"],
1961 }
1962 cc_library {
1963 name: "libvendor",
1964 shared_libs: ["libllndk"],
1965 vendor: true,
1966 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07001967 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08001968 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09001969 }
1970 `)
1971
1972 // _static variant is used since _shared reuses *.o from the static variant
Inseob Kim64c43952019-08-26 16:52:35 +09001973 cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor.VER_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09001974 cflags := cc.Args["cFlags"]
1975 if !strings.Contains(cflags, "-Imy_include") {
1976 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
1977 }
1978}
1979
Logan Chien43d34c32017-12-20 01:17:32 +08001980func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
1981 actual := module.Properties.AndroidMkRuntimeLibs
1982 if !reflect.DeepEqual(actual, expected) {
1983 t.Errorf("incorrect runtime_libs for shared libs"+
1984 "\nactual: %v"+
1985 "\nexpected: %v",
1986 actual,
1987 expected,
1988 )
1989 }
1990}
1991
1992const runtimeLibAndroidBp = `
1993 cc_library {
1994 name: "libvendor_available1",
1995 vendor_available: true,
Yi Konge7fe9912019-06-02 00:53:50 -07001996 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08001997 nocrt : true,
1998 system_shared_libs : [],
1999 }
2000 cc_library {
2001 name: "libvendor_available2",
2002 vendor_available: true,
2003 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002004 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002005 nocrt : true,
2006 system_shared_libs : [],
2007 }
2008 cc_library {
2009 name: "libvendor_available3",
2010 vendor_available: true,
2011 runtime_libs: ["libvendor_available1"],
2012 target: {
2013 vendor: {
2014 exclude_runtime_libs: ["libvendor_available1"],
2015 }
2016 },
Yi Konge7fe9912019-06-02 00:53:50 -07002017 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002018 nocrt : true,
2019 system_shared_libs : [],
2020 }
2021 cc_library {
2022 name: "libcore",
2023 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002024 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002025 nocrt : true,
2026 system_shared_libs : [],
2027 }
2028 cc_library {
2029 name: "libvendor1",
2030 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002031 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002032 nocrt : true,
2033 system_shared_libs : [],
2034 }
2035 cc_library {
2036 name: "libvendor2",
2037 vendor: true,
2038 runtime_libs: ["libvendor_available1", "libvendor1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002039 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002040 nocrt : true,
2041 system_shared_libs : [],
2042 }
2043`
2044
2045func TestRuntimeLibs(t *testing.T) {
2046 ctx := testCc(t, runtimeLibAndroidBp)
2047
2048 // runtime_libs for core variants use the module names without suffixes.
2049 variant := "android_arm64_armv8-a_core_shared"
2050
2051 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2052 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2053
2054 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
2055 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2056
2057 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2058 // and vendor variants.
Inseob Kim64c43952019-08-26 16:52:35 +09002059 variant = "android_arm64_armv8-a_vendor.VER_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002060
2061 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2062 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
2063
2064 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2065 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
2066}
2067
2068func TestExcludeRuntimeLibs(t *testing.T) {
2069 ctx := testCc(t, runtimeLibAndroidBp)
2070
2071 variant := "android_arm64_armv8-a_core_shared"
2072 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2073 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2074
Inseob Kim64c43952019-08-26 16:52:35 +09002075 variant = "android_arm64_armv8-a_vendor.VER_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002076 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2077 checkRuntimeLibs(t, nil, module)
2078}
2079
2080func TestRuntimeLibsNoVndk(t *testing.T) {
2081 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2082
2083 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2084
2085 variant := "android_arm64_armv8-a_core_shared"
2086
2087 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2088 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2089
2090 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2091 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
2092}
2093
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002094func checkStaticLibs(t *testing.T, expected []string, module *Module) {
2095 actual := module.Properties.AndroidMkStaticLibs
2096 if !reflect.DeepEqual(actual, expected) {
2097 t.Errorf("incorrect static_libs"+
2098 "\nactual: %v"+
2099 "\nexpected: %v",
2100 actual,
2101 expected,
2102 )
2103 }
2104}
2105
2106const staticLibAndroidBp = `
2107 cc_library {
2108 name: "lib1",
2109 }
2110 cc_library {
2111 name: "lib2",
2112 static_libs: ["lib1"],
2113 }
2114`
2115
2116func TestStaticLibDepExport(t *testing.T) {
2117 ctx := testCc(t, staticLibAndroidBp)
2118
2119 // Check the shared version of lib2.
2120 variant := "android_arm64_armv8-a_core_shared"
2121 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Dan Albert2da19cb2019-07-24 12:17:40 -07002122 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002123
2124 // Check the static version of lib2.
2125 variant = "android_arm64_armv8-a_core_static"
2126 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2127 // libc++_static is linked additionally.
Dan Albert2da19cb2019-07-24 12:17:40 -07002128 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002129}
2130
Jiyong Parkd08b6972017-09-26 10:50:54 +09002131var compilerFlagsTestCases = []struct {
2132 in string
2133 out bool
2134}{
2135 {
2136 in: "a",
2137 out: false,
2138 },
2139 {
2140 in: "-a",
2141 out: true,
2142 },
2143 {
2144 in: "-Ipath/to/something",
2145 out: false,
2146 },
2147 {
2148 in: "-isystempath/to/something",
2149 out: false,
2150 },
2151 {
2152 in: "--coverage",
2153 out: false,
2154 },
2155 {
2156 in: "-include a/b",
2157 out: true,
2158 },
2159 {
2160 in: "-include a/b c/d",
2161 out: false,
2162 },
2163 {
2164 in: "-DMACRO",
2165 out: true,
2166 },
2167 {
2168 in: "-DMAC RO",
2169 out: false,
2170 },
2171 {
2172 in: "-a -b",
2173 out: false,
2174 },
2175 {
2176 in: "-DMACRO=definition",
2177 out: true,
2178 },
2179 {
2180 in: "-DMACRO=defi nition",
2181 out: true, // TODO(jiyong): this should be false
2182 },
2183 {
2184 in: "-DMACRO(x)=x + 1",
2185 out: true,
2186 },
2187 {
2188 in: "-DMACRO=\"defi nition\"",
2189 out: true,
2190 },
2191}
2192
2193type mockContext struct {
2194 BaseModuleContext
2195 result bool
2196}
2197
2198func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2199 // CheckBadCompilerFlags calls this function when the flag should be rejected
2200 ctx.result = false
2201}
2202
2203func TestCompilerFlags(t *testing.T) {
2204 for _, testCase := range compilerFlagsTestCases {
2205 ctx := &mockContext{result: true}
2206 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2207 if ctx.result != testCase.out {
2208 t.Errorf("incorrect output:")
2209 t.Errorf(" input: %#v", testCase.in)
2210 t.Errorf(" expected: %#v", testCase.out)
2211 t.Errorf(" got: %#v", ctx.result)
2212 }
2213 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002214}
Jiyong Park374510b2018-03-19 18:23:01 +09002215
2216func TestVendorPublicLibraries(t *testing.T) {
2217 ctx := testCc(t, `
2218 cc_library_headers {
2219 name: "libvendorpublic_headers",
2220 export_include_dirs: ["my_include"],
2221 }
2222 vendor_public_library {
2223 name: "libvendorpublic",
2224 symbol_file: "",
2225 export_public_headers: ["libvendorpublic_headers"],
2226 }
2227 cc_library {
2228 name: "libvendorpublic",
2229 srcs: ["foo.c"],
2230 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002231 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002232 nocrt: true,
2233 }
2234
2235 cc_library {
2236 name: "libsystem",
2237 shared_libs: ["libvendorpublic"],
2238 vendor: false,
2239 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002240 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002241 nocrt: true,
2242 }
2243 cc_library {
2244 name: "libvendor",
2245 shared_libs: ["libvendorpublic"],
2246 vendor: true,
2247 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002248 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002249 nocrt: true,
2250 }
2251 `)
2252
2253 variant := "android_arm64_armv8-a_core_shared"
2254
2255 // test if header search paths are correctly added
2256 // _static variant is used since _shared reuses *.o from the static variant
2257 cc := ctx.ModuleForTests("libsystem", strings.Replace(variant, "_shared", "_static", 1)).Rule("cc")
2258 cflags := cc.Args["cFlags"]
2259 if !strings.Contains(cflags, "-Imy_include") {
2260 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
2261 }
2262
2263 // test if libsystem is linked to the stub
2264 ld := ctx.ModuleForTests("libsystem", variant).Rule("ld")
2265 libflags := ld.Args["libFlags"]
2266 stubPaths := getOutputPaths(ctx, variant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
2267 if !strings.Contains(libflags, stubPaths[0].String()) {
2268 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
2269 }
2270
2271 // test if libvendor is linked to the real shared lib
Inseob Kim64c43952019-08-26 16:52:35 +09002272 ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor.VER", 1)).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09002273 libflags = ld.Args["libFlags"]
Inseob Kim64c43952019-08-26 16:52:35 +09002274 stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor.VER", 1), []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09002275 if !strings.Contains(libflags, stubPaths[0].String()) {
2276 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
2277 }
2278
2279}
Jiyong Park37b25202018-07-11 10:49:27 +09002280
2281func TestRecovery(t *testing.T) {
2282 ctx := testCc(t, `
2283 cc_library_shared {
2284 name: "librecovery",
2285 recovery: true,
2286 }
2287 cc_library_shared {
2288 name: "librecovery32",
2289 recovery: true,
2290 compile_multilib:"32",
2291 }
Jiyong Park5baac542018-08-28 09:55:37 +09002292 cc_library_shared {
2293 name: "libHalInRecovery",
2294 recovery_available: true,
2295 vendor: true,
2296 }
Jiyong Park37b25202018-07-11 10:49:27 +09002297 `)
2298
2299 variants := ctx.ModuleVariantsForTests("librecovery")
2300 const arm64 = "android_arm64_armv8-a_recovery_shared"
2301 if len(variants) != 1 || !android.InList(arm64, variants) {
2302 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
2303 }
2304
2305 variants = ctx.ModuleVariantsForTests("librecovery32")
2306 if android.InList(arm64, variants) {
2307 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
2308 }
Jiyong Park5baac542018-08-28 09:55:37 +09002309
2310 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
2311 if !recoveryModule.Platform() {
2312 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
2313 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002314}
Jiyong Park5baac542018-08-28 09:55:37 +09002315
Jiyong Park7ed9de32018-10-15 22:25:07 +09002316func TestVersionedStubs(t *testing.T) {
2317 ctx := testCc(t, `
2318 cc_library_shared {
2319 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002320 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002321 stubs: {
2322 symbol_file: "foo.map.txt",
2323 versions: ["1", "2", "3"],
2324 },
2325 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002326
Jiyong Park7ed9de32018-10-15 22:25:07 +09002327 cc_library_shared {
2328 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002329 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002330 shared_libs: ["libFoo#1"],
2331 }`)
2332
2333 variants := ctx.ModuleVariantsForTests("libFoo")
2334 expectedVariants := []string{
2335 "android_arm64_armv8-a_core_shared",
2336 "android_arm64_armv8-a_core_shared_1",
2337 "android_arm64_armv8-a_core_shared_2",
2338 "android_arm64_armv8-a_core_shared_3",
2339 "android_arm_armv7-a-neon_core_shared",
2340 "android_arm_armv7-a-neon_core_shared_1",
2341 "android_arm_armv7-a-neon_core_shared_2",
2342 "android_arm_armv7-a-neon_core_shared_3",
2343 }
2344 variantsMismatch := false
2345 if len(variants) != len(expectedVariants) {
2346 variantsMismatch = true
2347 } else {
2348 for _, v := range expectedVariants {
2349 if !inList(v, variants) {
2350 variantsMismatch = false
2351 }
2352 }
2353 }
2354 if variantsMismatch {
2355 t.Errorf("variants of libFoo expected:\n")
2356 for _, v := range expectedVariants {
2357 t.Errorf("%q\n", v)
2358 }
2359 t.Errorf(", but got:\n")
2360 for _, v := range variants {
2361 t.Errorf("%q\n", v)
2362 }
2363 }
2364
2365 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("ld")
2366 libFlags := libBarLinkRule.Args["libFlags"]
2367 libFoo1StubPath := "libFoo/android_arm64_armv8-a_core_shared_1/libFoo.so"
2368 if !strings.Contains(libFlags, libFoo1StubPath) {
2369 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
2370 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002371
2372 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc")
2373 cFlags := libBarCompileRule.Args["cFlags"]
2374 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
2375 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
2376 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
2377 }
Jiyong Park37b25202018-07-11 10:49:27 +09002378}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002379
2380func TestStaticExecutable(t *testing.T) {
2381 ctx := testCc(t, `
2382 cc_binary {
2383 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01002384 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002385 static_executable: true,
2386 }`)
2387
2388 variant := "android_arm64_armv8-a_core"
2389 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
2390 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07002391 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002392 for _, lib := range systemStaticLibs {
2393 if !strings.Contains(libFlags, lib) {
2394 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
2395 }
2396 }
2397 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
2398 for _, lib := range systemSharedLibs {
2399 if strings.Contains(libFlags, lib) {
2400 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
2401 }
2402 }
2403}
Jiyong Parke4bb9862019-02-01 00:31:10 +09002404
2405func TestStaticDepsOrderWithStubs(t *testing.T) {
2406 ctx := testCc(t, `
2407 cc_binary {
2408 name: "mybin",
2409 srcs: ["foo.c"],
2410 static_libs: ["libB"],
2411 static_executable: true,
2412 stl: "none",
2413 }
2414
2415 cc_library {
2416 name: "libB",
2417 srcs: ["foo.c"],
2418 shared_libs: ["libC"],
2419 stl: "none",
2420 }
2421
2422 cc_library {
2423 name: "libC",
2424 srcs: ["foo.c"],
2425 stl: "none",
2426 stubs: {
2427 versions: ["1"],
2428 },
2429 }`)
2430
2431 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a_core").Module().(*Module)
2432 actual := mybin.depsInLinkOrder
2433 expected := getOutputPaths(ctx, "android_arm64_armv8-a_core_static", []string{"libB", "libC"})
2434
2435 if !reflect.DeepEqual(actual, expected) {
2436 t.Errorf("staticDeps orderings were not propagated correctly"+
2437 "\nactual: %v"+
2438 "\nexpected: %v",
2439 actual,
2440 expected,
2441 )
2442 }
2443}
Jooyung Han38002912019-05-16 04:01:54 +09002444
Jooyung Hand48f3c32019-08-23 11:18:57 +09002445func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
2446 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
2447 cc_library {
2448 name: "libA",
2449 srcs: ["foo.c"],
2450 shared_libs: ["libB"],
2451 stl: "none",
2452 }
2453
2454 cc_library {
2455 name: "libB",
2456 srcs: ["foo.c"],
2457 enabled: false,
2458 stl: "none",
2459 }
2460 `)
2461}
2462
Mitch Phillipsda9a4632019-07-15 09:34:09 -07002463// Simple smoke test for the cc_fuzz target that ensures the rule compiles
2464// correctly.
2465func TestFuzzTarget(t *testing.T) {
2466 ctx := testCc(t, `
2467 cc_fuzz {
2468 name: "fuzz_smoke_test",
2469 srcs: ["foo.c"],
2470 }`)
2471
2472 variant := "android_arm64_armv8-a_core"
2473 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
2474}
2475
Jiyong Park29074592019-07-07 16:27:47 +09002476func TestAidl(t *testing.T) {
2477}
2478
Jooyung Han38002912019-05-16 04:01:54 +09002479func assertString(t *testing.T, got, expected string) {
2480 t.Helper()
2481 if got != expected {
2482 t.Errorf("expected %q got %q", expected, got)
2483 }
2484}
2485
2486func assertArrayString(t *testing.T, got, expected []string) {
2487 t.Helper()
2488 if len(got) != len(expected) {
2489 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
2490 return
2491 }
2492 for i := range got {
2493 if got[i] != expected[i] {
2494 t.Errorf("expected %d-th %q (%q) got %q (%q)",
2495 i, expected[i], expected, got[i], got)
2496 return
2497 }
2498 }
2499}
Colin Crosse1bb5d02019-09-24 14:55:04 -07002500
Jooyung Han0302a842019-10-30 18:43:49 +09002501func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
2502 t.Helper()
2503 assertArrayString(t, android.SortedStringKeys(m), expected)
2504}
2505
Colin Crosse1bb5d02019-09-24 14:55:04 -07002506func TestDefaults(t *testing.T) {
2507 ctx := testCc(t, `
2508 cc_defaults {
2509 name: "defaults",
2510 srcs: ["foo.c"],
2511 static: {
2512 srcs: ["bar.c"],
2513 },
2514 shared: {
2515 srcs: ["baz.c"],
2516 },
2517 }
2518
2519 cc_library_static {
2520 name: "libstatic",
2521 defaults: ["defaults"],
2522 }
2523
2524 cc_library_shared {
2525 name: "libshared",
2526 defaults: ["defaults"],
2527 }
2528
2529 cc_library {
2530 name: "libboth",
2531 defaults: ["defaults"],
2532 }
2533
2534 cc_binary {
2535 name: "binary",
2536 defaults: ["defaults"],
2537 }`)
2538
2539 pathsToBase := func(paths android.Paths) []string {
2540 var ret []string
2541 for _, p := range paths {
2542 ret = append(ret, p.Base())
2543 }
2544 return ret
2545 }
2546
2547 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_core_shared").Rule("ld")
2548 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2549 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
2550 }
2551 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_shared").Rule("ld")
2552 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2553 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
2554 }
2555 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a_core").Rule("ld")
2556 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
2557 t.Errorf("binary ld rule wanted %q, got %q", w, g)
2558 }
2559
2560 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_core_static").Rule("ar")
2561 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
2562 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
2563 }
2564 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_static").Rule("ar")
2565 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
2566 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
2567 }
2568}