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