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