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