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