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 | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 848 | ` |
| 849 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 850 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 851 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 852 | ctx := testCcWithConfig(t, config) |
| 853 | |
| 854 | // Check Vendor snapshot output. |
| 855 | |
| 856 | snapshotDir := "vendor-snapshot" |
| 857 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame^] | 858 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 859 | |
| 860 | var jsonFiles []string |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 861 | |
| 862 | for _, arch := range [][]string{ |
| 863 | []string{"arm64", "armv8-a"}, |
| 864 | []string{"arm", "armv7-a-neon"}, |
| 865 | } { |
| 866 | archType := arch[0] |
| 867 | archVariant := arch[1] |
| 868 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 869 | |
| 870 | // For shared libraries, only non-VNDK vendor_available modules are captured |
| 871 | sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) |
| 872 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame^] | 873 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 874 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) |
| 875 | jsonFiles = append(jsonFiles, |
| 876 | filepath.Join(sharedDir, "libvendor.so.json"), |
| 877 | filepath.Join(sharedDir, "libvendor_available.so.json")) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 878 | |
| 879 | // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured. |
| 880 | staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant) |
| 881 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame^] | 882 | checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) |
| 883 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant) |
| 884 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant) |
| 885 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant) |
| 886 | jsonFiles = append(jsonFiles, |
| 887 | filepath.Join(staticDir, "libb.a.json"), |
| 888 | filepath.Join(staticDir, "libvndk.a.json"), |
| 889 | filepath.Join(staticDir, "libvendor.a.json"), |
| 890 | filepath.Join(staticDir, "libvendor_available.a.json")) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 891 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame^] | 892 | // For binary executables, all vendor:true and vendor_available modules are captured. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 893 | if archType == "arm64" { |
| 894 | binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) |
| 895 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame^] | 896 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant) |
| 897 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) |
| 898 | jsonFiles = append(jsonFiles, |
| 899 | filepath.Join(binaryDir, "vendor_bin.json"), |
| 900 | filepath.Join(binaryDir, "vendor_available_bin.json")) |
| 901 | } |
| 902 | |
| 903 | // For header libraries, all vendor:true and vendor_available modules are captured. |
| 904 | headerDir := filepath.Join(snapshotVariantPath, archDir, "header") |
| 905 | jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json")) |
| 906 | } |
| 907 | |
| 908 | for _, jsonFile := range jsonFiles { |
| 909 | // verify all json files exist |
| 910 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 911 | t.Errorf("%q expected but not found", jsonFile) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 916 | func TestDoubleLoadableDepError(t *testing.T) { |
| 917 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 918 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 919 | cc_library { |
| 920 | name: "libllndk", |
| 921 | shared_libs: ["libnondoubleloadable"], |
| 922 | } |
| 923 | |
| 924 | llndk_library { |
| 925 | name: "libllndk", |
| 926 | symbol_file: "", |
| 927 | } |
| 928 | |
| 929 | cc_library { |
| 930 | name: "libnondoubleloadable", |
| 931 | vendor_available: true, |
| 932 | vndk: { |
| 933 | enabled: true, |
| 934 | }, |
| 935 | } |
| 936 | `) |
| 937 | |
| 938 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 939 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 940 | cc_library { |
| 941 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 942 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 943 | shared_libs: ["libnondoubleloadable"], |
| 944 | } |
| 945 | |
| 946 | llndk_library { |
| 947 | name: "libllndk", |
| 948 | symbol_file: "", |
| 949 | } |
| 950 | |
| 951 | cc_library { |
| 952 | name: "libnondoubleloadable", |
| 953 | vendor_available: true, |
| 954 | } |
| 955 | `) |
| 956 | |
| 957 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib. |
| 958 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 959 | cc_library { |
| 960 | name: "libdoubleloadable", |
| 961 | vendor_available: true, |
| 962 | double_loadable: true, |
| 963 | shared_libs: ["libnondoubleloadable"], |
| 964 | } |
| 965 | |
| 966 | cc_library { |
| 967 | name: "libnondoubleloadable", |
| 968 | vendor_available: true, |
| 969 | } |
| 970 | `) |
| 971 | |
| 972 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib. |
| 973 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 974 | cc_library { |
| 975 | name: "libdoubleloadable", |
| 976 | vendor_available: true, |
| 977 | double_loadable: true, |
| 978 | shared_libs: ["libnondoubleloadable"], |
| 979 | } |
| 980 | |
| 981 | cc_library { |
| 982 | name: "libnondoubleloadable", |
| 983 | vendor_available: true, |
| 984 | vndk: { |
| 985 | enabled: true, |
| 986 | }, |
| 987 | } |
| 988 | `) |
| 989 | |
| 990 | // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib. |
| 991 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 992 | cc_library { |
| 993 | name: "libdoubleloadable", |
| 994 | vendor_available: true, |
| 995 | vndk: { |
| 996 | enabled: true, |
| 997 | }, |
| 998 | double_loadable: true, |
| 999 | shared_libs: ["libnondoubleloadable"], |
| 1000 | } |
| 1001 | |
| 1002 | cc_library { |
| 1003 | name: "libnondoubleloadable", |
| 1004 | vendor_available: false, |
| 1005 | vndk: { |
| 1006 | enabled: true, |
| 1007 | }, |
| 1008 | } |
| 1009 | `) |
| 1010 | |
| 1011 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 1012 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1013 | cc_library { |
| 1014 | name: "libllndk", |
| 1015 | shared_libs: ["libcoreonly"], |
| 1016 | } |
| 1017 | |
| 1018 | llndk_library { |
| 1019 | name: "libllndk", |
| 1020 | symbol_file: "", |
| 1021 | } |
| 1022 | |
| 1023 | cc_library { |
| 1024 | name: "libcoreonly", |
| 1025 | shared_libs: ["libvendoravailable"], |
| 1026 | } |
| 1027 | |
| 1028 | // indirect dependency of LLNDK |
| 1029 | cc_library { |
| 1030 | name: "libvendoravailable", |
| 1031 | vendor_available: true, |
| 1032 | } |
| 1033 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1036 | func TestVndkExt(t *testing.T) { |
| 1037 | // This test checks the VNDK-Ext properties. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1038 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1039 | cc_library { |
| 1040 | name: "libvndk", |
| 1041 | vendor_available: true, |
| 1042 | vndk: { |
| 1043 | enabled: true, |
| 1044 | }, |
| 1045 | nocrt: true, |
| 1046 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1047 | cc_library { |
| 1048 | name: "libvndk2", |
| 1049 | vendor_available: true, |
| 1050 | vndk: { |
| 1051 | enabled: true, |
| 1052 | }, |
| 1053 | target: { |
| 1054 | vendor: { |
| 1055 | suffix: "-suffix", |
| 1056 | }, |
| 1057 | }, |
| 1058 | nocrt: true, |
| 1059 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1060 | |
| 1061 | cc_library { |
| 1062 | name: "libvndk_ext", |
| 1063 | vendor: true, |
| 1064 | vndk: { |
| 1065 | enabled: true, |
| 1066 | extends: "libvndk", |
| 1067 | }, |
| 1068 | nocrt: true, |
| 1069 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1070 | |
| 1071 | cc_library { |
| 1072 | name: "libvndk2_ext", |
| 1073 | vendor: true, |
| 1074 | vndk: { |
| 1075 | enabled: true, |
| 1076 | extends: "libvndk2", |
| 1077 | }, |
| 1078 | nocrt: true, |
| 1079 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1080 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1081 | cc_library { |
| 1082 | name: "libvndk_ext_product", |
| 1083 | product_specific: true, |
| 1084 | vndk: { |
| 1085 | enabled: true, |
| 1086 | extends: "libvndk", |
| 1087 | }, |
| 1088 | nocrt: true, |
| 1089 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1090 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1091 | cc_library { |
| 1092 | name: "libvndk2_ext_product", |
| 1093 | product_specific: true, |
| 1094 | vndk: { |
| 1095 | enabled: true, |
| 1096 | extends: "libvndk2", |
| 1097 | }, |
| 1098 | nocrt: true, |
| 1099 | } |
| 1100 | ` |
| 1101 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1102 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1103 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 1104 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1105 | |
| 1106 | ctx := testCcWithConfig(t, config) |
| 1107 | |
| 1108 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) |
| 1109 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) |
| 1110 | |
| 1111 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 1112 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") |
| 1113 | |
| 1114 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) |
| 1115 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1116 | } |
| 1117 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1118 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1119 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. |
| 1120 | ctx := testCcNoVndk(t, ` |
| 1121 | cc_library { |
| 1122 | name: "libvndk", |
| 1123 | vendor_available: true, |
| 1124 | vndk: { |
| 1125 | enabled: true, |
| 1126 | }, |
| 1127 | nocrt: true, |
| 1128 | } |
| 1129 | |
| 1130 | cc_library { |
| 1131 | name: "libvndk_ext", |
| 1132 | vendor: true, |
| 1133 | vndk: { |
| 1134 | enabled: true, |
| 1135 | extends: "libvndk", |
| 1136 | }, |
| 1137 | nocrt: true, |
| 1138 | } |
| 1139 | `) |
| 1140 | |
| 1141 | // Ensures that the core variant of "libvndk_ext" can be found. |
| 1142 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) |
| 1143 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 1144 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) |
| 1145 | } |
| 1146 | } |
| 1147 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1148 | func TestVndkExtWithoutProductVndkVersion(t *testing.T) { |
| 1149 | // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set. |
| 1150 | ctx := testCc(t, ` |
| 1151 | cc_library { |
| 1152 | name: "libvndk", |
| 1153 | vendor_available: true, |
| 1154 | vndk: { |
| 1155 | enabled: true, |
| 1156 | }, |
| 1157 | nocrt: true, |
| 1158 | } |
| 1159 | |
| 1160 | cc_library { |
| 1161 | name: "libvndk_ext_product", |
| 1162 | product_specific: true, |
| 1163 | vndk: { |
| 1164 | enabled: true, |
| 1165 | extends: "libvndk", |
| 1166 | }, |
| 1167 | nocrt: true, |
| 1168 | } |
| 1169 | `) |
| 1170 | |
| 1171 | // Ensures that the core variant of "libvndk_ext_product" can be found. |
| 1172 | mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module) |
| 1173 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 1174 | t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends) |
| 1175 | } |
| 1176 | } |
| 1177 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1178 | func TestVndkExtError(t *testing.T) { |
| 1179 | // 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] | 1180 | 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] | 1181 | cc_library { |
| 1182 | name: "libvndk", |
| 1183 | vendor_available: true, |
| 1184 | vndk: { |
| 1185 | enabled: true, |
| 1186 | }, |
| 1187 | nocrt: true, |
| 1188 | } |
| 1189 | |
| 1190 | cc_library { |
| 1191 | name: "libvndk_ext", |
| 1192 | vndk: { |
| 1193 | enabled: true, |
| 1194 | extends: "libvndk", |
| 1195 | }, |
| 1196 | nocrt: true, |
| 1197 | } |
| 1198 | `) |
| 1199 | |
| 1200 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1201 | cc_library { |
| 1202 | name: "libvndk", |
| 1203 | vendor_available: true, |
| 1204 | vndk: { |
| 1205 | enabled: true, |
| 1206 | }, |
| 1207 | nocrt: true, |
| 1208 | } |
| 1209 | |
| 1210 | cc_library { |
| 1211 | name: "libvndk_ext", |
| 1212 | vendor: true, |
| 1213 | vndk: { |
| 1214 | enabled: true, |
| 1215 | }, |
| 1216 | nocrt: true, |
| 1217 | } |
| 1218 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1219 | |
| 1220 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1221 | cc_library { |
| 1222 | name: "libvndk", |
| 1223 | vendor_available: true, |
| 1224 | vndk: { |
| 1225 | enabled: true, |
| 1226 | }, |
| 1227 | nocrt: true, |
| 1228 | } |
| 1229 | |
| 1230 | cc_library { |
| 1231 | name: "libvndk_ext_product", |
| 1232 | product_specific: true, |
| 1233 | vndk: { |
| 1234 | enabled: true, |
| 1235 | }, |
| 1236 | nocrt: true, |
| 1237 | } |
| 1238 | `) |
| 1239 | |
| 1240 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` |
| 1241 | cc_library { |
| 1242 | name: "libvndk", |
| 1243 | vendor_available: true, |
| 1244 | vndk: { |
| 1245 | enabled: true, |
| 1246 | }, |
| 1247 | nocrt: true, |
| 1248 | } |
| 1249 | |
| 1250 | cc_library { |
| 1251 | name: "libvndk_ext_product", |
| 1252 | product_specific: true, |
| 1253 | vendor_available: true, |
| 1254 | vndk: { |
| 1255 | enabled: true, |
| 1256 | extends: "libvndk", |
| 1257 | }, |
| 1258 | nocrt: true, |
| 1259 | } |
| 1260 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
| 1264 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 1265 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1266 | cc_library { |
| 1267 | name: "libvndk", |
| 1268 | vendor_available: true, |
| 1269 | vndk: { |
| 1270 | enabled: true, |
| 1271 | }, |
| 1272 | nocrt: true, |
| 1273 | } |
| 1274 | |
| 1275 | cc_library { |
| 1276 | name: "libvndk_sp_ext", |
| 1277 | vendor: true, |
| 1278 | vndk: { |
| 1279 | enabled: true, |
| 1280 | extends: "libvndk", |
| 1281 | support_system_process: true, |
| 1282 | }, |
| 1283 | nocrt: true, |
| 1284 | } |
| 1285 | `) |
| 1286 | |
| 1287 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1288 | cc_library { |
| 1289 | name: "libvndk_sp", |
| 1290 | vendor_available: true, |
| 1291 | vndk: { |
| 1292 | enabled: true, |
| 1293 | support_system_process: true, |
| 1294 | }, |
| 1295 | nocrt: true, |
| 1296 | } |
| 1297 | |
| 1298 | cc_library { |
| 1299 | name: "libvndk_ext", |
| 1300 | vendor: true, |
| 1301 | vndk: { |
| 1302 | enabled: true, |
| 1303 | extends: "libvndk_sp", |
| 1304 | }, |
| 1305 | nocrt: true, |
| 1306 | } |
| 1307 | `) |
| 1308 | } |
| 1309 | |
| 1310 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1311 | // 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] | 1312 | // with `vendor_available: false`. |
| 1313 | testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` |
| 1314 | cc_library { |
| 1315 | name: "libvndk", |
| 1316 | vendor_available: false, |
| 1317 | vndk: { |
| 1318 | enabled: true, |
| 1319 | }, |
| 1320 | nocrt: true, |
| 1321 | } |
| 1322 | |
| 1323 | cc_library { |
| 1324 | name: "libvndk_ext", |
| 1325 | vendor: true, |
| 1326 | vndk: { |
| 1327 | enabled: true, |
| 1328 | extends: "libvndk", |
| 1329 | }, |
| 1330 | nocrt: true, |
| 1331 | } |
| 1332 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1333 | |
| 1334 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` |
| 1335 | cc_library { |
| 1336 | name: "libvndk", |
| 1337 | vendor_available: false, |
| 1338 | vndk: { |
| 1339 | enabled: true, |
| 1340 | }, |
| 1341 | nocrt: true, |
| 1342 | } |
| 1343 | |
| 1344 | cc_library { |
| 1345 | name: "libvndk_ext_product", |
| 1346 | product_specific: true, |
| 1347 | vndk: { |
| 1348 | enabled: true, |
| 1349 | extends: "libvndk", |
| 1350 | }, |
| 1351 | nocrt: true, |
| 1352 | } |
| 1353 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1354 | } |
| 1355 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1356 | func TestVendorModuleUseVndkExt(t *testing.T) { |
| 1357 | // 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] | 1358 | testCc(t, ` |
| 1359 | cc_library { |
| 1360 | name: "libvndk", |
| 1361 | vendor_available: true, |
| 1362 | vndk: { |
| 1363 | enabled: true, |
| 1364 | }, |
| 1365 | nocrt: true, |
| 1366 | } |
| 1367 | |
| 1368 | cc_library { |
| 1369 | name: "libvndk_ext", |
| 1370 | vendor: true, |
| 1371 | vndk: { |
| 1372 | enabled: true, |
| 1373 | extends: "libvndk", |
| 1374 | }, |
| 1375 | nocrt: true, |
| 1376 | } |
| 1377 | |
| 1378 | cc_library { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1379 | name: "libvndk_sp", |
| 1380 | vendor_available: true, |
| 1381 | vndk: { |
| 1382 | enabled: true, |
| 1383 | support_system_process: true, |
| 1384 | }, |
| 1385 | nocrt: true, |
| 1386 | } |
| 1387 | |
| 1388 | cc_library { |
| 1389 | name: "libvndk_sp_ext", |
| 1390 | vendor: true, |
| 1391 | vndk: { |
| 1392 | enabled: true, |
| 1393 | extends: "libvndk_sp", |
| 1394 | support_system_process: true, |
| 1395 | }, |
| 1396 | nocrt: true, |
| 1397 | } |
| 1398 | |
| 1399 | cc_library { |
| 1400 | name: "libvendor", |
| 1401 | vendor: true, |
| 1402 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 1403 | nocrt: true, |
| 1404 | } |
| 1405 | `) |
| 1406 | } |
| 1407 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1408 | func TestVndkExtUseVendorLib(t *testing.T) { |
| 1409 | // 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] | 1410 | testCc(t, ` |
| 1411 | cc_library { |
| 1412 | name: "libvndk", |
| 1413 | vendor_available: true, |
| 1414 | vndk: { |
| 1415 | enabled: true, |
| 1416 | }, |
| 1417 | nocrt: true, |
| 1418 | } |
| 1419 | |
| 1420 | cc_library { |
| 1421 | name: "libvndk_ext", |
| 1422 | vendor: true, |
| 1423 | vndk: { |
| 1424 | enabled: true, |
| 1425 | extends: "libvndk", |
| 1426 | }, |
| 1427 | shared_libs: ["libvendor"], |
| 1428 | nocrt: true, |
| 1429 | } |
| 1430 | |
| 1431 | cc_library { |
| 1432 | name: "libvendor", |
| 1433 | vendor: true, |
| 1434 | nocrt: true, |
| 1435 | } |
| 1436 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1437 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1438 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 1439 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1440 | cc_library { |
| 1441 | name: "libvndk_sp", |
| 1442 | vendor_available: true, |
| 1443 | vndk: { |
| 1444 | enabled: true, |
| 1445 | support_system_process: true, |
| 1446 | }, |
| 1447 | nocrt: true, |
| 1448 | } |
| 1449 | |
| 1450 | cc_library { |
| 1451 | name: "libvndk_sp_ext", |
| 1452 | vendor: true, |
| 1453 | vndk: { |
| 1454 | enabled: true, |
| 1455 | extends: "libvndk_sp", |
| 1456 | support_system_process: true, |
| 1457 | }, |
| 1458 | shared_libs: ["libvendor"], // Cause an error |
| 1459 | nocrt: true, |
| 1460 | } |
| 1461 | |
| 1462 | cc_library { |
| 1463 | name: "libvendor", |
| 1464 | vendor: true, |
| 1465 | nocrt: true, |
| 1466 | } |
| 1467 | `) |
| 1468 | } |
| 1469 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1470 | func TestProductVndkExtDependency(t *testing.T) { |
| 1471 | bp := ` |
| 1472 | cc_library { |
| 1473 | name: "libvndk", |
| 1474 | vendor_available: true, |
| 1475 | vndk: { |
| 1476 | enabled: true, |
| 1477 | }, |
| 1478 | nocrt: true, |
| 1479 | } |
| 1480 | |
| 1481 | cc_library { |
| 1482 | name: "libvndk_ext_product", |
| 1483 | product_specific: true, |
| 1484 | vndk: { |
| 1485 | enabled: true, |
| 1486 | extends: "libvndk", |
| 1487 | }, |
| 1488 | shared_libs: ["libproduct_for_vndklibs"], |
| 1489 | nocrt: true, |
| 1490 | } |
| 1491 | |
| 1492 | cc_library { |
| 1493 | name: "libvndk_sp", |
| 1494 | vendor_available: true, |
| 1495 | vndk: { |
| 1496 | enabled: true, |
| 1497 | support_system_process: true, |
| 1498 | }, |
| 1499 | nocrt: true, |
| 1500 | } |
| 1501 | |
| 1502 | cc_library { |
| 1503 | name: "libvndk_sp_ext_product", |
| 1504 | product_specific: true, |
| 1505 | vndk: { |
| 1506 | enabled: true, |
| 1507 | extends: "libvndk_sp", |
| 1508 | support_system_process: true, |
| 1509 | }, |
| 1510 | shared_libs: ["libproduct_for_vndklibs"], |
| 1511 | nocrt: true, |
| 1512 | } |
| 1513 | |
| 1514 | cc_library { |
| 1515 | name: "libproduct", |
| 1516 | product_specific: true, |
| 1517 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], |
| 1518 | nocrt: true, |
| 1519 | } |
| 1520 | |
| 1521 | cc_library { |
| 1522 | name: "libproduct_for_vndklibs", |
| 1523 | product_specific: true, |
| 1524 | nocrt: true, |
| 1525 | } |
| 1526 | ` |
| 1527 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1528 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1529 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 1530 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1531 | |
| 1532 | testCcWithConfig(t, config) |
| 1533 | } |
| 1534 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1535 | func TestVndkSpExtUseVndkError(t *testing.T) { |
| 1536 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 1537 | // library. |
| 1538 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1539 | cc_library { |
| 1540 | name: "libvndk", |
| 1541 | vendor_available: true, |
| 1542 | vndk: { |
| 1543 | enabled: true, |
| 1544 | }, |
| 1545 | nocrt: true, |
| 1546 | } |
| 1547 | |
| 1548 | cc_library { |
| 1549 | name: "libvndk_sp", |
| 1550 | vendor_available: true, |
| 1551 | vndk: { |
| 1552 | enabled: true, |
| 1553 | support_system_process: true, |
| 1554 | }, |
| 1555 | nocrt: true, |
| 1556 | } |
| 1557 | |
| 1558 | cc_library { |
| 1559 | name: "libvndk_sp_ext", |
| 1560 | vendor: true, |
| 1561 | vndk: { |
| 1562 | enabled: true, |
| 1563 | extends: "libvndk_sp", |
| 1564 | support_system_process: true, |
| 1565 | }, |
| 1566 | shared_libs: ["libvndk"], // Cause an error |
| 1567 | nocrt: true, |
| 1568 | } |
| 1569 | `) |
| 1570 | |
| 1571 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 1572 | // library. |
| 1573 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1574 | cc_library { |
| 1575 | name: "libvndk", |
| 1576 | vendor_available: true, |
| 1577 | vndk: { |
| 1578 | enabled: true, |
| 1579 | }, |
| 1580 | nocrt: true, |
| 1581 | } |
| 1582 | |
| 1583 | cc_library { |
| 1584 | name: "libvndk_ext", |
| 1585 | vendor: true, |
| 1586 | vndk: { |
| 1587 | enabled: true, |
| 1588 | extends: "libvndk", |
| 1589 | }, |
| 1590 | nocrt: true, |
| 1591 | } |
| 1592 | |
| 1593 | cc_library { |
| 1594 | name: "libvndk_sp", |
| 1595 | vendor_available: true, |
| 1596 | vndk: { |
| 1597 | enabled: true, |
| 1598 | support_system_process: true, |
| 1599 | }, |
| 1600 | nocrt: true, |
| 1601 | } |
| 1602 | |
| 1603 | cc_library { |
| 1604 | name: "libvndk_sp_ext", |
| 1605 | vendor: true, |
| 1606 | vndk: { |
| 1607 | enabled: true, |
| 1608 | extends: "libvndk_sp", |
| 1609 | support_system_process: true, |
| 1610 | }, |
| 1611 | shared_libs: ["libvndk_ext"], // Cause an error |
| 1612 | nocrt: true, |
| 1613 | } |
| 1614 | `) |
| 1615 | } |
| 1616 | |
| 1617 | func TestVndkUseVndkExtError(t *testing.T) { |
| 1618 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 1619 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1620 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1621 | cc_library { |
| 1622 | name: "libvndk", |
| 1623 | vendor_available: true, |
| 1624 | vndk: { |
| 1625 | enabled: true, |
| 1626 | }, |
| 1627 | nocrt: true, |
| 1628 | } |
| 1629 | |
| 1630 | cc_library { |
| 1631 | name: "libvndk_ext", |
| 1632 | vendor: true, |
| 1633 | vndk: { |
| 1634 | enabled: true, |
| 1635 | extends: "libvndk", |
| 1636 | }, |
| 1637 | nocrt: true, |
| 1638 | } |
| 1639 | |
| 1640 | cc_library { |
| 1641 | name: "libvndk2", |
| 1642 | vendor_available: true, |
| 1643 | vndk: { |
| 1644 | enabled: true, |
| 1645 | }, |
| 1646 | shared_libs: ["libvndk_ext"], |
| 1647 | nocrt: true, |
| 1648 | } |
| 1649 | `) |
| 1650 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1651 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1652 | cc_library { |
| 1653 | name: "libvndk", |
| 1654 | vendor_available: true, |
| 1655 | vndk: { |
| 1656 | enabled: true, |
| 1657 | }, |
| 1658 | nocrt: true, |
| 1659 | } |
| 1660 | |
| 1661 | cc_library { |
| 1662 | name: "libvndk_ext", |
| 1663 | vendor: true, |
| 1664 | vndk: { |
| 1665 | enabled: true, |
| 1666 | extends: "libvndk", |
| 1667 | }, |
| 1668 | nocrt: true, |
| 1669 | } |
| 1670 | |
| 1671 | cc_library { |
| 1672 | name: "libvndk2", |
| 1673 | vendor_available: true, |
| 1674 | vndk: { |
| 1675 | enabled: true, |
| 1676 | }, |
| 1677 | target: { |
| 1678 | vendor: { |
| 1679 | shared_libs: ["libvndk_ext"], |
| 1680 | }, |
| 1681 | }, |
| 1682 | nocrt: true, |
| 1683 | } |
| 1684 | `) |
| 1685 | |
| 1686 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1687 | cc_library { |
| 1688 | name: "libvndk_sp", |
| 1689 | vendor_available: true, |
| 1690 | vndk: { |
| 1691 | enabled: true, |
| 1692 | support_system_process: true, |
| 1693 | }, |
| 1694 | nocrt: true, |
| 1695 | } |
| 1696 | |
| 1697 | cc_library { |
| 1698 | name: "libvndk_sp_ext", |
| 1699 | vendor: true, |
| 1700 | vndk: { |
| 1701 | enabled: true, |
| 1702 | extends: "libvndk_sp", |
| 1703 | support_system_process: true, |
| 1704 | }, |
| 1705 | nocrt: true, |
| 1706 | } |
| 1707 | |
| 1708 | cc_library { |
| 1709 | name: "libvndk_sp_2", |
| 1710 | vendor_available: true, |
| 1711 | vndk: { |
| 1712 | enabled: true, |
| 1713 | support_system_process: true, |
| 1714 | }, |
| 1715 | shared_libs: ["libvndk_sp_ext"], |
| 1716 | nocrt: true, |
| 1717 | } |
| 1718 | `) |
| 1719 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1720 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1721 | cc_library { |
| 1722 | name: "libvndk_sp", |
| 1723 | vendor_available: true, |
| 1724 | vndk: { |
| 1725 | enabled: true, |
| 1726 | }, |
| 1727 | nocrt: true, |
| 1728 | } |
| 1729 | |
| 1730 | cc_library { |
| 1731 | name: "libvndk_sp_ext", |
| 1732 | vendor: true, |
| 1733 | vndk: { |
| 1734 | enabled: true, |
| 1735 | extends: "libvndk_sp", |
| 1736 | }, |
| 1737 | nocrt: true, |
| 1738 | } |
| 1739 | |
| 1740 | cc_library { |
| 1741 | name: "libvndk_sp2", |
| 1742 | vendor_available: true, |
| 1743 | vndk: { |
| 1744 | enabled: true, |
| 1745 | }, |
| 1746 | target: { |
| 1747 | vendor: { |
| 1748 | shared_libs: ["libvndk_sp_ext"], |
| 1749 | }, |
| 1750 | }, |
| 1751 | nocrt: true, |
| 1752 | } |
| 1753 | `) |
| 1754 | } |
| 1755 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1756 | func TestEnforceProductVndkVersion(t *testing.T) { |
| 1757 | bp := ` |
| 1758 | cc_library { |
| 1759 | name: "libllndk", |
| 1760 | } |
| 1761 | llndk_library { |
| 1762 | name: "libllndk", |
| 1763 | symbol_file: "", |
| 1764 | } |
| 1765 | cc_library { |
| 1766 | name: "libvndk", |
| 1767 | vendor_available: true, |
| 1768 | vndk: { |
| 1769 | enabled: true, |
| 1770 | }, |
| 1771 | nocrt: true, |
| 1772 | } |
| 1773 | cc_library { |
| 1774 | name: "libvndk_sp", |
| 1775 | vendor_available: true, |
| 1776 | vndk: { |
| 1777 | enabled: true, |
| 1778 | support_system_process: true, |
| 1779 | }, |
| 1780 | nocrt: true, |
| 1781 | } |
| 1782 | cc_library { |
| 1783 | name: "libva", |
| 1784 | vendor_available: true, |
| 1785 | nocrt: true, |
| 1786 | } |
| 1787 | cc_library { |
| 1788 | name: "libproduct_va", |
| 1789 | product_specific: true, |
| 1790 | vendor_available: true, |
| 1791 | nocrt: true, |
| 1792 | } |
| 1793 | cc_library { |
| 1794 | name: "libprod", |
| 1795 | product_specific: true, |
| 1796 | shared_libs: [ |
| 1797 | "libllndk", |
| 1798 | "libvndk", |
| 1799 | "libvndk_sp", |
| 1800 | "libva", |
| 1801 | "libproduct_va", |
| 1802 | ], |
| 1803 | nocrt: true, |
| 1804 | } |
| 1805 | cc_library { |
| 1806 | name: "libvendor", |
| 1807 | vendor: true, |
| 1808 | shared_libs: [ |
| 1809 | "libllndk", |
| 1810 | "libvndk", |
| 1811 | "libvndk_sp", |
| 1812 | "libva", |
| 1813 | "libproduct_va", |
| 1814 | ], |
| 1815 | nocrt: true, |
| 1816 | } |
| 1817 | ` |
| 1818 | |
| 1819 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1820 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1821 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 1822 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1823 | |
| 1824 | ctx := testCcWithConfig(t, config) |
| 1825 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1826 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "", productVariant) |
| 1827 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "", productVariant) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
| 1831 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 1832 | cc_library { |
| 1833 | name: "libprod", |
| 1834 | product_specific: true, |
| 1835 | shared_libs: [ |
| 1836 | "libvendor", |
| 1837 | ], |
| 1838 | nocrt: true, |
| 1839 | } |
| 1840 | cc_library { |
| 1841 | name: "libvendor", |
| 1842 | vendor: true, |
| 1843 | nocrt: true, |
| 1844 | } |
| 1845 | `) |
| 1846 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 1847 | cc_library { |
| 1848 | name: "libprod", |
| 1849 | product_specific: true, |
| 1850 | shared_libs: [ |
| 1851 | "libsystem", |
| 1852 | ], |
| 1853 | nocrt: true, |
| 1854 | } |
| 1855 | cc_library { |
| 1856 | name: "libsystem", |
| 1857 | nocrt: true, |
| 1858 | } |
| 1859 | `) |
| 1860 | testCcErrorProductVndk(t, "Vendor module that is not VNDK should not link to \".*\" which is marked as `vendor_available: false`", ` |
| 1861 | cc_library { |
| 1862 | name: "libprod", |
| 1863 | product_specific: true, |
| 1864 | shared_libs: [ |
| 1865 | "libvndk_private", |
| 1866 | ], |
| 1867 | nocrt: true, |
| 1868 | } |
| 1869 | cc_library { |
| 1870 | name: "libvndk_private", |
| 1871 | vendor_available: false, |
| 1872 | vndk: { |
| 1873 | enabled: true, |
| 1874 | }, |
| 1875 | nocrt: true, |
| 1876 | } |
| 1877 | `) |
| 1878 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 1879 | cc_library { |
| 1880 | name: "libprod", |
| 1881 | product_specific: true, |
| 1882 | shared_libs: [ |
| 1883 | "libsystem_ext", |
| 1884 | ], |
| 1885 | nocrt: true, |
| 1886 | } |
| 1887 | cc_library { |
| 1888 | name: "libsystem_ext", |
| 1889 | system_ext_specific: true, |
| 1890 | nocrt: true, |
| 1891 | } |
| 1892 | `) |
| 1893 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 1894 | cc_library { |
| 1895 | name: "libsystem", |
| 1896 | shared_libs: [ |
| 1897 | "libproduct_va", |
| 1898 | ], |
| 1899 | nocrt: true, |
| 1900 | } |
| 1901 | cc_library { |
| 1902 | name: "libproduct_va", |
| 1903 | product_specific: true, |
| 1904 | vendor_available: true, |
| 1905 | nocrt: true, |
| 1906 | } |
| 1907 | `) |
| 1908 | } |
| 1909 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1910 | func TestMakeLinkType(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1911 | bp := ` |
| 1912 | cc_library { |
| 1913 | name: "libvndk", |
| 1914 | vendor_available: true, |
| 1915 | vndk: { |
| 1916 | enabled: true, |
| 1917 | }, |
| 1918 | } |
| 1919 | cc_library { |
| 1920 | name: "libvndksp", |
| 1921 | vendor_available: true, |
| 1922 | vndk: { |
| 1923 | enabled: true, |
| 1924 | support_system_process: true, |
| 1925 | }, |
| 1926 | } |
| 1927 | cc_library { |
| 1928 | name: "libvndkprivate", |
| 1929 | vendor_available: false, |
| 1930 | vndk: { |
| 1931 | enabled: true, |
| 1932 | }, |
| 1933 | } |
| 1934 | cc_library { |
| 1935 | name: "libvendor", |
| 1936 | vendor: true, |
| 1937 | } |
| 1938 | cc_library { |
| 1939 | name: "libvndkext", |
| 1940 | vendor: true, |
| 1941 | vndk: { |
| 1942 | enabled: true, |
| 1943 | extends: "libvndk", |
| 1944 | }, |
| 1945 | } |
| 1946 | vndk_prebuilt_shared { |
| 1947 | name: "prevndk", |
| 1948 | version: "27", |
| 1949 | target_arch: "arm", |
| 1950 | binder32bit: true, |
| 1951 | vendor_available: true, |
| 1952 | vndk: { |
| 1953 | enabled: true, |
| 1954 | }, |
| 1955 | arch: { |
| 1956 | arm: { |
| 1957 | srcs: ["liba.so"], |
| 1958 | }, |
| 1959 | }, |
| 1960 | } |
| 1961 | cc_library { |
| 1962 | name: "libllndk", |
| 1963 | } |
| 1964 | llndk_library { |
| 1965 | name: "libllndk", |
| 1966 | symbol_file: "", |
| 1967 | } |
| 1968 | cc_library { |
| 1969 | name: "libllndkprivate", |
| 1970 | } |
| 1971 | llndk_library { |
| 1972 | name: "libllndkprivate", |
| 1973 | vendor_available: false, |
| 1974 | symbol_file: "", |
| 1975 | }` |
| 1976 | |
| 1977 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1978 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1979 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1980 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1981 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1982 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1983 | assertMapKeys(t, vndkCoreLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1984 | []string{"libvndk", "libvndkprivate"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1985 | assertMapKeys(t, vndkSpLibraries(config), |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1986 | []string{"libc++", "libvndksp"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1987 | assertMapKeys(t, llndkLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 1988 | []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"}) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1989 | assertMapKeys(t, vndkPrivateLibraries(config), |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 1990 | []string{"libft2", "libllndkprivate", "libvndkprivate"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1991 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 1992 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1993 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1994 | tests := []struct { |
| 1995 | variant string |
| 1996 | name string |
| 1997 | expected string |
| 1998 | }{ |
| 1999 | {vendorVariant, "libvndk", "native:vndk"}, |
| 2000 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 2001 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 2002 | {vendorVariant, "libvendor", "native:vendor"}, |
| 2003 | {vendorVariant, "libvndkext", "native:vendor"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2004 | {vendorVariant, "libllndk.llndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2005 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2006 | {coreVariant, "libvndk", "native:platform"}, |
| 2007 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 2008 | {coreVariant, "libllndk", "native:platform"}, |
| 2009 | } |
| 2010 | for _, test := range tests { |
| 2011 | t.Run(test.name, func(t *testing.T) { |
| 2012 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 2013 | assertString(t, module.makeLinkType, test.expected) |
| 2014 | }) |
| 2015 | } |
| 2016 | } |
| 2017 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2018 | var ( |
| 2019 | str11 = "01234567891" |
| 2020 | str10 = str11[:10] |
| 2021 | str9 = str11[:9] |
| 2022 | str5 = str11[:5] |
| 2023 | str4 = str11[:4] |
| 2024 | ) |
| 2025 | |
| 2026 | var splitListForSizeTestCases = []struct { |
| 2027 | in []string |
| 2028 | out [][]string |
| 2029 | size int |
| 2030 | }{ |
| 2031 | { |
| 2032 | in: []string{str10}, |
| 2033 | out: [][]string{{str10}}, |
| 2034 | size: 10, |
| 2035 | }, |
| 2036 | { |
| 2037 | in: []string{str9}, |
| 2038 | out: [][]string{{str9}}, |
| 2039 | size: 10, |
| 2040 | }, |
| 2041 | { |
| 2042 | in: []string{str5}, |
| 2043 | out: [][]string{{str5}}, |
| 2044 | size: 10, |
| 2045 | }, |
| 2046 | { |
| 2047 | in: []string{str11}, |
| 2048 | out: nil, |
| 2049 | size: 10, |
| 2050 | }, |
| 2051 | { |
| 2052 | in: []string{str10, str10}, |
| 2053 | out: [][]string{{str10}, {str10}}, |
| 2054 | size: 10, |
| 2055 | }, |
| 2056 | { |
| 2057 | in: []string{str9, str10}, |
| 2058 | out: [][]string{{str9}, {str10}}, |
| 2059 | size: 10, |
| 2060 | }, |
| 2061 | { |
| 2062 | in: []string{str10, str9}, |
| 2063 | out: [][]string{{str10}, {str9}}, |
| 2064 | size: 10, |
| 2065 | }, |
| 2066 | { |
| 2067 | in: []string{str5, str4}, |
| 2068 | out: [][]string{{str5, str4}}, |
| 2069 | size: 10, |
| 2070 | }, |
| 2071 | { |
| 2072 | in: []string{str5, str4, str5}, |
| 2073 | out: [][]string{{str5, str4}, {str5}}, |
| 2074 | size: 10, |
| 2075 | }, |
| 2076 | { |
| 2077 | in: []string{str5, str4, str5, str4}, |
| 2078 | out: [][]string{{str5, str4}, {str5, str4}}, |
| 2079 | size: 10, |
| 2080 | }, |
| 2081 | { |
| 2082 | in: []string{str5, str4, str5, str5}, |
| 2083 | out: [][]string{{str5, str4}, {str5}, {str5}}, |
| 2084 | size: 10, |
| 2085 | }, |
| 2086 | { |
| 2087 | in: []string{str5, str5, str5, str4}, |
| 2088 | out: [][]string{{str5}, {str5}, {str5, str4}}, |
| 2089 | size: 10, |
| 2090 | }, |
| 2091 | { |
| 2092 | in: []string{str9, str11}, |
| 2093 | out: nil, |
| 2094 | size: 10, |
| 2095 | }, |
| 2096 | { |
| 2097 | in: []string{str11, str9}, |
| 2098 | out: nil, |
| 2099 | size: 10, |
| 2100 | }, |
| 2101 | } |
| 2102 | |
| 2103 | func TestSplitListForSize(t *testing.T) { |
| 2104 | for _, testCase := range splitListForSizeTestCases { |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 2105 | out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size) |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 2106 | |
| 2107 | var outStrings [][]string |
| 2108 | |
| 2109 | if len(out) > 0 { |
| 2110 | outStrings = make([][]string, len(out)) |
| 2111 | for i, o := range out { |
| 2112 | outStrings[i] = o.Strings() |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | if !reflect.DeepEqual(outStrings, testCase.out) { |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2117 | t.Errorf("incorrect output:") |
| 2118 | t.Errorf(" input: %#v", testCase.in) |
| 2119 | t.Errorf(" size: %d", testCase.size) |
| 2120 | t.Errorf(" expected: %#v", testCase.out) |
Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 2121 | t.Errorf(" got: %#v", outStrings) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2122 | } |
| 2123 | } |
| 2124 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2125 | |
| 2126 | var staticLinkDepOrderTestCases = []struct { |
| 2127 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2128 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2129 | inStatic string |
| 2130 | |
| 2131 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2132 | // It models the dependencies declared in an Android.bp file. |
| 2133 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2134 | |
| 2135 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2136 | // The keys of allOrdered specify which modules we would like to check. |
| 2137 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 2138 | // dependencies) for each module to test |
| 2139 | allOrdered string |
| 2140 | |
| 2141 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2142 | // The keys of outOrdered specify which modules we would like to check. |
| 2143 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 2144 | // for each module to test. |
| 2145 | outOrdered string |
| 2146 | }{ |
| 2147 | // Simple tests |
| 2148 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2149 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2150 | outOrdered: "", |
| 2151 | }, |
| 2152 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2153 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2154 | outOrdered: "a:", |
| 2155 | }, |
| 2156 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2157 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2158 | outOrdered: "a:b; b:", |
| 2159 | }, |
| 2160 | // Tests of reordering |
| 2161 | { |
| 2162 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2163 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2164 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 2165 | }, |
| 2166 | { |
| 2167 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2168 | 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] | 2169 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 2170 | }, |
| 2171 | { |
| 2172 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2173 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2174 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 2175 | }, |
| 2176 | { |
| 2177 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2178 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2179 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 2180 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 2181 | }, |
| 2182 | { |
| 2183 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2184 | 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] | 2185 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2186 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2187 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2188 | // shared dependencies |
| 2189 | { |
| 2190 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 2191 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 2192 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 2193 | // a shared dependency on b, that that shows up in allOrdered. |
| 2194 | inShared: "c:b", |
| 2195 | allOrdered: "c:b", |
| 2196 | outOrdered: "c:", |
| 2197 | }, |
| 2198 | { |
| 2199 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 2200 | // the second phase of the above test would look like |
| 2201 | inStatic: "a:b,c; c:b", |
| 2202 | allOrdered: "a:c,b; c:b", |
| 2203 | outOrdered: "a:c,b; c:b", |
| 2204 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2205 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 2206 | // to dictate an order |
| 2207 | { |
| 2208 | // 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] | 2209 | 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] | 2210 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 2211 | }, |
| 2212 | { |
| 2213 | // 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] | 2214 | 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] | 2215 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 2216 | }, |
| 2217 | // Tests involving duplicate dependencies |
| 2218 | { |
| 2219 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2220 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2221 | outOrdered: "a:c,b", |
| 2222 | }, |
| 2223 | { |
| 2224 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2225 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2226 | outOrdered: "a:d,c,b", |
| 2227 | }, |
| 2228 | // Tests to confirm the nonexistence of infinite loops. |
| 2229 | // These cases should never happen, so as long as the test terminates and the |
| 2230 | // result is deterministic then that should be fine. |
| 2231 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2232 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2233 | outOrdered: "a:a", |
| 2234 | }, |
| 2235 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2236 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2237 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 2238 | outOrdered: "a:b; b:c; c:a", |
| 2239 | }, |
| 2240 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2241 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2242 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 2243 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 2244 | }, |
| 2245 | } |
| 2246 | |
| 2247 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 2248 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 2249 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 2250 | strippedText := strings.Replace(text, " ", "", -1) |
| 2251 | if len(strippedText) < 1 { |
| 2252 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 2253 | } |
| 2254 | allDeps = make(map[android.Path][]android.Path, 0) |
| 2255 | |
| 2256 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 2257 | moduleTexts := strings.Split(strippedText, ";") |
| 2258 | |
| 2259 | outputForModuleName := func(moduleName string) android.Path { |
| 2260 | return android.PathForTesting(moduleName) |
| 2261 | } |
| 2262 | |
| 2263 | for _, moduleText := range moduleTexts { |
| 2264 | // convert from "a:b,c" to ["a", "b,c"] |
| 2265 | components := strings.Split(moduleText, ":") |
| 2266 | if len(components) != 2 { |
| 2267 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 2268 | } |
| 2269 | moduleName := components[0] |
| 2270 | moduleOutput := outputForModuleName(moduleName) |
| 2271 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 2272 | |
| 2273 | depString := components[1] |
| 2274 | // convert from "b,c" to ["b", "c"] |
| 2275 | depNames := strings.Split(depString, ",") |
| 2276 | if len(depString) < 1 { |
| 2277 | depNames = []string{} |
| 2278 | } |
| 2279 | var deps []android.Path |
| 2280 | for _, depName := range depNames { |
| 2281 | deps = append(deps, outputForModuleName(depName)) |
| 2282 | } |
| 2283 | allDeps[moduleOutput] = deps |
| 2284 | } |
| 2285 | return modulesInOrder, allDeps |
| 2286 | } |
| 2287 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2288 | func TestLinkReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2289 | for _, testCase := range staticLinkDepOrderTestCases { |
| 2290 | errs := []string{} |
| 2291 | |
| 2292 | // parse testcase |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2293 | _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2294 | expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered) |
| 2295 | if testCase.allOrdered == "" { |
| 2296 | // allow the test case to skip specifying allOrdered |
| 2297 | testCase.allOrdered = testCase.outOrdered |
| 2298 | } |
| 2299 | _, expectedAllDeps := parseModuleDeps(testCase.allOrdered) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2300 | _, givenAllSharedDeps := parseModuleDeps(testCase.inShared) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2301 | |
| 2302 | // For each module whose post-reordered dependencies were specified, validate that |
| 2303 | // reordering the inputs produces the expected outputs. |
| 2304 | for _, moduleName := range expectedModuleNames { |
| 2305 | moduleDeps := givenTransitiveDeps[moduleName] |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2306 | givenSharedDeps := givenAllSharedDeps[moduleName] |
| 2307 | orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2308 | |
| 2309 | correctAllOrdered := expectedAllDeps[moduleName] |
| 2310 | if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) { |
| 2311 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+ |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2312 | "\nin static:%q"+ |
| 2313 | "\nin shared:%q"+ |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2314 | "\nmodule: %v"+ |
| 2315 | "\nexpected: %s"+ |
| 2316 | "\nactual: %s", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2317 | testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps)) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | correctOutputDeps := expectedTransitiveDeps[moduleName] |
| 2321 | if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) { |
| 2322 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+ |
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, correctOutputDeps, orderedDeclaredDeps)) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | if len(errs) > 0 { |
| 2333 | sort.Strings(errs) |
| 2334 | for _, err := range errs { |
| 2335 | t.Error(err) |
| 2336 | } |
| 2337 | } |
| 2338 | } |
| 2339 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2340 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2341 | func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { |
| 2342 | for _, moduleName := range moduleNames { |
| 2343 | module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) |
| 2344 | output := module.outputFile.Path() |
| 2345 | paths = append(paths, output) |
| 2346 | } |
| 2347 | return paths |
| 2348 | } |
| 2349 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2350 | func TestStaticLibDepReordering(t *testing.T) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2351 | ctx := testCc(t, ` |
| 2352 | cc_library { |
| 2353 | name: "a", |
| 2354 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2355 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2356 | } |
| 2357 | cc_library { |
| 2358 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2359 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2360 | } |
| 2361 | cc_library { |
| 2362 | name: "c", |
| 2363 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2364 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2365 | } |
| 2366 | cc_library { |
| 2367 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2368 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | `) |
| 2372 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2373 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2374 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2375 | actual := moduleA.depsInLinkOrder |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2376 | expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"}) |
| 2377 | |
| 2378 | if !reflect.DeepEqual(actual, expected) { |
| 2379 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2380 | "\nactual: %v"+ |
| 2381 | "\nexpected: %v", |
| 2382 | actual, |
| 2383 | expected, |
| 2384 | ) |
| 2385 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2386 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2387 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2388 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
| 2389 | ctx := testCc(t, ` |
| 2390 | cc_library { |
| 2391 | name: "a", |
| 2392 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2393 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2394 | } |
| 2395 | cc_library { |
| 2396 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2397 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2398 | } |
| 2399 | cc_library { |
| 2400 | name: "c", |
| 2401 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2402 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | `) |
| 2406 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2407 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2408 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
| 2409 | actual := moduleA.depsInLinkOrder |
| 2410 | expected := getOutputPaths(ctx, variant, []string{"c", "b"}) |
| 2411 | |
| 2412 | if !reflect.DeepEqual(actual, expected) { |
| 2413 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 2414 | "\nactual: %v"+ |
| 2415 | "\nexpected: %v", |
| 2416 | actual, |
| 2417 | expected, |
| 2418 | ) |
| 2419 | } |
| 2420 | } |
| 2421 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2422 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { |
| 2423 | if !reflect.DeepEqual(actual, expected) { |
| 2424 | t.Errorf(message+ |
| 2425 | "\nactual: %v"+ |
| 2426 | "\nexpected: %v", |
| 2427 | actual, |
| 2428 | expected, |
| 2429 | ) |
| 2430 | } |
| 2431 | } |
| 2432 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2433 | func TestLlndkLibrary(t *testing.T) { |
| 2434 | ctx := testCc(t, ` |
| 2435 | cc_library { |
| 2436 | name: "libllndk", |
| 2437 | stubs: { versions: ["1", "2"] }, |
| 2438 | } |
| 2439 | llndk_library { |
| 2440 | name: "libllndk", |
| 2441 | } |
| 2442 | `) |
| 2443 | actual := ctx.ModuleVariantsForTests("libllndk.llndk") |
| 2444 | expected := []string{ |
| 2445 | "android_vendor.VER_arm64_armv8-a_shared", |
| 2446 | "android_vendor.VER_arm64_armv8-a_shared_1", |
| 2447 | "android_vendor.VER_arm64_armv8-a_shared_2", |
| 2448 | "android_vendor.VER_arm_armv7-a-neon_shared", |
| 2449 | "android_vendor.VER_arm_armv7-a-neon_shared_1", |
| 2450 | "android_vendor.VER_arm_armv7-a-neon_shared_2", |
| 2451 | } |
| 2452 | checkEquals(t, "variants for llndk stubs", expected, actual) |
| 2453 | |
| 2454 | params := ctx.ModuleForTests("libllndk.llndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub") |
| 2455 | checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"]) |
| 2456 | |
| 2457 | params = ctx.ModuleForTests("libllndk.llndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub") |
| 2458 | checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"]) |
| 2459 | } |
| 2460 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2461 | func TestLlndkHeaders(t *testing.T) { |
| 2462 | ctx := testCc(t, ` |
| 2463 | llndk_headers { |
| 2464 | name: "libllndk_headers", |
| 2465 | export_include_dirs: ["my_include"], |
| 2466 | } |
| 2467 | llndk_library { |
| 2468 | name: "libllndk", |
| 2469 | export_llndk_headers: ["libllndk_headers"], |
| 2470 | } |
| 2471 | cc_library { |
| 2472 | name: "libvendor", |
| 2473 | shared_libs: ["libllndk"], |
| 2474 | vendor: true, |
| 2475 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2476 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2477 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2478 | } |
| 2479 | `) |
| 2480 | |
| 2481 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2482 | 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] | 2483 | cflags := cc.Args["cFlags"] |
| 2484 | if !strings.Contains(cflags, "-Imy_include") { |
| 2485 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 2486 | } |
| 2487 | } |
| 2488 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2489 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 2490 | actual := module.Properties.AndroidMkRuntimeLibs |
| 2491 | if !reflect.DeepEqual(actual, expected) { |
| 2492 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 2493 | "\nactual: %v"+ |
| 2494 | "\nexpected: %v", |
| 2495 | actual, |
| 2496 | expected, |
| 2497 | ) |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | const runtimeLibAndroidBp = ` |
| 2502 | cc_library { |
| 2503 | name: "libvendor_available1", |
| 2504 | vendor_available: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2505 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2506 | nocrt : true, |
| 2507 | system_shared_libs : [], |
| 2508 | } |
| 2509 | cc_library { |
| 2510 | name: "libvendor_available2", |
| 2511 | vendor_available: true, |
| 2512 | runtime_libs: ["libvendor_available1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2513 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2514 | nocrt : true, |
| 2515 | system_shared_libs : [], |
| 2516 | } |
| 2517 | cc_library { |
| 2518 | name: "libvendor_available3", |
| 2519 | vendor_available: true, |
| 2520 | runtime_libs: ["libvendor_available1"], |
| 2521 | target: { |
| 2522 | vendor: { |
| 2523 | exclude_runtime_libs: ["libvendor_available1"], |
| 2524 | } |
| 2525 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2526 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2527 | nocrt : true, |
| 2528 | system_shared_libs : [], |
| 2529 | } |
| 2530 | cc_library { |
| 2531 | name: "libcore", |
| 2532 | runtime_libs: ["libvendor_available1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2533 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2534 | nocrt : true, |
| 2535 | system_shared_libs : [], |
| 2536 | } |
| 2537 | cc_library { |
| 2538 | name: "libvendor1", |
| 2539 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2540 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2541 | nocrt : true, |
| 2542 | system_shared_libs : [], |
| 2543 | } |
| 2544 | cc_library { |
| 2545 | name: "libvendor2", |
| 2546 | vendor: true, |
| 2547 | runtime_libs: ["libvendor_available1", "libvendor1"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2548 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2549 | nocrt : true, |
| 2550 | system_shared_libs : [], |
| 2551 | } |
| 2552 | ` |
| 2553 | |
| 2554 | func TestRuntimeLibs(t *testing.T) { |
| 2555 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2556 | |
| 2557 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2558 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2559 | |
| 2560 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2561 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2562 | |
| 2563 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
| 2564 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2565 | |
| 2566 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 2567 | // and vendor variants. |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2568 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2569 | |
| 2570 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2571 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module) |
| 2572 | |
| 2573 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 2574 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module) |
| 2575 | } |
| 2576 | |
| 2577 | func TestExcludeRuntimeLibs(t *testing.T) { |
| 2578 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2579 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2580 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2581 | module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 2582 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2583 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2584 | variant = "android_vendor.VER_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2585 | module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) |
| 2586 | checkRuntimeLibs(t, nil, module) |
| 2587 | } |
| 2588 | |
| 2589 | func TestRuntimeLibsNoVndk(t *testing.T) { |
| 2590 | ctx := testCcNoVndk(t, runtimeLibAndroidBp) |
| 2591 | |
| 2592 | // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is. |
| 2593 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2594 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2595 | |
| 2596 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2597 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) |
| 2598 | |
| 2599 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
| 2600 | checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module) |
| 2601 | } |
| 2602 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2603 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2604 | t.Helper() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2605 | actual := module.Properties.AndroidMkStaticLibs |
| 2606 | if !reflect.DeepEqual(actual, expected) { |
| 2607 | t.Errorf("incorrect static_libs"+ |
| 2608 | "\nactual: %v"+ |
| 2609 | "\nexpected: %v", |
| 2610 | actual, |
| 2611 | expected, |
| 2612 | ) |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | const staticLibAndroidBp = ` |
| 2617 | cc_library { |
| 2618 | name: "lib1", |
| 2619 | } |
| 2620 | cc_library { |
| 2621 | name: "lib2", |
| 2622 | static_libs: ["lib1"], |
| 2623 | } |
| 2624 | ` |
| 2625 | |
| 2626 | func TestStaticLibDepExport(t *testing.T) { |
| 2627 | ctx := testCc(t, staticLibAndroidBp) |
| 2628 | |
| 2629 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2630 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2631 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2632 | 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] | 2633 | |
| 2634 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2635 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2636 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 2637 | // libc++_static is linked additionally. |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2638 | 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] | 2639 | } |
| 2640 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2641 | var compilerFlagsTestCases = []struct { |
| 2642 | in string |
| 2643 | out bool |
| 2644 | }{ |
| 2645 | { |
| 2646 | in: "a", |
| 2647 | out: false, |
| 2648 | }, |
| 2649 | { |
| 2650 | in: "-a", |
| 2651 | out: true, |
| 2652 | }, |
| 2653 | { |
| 2654 | in: "-Ipath/to/something", |
| 2655 | out: false, |
| 2656 | }, |
| 2657 | { |
| 2658 | in: "-isystempath/to/something", |
| 2659 | out: false, |
| 2660 | }, |
| 2661 | { |
| 2662 | in: "--coverage", |
| 2663 | out: false, |
| 2664 | }, |
| 2665 | { |
| 2666 | in: "-include a/b", |
| 2667 | out: true, |
| 2668 | }, |
| 2669 | { |
| 2670 | in: "-include a/b c/d", |
| 2671 | out: false, |
| 2672 | }, |
| 2673 | { |
| 2674 | in: "-DMACRO", |
| 2675 | out: true, |
| 2676 | }, |
| 2677 | { |
| 2678 | in: "-DMAC RO", |
| 2679 | out: false, |
| 2680 | }, |
| 2681 | { |
| 2682 | in: "-a -b", |
| 2683 | out: false, |
| 2684 | }, |
| 2685 | { |
| 2686 | in: "-DMACRO=definition", |
| 2687 | out: true, |
| 2688 | }, |
| 2689 | { |
| 2690 | in: "-DMACRO=defi nition", |
| 2691 | out: true, // TODO(jiyong): this should be false |
| 2692 | }, |
| 2693 | { |
| 2694 | in: "-DMACRO(x)=x + 1", |
| 2695 | out: true, |
| 2696 | }, |
| 2697 | { |
| 2698 | in: "-DMACRO=\"defi nition\"", |
| 2699 | out: true, |
| 2700 | }, |
| 2701 | } |
| 2702 | |
| 2703 | type mockContext struct { |
| 2704 | BaseModuleContext |
| 2705 | result bool |
| 2706 | } |
| 2707 | |
| 2708 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 2709 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 2710 | ctx.result = false |
| 2711 | } |
| 2712 | |
| 2713 | func TestCompilerFlags(t *testing.T) { |
| 2714 | for _, testCase := range compilerFlagsTestCases { |
| 2715 | ctx := &mockContext{result: true} |
| 2716 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 2717 | if ctx.result != testCase.out { |
| 2718 | t.Errorf("incorrect output:") |
| 2719 | t.Errorf(" input: %#v", testCase.in) |
| 2720 | t.Errorf(" expected: %#v", testCase.out) |
| 2721 | t.Errorf(" got: %#v", ctx.result) |
| 2722 | } |
| 2723 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2724 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2725 | |
| 2726 | func TestVendorPublicLibraries(t *testing.T) { |
| 2727 | ctx := testCc(t, ` |
| 2728 | cc_library_headers { |
| 2729 | name: "libvendorpublic_headers", |
| 2730 | export_include_dirs: ["my_include"], |
| 2731 | } |
| 2732 | vendor_public_library { |
| 2733 | name: "libvendorpublic", |
| 2734 | symbol_file: "", |
| 2735 | export_public_headers: ["libvendorpublic_headers"], |
| 2736 | } |
| 2737 | cc_library { |
| 2738 | name: "libvendorpublic", |
| 2739 | srcs: ["foo.c"], |
| 2740 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2741 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2742 | nocrt: true, |
| 2743 | } |
| 2744 | |
| 2745 | cc_library { |
| 2746 | name: "libsystem", |
| 2747 | shared_libs: ["libvendorpublic"], |
| 2748 | vendor: false, |
| 2749 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2750 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2751 | nocrt: true, |
| 2752 | } |
| 2753 | cc_library { |
| 2754 | name: "libvendor", |
| 2755 | shared_libs: ["libvendorpublic"], |
| 2756 | vendor: true, |
| 2757 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2758 | no_libcrt: true, |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2759 | nocrt: true, |
| 2760 | } |
| 2761 | `) |
| 2762 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2763 | coreVariant := "android_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2764 | vendorVariant := "android_vendor.VER_arm64_armv8-a_shared" |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2765 | |
| 2766 | // test if header search paths are correctly added |
| 2767 | // _static variant is used since _shared reuses *.o from the static variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2768 | cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2769 | cflags := cc.Args["cFlags"] |
| 2770 | if !strings.Contains(cflags, "-Imy_include") { |
| 2771 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) |
| 2772 | } |
| 2773 | |
| 2774 | // test if libsystem is linked to the stub |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2775 | ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2776 | libflags := ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2777 | stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2778 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 2779 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) |
| 2780 | } |
| 2781 | |
| 2782 | // test if libvendor is linked to the real shared lib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2783 | ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2784 | libflags = ld.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2785 | stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2786 | if !strings.Contains(libflags, stubPaths[0].String()) { |
| 2787 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) |
| 2788 | } |
| 2789 | |
| 2790 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2791 | |
| 2792 | func TestRecovery(t *testing.T) { |
| 2793 | ctx := testCc(t, ` |
| 2794 | cc_library_shared { |
| 2795 | name: "librecovery", |
| 2796 | recovery: true, |
| 2797 | } |
| 2798 | cc_library_shared { |
| 2799 | name: "librecovery32", |
| 2800 | recovery: true, |
| 2801 | compile_multilib:"32", |
| 2802 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2803 | cc_library_shared { |
| 2804 | name: "libHalInRecovery", |
| 2805 | recovery_available: true, |
| 2806 | vendor: true, |
| 2807 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2808 | `) |
| 2809 | |
| 2810 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2811 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2812 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 2813 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 2814 | } |
| 2815 | |
| 2816 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 2817 | if android.InList(arm64, variants) { |
| 2818 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 2819 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2820 | |
| 2821 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 2822 | if !recoveryModule.Platform() { |
| 2823 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 2824 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2825 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2826 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2827 | func TestVersionedStubs(t *testing.T) { |
| 2828 | ctx := testCc(t, ` |
| 2829 | cc_library_shared { |
| 2830 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2831 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2832 | stubs: { |
| 2833 | symbol_file: "foo.map.txt", |
| 2834 | versions: ["1", "2", "3"], |
| 2835 | }, |
| 2836 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2837 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2838 | cc_library_shared { |
| 2839 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2840 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2841 | shared_libs: ["libFoo#1"], |
| 2842 | }`) |
| 2843 | |
| 2844 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 2845 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2846 | "android_arm64_armv8-a_shared", |
| 2847 | "android_arm64_armv8-a_shared_1", |
| 2848 | "android_arm64_armv8-a_shared_2", |
| 2849 | "android_arm64_armv8-a_shared_3", |
| 2850 | "android_arm_armv7-a-neon_shared", |
| 2851 | "android_arm_armv7-a-neon_shared_1", |
| 2852 | "android_arm_armv7-a-neon_shared_2", |
| 2853 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2854 | } |
| 2855 | variantsMismatch := false |
| 2856 | if len(variants) != len(expectedVariants) { |
| 2857 | variantsMismatch = true |
| 2858 | } else { |
| 2859 | for _, v := range expectedVariants { |
| 2860 | if !inList(v, variants) { |
| 2861 | variantsMismatch = false |
| 2862 | } |
| 2863 | } |
| 2864 | } |
| 2865 | if variantsMismatch { |
| 2866 | t.Errorf("variants of libFoo expected:\n") |
| 2867 | for _, v := range expectedVariants { |
| 2868 | t.Errorf("%q\n", v) |
| 2869 | } |
| 2870 | t.Errorf(", but got:\n") |
| 2871 | for _, v := range variants { |
| 2872 | t.Errorf("%q\n", v) |
| 2873 | } |
| 2874 | } |
| 2875 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2876 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2877 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2878 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2879 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 2880 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 2881 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2882 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2883 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2884 | cFlags := libBarCompileRule.Args["cFlags"] |
| 2885 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 2886 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 2887 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 2888 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2889 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2890 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2891 | func TestVersioningMacro(t *testing.T) { |
| 2892 | for _, tc := range []struct{ moduleName, expected string }{ |
| 2893 | {"libc", "__LIBC_API__"}, |
| 2894 | {"libfoo", "__LIBFOO_API__"}, |
| 2895 | {"libfoo@1", "__LIBFOO_1_API__"}, |
| 2896 | {"libfoo-v1", "__LIBFOO_V1_API__"}, |
| 2897 | {"libfoo.v1", "__LIBFOO_V1_API__"}, |
| 2898 | } { |
| 2899 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) |
| 2900 | } |
| 2901 | } |
| 2902 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2903 | func TestStaticExecutable(t *testing.T) { |
| 2904 | ctx := testCc(t, ` |
| 2905 | cc_binary { |
| 2906 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 2907 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2908 | static_executable: true, |
| 2909 | }`) |
| 2910 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2911 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2912 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 2913 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 2914 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2915 | for _, lib := range systemStaticLibs { |
| 2916 | if !strings.Contains(libFlags, lib) { |
| 2917 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 2918 | } |
| 2919 | } |
| 2920 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 2921 | for _, lib := range systemSharedLibs { |
| 2922 | if strings.Contains(libFlags, lib) { |
| 2923 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 2924 | } |
| 2925 | } |
| 2926 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2927 | |
| 2928 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
| 2929 | ctx := testCc(t, ` |
| 2930 | cc_binary { |
| 2931 | name: "mybin", |
| 2932 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2933 | static_libs: ["libfooB"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2934 | static_executable: true, |
| 2935 | stl: "none", |
| 2936 | } |
| 2937 | |
| 2938 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2939 | name: "libfooB", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2940 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2941 | shared_libs: ["libfooC"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2942 | stl: "none", |
| 2943 | } |
| 2944 | |
| 2945 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2946 | name: "libfooC", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2947 | srcs: ["foo.c"], |
| 2948 | stl: "none", |
| 2949 | stubs: { |
| 2950 | versions: ["1"], |
| 2951 | }, |
| 2952 | }`) |
| 2953 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2954 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Module().(*Module) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2955 | actual := mybin.depsInLinkOrder |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2956 | expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2957 | |
| 2958 | if !reflect.DeepEqual(actual, expected) { |
| 2959 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2960 | "\nactual: %v"+ |
| 2961 | "\nexpected: %v", |
| 2962 | actual, |
| 2963 | expected, |
| 2964 | ) |
| 2965 | } |
| 2966 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2967 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2968 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
| 2969 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 2970 | cc_library { |
| 2971 | name: "libA", |
| 2972 | srcs: ["foo.c"], |
| 2973 | shared_libs: ["libB"], |
| 2974 | stl: "none", |
| 2975 | } |
| 2976 | |
| 2977 | cc_library { |
| 2978 | name: "libB", |
| 2979 | srcs: ["foo.c"], |
| 2980 | enabled: false, |
| 2981 | stl: "none", |
| 2982 | } |
| 2983 | `) |
| 2984 | } |
| 2985 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 2986 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 2987 | // correctly. |
| 2988 | func TestFuzzTarget(t *testing.T) { |
| 2989 | ctx := testCc(t, ` |
| 2990 | cc_fuzz { |
| 2991 | name: "fuzz_smoke_test", |
| 2992 | srcs: ["foo.c"], |
| 2993 | }`) |
| 2994 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 2995 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 2996 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 2997 | } |
| 2998 | |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 2999 | func TestAidl(t *testing.T) { |
| 3000 | } |
| 3001 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3002 | func assertString(t *testing.T, got, expected string) { |
| 3003 | t.Helper() |
| 3004 | if got != expected { |
| 3005 | t.Errorf("expected %q got %q", expected, got) |
| 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | func assertArrayString(t *testing.T, got, expected []string) { |
| 3010 | t.Helper() |
| 3011 | if len(got) != len(expected) { |
| 3012 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 3013 | return |
| 3014 | } |
| 3015 | for i := range got { |
| 3016 | if got[i] != expected[i] { |
| 3017 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 3018 | i, expected[i], expected, got[i], got) |
| 3019 | return |
| 3020 | } |
| 3021 | } |
| 3022 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3023 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3024 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 3025 | t.Helper() |
| 3026 | assertArrayString(t, android.SortedStringKeys(m), expected) |
| 3027 | } |
| 3028 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3029 | func TestDefaults(t *testing.T) { |
| 3030 | ctx := testCc(t, ` |
| 3031 | cc_defaults { |
| 3032 | name: "defaults", |
| 3033 | srcs: ["foo.c"], |
| 3034 | static: { |
| 3035 | srcs: ["bar.c"], |
| 3036 | }, |
| 3037 | shared: { |
| 3038 | srcs: ["baz.c"], |
| 3039 | }, |
| 3040 | } |
| 3041 | |
| 3042 | cc_library_static { |
| 3043 | name: "libstatic", |
| 3044 | defaults: ["defaults"], |
| 3045 | } |
| 3046 | |
| 3047 | cc_library_shared { |
| 3048 | name: "libshared", |
| 3049 | defaults: ["defaults"], |
| 3050 | } |
| 3051 | |
| 3052 | cc_library { |
| 3053 | name: "libboth", |
| 3054 | defaults: ["defaults"], |
| 3055 | } |
| 3056 | |
| 3057 | cc_binary { |
| 3058 | name: "binary", |
| 3059 | defaults: ["defaults"], |
| 3060 | }`) |
| 3061 | |
| 3062 | pathsToBase := func(paths android.Paths) []string { |
| 3063 | var ret []string |
| 3064 | for _, p := range paths { |
| 3065 | ret = append(ret, p.Base()) |
| 3066 | } |
| 3067 | return ret |
| 3068 | } |
| 3069 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3070 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3071 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3072 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 3073 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3074 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3075 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3076 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 3077 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3078 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3079 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 3080 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 3081 | } |
| 3082 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3083 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3084 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3085 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 3086 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3087 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3088 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3089 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 3090 | } |
| 3091 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3092 | |
| 3093 | func TestProductVariableDefaults(t *testing.T) { |
| 3094 | bp := ` |
| 3095 | cc_defaults { |
| 3096 | name: "libfoo_defaults", |
| 3097 | srcs: ["foo.c"], |
| 3098 | cppflags: ["-DFOO"], |
| 3099 | product_variables: { |
| 3100 | debuggable: { |
| 3101 | cppflags: ["-DBAR"], |
| 3102 | }, |
| 3103 | }, |
| 3104 | } |
| 3105 | |
| 3106 | cc_library { |
| 3107 | name: "libfoo", |
| 3108 | defaults: ["libfoo_defaults"], |
| 3109 | } |
| 3110 | ` |
| 3111 | |
| 3112 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 3113 | config.TestProductVariables.Debuggable = BoolPtr(true) |
| 3114 | |
| 3115 | ctx := CreateTestContext() |
| 3116 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 3117 | ctx.BottomUp("variable", android.VariableMutator).Parallel() |
| 3118 | }) |
| 3119 | ctx.Register(config) |
| 3120 | |
| 3121 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 3122 | android.FailIfErrored(t, errs) |
| 3123 | _, errs = ctx.PrepareBuildActions(config) |
| 3124 | android.FailIfErrored(t, errs) |
| 3125 | |
| 3126 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) |
| 3127 | if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) { |
| 3128 | t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags) |
| 3129 | } |
| 3130 | } |