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