Colin Cross | d00350c | 2017-11-17 10:55:38 -0800 | [diff] [blame] | 1 | // 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 Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 15 | package cc |
| 16 | |
| 17 | import ( |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 18 | "fmt" |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 19 | "io/ioutil" |
| 20 | "os" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 21 | "path/filepath" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 22 | "reflect" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 23 | "sort" |
| 24 | "strings" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 25 | "testing" |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 26 | |
| 27 | "android/soong/android" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 30 | var buildDir string |
| 31 | |
| 32 | func setUp() { |
| 33 | var err error |
| 34 | buildDir, err = ioutil.TempDir("", "soong_cc_test") |
| 35 | if err != nil { |
| 36 | panic(err) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func tearDown() { |
| 41 | os.RemoveAll(buildDir) |
| 42 | } |
| 43 | |
| 44 | func TestMain(m *testing.M) { |
| 45 | run := func() int { |
| 46 | setUp() |
| 47 | defer tearDown() |
| 48 | |
| 49 | return m.Run() |
| 50 | } |
| 51 | |
| 52 | os.Exit(run()) |
| 53 | } |
| 54 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 55 | func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext { |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 56 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 57 | ctx := CreateTestContext() |
| 58 | ctx.Register(config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 59 | |
Jeff Gaston | d3e141d | 2017-08-08 17:46:01 -0700 | [diff] [blame] | 60 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 61 | android.FailIfErrored(t, errs) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 62 | _, errs = ctx.PrepareBuildActions(config) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 63 | android.FailIfErrored(t, errs) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 64 | |
| 65 | return ctx |
| 66 | } |
| 67 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 68 | func testCc(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 69 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 70 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 71 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 72 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 73 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 74 | return testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | func testCcNoVndk(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 78 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 79 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 80 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 81 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 82 | return testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 83 | } |
| 84 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 85 | func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 86 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 87 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 88 | ctx := CreateTestContext() |
| 89 | ctx.Register(config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 90 | |
| 91 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 92 | if len(errs) > 0 { |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 93 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 94 | return |
| 95 | } |
| 96 | |
| 97 | _, errs = ctx.PrepareBuildActions(config) |
| 98 | if len(errs) > 0 { |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 99 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 100 | return |
| 101 | } |
| 102 | |
| 103 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 104 | } |
| 105 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 106 | func testCcError(t *testing.T, pattern string, bp string) { |
| 107 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 108 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 109 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 110 | testCcErrorWithConfig(t, pattern, config) |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | func testCcErrorProductVndk(t *testing.T, pattern string, bp string) { |
| 115 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 116 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 117 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 118 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 119 | testCcErrorWithConfig(t, pattern, config) |
| 120 | return |
| 121 | } |
| 122 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 123 | const ( |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 124 | coreVariant = "android_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 125 | vendorVariant = "android_vendor.VER_arm64_armv8-a_shared" |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 126 | productVariant = "android_product.VER_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 127 | recoveryVariant = "android_recovery_arm64_armv8-a_shared" |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 128 | ) |
| 129 | |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 130 | func TestFuchsiaDeps(t *testing.T) { |
| 131 | t.Helper() |
| 132 | |
| 133 | bp := ` |
| 134 | cc_library { |
| 135 | name: "libTest", |
| 136 | srcs: ["foo.c"], |
| 137 | target: { |
| 138 | fuchsia: { |
| 139 | srcs: ["bar.c"], |
| 140 | }, |
| 141 | }, |
| 142 | }` |
| 143 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 144 | config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil) |
| 145 | ctx := testCcWithConfig(t, config) |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 146 | |
| 147 | rt := false |
| 148 | fb := false |
| 149 | |
| 150 | ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld") |
| 151 | implicits := ld.Implicits |
| 152 | for _, lib := range implicits { |
| 153 | if strings.Contains(lib.Rel(), "libcompiler_rt") { |
| 154 | rt = true |
| 155 | } |
| 156 | |
| 157 | if strings.Contains(lib.Rel(), "libbioniccompat") { |
| 158 | fb = true |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if !rt || !fb { |
| 163 | t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat") |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | func TestFuchsiaTargetDecl(t *testing.T) { |
| 168 | t.Helper() |
| 169 | |
| 170 | bp := ` |
| 171 | cc_library { |
| 172 | name: "libTest", |
| 173 | srcs: ["foo.c"], |
| 174 | target: { |
| 175 | fuchsia: { |
| 176 | srcs: ["bar.c"], |
| 177 | }, |
| 178 | }, |
| 179 | }` |
| 180 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 181 | config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil) |
| 182 | ctx := testCcWithConfig(t, config) |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 183 | ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld") |
| 184 | var objs []string |
| 185 | for _, o := range ld.Inputs { |
| 186 | objs = append(objs, o.Base()) |
| 187 | } |
| 188 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
| 189 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 190 | } |
| 191 | } |
| 192 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 193 | func TestVendorSrc(t *testing.T) { |
| 194 | ctx := testCc(t, ` |
| 195 | cc_library { |
| 196 | name: "libTest", |
| 197 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 198 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 199 | nocrt: true, |
| 200 | system_shared_libs: [], |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 201 | vendor_available: true, |
| 202 | target: { |
| 203 | vendor: { |
| 204 | srcs: ["bar.c"], |
| 205 | }, |
| 206 | }, |
| 207 | } |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 208 | `) |
| 209 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 210 | ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld") |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 211 | var objs []string |
| 212 | for _, o := range ld.Inputs { |
| 213 | objs = append(objs, o.Base()) |
| 214 | } |
Colin Cross | 95d33fe | 2018-01-03 13:40:46 -0800 | [diff] [blame] | 215 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 216 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 217 | } |
| 218 | } |
| 219 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 220 | func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string, |
| 221 | isVndkSp bool, extends string) { |
| 222 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 223 | t.Helper() |
| 224 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 225 | mod := ctx.ModuleForTests(name, vendorVariant).Module().(*Module) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 226 | if !mod.HasVendorVariant() { |
Colin Cross | f46e37f | 2018-03-21 16:25:58 -0700 | [diff] [blame] | 227 | t.Errorf("%q must have vendor variant", name) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // Check library properties. |
| 231 | lib, ok := mod.compiler.(*libraryDecorator) |
| 232 | if !ok { |
| 233 | t.Errorf("%q must have libraryDecorator", name) |
| 234 | } else if lib.baseInstaller.subDir != subDir { |
| 235 | t.Errorf("%q must use %q as subdir but it is using %q", name, subDir, |
| 236 | lib.baseInstaller.subDir) |
| 237 | } |
| 238 | |
| 239 | // Check VNDK properties. |
| 240 | if mod.vndkdep == nil { |
| 241 | t.Fatalf("%q must have `vndkdep`", name) |
| 242 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 243 | if !mod.IsVndk() { |
| 244 | t.Errorf("%q IsVndk() must equal to true", name) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 245 | } |
| 246 | if mod.isVndkSp() != isVndkSp { |
| 247 | t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp) |
| 248 | } |
| 249 | |
| 250 | // Check VNDK extension properties. |
| 251 | isVndkExt := extends != "" |
| 252 | if mod.isVndkExt() != isVndkExt { |
| 253 | t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt) |
| 254 | } |
| 255 | |
| 256 | if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends { |
| 257 | t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends) |
| 258 | } |
| 259 | } |
| 260 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 261 | func checkVndkSnapshot(t *testing.T, ctx *android.TestContext, moduleName, snapshotFilename, subDir, variant string) { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 262 | vndkSnapshot := ctx.SingletonForTests("vndk-snapshot") |
| 263 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 264 | mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer) |
| 265 | if !ok { |
| 266 | t.Errorf("%q must have output\n", moduleName) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 267 | return |
| 268 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 269 | outputFiles, err := mod.OutputFiles("") |
| 270 | if err != nil || len(outputFiles) != 1 { |
| 271 | t.Errorf("%q must have single output\n", moduleName) |
| 272 | return |
| 273 | } |
| 274 | snapshotPath := filepath.Join(subDir, snapshotFilename) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 275 | |
| 276 | out := vndkSnapshot.Output(snapshotPath) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 277 | if out.Input.String() != outputFiles[0].String() { |
| 278 | t.Errorf("The input of VNDK snapshot must be %q, but %q", out.Input.String(), outputFiles[0]) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 282 | func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) { |
| 283 | t.Helper() |
| 284 | assertString(t, params.Rule.String(), android.WriteFile.String()) |
| 285 | actual := strings.FieldsFunc(strings.ReplaceAll(params.Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' }) |
| 286 | assertArrayString(t, actual, expected) |
| 287 | } |
| 288 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 289 | func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) { |
| 290 | t.Helper() |
| 291 | vndkSnapshot := ctx.SingletonForTests("vndk-snapshot") |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 292 | checkWriteFileOutput(t, vndkSnapshot.Output(output), expected) |
| 293 | } |
| 294 | |
| 295 | func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) { |
| 296 | t.Helper() |
| 297 | vndkLibraries := ctx.ModuleForTests(module, "") |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 298 | |
| 299 | var output string |
| 300 | if module != "vndkcorevariant.libraries.txt" { |
| 301 | output = insertVndkVersion(module, "VER") |
| 302 | } else { |
| 303 | output = module |
| 304 | } |
| 305 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 306 | checkWriteFileOutput(t, vndkLibraries.Output(output), expected) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 307 | } |
| 308 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 309 | func TestVndk(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 310 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 311 | cc_library { |
| 312 | name: "libvndk", |
| 313 | vendor_available: true, |
| 314 | vndk: { |
| 315 | enabled: true, |
| 316 | }, |
| 317 | nocrt: true, |
| 318 | } |
| 319 | |
| 320 | cc_library { |
| 321 | name: "libvndk_private", |
| 322 | vendor_available: false, |
| 323 | vndk: { |
| 324 | enabled: true, |
| 325 | }, |
| 326 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 327 | stem: "libvndk-private", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | cc_library { |
| 331 | name: "libvndk_sp", |
| 332 | vendor_available: true, |
| 333 | vndk: { |
| 334 | enabled: true, |
| 335 | support_system_process: true, |
| 336 | }, |
| 337 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 338 | suffix: "-x", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | cc_library { |
| 342 | name: "libvndk_sp_private", |
| 343 | vendor_available: false, |
| 344 | vndk: { |
| 345 | enabled: true, |
| 346 | support_system_process: true, |
| 347 | }, |
| 348 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 349 | target: { |
| 350 | vendor: { |
| 351 | suffix: "-x", |
| 352 | }, |
| 353 | }, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 354 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 355 | vndk_libraries_txt { |
| 356 | name: "llndk.libraries.txt", |
| 357 | } |
| 358 | vndk_libraries_txt { |
| 359 | name: "vndkcore.libraries.txt", |
| 360 | } |
| 361 | vndk_libraries_txt { |
| 362 | name: "vndksp.libraries.txt", |
| 363 | } |
| 364 | vndk_libraries_txt { |
| 365 | name: "vndkprivate.libraries.txt", |
| 366 | } |
| 367 | vndk_libraries_txt { |
| 368 | name: "vndkcorevariant.libraries.txt", |
| 369 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 370 | ` |
| 371 | |
| 372 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 373 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 374 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 375 | |
| 376 | ctx := testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 377 | |
| 378 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "") |
| 379 | checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "") |
| 380 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "") |
| 381 | checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 382 | |
| 383 | // Check VNDK snapshot output. |
| 384 | |
| 385 | snapshotDir := "vndk-snapshot" |
| 386 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 387 | |
| 388 | vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 389 | "arm64", "armv8-a")) |
| 390 | vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 391 | "arm", "armv7-a-neon")) |
| 392 | |
| 393 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") |
| 394 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") |
| 395 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") |
| 396 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") |
| 397 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 398 | variant := "android_vendor.VER_arm64_armv8-a_shared" |
| 399 | variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 400 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 401 | checkVndkSnapshot(t, ctx, "libvndk", "libvndk.so", vndkCoreLibPath, variant) |
| 402 | checkVndkSnapshot(t, ctx, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) |
| 403 | checkVndkSnapshot(t, ctx, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) |
| 404 | checkVndkSnapshot(t, ctx, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 405 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 406 | snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") |
| 407 | checkVndkSnapshot(t, ctx, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "") |
| 408 | checkVndkSnapshot(t, ctx, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "") |
| 409 | checkVndkSnapshot(t, ctx, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "") |
| 410 | checkVndkSnapshot(t, ctx, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "") |
| 411 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 412 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 413 | "LLNDK: libc.so", |
| 414 | "LLNDK: libdl.so", |
| 415 | "LLNDK: libft2.so", |
| 416 | "LLNDK: libm.so", |
| 417 | "VNDK-SP: libc++.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 418 | "VNDK-SP: libvndk_sp-x.so", |
| 419 | "VNDK-SP: libvndk_sp_private-x.so", |
| 420 | "VNDK-core: libvndk-private.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 421 | "VNDK-core: libvndk.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 422 | "VNDK-private: libft2.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 423 | "VNDK-private: libvndk-private.so", |
| 424 | "VNDK-private: libvndk_sp_private-x.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 425 | }) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 426 | checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"}) |
| 427 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"}) |
| 428 | checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"}) |
| 429 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"}) |
| 430 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) |
| 431 | } |
| 432 | |
| 433 | func TestVndkLibrariesTxtAndroidMk(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 434 | bp := ` |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 435 | vndk_libraries_txt { |
| 436 | name: "llndk.libraries.txt", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 437 | }` |
| 438 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 439 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 440 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 441 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 442 | |
| 443 | module := ctx.ModuleForTests("llndk.libraries.txt", "") |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 444 | entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0] |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 445 | assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"}) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | func TestVndkUsingCoreVariant(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 449 | bp := ` |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 450 | cc_library { |
| 451 | name: "libvndk", |
| 452 | vendor_available: true, |
| 453 | vndk: { |
| 454 | enabled: true, |
| 455 | }, |
| 456 | nocrt: true, |
| 457 | } |
| 458 | |
| 459 | cc_library { |
| 460 | name: "libvndk_sp", |
| 461 | vendor_available: true, |
| 462 | vndk: { |
| 463 | enabled: true, |
| 464 | support_system_process: true, |
| 465 | }, |
| 466 | nocrt: true, |
| 467 | } |
| 468 | |
| 469 | cc_library { |
| 470 | name: "libvndk2", |
| 471 | vendor_available: false, |
| 472 | vndk: { |
| 473 | enabled: true, |
| 474 | }, |
| 475 | nocrt: true, |
| 476 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 477 | |
| 478 | vndk_libraries_txt { |
| 479 | name: "vndkcorevariant.libraries.txt", |
| 480 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 481 | ` |
| 482 | |
| 483 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 484 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 485 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 486 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 487 | |
| 488 | setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"}) |
| 489 | |
| 490 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 491 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 492 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | func TestVndkWhenVndkVersionIsNotSet(t *testing.T) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 496 | ctx := testCcNoVndk(t, ` |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 497 | cc_library { |
| 498 | name: "libvndk", |
| 499 | vendor_available: true, |
| 500 | vndk: { |
| 501 | enabled: true, |
| 502 | }, |
| 503 | nocrt: true, |
| 504 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 505 | `) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 506 | |
| 507 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 508 | "LLNDK: libc.so", |
| 509 | "LLNDK: libdl.so", |
| 510 | "LLNDK: libft2.so", |
| 511 | "LLNDK: libm.so", |
| 512 | "VNDK-SP: libc++.so", |
| 513 | "VNDK-core: libvndk.so", |
| 514 | "VNDK-private: libft2.so", |
| 515 | }) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 516 | } |
| 517 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 518 | func TestVndkDepError(t *testing.T) { |
| 519 | // Check whether an error is emitted when a VNDK lib depends on a system lib. |
| 520 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 521 | cc_library { |
| 522 | name: "libvndk", |
| 523 | vendor_available: true, |
| 524 | vndk: { |
| 525 | enabled: true, |
| 526 | }, |
| 527 | shared_libs: ["libfwk"], // Cause error |
| 528 | nocrt: true, |
| 529 | } |
| 530 | |
| 531 | cc_library { |
| 532 | name: "libfwk", |
| 533 | nocrt: true, |
| 534 | } |
| 535 | `) |
| 536 | |
| 537 | // Check whether an error is emitted when a VNDK lib depends on a vendor lib. |
| 538 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 539 | cc_library { |
| 540 | name: "libvndk", |
| 541 | vendor_available: true, |
| 542 | vndk: { |
| 543 | enabled: true, |
| 544 | }, |
| 545 | shared_libs: ["libvendor"], // Cause error |
| 546 | nocrt: true, |
| 547 | } |
| 548 | |
| 549 | cc_library { |
| 550 | name: "libvendor", |
| 551 | vendor: true, |
| 552 | nocrt: true, |
| 553 | } |
| 554 | `) |
| 555 | |
| 556 | // Check whether an error is emitted when a VNDK-SP lib depends on a system lib. |
| 557 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 558 | cc_library { |
| 559 | name: "libvndk_sp", |
| 560 | vendor_available: true, |
| 561 | vndk: { |
| 562 | enabled: true, |
| 563 | support_system_process: true, |
| 564 | }, |
| 565 | shared_libs: ["libfwk"], // Cause error |
| 566 | nocrt: true, |
| 567 | } |
| 568 | |
| 569 | cc_library { |
| 570 | name: "libfwk", |
| 571 | nocrt: true, |
| 572 | } |
| 573 | `) |
| 574 | |
| 575 | // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib. |
| 576 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 577 | cc_library { |
| 578 | name: "libvndk_sp", |
| 579 | vendor_available: true, |
| 580 | vndk: { |
| 581 | enabled: true, |
| 582 | support_system_process: true, |
| 583 | }, |
| 584 | shared_libs: ["libvendor"], // Cause error |
| 585 | nocrt: true, |
| 586 | } |
| 587 | |
| 588 | cc_library { |
| 589 | name: "libvendor", |
| 590 | vendor: true, |
| 591 | nocrt: true, |
| 592 | } |
| 593 | `) |
| 594 | |
| 595 | // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib. |
| 596 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 597 | cc_library { |
| 598 | name: "libvndk_sp", |
| 599 | vendor_available: true, |
| 600 | vndk: { |
| 601 | enabled: true, |
| 602 | support_system_process: true, |
| 603 | }, |
| 604 | shared_libs: ["libvndk"], // Cause error |
| 605 | nocrt: true, |
| 606 | } |
| 607 | |
| 608 | cc_library { |
| 609 | name: "libvndk", |
| 610 | vendor_available: true, |
| 611 | vndk: { |
| 612 | enabled: true, |
| 613 | }, |
| 614 | nocrt: true, |
| 615 | } |
| 616 | `) |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 617 | |
| 618 | // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib. |
| 619 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 620 | cc_library { |
| 621 | name: "libvndk", |
| 622 | vendor_available: true, |
| 623 | vndk: { |
| 624 | enabled: true, |
| 625 | }, |
| 626 | shared_libs: ["libnonvndk"], |
| 627 | nocrt: true, |
| 628 | } |
| 629 | |
| 630 | cc_library { |
| 631 | name: "libnonvndk", |
| 632 | vendor_available: true, |
| 633 | nocrt: true, |
| 634 | } |
| 635 | `) |
| 636 | |
| 637 | // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib. |
| 638 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 639 | cc_library { |
| 640 | name: "libvndkprivate", |
| 641 | vendor_available: false, |
| 642 | vndk: { |
| 643 | enabled: true, |
| 644 | }, |
| 645 | shared_libs: ["libnonvndk"], |
| 646 | nocrt: true, |
| 647 | } |
| 648 | |
| 649 | cc_library { |
| 650 | name: "libnonvndk", |
| 651 | vendor_available: true, |
| 652 | nocrt: true, |
| 653 | } |
| 654 | `) |
| 655 | |
| 656 | // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib. |
| 657 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 658 | cc_library { |
| 659 | name: "libvndksp", |
| 660 | vendor_available: true, |
| 661 | vndk: { |
| 662 | enabled: true, |
| 663 | support_system_process: true, |
| 664 | }, |
| 665 | shared_libs: ["libnonvndk"], |
| 666 | nocrt: true, |
| 667 | } |
| 668 | |
| 669 | cc_library { |
| 670 | name: "libnonvndk", |
| 671 | vendor_available: true, |
| 672 | nocrt: true, |
| 673 | } |
| 674 | `) |
| 675 | |
| 676 | // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib. |
| 677 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 678 | cc_library { |
| 679 | name: "libvndkspprivate", |
| 680 | vendor_available: false, |
| 681 | vndk: { |
| 682 | enabled: true, |
| 683 | support_system_process: true, |
| 684 | }, |
| 685 | shared_libs: ["libnonvndk"], |
| 686 | nocrt: true, |
| 687 | } |
| 688 | |
| 689 | cc_library { |
| 690 | name: "libnonvndk", |
| 691 | vendor_available: true, |
| 692 | nocrt: true, |
| 693 | } |
| 694 | `) |
| 695 | } |
| 696 | |
| 697 | func TestDoubleLoadbleDep(t *testing.T) { |
| 698 | // okay to link : LLNDK -> double_loadable VNDK |
| 699 | testCc(t, ` |
| 700 | cc_library { |
| 701 | name: "libllndk", |
| 702 | shared_libs: ["libdoubleloadable"], |
| 703 | } |
| 704 | |
| 705 | llndk_library { |
| 706 | name: "libllndk", |
| 707 | symbol_file: "", |
| 708 | } |
| 709 | |
| 710 | cc_library { |
| 711 | name: "libdoubleloadable", |
| 712 | vendor_available: true, |
| 713 | vndk: { |
| 714 | enabled: true, |
| 715 | }, |
| 716 | double_loadable: true, |
| 717 | } |
| 718 | `) |
| 719 | // okay to link : LLNDK -> VNDK-SP |
| 720 | testCc(t, ` |
| 721 | cc_library { |
| 722 | name: "libllndk", |
| 723 | shared_libs: ["libvndksp"], |
| 724 | } |
| 725 | |
| 726 | llndk_library { |
| 727 | name: "libllndk", |
| 728 | symbol_file: "", |
| 729 | } |
| 730 | |
| 731 | cc_library { |
| 732 | name: "libvndksp", |
| 733 | vendor_available: true, |
| 734 | vndk: { |
| 735 | enabled: true, |
| 736 | support_system_process: true, |
| 737 | }, |
| 738 | } |
| 739 | `) |
| 740 | // okay to link : double_loadable -> double_loadable |
| 741 | testCc(t, ` |
| 742 | cc_library { |
| 743 | name: "libdoubleloadable1", |
| 744 | shared_libs: ["libdoubleloadable2"], |
| 745 | vendor_available: true, |
| 746 | double_loadable: true, |
| 747 | } |
| 748 | |
| 749 | cc_library { |
| 750 | name: "libdoubleloadable2", |
| 751 | vendor_available: true, |
| 752 | double_loadable: true, |
| 753 | } |
| 754 | `) |
| 755 | // okay to link : double_loadable VNDK -> double_loadable VNDK private |
| 756 | testCc(t, ` |
| 757 | cc_library { |
| 758 | name: "libdoubleloadable", |
| 759 | vendor_available: true, |
| 760 | vndk: { |
| 761 | enabled: true, |
| 762 | }, |
| 763 | double_loadable: true, |
| 764 | shared_libs: ["libnondoubleloadable"], |
| 765 | } |
| 766 | |
| 767 | cc_library { |
| 768 | name: "libnondoubleloadable", |
| 769 | vendor_available: false, |
| 770 | vndk: { |
| 771 | enabled: true, |
| 772 | }, |
| 773 | double_loadable: true, |
| 774 | } |
| 775 | `) |
| 776 | // okay to link : LLNDK -> core-only -> vendor_available & double_loadable |
| 777 | testCc(t, ` |
| 778 | cc_library { |
| 779 | name: "libllndk", |
| 780 | shared_libs: ["libcoreonly"], |
| 781 | } |
| 782 | |
| 783 | llndk_library { |
| 784 | name: "libllndk", |
| 785 | symbol_file: "", |
| 786 | } |
| 787 | |
| 788 | cc_library { |
| 789 | name: "libcoreonly", |
| 790 | shared_libs: ["libvendoravailable"], |
| 791 | } |
| 792 | |
| 793 | // indirect dependency of LLNDK |
| 794 | cc_library { |
| 795 | name: "libvendoravailable", |
| 796 | vendor_available: true, |
| 797 | double_loadable: true, |
| 798 | } |
| 799 | `) |
| 800 | } |
| 801 | |
| 802 | func TestDoubleLoadableDepError(t *testing.T) { |
| 803 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 804 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 805 | cc_library { |
| 806 | name: "libllndk", |
| 807 | 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 | vndk: { |
| 819 | enabled: true, |
| 820 | }, |
| 821 | } |
| 822 | `) |
| 823 | |
| 824 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 825 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 826 | cc_library { |
| 827 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 828 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 829 | shared_libs: ["libnondoubleloadable"], |
| 830 | } |
| 831 | |
| 832 | llndk_library { |
| 833 | name: "libllndk", |
| 834 | symbol_file: "", |
| 835 | } |
| 836 | |
| 837 | cc_library { |
| 838 | name: "libnondoubleloadable", |
| 839 | vendor_available: true, |
| 840 | } |
| 841 | `) |
| 842 | |
| 843 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib. |
| 844 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 845 | cc_library { |
| 846 | name: "libdoubleloadable", |
| 847 | vendor_available: true, |
| 848 | double_loadable: true, |
| 849 | shared_libs: ["libnondoubleloadable"], |
| 850 | } |
| 851 | |
| 852 | cc_library { |
| 853 | name: "libnondoubleloadable", |
| 854 | vendor_available: true, |
| 855 | } |
| 856 | `) |
| 857 | |
| 858 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib. |
| 859 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 860 | cc_library { |
| 861 | name: "libdoubleloadable", |
| 862 | vendor_available: true, |
| 863 | double_loadable: true, |
| 864 | shared_libs: ["libnondoubleloadable"], |
| 865 | } |
| 866 | |
| 867 | cc_library { |
| 868 | name: "libnondoubleloadable", |
| 869 | vendor_available: true, |
| 870 | vndk: { |
| 871 | enabled: true, |
| 872 | }, |
| 873 | } |
| 874 | `) |
| 875 | |
| 876 | // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib. |
| 877 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 878 | cc_library { |
| 879 | name: "libdoubleloadable", |
| 880 | vendor_available: true, |
| 881 | vndk: { |
| 882 | enabled: true, |
| 883 | }, |
| 884 | double_loadable: true, |
| 885 | shared_libs: ["libnondoubleloadable"], |
| 886 | } |
| 887 | |
| 888 | cc_library { |
| 889 | name: "libnondoubleloadable", |
| 890 | vendor_available: false, |
| 891 | vndk: { |
| 892 | enabled: true, |
| 893 | }, |
| 894 | } |
| 895 | `) |
| 896 | |
| 897 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 898 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 899 | cc_library { |
| 900 | name: "libllndk", |
| 901 | shared_libs: ["libcoreonly"], |
| 902 | } |
| 903 | |
| 904 | llndk_library { |
| 905 | name: "libllndk", |
| 906 | symbol_file: "", |
| 907 | } |
| 908 | |
| 909 | cc_library { |
| 910 | name: "libcoreonly", |
| 911 | shared_libs: ["libvendoravailable"], |
| 912 | } |
| 913 | |
| 914 | // indirect dependency of LLNDK |
| 915 | cc_library { |
| 916 | name: "libvendoravailable", |
| 917 | vendor_available: true, |
| 918 | } |
| 919 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 920 | } |
| 921 | |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 922 | func TestVndkMustNotBeProductSpecific(t *testing.T) { |
| 923 | // Check whether an error is emitted when a vndk lib has 'product_specific: true'. |
| 924 | testCcError(t, "product_specific must not be true when `vndk: {enabled: true}`", ` |
| 925 | cc_library { |
| 926 | name: "libvndk", |
| 927 | product_specific: true, // Cause error |
| 928 | vendor_available: true, |
| 929 | vndk: { |
| 930 | enabled: true, |
| 931 | }, |
| 932 | nocrt: true, |
| 933 | } |
| 934 | `) |
| 935 | } |
| 936 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 937 | func TestVndkExt(t *testing.T) { |
| 938 | // This test checks the VNDK-Ext properties. |
| 939 | ctx := testCc(t, ` |
| 940 | cc_library { |
| 941 | name: "libvndk", |
| 942 | vendor_available: true, |
| 943 | vndk: { |
| 944 | enabled: true, |
| 945 | }, |
| 946 | nocrt: true, |
| 947 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 948 | cc_library { |
| 949 | name: "libvndk2", |
| 950 | vendor_available: true, |
| 951 | vndk: { |
| 952 | enabled: true, |
| 953 | }, |
| 954 | target: { |
| 955 | vendor: { |
| 956 | suffix: "-suffix", |
| 957 | }, |
| 958 | }, |
| 959 | nocrt: true, |
| 960 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 961 | |
| 962 | cc_library { |
| 963 | name: "libvndk_ext", |
| 964 | vendor: true, |
| 965 | vndk: { |
| 966 | enabled: true, |
| 967 | extends: "libvndk", |
| 968 | }, |
| 969 | nocrt: true, |
| 970 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 971 | |
| 972 | cc_library { |
| 973 | name: "libvndk2_ext", |
| 974 | vendor: true, |
| 975 | vndk: { |
| 976 | enabled: true, |
| 977 | extends: "libvndk2", |
| 978 | }, |
| 979 | nocrt: true, |
| 980 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 981 | `) |
| 982 | |
| 983 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk") |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 984 | |
| 985 | mod := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 986 | assertString(t, mod.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 987 | } |
| 988 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 989 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 990 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. |
| 991 | ctx := testCcNoVndk(t, ` |
| 992 | cc_library { |
| 993 | name: "libvndk", |
| 994 | vendor_available: true, |
| 995 | vndk: { |
| 996 | enabled: true, |
| 997 | }, |
| 998 | nocrt: true, |
| 999 | } |
| 1000 | |
| 1001 | cc_library { |
| 1002 | name: "libvndk_ext", |
| 1003 | vendor: true, |
| 1004 | vndk: { |
| 1005 | enabled: true, |
| 1006 | extends: "libvndk", |
| 1007 | }, |
| 1008 | nocrt: true, |
| 1009 | } |
| 1010 | `) |
| 1011 | |
| 1012 | // Ensures that the core variant of "libvndk_ext" can be found. |
| 1013 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) |
| 1014 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 1015 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | func TestVndkExtError(t *testing.T) { |
| 1020 | // This test ensures an error is emitted in ill-formed vndk-ext definition. |
| 1021 | testCcError(t, "must set `vendor: true` to set `extends: \".*\"`", ` |
| 1022 | cc_library { |
| 1023 | name: "libvndk", |
| 1024 | vendor_available: true, |
| 1025 | vndk: { |
| 1026 | enabled: true, |
| 1027 | }, |
| 1028 | nocrt: true, |
| 1029 | } |
| 1030 | |
| 1031 | cc_library { |
| 1032 | name: "libvndk_ext", |
| 1033 | vndk: { |
| 1034 | enabled: true, |
| 1035 | extends: "libvndk", |
| 1036 | }, |
| 1037 | nocrt: true, |
| 1038 | } |
| 1039 | `) |
| 1040 | |
| 1041 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1042 | cc_library { |
| 1043 | name: "libvndk", |
| 1044 | vendor_available: true, |
| 1045 | vndk: { |
| 1046 | enabled: true, |
| 1047 | }, |
| 1048 | nocrt: true, |
| 1049 | } |
| 1050 | |
| 1051 | cc_library { |
| 1052 | name: "libvndk_ext", |
| 1053 | vendor: true, |
| 1054 | vndk: { |
| 1055 | enabled: true, |
| 1056 | }, |
| 1057 | nocrt: true, |
| 1058 | } |
| 1059 | `) |
| 1060 | } |
| 1061 | |
| 1062 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
| 1063 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 1064 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1065 | cc_library { |
| 1066 | name: "libvndk", |
| 1067 | vendor_available: true, |
| 1068 | vndk: { |
| 1069 | enabled: true, |
| 1070 | }, |
| 1071 | nocrt: true, |
| 1072 | } |
| 1073 | |
| 1074 | cc_library { |
| 1075 | name: "libvndk_sp_ext", |
| 1076 | vendor: true, |
| 1077 | vndk: { |
| 1078 | enabled: true, |
| 1079 | extends: "libvndk", |
| 1080 | support_system_process: true, |
| 1081 | }, |
| 1082 | nocrt: true, |
| 1083 | } |
| 1084 | `) |
| 1085 | |
| 1086 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1087 | cc_library { |
| 1088 | name: "libvndk_sp", |
| 1089 | vendor_available: true, |
| 1090 | vndk: { |
| 1091 | enabled: true, |
| 1092 | support_system_process: true, |
| 1093 | }, |
| 1094 | nocrt: true, |
| 1095 | } |
| 1096 | |
| 1097 | cc_library { |
| 1098 | name: "libvndk_ext", |
| 1099 | vendor: true, |
| 1100 | vndk: { |
| 1101 | enabled: true, |
| 1102 | extends: "libvndk_sp", |
| 1103 | }, |
| 1104 | nocrt: true, |
| 1105 | } |
| 1106 | `) |
| 1107 | } |
| 1108 | |
| 1109 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1110 | // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1111 | // with `vendor_available: false`. |
| 1112 | testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` |
| 1113 | cc_library { |
| 1114 | name: "libvndk", |
| 1115 | vendor_available: false, |
| 1116 | vndk: { |
| 1117 | enabled: true, |
| 1118 | }, |
| 1119 | nocrt: true, |
| 1120 | } |
| 1121 | |
| 1122 | cc_library { |
| 1123 | name: "libvndk_ext", |
| 1124 | vendor: true, |
| 1125 | vndk: { |
| 1126 | enabled: true, |
| 1127 | extends: "libvndk", |
| 1128 | }, |
| 1129 | nocrt: true, |
| 1130 | } |
| 1131 | `) |
| 1132 | } |
| 1133 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1134 | func TestVendorModuleUseVndkExt(t *testing.T) { |
| 1135 | // This test ensures a vendor module can depend on a VNDK-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1136 | testCc(t, ` |
| 1137 | cc_library { |
| 1138 | name: "libvndk", |
| 1139 | vendor_available: true, |
| 1140 | vndk: { |
| 1141 | enabled: true, |
| 1142 | }, |
| 1143 | nocrt: true, |
| 1144 | } |
| 1145 | |
| 1146 | cc_library { |
| 1147 | name: "libvndk_ext", |
| 1148 | vendor: true, |
| 1149 | vndk: { |
| 1150 | enabled: true, |
| 1151 | extends: "libvndk", |
| 1152 | }, |
| 1153 | nocrt: true, |
| 1154 | } |
| 1155 | |
| 1156 | cc_library { |
| 1157 | |
| 1158 | name: "libvndk_sp", |
| 1159 | vendor_available: true, |
| 1160 | vndk: { |
| 1161 | enabled: true, |
| 1162 | support_system_process: true, |
| 1163 | }, |
| 1164 | nocrt: true, |
| 1165 | } |
| 1166 | |
| 1167 | cc_library { |
| 1168 | name: "libvndk_sp_ext", |
| 1169 | vendor: true, |
| 1170 | vndk: { |
| 1171 | enabled: true, |
| 1172 | extends: "libvndk_sp", |
| 1173 | support_system_process: true, |
| 1174 | }, |
| 1175 | nocrt: true, |
| 1176 | } |
| 1177 | |
| 1178 | cc_library { |
| 1179 | name: "libvendor", |
| 1180 | vendor: true, |
| 1181 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 1182 | nocrt: true, |
| 1183 | } |
| 1184 | `) |
| 1185 | } |
| 1186 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1187 | func TestVndkExtUseVendorLib(t *testing.T) { |
| 1188 | // This test ensures a VNDK-Ext library can depend on a vendor library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1189 | testCc(t, ` |
| 1190 | cc_library { |
| 1191 | name: "libvndk", |
| 1192 | vendor_available: true, |
| 1193 | vndk: { |
| 1194 | enabled: true, |
| 1195 | }, |
| 1196 | nocrt: true, |
| 1197 | } |
| 1198 | |
| 1199 | cc_library { |
| 1200 | name: "libvndk_ext", |
| 1201 | vendor: true, |
| 1202 | vndk: { |
| 1203 | enabled: true, |
| 1204 | extends: "libvndk", |
| 1205 | }, |
| 1206 | shared_libs: ["libvendor"], |
| 1207 | nocrt: true, |
| 1208 | } |
| 1209 | |
| 1210 | cc_library { |
| 1211 | name: "libvendor", |
| 1212 | vendor: true, |
| 1213 | nocrt: true, |
| 1214 | } |
| 1215 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1216 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1217 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 1218 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1219 | cc_library { |
| 1220 | name: "libvndk_sp", |
| 1221 | vendor_available: true, |
| 1222 | vndk: { |
| 1223 | enabled: true, |
| 1224 | support_system_process: true, |
| 1225 | }, |
| 1226 | nocrt: true, |
| 1227 | } |
| 1228 | |
| 1229 | cc_library { |
| 1230 | name: "libvndk_sp_ext", |
| 1231 | vendor: true, |
| 1232 | vndk: { |
| 1233 | enabled: true, |
| 1234 | extends: "libvndk_sp", |
| 1235 | support_system_process: true, |
| 1236 | }, |
| 1237 | shared_libs: ["libvendor"], // Cause an error |
| 1238 | nocrt: true, |
| 1239 | } |
| 1240 | |
| 1241 | cc_library { |
| 1242 | name: "libvendor", |
| 1243 | vendor: true, |
| 1244 | nocrt: true, |
| 1245 | } |
| 1246 | `) |
| 1247 | } |
| 1248 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1249 | func TestVndkSpExtUseVndkError(t *testing.T) { |
| 1250 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 1251 | // library. |
| 1252 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1253 | cc_library { |
| 1254 | name: "libvndk", |
| 1255 | vendor_available: true, |
| 1256 | vndk: { |
| 1257 | enabled: true, |
| 1258 | }, |
| 1259 | nocrt: true, |
| 1260 | } |
| 1261 | |
| 1262 | cc_library { |
| 1263 | name: "libvndk_sp", |
| 1264 | vendor_available: true, |
| 1265 | vndk: { |
| 1266 | enabled: true, |
| 1267 | support_system_process: true, |
| 1268 | }, |
| 1269 | nocrt: true, |
| 1270 | } |
| 1271 | |
| 1272 | cc_library { |
| 1273 | name: "libvndk_sp_ext", |
| 1274 | vendor: true, |
| 1275 | vndk: { |
| 1276 | enabled: true, |
| 1277 | extends: "libvndk_sp", |
| 1278 | support_system_process: true, |
| 1279 | }, |
| 1280 | shared_libs: ["libvndk"], // Cause an error |
| 1281 | nocrt: true, |
| 1282 | } |
| 1283 | `) |
| 1284 | |
| 1285 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 1286 | // library. |
| 1287 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1288 | cc_library { |
| 1289 | name: "libvndk", |
| 1290 | vendor_available: true, |
| 1291 | vndk: { |
| 1292 | enabled: true, |
| 1293 | }, |
| 1294 | nocrt: true, |
| 1295 | } |
| 1296 | |
| 1297 | cc_library { |
| 1298 | name: "libvndk_ext", |
| 1299 | vendor: true, |
| 1300 | vndk: { |
| 1301 | enabled: true, |
| 1302 | extends: "libvndk", |
| 1303 | }, |
| 1304 | nocrt: true, |
| 1305 | } |
| 1306 | |
| 1307 | cc_library { |
| 1308 | name: "libvndk_sp", |
| 1309 | vendor_available: true, |
| 1310 | vndk: { |
| 1311 | enabled: true, |
| 1312 | support_system_process: true, |
| 1313 | }, |
| 1314 | nocrt: true, |
| 1315 | } |
| 1316 | |
| 1317 | cc_library { |
| 1318 | name: "libvndk_sp_ext", |
| 1319 | vendor: true, |
| 1320 | vndk: { |
| 1321 | enabled: true, |
| 1322 | extends: "libvndk_sp", |
| 1323 | support_system_process: true, |
| 1324 | }, |
| 1325 | shared_libs: ["libvndk_ext"], // Cause an error |
| 1326 | nocrt: true, |
| 1327 | } |
| 1328 | `) |
| 1329 | } |
| 1330 | |
| 1331 | func TestVndkUseVndkExtError(t *testing.T) { |
| 1332 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 1333 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1334 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1335 | cc_library { |
| 1336 | name: "libvndk", |
| 1337 | vendor_available: true, |
| 1338 | vndk: { |
| 1339 | enabled: true, |
| 1340 | }, |
| 1341 | nocrt: true, |
| 1342 | } |
| 1343 | |
| 1344 | cc_library { |
| 1345 | name: "libvndk_ext", |
| 1346 | vendor: true, |
| 1347 | vndk: { |
| 1348 | enabled: true, |
| 1349 | extends: "libvndk", |
| 1350 | }, |
| 1351 | nocrt: true, |
| 1352 | } |
| 1353 | |
| 1354 | cc_library { |
| 1355 | name: "libvndk2", |
| 1356 | vendor_available: true, |
| 1357 | vndk: { |
| 1358 | enabled: true, |
| 1359 | }, |
| 1360 | shared_libs: ["libvndk_ext"], |
| 1361 | nocrt: true, |
| 1362 | } |
| 1363 | `) |
| 1364 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1365 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1366 | cc_library { |
| 1367 | name: "libvndk", |
| 1368 | vendor_available: true, |
| 1369 | vndk: { |
| 1370 | enabled: true, |
| 1371 | }, |
| 1372 | nocrt: true, |
| 1373 | } |
| 1374 | |
| 1375 | cc_library { |
| 1376 | name: "libvndk_ext", |
| 1377 | vendor: true, |
| 1378 | vndk: { |
| 1379 | enabled: true, |
| 1380 | extends: "libvndk", |
| 1381 | }, |
| 1382 | nocrt: true, |
| 1383 | } |
| 1384 | |
| 1385 | cc_library { |
| 1386 | name: "libvndk2", |
| 1387 | vendor_available: true, |
| 1388 | vndk: { |
| 1389 | enabled: true, |
| 1390 | }, |
| 1391 | target: { |
| 1392 | vendor: { |
| 1393 | shared_libs: ["libvndk_ext"], |
| 1394 | }, |
| 1395 | }, |
| 1396 | nocrt: true, |
| 1397 | } |
| 1398 | `) |
| 1399 | |
| 1400 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1401 | cc_library { |
| 1402 | name: "libvndk_sp", |
| 1403 | vendor_available: true, |
| 1404 | vndk: { |
| 1405 | enabled: true, |
| 1406 | support_system_process: true, |
| 1407 | }, |
| 1408 | nocrt: true, |
| 1409 | } |
| 1410 | |
| 1411 | cc_library { |
| 1412 | name: "libvndk_sp_ext", |
| 1413 | vendor: true, |
| 1414 | vndk: { |
| 1415 | enabled: true, |
| 1416 | extends: "libvndk_sp", |
| 1417 | support_system_process: true, |
| 1418 | }, |
| 1419 | nocrt: true, |
| 1420 | } |
| 1421 | |
| 1422 | cc_library { |
| 1423 | name: "libvndk_sp_2", |
| 1424 | vendor_available: true, |
| 1425 | vndk: { |
| 1426 | enabled: true, |
| 1427 | support_system_process: true, |
| 1428 | }, |
| 1429 | shared_libs: ["libvndk_sp_ext"], |
| 1430 | nocrt: true, |
| 1431 | } |
| 1432 | `) |
| 1433 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1434 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1435 | cc_library { |
| 1436 | name: "libvndk_sp", |
| 1437 | vendor_available: true, |
| 1438 | vndk: { |
| 1439 | enabled: true, |
| 1440 | }, |
| 1441 | nocrt: true, |
| 1442 | } |
| 1443 | |
| 1444 | cc_library { |
| 1445 | name: "libvndk_sp_ext", |
| 1446 | vendor: true, |
| 1447 | vndk: { |
| 1448 | enabled: true, |
| 1449 | extends: "libvndk_sp", |
| 1450 | }, |
| 1451 | nocrt: true, |
| 1452 | } |
| 1453 | |
| 1454 | cc_library { |
| 1455 | name: "libvndk_sp2", |
| 1456 | vendor_available: true, |
| 1457 | vndk: { |
| 1458 | enabled: true, |
| 1459 | }, |
| 1460 | target: { |
| 1461 | vendor: { |
| 1462 | shared_libs: ["libvndk_sp_ext"], |
| 1463 | }, |
| 1464 | }, |
| 1465 | nocrt: true, |
| 1466 | } |
| 1467 | `) |
| 1468 | } |
| 1469 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1470 | func TestEnforceProductVndkVersion(t *testing.T) { |
| 1471 | bp := ` |
| 1472 | cc_library { |
| 1473 | name: "libllndk", |
| 1474 | } |
| 1475 | llndk_library { |
| 1476 | name: "libllndk", |
| 1477 | symbol_file: "", |
| 1478 | } |
| 1479 | cc_library { |
| 1480 | name: "libvndk", |
| 1481 | vendor_available: true, |
| 1482 | vndk: { |
| 1483 | enabled: true, |
| 1484 | }, |
| 1485 | nocrt: true, |
| 1486 | } |
| 1487 | cc_library { |
| 1488 | name: "libvndk_sp", |
| 1489 | vendor_available: true, |
| 1490 | vndk: { |
| 1491 | enabled: true, |
| 1492 | support_system_process: true, |
| 1493 | }, |
| 1494 | nocrt: true, |
| 1495 | } |
| 1496 | cc_library { |
| 1497 | name: "libva", |
| 1498 | vendor_available: true, |
| 1499 | nocrt: true, |
| 1500 | } |
| 1501 | cc_library { |
| 1502 | name: "libproduct_va", |
| 1503 | product_specific: true, |
| 1504 | vendor_available: true, |
| 1505 | nocrt: true, |
| 1506 | } |
| 1507 | cc_library { |
| 1508 | name: "libprod", |
| 1509 | product_specific: true, |
| 1510 | shared_libs: [ |
| 1511 | "libllndk", |
| 1512 | "libvndk", |
| 1513 | "libvndk_sp", |
| 1514 | "libva", |
| 1515 | "libproduct_va", |
| 1516 | ], |
| 1517 | nocrt: true, |
| 1518 | } |
| 1519 | cc_library { |
| 1520 | name: "libvendor", |
| 1521 | vendor: true, |
| 1522 | shared_libs: [ |
| 1523 | "libllndk", |
| 1524 | "libvndk", |
| 1525 | "libvndk_sp", |
| 1526 | "libva", |
| 1527 | "libproduct_va", |
| 1528 | ], |
| 1529 | nocrt: true, |
| 1530 | } |
| 1531 | ` |
| 1532 | |
| 1533 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1534 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1535 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 1536 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1537 | |
| 1538 | ctx := testCcWithConfig(t, config) |
| 1539 | |
| 1540 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "") |
| 1541 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "") |
| 1542 | } |
| 1543 | |
| 1544 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
| 1545 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 1546 | cc_library { |
| 1547 | name: "libprod", |
| 1548 | product_specific: true, |
| 1549 | shared_libs: [ |
| 1550 | "libvendor", |
| 1551 | ], |
| 1552 | nocrt: true, |
| 1553 | } |
| 1554 | cc_library { |
| 1555 | name: "libvendor", |
| 1556 | vendor: true, |
| 1557 | nocrt: true, |
| 1558 | } |
| 1559 | `) |
| 1560 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 1561 | cc_library { |
| 1562 | name: "libprod", |
| 1563 | product_specific: true, |
| 1564 | shared_libs: [ |
| 1565 | "libsystem", |
| 1566 | ], |
| 1567 | nocrt: true, |
| 1568 | } |
| 1569 | cc_library { |
| 1570 | name: "libsystem", |
| 1571 | nocrt: true, |
| 1572 | } |
| 1573 | `) |
| 1574 | testCcErrorProductVndk(t, "Vendor module that is not VNDK should not link to \".*\" which is marked as `vendor_available: false`", ` |
| 1575 | cc_library { |
| 1576 | name: "libprod", |
| 1577 | product_specific: true, |
| 1578 | shared_libs: [ |
| 1579 | "libvndk_private", |
| 1580 | ], |
| 1581 | nocrt: true, |
| 1582 | } |
| 1583 | cc_library { |
| 1584 | name: "libvndk_private", |
| 1585 | vendor_available: false, |
| 1586 | vndk: { |
| 1587 | enabled: true, |
| 1588 | }, |
| 1589 | nocrt: true, |
| 1590 | } |
| 1591 | `) |
| 1592 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 1593 | cc_library { |
| 1594 | name: "libprod", |
| 1595 | product_specific: true, |
| 1596 | shared_libs: [ |
| 1597 | "libsystem_ext", |
| 1598 | ], |
| 1599 | nocrt: true, |
| 1600 | } |
| 1601 | cc_library { |
| 1602 | name: "libsystem_ext", |
| 1603 | system_ext_specific: true, |
| 1604 | nocrt: true, |
| 1605 | } |
| 1606 | `) |
| 1607 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 1608 | cc_library { |
| 1609 | name: "libsystem", |
| 1610 | shared_libs: [ |
| 1611 | "libproduct_va", |
| 1612 | ], |
| 1613 | nocrt: true, |
| 1614 | } |
| 1615 | cc_library { |
| 1616 | name: "libproduct_va", |
| 1617 | product_specific: true, |
| 1618 | vendor_available: true, |
| 1619 | nocrt: true, |
| 1620 | } |
| 1621 | `) |
| 1622 | } |
| 1623 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1624 | func TestMakeLinkType(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1625 | bp := ` |
| 1626 | cc_library { |
| 1627 | name: "libvndk", |
| 1628 | vendor_available: true, |
| 1629 | vndk: { |
| 1630 | enabled: true, |
| 1631 | }, |
| 1632 | } |
| 1633 | cc_library { |
| 1634 | name: "libvndksp", |
| 1635 | vendor_available: true, |
| 1636 | vndk: { |
| 1637 | enabled: true, |
| 1638 | support_system_process: true, |
| 1639 | }, |
| 1640 | } |
| 1641 | cc_library { |
| 1642 | name: "libvndkprivate", |
| 1643 | vendor_available: false, |
| 1644 | vndk: { |
| 1645 | enabled: true, |
| 1646 | }, |
| 1647 | } |
| 1648 | cc_library { |
| 1649 | name: "libvendor", |
| 1650 | vendor: true, |
| 1651 | } |
| 1652 | cc_library { |
| 1653 | name: "libvndkext", |
| 1654 | vendor: true, |
| 1655 | vndk: { |
| 1656 | enabled: true, |
| 1657 | extends: "libvndk", |
| 1658 | }, |
| 1659 | } |
| 1660 | vndk_prebuilt_shared { |
| 1661 | name: "prevndk", |
| 1662 | version: "27", |
| 1663 | target_arch: "arm", |
| 1664 | binder32bit: true, |
| 1665 | vendor_available: true, |
| 1666 | vndk: { |
| 1667 | enabled: true, |
| 1668 | }, |
| 1669 | arch: { |
| 1670 | arm: { |
| 1671 | srcs: ["liba.so"], |
| 1672 | }, |
| 1673 | }, |
| 1674 | } |
| 1675 | cc_library { |
| 1676 | name: "libllndk", |
| 1677 | } |
| 1678 | llndk_library { |
| 1679 | name: "libllndk", |
| 1680 | symbol_file: "", |
| 1681 | } |
| 1682 | cc_library { |
| 1683 | name: "libllndkprivate", |
| 1684 | } |
| 1685 | llndk_library { |
| 1686 | name: "libllndkprivate", |
| 1687 | vendor_available: false, |
| 1688 | symbol_file: "", |
| 1689 | }` |
| 1690 | |
| 1691 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1692 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1693 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1694 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1695 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1696 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1697 | assertMapKeys(t, vndkCoreLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1698 | []string{"libvndk", "libvndkprivate"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1699 | assertMapKeys(t, vndkSpLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1700 | []string{"libc++", "libvndksp"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1701 | assertMapKeys(t, llndkLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 1702 | []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1703 | assertMapKeys(t, vndkPrivateLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 1704 | []string{"libft2", "libllndkprivate", "libvndkprivate"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1705 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 1706 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1707 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1708 | tests := []struct { |
| 1709 | variant string |
| 1710 | name string |
| 1711 | expected string |
| 1712 | }{ |
| 1713 | {vendorVariant, "libvndk", "native:vndk"}, |
| 1714 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 1715 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 1716 | {vendorVariant, "libvendor", "native:vendor"}, |
| 1717 | {vendorVariant, "libvndkext", "native:vendor"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1718 | {vendorVariant, "libllndk.llndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1719 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1720 | {coreVariant, "libvndk", "native:platform"}, |
| 1721 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 1722 | {coreVariant, "libllndk", "native:platform"}, |
| 1723 | } |
| 1724 | for _, test := range tests { |
| 1725 | t.Run(test.name, func(t *testing.T) { |
| 1726 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 1727 | assertString(t, module.makeLinkType, test.expected) |
| 1728 | }) |
| 1729 | } |
| 1730 | } |
| 1731 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1732 | var ( |
| 1733 | str11 = "01234567891" |
| 1734 | str10 = str11[:10] |
| 1735 | str9 = str11[:9] |
| 1736 | str5 = str11[:5] |
| 1737 | str4 = str11[:4] |
| 1738 | ) |
| 1739 | |
| 1740 | var splitListForSizeTestCases = []struct { |
| 1741 | in []string |
| 1742 | out [][]string |
| 1743 | size int |
| 1744 | }{ |
| 1745 | { |
| 1746 | in: []string{str10}, |
| 1747 | out: [][]string{{str10}}, |
| 1748 | size: 10, |
| 1749 | }, |
| 1750 | { |
| 1751 | in: []string{str9}, |
| 1752 | out: [][]string{{str9}}, |
| 1753 | size: 10, |
| 1754 | }, |
| 1755 | { |
| 1756 | in: []string{str5}, |
| 1757 | out: [][]string{{str5}}, |
| 1758 | size: 10, |
| 1759 | }, |
| 1760 | { |
| 1761 | in: []string{str11}, |
| 1762 | out: nil, |
| 1763 | size: 10, |
| 1764 | }, |
| 1765 | { |
| 1766 | in: []string{str10, str10}, |
| 1767 | out: [][]string{{str10}, {str10}}, |
| 1768 | size: 10, |
| 1769 | }, |
| 1770 | { |
| 1771 | in: []string{str9, str10}, |
| 1772 | out: [][]string{{str9}, {str10}}, |
| 1773 | size: 10, |
| 1774 | }, |
| 1775 | { |
| 1776 | in: []string{str10, str9}, |
| 1777 | out: [][]string{{str10}, {str9}}, |
| 1778 | size: 10, |
| 1779 | }, |
| 1780 | { |
| 1781 | in: []string{str5, str4}, |
| 1782 | out: [][]string{{str5, str4}}, |
| 1783 | size: 10, |
| 1784 | }, |
| 1785 | { |
| 1786 | in: []string{str5, str4, str5}, |
| 1787 | out: [][]string{{str5, str4}, {str5}}, |
| 1788 | size: 10, |
| 1789 | }, |
| 1790 | { |
| 1791 | in: []string{str5, str4, str5, str4}, |
| 1792 | out: [][]string{{str5, str4}, {str5, str4}}, |
| 1793 | size: 10, |
| 1794 | }, |
| 1795 | { |
| 1796 | in: []string{str5, str4, str5, str5}, |
| 1797 | out: [][]string{{str5, str4}, {str5}, {str5}}, |
| 1798 | size: 10, |
| 1799 | }, |
| 1800 | { |
| 1801 | in: []string{str5, str5, str5, str4}, |
| 1802 | out: [][]string{{str5}, {str5}, {str5, str4}}, |
| 1803 | size: 10, |
| 1804 | }, |
| 1805 | { |
| 1806 | in: []string{str9, str11}, |
| 1807 | out: nil, |
| 1808 | size: 10, |
| 1809 | }, |
| 1810 | { |
| 1811 | in: []string{str11, str9}, |
| 1812 | out: nil, |
| 1813 | size: 10, |
| 1814 | }, |
| 1815 | } |
| 1816 | |
| 1817 | func TestSplitListForSize(t *testing.T) { |
| 1818 | for _, testCase := range splitListForSizeTestCases { |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 1819 | out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size) |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 1820 | |
| 1821 | var outStrings [][]string |
| 1822 | |
| 1823 | if len(out) > 0 { |
| 1824 | outStrings = make([][]string, len(out)) |
| 1825 | for i, o := range out { |
| 1826 | outStrings[i] = o.Strings() |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | if !reflect.DeepEqual(outStrings, testCase.out) { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1831 | t.Errorf("incorrect output:") |
| 1832 | t.Errorf(" input: %#v", testCase.in) |
| 1833 | t.Errorf(" size: %d", testCase.size) |
| 1834 | t.Errorf(" expected: %#v", testCase.out) |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 1835 | t.Errorf(" got: %#v", outStrings) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1839 | |
| 1840 | var staticLinkDepOrderTestCases = []struct { |
| 1841 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 1842 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1843 | inStatic string |
| 1844 | |
| 1845 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 1846 | // It models the dependencies declared in an Android.bp file. |
| 1847 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1848 | |
| 1849 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 1850 | // The keys of allOrdered specify which modules we would like to check. |
| 1851 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 1852 | // dependencies) for each module to test |
| 1853 | allOrdered string |
| 1854 | |
| 1855 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 1856 | // The keys of outOrdered specify which modules we would like to check. |
| 1857 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 1858 | // for each module to test. |
| 1859 | outOrdered string |
| 1860 | }{ |
| 1861 | // Simple tests |
| 1862 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1863 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1864 | outOrdered: "", |
| 1865 | }, |
| 1866 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1867 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1868 | outOrdered: "a:", |
| 1869 | }, |
| 1870 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1871 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1872 | outOrdered: "a:b; b:", |
| 1873 | }, |
| 1874 | // Tests of reordering |
| 1875 | { |
| 1876 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1877 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1878 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 1879 | }, |
| 1880 | { |
| 1881 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1882 | inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1883 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 1884 | }, |
| 1885 | { |
| 1886 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1887 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1888 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 1889 | }, |
| 1890 | { |
| 1891 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1892 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1893 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 1894 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 1895 | }, |
| 1896 | { |
| 1897 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1898 | inStatic: "a:b,c,d,e,f,g,h; f:b,c,d; b:c,d; c:d", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1899 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 1900 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 1901 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1902 | // shared dependencies |
| 1903 | { |
| 1904 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 1905 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 1906 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 1907 | // a shared dependency on b, that that shows up in allOrdered. |
| 1908 | inShared: "c:b", |
| 1909 | allOrdered: "c:b", |
| 1910 | outOrdered: "c:", |
| 1911 | }, |
| 1912 | { |
| 1913 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 1914 | // the second phase of the above test would look like |
| 1915 | inStatic: "a:b,c; c:b", |
| 1916 | allOrdered: "a:c,b; c:b", |
| 1917 | outOrdered: "a:c,b; c:b", |
| 1918 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1919 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 1920 | // to dictate an order |
| 1921 | { |
| 1922 | // if the tie is between two modules at the end of a's deps, then a's order wins |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1923 | inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1924 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 1925 | }, |
| 1926 | { |
| 1927 | // if the tie is between two modules at the start of a's deps, then c's order is used |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1928 | inStatic: "a1:d,e,b1,c1; b1:d,e; c1:e,d; a2:d,e,b2,c2; b2:d,e; c2:d,e", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1929 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 1930 | }, |
| 1931 | // Tests involving duplicate dependencies |
| 1932 | { |
| 1933 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1934 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1935 | outOrdered: "a:c,b", |
| 1936 | }, |
| 1937 | { |
| 1938 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1939 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1940 | outOrdered: "a:d,c,b", |
| 1941 | }, |
| 1942 | // Tests to confirm the nonexistence of infinite loops. |
| 1943 | // These cases should never happen, so as long as the test terminates and the |
| 1944 | // result is deterministic then that should be fine. |
| 1945 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1946 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1947 | outOrdered: "a:a", |
| 1948 | }, |
| 1949 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1950 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1951 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 1952 | outOrdered: "a:b; b:c; c:a", |
| 1953 | }, |
| 1954 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1955 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1956 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 1957 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 1958 | }, |
| 1959 | } |
| 1960 | |
| 1961 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 1962 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 1963 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 1964 | strippedText := strings.Replace(text, " ", "", -1) |
| 1965 | if len(strippedText) < 1 { |
| 1966 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 1967 | } |
| 1968 | allDeps = make(map[android.Path][]android.Path, 0) |
| 1969 | |
| 1970 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 1971 | moduleTexts := strings.Split(strippedText, ";") |
| 1972 | |
| 1973 | outputForModuleName := func(moduleName string) android.Path { |
| 1974 | return android.PathForTesting(moduleName) |
| 1975 | } |
| 1976 | |
| 1977 | for _, moduleText := range moduleTexts { |
| 1978 | // convert from "a:b,c" to ["a", "b,c"] |
| 1979 | components := strings.Split(moduleText, ":") |
| 1980 | if len(components) != 2 { |
| 1981 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 1982 | } |
| 1983 | moduleName := components[0] |
| 1984 | moduleOutput := outputForModuleName(moduleName) |
| 1985 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 1986 | |
| 1987 | depString := components[1] |
| 1988 | // convert from "b,c" to ["b", "c"] |
| 1989 | depNames := strings.Split(depString, ",") |
| 1990 | if len(depString) < 1 { |
| 1991 | depNames = []string{} |
| 1992 | } |
| 1993 | var deps []android.Path |
| 1994 | for _, depName := range depNames { |
| 1995 | deps = append(deps, outputForModuleName(depName)) |
| 1996 | } |
| 1997 | allDeps[moduleOutput] = deps |
| 1998 | } |
| 1999 | return modulesInOrder, allDeps |
| 2000 | } |
| 2001 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2002 | func TestLinkReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2003 | for _, testCase := range staticLinkDepOrderTestCases { |
| 2004 | errs := []string{} |
| 2005 | |
| 2006 | // parse testcase |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2007 | _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2008 | expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered) |
| 2009 | if testCase.allOrdered == "" { |
| 2010 | // allow the test case to skip specifying allOrdered |
| 2011 | testCase.allOrdered = testCase.outOrdered |
| 2012 | } |
| 2013 | _, expectedAllDeps := parseModuleDeps(testCase.allOrdered) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2014 | _, givenAllSharedDeps := parseModuleDeps(testCase.inShared) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2015 | |
| 2016 | // For each module whose post-reordered dependencies were specified, validate that |
| 2017 | // reordering the inputs produces the expected outputs. |
| 2018 | for _, moduleName := range expectedModuleNames { |
| 2019 | moduleDeps := givenTransitiveDeps[moduleName] |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2020 | givenSharedDeps := givenAllSharedDeps[moduleName] |
| 2021 | orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2022 | |
| 2023 | correctAllOrdered := expectedAllDeps[moduleName] |
| 2024 | if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) { |
| 2025 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+ |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2026 | "\nin static:%q"+ |
| 2027 | "\nin shared:%q"+ |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2028 | "\nmodule: %v"+ |
| 2029 | "\nexpected: %s"+ |
| 2030 | "\nactual: %s", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2031 | testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps)) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | correctOutputDeps := expectedTransitiveDeps[moduleName] |
| 2035 | if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) { |
| 2036 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+ |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2037 | "\nin static:%q"+ |
| 2038 | "\nin shared:%q"+ |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2039 | "\nmodule: %v"+ |
| 2040 | "\nexpected: %s"+ |
| 2041 | "\nactual: %s", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2042 | testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps)) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | if len(errs) > 0 { |
| 2047 | sort.Strings(errs) |
| 2048 | for _, err := range errs { |
| 2049 | t.Error(err) |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2054 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2055 | func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { |
| 2056 | for _, moduleName := range moduleNames { |
| 2057 | module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) |
| 2058 | output := module.outputFile.Path() |
| 2059 | paths = append(paths, output) |
| 2060 | } |
| 2061 | return paths |
| 2062 | } |
| 2063 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2064 | func TestStaticLibDepReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2065 | ctx := testCc(t, ` |
| 2066 | cc_library { |
| 2067 | name: "a", |
| 2068 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2069 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2070 | } |
| 2071 | cc_library { |
| 2072 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2073 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2074 | } |
| 2075 | cc_library { |
| 2076 | name: "c", |
| 2077 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2078 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2079 | } |
| 2080 | cc_library { |
| 2081 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2082 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | `) |
| 2086 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2087 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2088 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2089 | actual := moduleA.depsInLinkOrder |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2090 | expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"}) |
| 2091 | |
| 2092 | if !reflect.DeepEqual(actual, expected) { |
| 2093 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2094 | "\nactual: %v"+ |
| 2095 | "\nexpected: %v", |
| 2096 | actual, |
| 2097 | expected, |
| 2098 | ) |
| 2099 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2100 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2101 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2102 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
| 2103 | ctx := testCc(t, ` |
| 2104 | cc_library { |
| 2105 | name: "a", |
| 2106 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2107 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2108 | } |
| 2109 | cc_library { |
| 2110 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2111 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2112 | } |
| 2113 | cc_library { |
| 2114 | name: "c", |
| 2115 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2116 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | `) |
| 2120 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2121 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2122 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
| 2123 | actual := moduleA.depsInLinkOrder |
| 2124 | expected := getOutputPaths(ctx, variant, []string{"c", "b"}) |
| 2125 | |
| 2126 | if !reflect.DeepEqual(actual, expected) { |
| 2127 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 2128 | "\nactual: %v"+ |
| 2129 | "\nexpected: %v", |
| 2130 | actual, |
| 2131 | expected, |
| 2132 | ) |
| 2133 | } |
| 2134 | } |
| 2135 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2136 | func TestLlndkHeaders(t *testing.T) { |
| 2137 | ctx := testCc(t, ` |
| 2138 | llndk_headers { |
| 2139 | name: "libllndk_headers", |
| 2140 | export_include_dirs: ["my_include"], |
| 2141 | } |
| 2142 | llndk_library { |
| 2143 | name: "libllndk", |
| 2144 | export_llndk_headers: ["libllndk_headers"], |
| 2145 | } |
| 2146 | cc_library { |
| 2147 | name: "libvendor", |
| 2148 | shared_libs: ["libllndk"], |
| 2149 | vendor: true, |
| 2150 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2151 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2152 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2153 | } |
| 2154 | `) |
| 2155 | |
| 2156 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2157 | cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc") |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2158 | cflags := cc.Args["cFlags"] |
| 2159 | if !strings.Contains(cflags, "-Imy_include") { |
| 2160 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 2161 | } |
| 2162 | } |
| 2163 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2164 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 2165 | actual := module.Properties.AndroidMkRuntimeLibs |
| 2166 | if !reflect.DeepEqual(actual, expected) { |
| 2167 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 2168 | "\nactual: %v"+ |
| 2169 | "\nexpected: %v", |
| 2170 | actual, |
| 2171 | expected, |
| 2172 | ) |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | const runtimeLibAndroidBp = ` |
| 2177 | cc_library { |
| 2178 | name: "libvendor_available1", |
| 2179 | vendor_available: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2180 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2181 | nocrt : true, |
| 2182 | system_shared_libs : [], |
| 2183 | } |
| 2184 | cc_library { |
| 2185 | name: "libvendor_available2", |
| 2186 | vendor_available: true, |
| 2187 | runtime_libs: ["libvendor_available1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2188 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2189 | nocrt : true, |
| 2190 | system_shared_libs : [], |
| 2191 | } |
| 2192 | cc_library { |
| 2193 | name: "libvendor_available3", |
| 2194 | vendor_available: true, |
| 2195 | runtime_libs: ["libvendor_available1"], |
| 2196 | target: { |
| 2197 | vendor: { |
| 2198 | exclude_runtime_libs: ["libvendor_available1"], |
| 2199 | } |
| 2200 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2201 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2202 | nocrt : true, |
| 2203 | system_shared_libs : [], |
| 2204 | } |
| 2205 | cc_library { |
| 2206 | name: "libcore", |
| 2207 | runtime_libs: ["libvendor_available1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2208 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2209 | nocrt : true, |
| 2210 | system_shared_libs : [], |
| 2211 | } |
| 2212 | cc_library { |
| 2213 | name: "libvendor1", |
| 2214 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2215 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2216 | nocrt : true, |
| 2217 | system_shared_libs : [], |
| 2218 | } |
| 2219 | cc_library { |
| 2220 | name: "libvendor2", |
| 2221 | vendor: true, |
| 2222 | runtime_libs: ["libvendor_available1", "libvendor1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2223 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2224 | nocrt : true, |
| 2225 | system_shared_libs : [], |
| 2226 | } |
| 2227 | ` |
| 2228 | |
| 2229 | func TestRuntimeLibs(t *testing.T) { |
| 2230 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2231 | |
| 2232 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2233 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2234 | |
| 2235 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2236 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2237 | |
| 2238 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
| 2239 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2240 | |
| 2241 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 2242 | // and vendor variants. |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2243 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2244 | |
| 2245 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2246 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module) |
| 2247 | |
| 2248 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 2249 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module) |
| 2250 | } |
| 2251 | |
| 2252 | func TestExcludeRuntimeLibs(t *testing.T) { |
| 2253 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2254 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2255 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2256 | module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 2257 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2258 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2259 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2260 | module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 2261 | checkRuntimeLibs(t, nil, module) |
| 2262 | } |
| 2263 | |
| 2264 | func TestRuntimeLibsNoVndk(t *testing.T) { |
| 2265 | ctx := testCcNoVndk(t, runtimeLibAndroidBp) |
| 2266 | |
| 2267 | // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is. |
| 2268 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2269 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2270 | |
| 2271 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2272 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2273 | |
| 2274 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 2275 | checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module) |
| 2276 | } |
| 2277 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2278 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
| 2279 | actual := module.Properties.AndroidMkStaticLibs |
| 2280 | if !reflect.DeepEqual(actual, expected) { |
| 2281 | t.Errorf("incorrect static_libs"+ |
| 2282 | "\nactual: %v"+ |
| 2283 | "\nexpected: %v", |
| 2284 | actual, |
| 2285 | expected, |
| 2286 | ) |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | const staticLibAndroidBp = ` |
| 2291 | cc_library { |
| 2292 | name: "lib1", |
| 2293 | } |
| 2294 | cc_library { |
| 2295 | name: "lib2", |
| 2296 | static_libs: ["lib1"], |
| 2297 | } |
| 2298 | ` |
| 2299 | |
| 2300 | func TestStaticLibDepExport(t *testing.T) { |
| 2301 | ctx := testCc(t, staticLibAndroidBp) |
| 2302 | |
| 2303 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2304 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2305 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2306 | checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2307 | |
| 2308 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2309 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2310 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 2311 | // libc++_static is linked additionally. |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2312 | checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2315 | var compilerFlagsTestCases = []struct { |
| 2316 | in string |
| 2317 | out bool |
| 2318 | }{ |
| 2319 | { |
| 2320 | in: "a", |
| 2321 | out: false, |
| 2322 | }, |
| 2323 | { |
| 2324 | in: "-a", |
| 2325 | out: true, |
| 2326 | }, |
| 2327 | { |
| 2328 | in: "-Ipath/to/something", |
| 2329 | out: false, |
| 2330 | }, |
| 2331 | { |
| 2332 | in: "-isystempath/to/something", |
| 2333 | out: false, |
| 2334 | }, |
| 2335 | { |
| 2336 | in: "--coverage", |
| 2337 | out: false, |
| 2338 | }, |
| 2339 | { |
| 2340 | in: "-include a/b", |
| 2341 | out: true, |
| 2342 | }, |
| 2343 | { |
| 2344 | in: "-include a/b c/d", |
| 2345 | out: false, |
| 2346 | }, |
| 2347 | { |
| 2348 | in: "-DMACRO", |
| 2349 | out: true, |
| 2350 | }, |
| 2351 | { |
| 2352 | in: "-DMAC RO", |
| 2353 | out: false, |
| 2354 | }, |
| 2355 | { |
| 2356 | in: "-a -b", |
| 2357 | out: false, |
| 2358 | }, |
| 2359 | { |
| 2360 | in: "-DMACRO=definition", |
| 2361 | out: true, |
| 2362 | }, |
| 2363 | { |
| 2364 | in: "-DMACRO=defi nition", |
| 2365 | out: true, // TODO(jiyong): this should be false |
| 2366 | }, |
| 2367 | { |
| 2368 | in: "-DMACRO(x)=x + 1", |
| 2369 | out: true, |
| 2370 | }, |
| 2371 | { |
| 2372 | in: "-DMACRO=\"defi nition\"", |
| 2373 | out: true, |
| 2374 | }, |
| 2375 | } |
| 2376 | |
| 2377 | type mockContext struct { |
| 2378 | BaseModuleContext |
| 2379 | result bool |
| 2380 | } |
| 2381 | |
| 2382 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 2383 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 2384 | ctx.result = false |
| 2385 | } |
| 2386 | |
| 2387 | func TestCompilerFlags(t *testing.T) { |
| 2388 | for _, testCase := range compilerFlagsTestCases { |
| 2389 | ctx := &mockContext{result: true} |
| 2390 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 2391 | if ctx.result != testCase.out { |
| 2392 | t.Errorf("incorrect output:") |
| 2393 | t.Errorf(" input: %#v", testCase.in) |
| 2394 | t.Errorf(" expected: %#v", testCase.out) |
| 2395 | t.Errorf(" got: %#v", ctx.result) |
| 2396 | } |
| 2397 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2398 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2399 | |
| 2400 | func TestVendorPublicLibraries(t *testing.T) { |
| 2401 | ctx := testCc(t, ` |
| 2402 | cc_library_headers { |
| 2403 | name: "libvendorpublic_headers", |
| 2404 | export_include_dirs: ["my_include"], |
| 2405 | } |
| 2406 | vendor_public_library { |
| 2407 | name: "libvendorpublic", |
| 2408 | symbol_file: "", |
| 2409 | export_public_headers: ["libvendorpublic_headers"], |
| 2410 | } |
| 2411 | cc_library { |
| 2412 | name: "libvendorpublic", |
| 2413 | srcs: ["foo.c"], |
| 2414 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2415 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2416 | nocrt: true, |
| 2417 | } |
| 2418 | |
| 2419 | cc_library { |
| 2420 | name: "libsystem", |
| 2421 | shared_libs: ["libvendorpublic"], |
| 2422 | vendor: false, |
| 2423 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2424 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2425 | nocrt: true, |
| 2426 | } |
| 2427 | cc_library { |
| 2428 | name: "libvendor", |
| 2429 | shared_libs: ["libvendorpublic"], |
| 2430 | vendor: true, |
| 2431 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2432 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2433 | nocrt: true, |
| 2434 | } |
| 2435 | `) |
| 2436 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2437 | coreVariant := "android_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2438 | vendorVariant := "android_vendor.VER_arm64_armv8-a_shared" |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2439 | |
| 2440 | // test if header search paths are correctly added |
| 2441 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2442 | cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2443 | cflags := cc.Args["cFlags"] |
| 2444 | if !strings.Contains(cflags, "-Imy_include") { |
| 2445 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) |
| 2446 | } |
| 2447 | |
| 2448 | // test if libsystem is linked to the stub |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2449 | ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2450 | libflags := ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2451 | stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2452 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 2453 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) |
| 2454 | } |
| 2455 | |
| 2456 | // test if libvendor is linked to the real shared lib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2457 | ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2458 | libflags = ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2459 | stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2460 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 2461 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) |
| 2462 | } |
| 2463 | |
| 2464 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2465 | |
| 2466 | func TestRecovery(t *testing.T) { |
| 2467 | ctx := testCc(t, ` |
| 2468 | cc_library_shared { |
| 2469 | name: "librecovery", |
| 2470 | recovery: true, |
| 2471 | } |
| 2472 | cc_library_shared { |
| 2473 | name: "librecovery32", |
| 2474 | recovery: true, |
| 2475 | compile_multilib:"32", |
| 2476 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2477 | cc_library_shared { |
| 2478 | name: "libHalInRecovery", |
| 2479 | recovery_available: true, |
| 2480 | vendor: true, |
| 2481 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2482 | `) |
| 2483 | |
| 2484 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2485 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2486 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 2487 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 2488 | } |
| 2489 | |
| 2490 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 2491 | if android.InList(arm64, variants) { |
| 2492 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 2493 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2494 | |
| 2495 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 2496 | if !recoveryModule.Platform() { |
| 2497 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 2498 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2499 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2500 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2501 | func TestVersionedStubs(t *testing.T) { |
| 2502 | ctx := testCc(t, ` |
| 2503 | cc_library_shared { |
| 2504 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2505 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2506 | stubs: { |
| 2507 | symbol_file: "foo.map.txt", |
| 2508 | versions: ["1", "2", "3"], |
| 2509 | }, |
| 2510 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2511 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2512 | cc_library_shared { |
| 2513 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2514 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2515 | shared_libs: ["libFoo#1"], |
| 2516 | }`) |
| 2517 | |
| 2518 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 2519 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2520 | "android_arm64_armv8-a_shared", |
| 2521 | "android_arm64_armv8-a_shared_1", |
| 2522 | "android_arm64_armv8-a_shared_2", |
| 2523 | "android_arm64_armv8-a_shared_3", |
| 2524 | "android_arm_armv7-a-neon_shared", |
| 2525 | "android_arm_armv7-a-neon_shared_1", |
| 2526 | "android_arm_armv7-a-neon_shared_2", |
| 2527 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2528 | } |
| 2529 | variantsMismatch := false |
| 2530 | if len(variants) != len(expectedVariants) { |
| 2531 | variantsMismatch = true |
| 2532 | } else { |
| 2533 | for _, v := range expectedVariants { |
| 2534 | if !inList(v, variants) { |
| 2535 | variantsMismatch = false |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | if variantsMismatch { |
| 2540 | t.Errorf("variants of libFoo expected:\n") |
| 2541 | for _, v := range expectedVariants { |
| 2542 | t.Errorf("%q\n", v) |
| 2543 | } |
| 2544 | t.Errorf(", but got:\n") |
| 2545 | for _, v := range variants { |
| 2546 | t.Errorf("%q\n", v) |
| 2547 | } |
| 2548 | } |
| 2549 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2550 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2551 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2552 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2553 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 2554 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 2555 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2556 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2557 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2558 | cFlags := libBarCompileRule.Args["cFlags"] |
| 2559 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 2560 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 2561 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 2562 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2563 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2564 | |
| 2565 | func TestStaticExecutable(t *testing.T) { |
| 2566 | ctx := testCc(t, ` |
| 2567 | cc_binary { |
| 2568 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 2569 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2570 | static_executable: true, |
| 2571 | }`) |
| 2572 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2573 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2574 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 2575 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 2576 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2577 | for _, lib := range systemStaticLibs { |
| 2578 | if !strings.Contains(libFlags, lib) { |
| 2579 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 2580 | } |
| 2581 | } |
| 2582 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 2583 | for _, lib := range systemSharedLibs { |
| 2584 | if strings.Contains(libFlags, lib) { |
| 2585 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 2586 | } |
| 2587 | } |
| 2588 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2589 | |
| 2590 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
| 2591 | ctx := testCc(t, ` |
| 2592 | cc_binary { |
| 2593 | name: "mybin", |
| 2594 | srcs: ["foo.c"], |
| 2595 | static_libs: ["libB"], |
| 2596 | static_executable: true, |
| 2597 | stl: "none", |
| 2598 | } |
| 2599 | |
| 2600 | cc_library { |
| 2601 | name: "libB", |
| 2602 | srcs: ["foo.c"], |
| 2603 | shared_libs: ["libC"], |
| 2604 | stl: "none", |
| 2605 | } |
| 2606 | |
| 2607 | cc_library { |
| 2608 | name: "libC", |
| 2609 | srcs: ["foo.c"], |
| 2610 | stl: "none", |
| 2611 | stubs: { |
| 2612 | versions: ["1"], |
| 2613 | }, |
| 2614 | }`) |
| 2615 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2616 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Module().(*Module) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2617 | actual := mybin.depsInLinkOrder |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2618 | expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libB", "libC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2619 | |
| 2620 | if !reflect.DeepEqual(actual, expected) { |
| 2621 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2622 | "\nactual: %v"+ |
| 2623 | "\nexpected: %v", |
| 2624 | actual, |
| 2625 | expected, |
| 2626 | ) |
| 2627 | } |
| 2628 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2629 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2630 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
| 2631 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 2632 | cc_library { |
| 2633 | name: "libA", |
| 2634 | srcs: ["foo.c"], |
| 2635 | shared_libs: ["libB"], |
| 2636 | stl: "none", |
| 2637 | } |
| 2638 | |
| 2639 | cc_library { |
| 2640 | name: "libB", |
| 2641 | srcs: ["foo.c"], |
| 2642 | enabled: false, |
| 2643 | stl: "none", |
| 2644 | } |
| 2645 | `) |
| 2646 | } |
| 2647 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 2648 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 2649 | // correctly. |
| 2650 | func TestFuzzTarget(t *testing.T) { |
| 2651 | ctx := testCc(t, ` |
| 2652 | cc_fuzz { |
| 2653 | name: "fuzz_smoke_test", |
| 2654 | srcs: ["foo.c"], |
| 2655 | }`) |
| 2656 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 2657 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 2658 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 2659 | } |
| 2660 | |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 2661 | func TestAidl(t *testing.T) { |
| 2662 | } |
| 2663 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2664 | func assertString(t *testing.T, got, expected string) { |
| 2665 | t.Helper() |
| 2666 | if got != expected { |
| 2667 | t.Errorf("expected %q got %q", expected, got) |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | func assertArrayString(t *testing.T, got, expected []string) { |
| 2672 | t.Helper() |
| 2673 | if len(got) != len(expected) { |
| 2674 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 2675 | return |
| 2676 | } |
| 2677 | for i := range got { |
| 2678 | if got[i] != expected[i] { |
| 2679 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 2680 | i, expected[i], expected, got[i], got) |
| 2681 | return |
| 2682 | } |
| 2683 | } |
| 2684 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2685 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2686 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 2687 | t.Helper() |
| 2688 | assertArrayString(t, android.SortedStringKeys(m), expected) |
| 2689 | } |
| 2690 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2691 | func TestDefaults(t *testing.T) { |
| 2692 | ctx := testCc(t, ` |
| 2693 | cc_defaults { |
| 2694 | name: "defaults", |
| 2695 | srcs: ["foo.c"], |
| 2696 | static: { |
| 2697 | srcs: ["bar.c"], |
| 2698 | }, |
| 2699 | shared: { |
| 2700 | srcs: ["baz.c"], |
| 2701 | }, |
| 2702 | } |
| 2703 | |
| 2704 | cc_library_static { |
| 2705 | name: "libstatic", |
| 2706 | defaults: ["defaults"], |
| 2707 | } |
| 2708 | |
| 2709 | cc_library_shared { |
| 2710 | name: "libshared", |
| 2711 | defaults: ["defaults"], |
| 2712 | } |
| 2713 | |
| 2714 | cc_library { |
| 2715 | name: "libboth", |
| 2716 | defaults: ["defaults"], |
| 2717 | } |
| 2718 | |
| 2719 | cc_binary { |
| 2720 | name: "binary", |
| 2721 | defaults: ["defaults"], |
| 2722 | }`) |
| 2723 | |
| 2724 | pathsToBase := func(paths android.Paths) []string { |
| 2725 | var ret []string |
| 2726 | for _, p := range paths { |
| 2727 | ret = append(ret, p.Base()) |
| 2728 | } |
| 2729 | return ret |
| 2730 | } |
| 2731 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2732 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2733 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 2734 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 2735 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2736 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2737 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 2738 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 2739 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2740 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2741 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 2742 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 2743 | } |
| 2744 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2745 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2746 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 2747 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 2748 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2749 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2750 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 2751 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 2752 | } |
| 2753 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame^] | 2754 | |
| 2755 | func TestProductVariableDefaults(t *testing.T) { |
| 2756 | bp := ` |
| 2757 | cc_defaults { |
| 2758 | name: "libfoo_defaults", |
| 2759 | srcs: ["foo.c"], |
| 2760 | cppflags: ["-DFOO"], |
| 2761 | product_variables: { |
| 2762 | debuggable: { |
| 2763 | cppflags: ["-DBAR"], |
| 2764 | }, |
| 2765 | }, |
| 2766 | } |
| 2767 | |
| 2768 | cc_library { |
| 2769 | name: "libfoo", |
| 2770 | defaults: ["libfoo_defaults"], |
| 2771 | } |
| 2772 | ` |
| 2773 | |
| 2774 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2775 | config.TestProductVariables.Debuggable = BoolPtr(true) |
| 2776 | |
| 2777 | ctx := CreateTestContext() |
| 2778 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 2779 | ctx.BottomUp("variable", android.VariableMutator).Parallel() |
| 2780 | }) |
| 2781 | ctx.Register(config) |
| 2782 | |
| 2783 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 2784 | android.FailIfErrored(t, errs) |
| 2785 | _, errs = ctx.PrepareBuildActions(config) |
| 2786 | android.FailIfErrored(t, errs) |
| 2787 | |
| 2788 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) |
| 2789 | if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) { |
| 2790 | t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags) |
| 2791 | } |
| 2792 | } |