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