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