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