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", |
| 337 | vendor_available: false, |
| 338 | vndk: { |
| 339 | enabled: true, |
| 340 | }, |
| 341 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 342 | stem: "libvndk-private", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 346 | name: "libvndk_product", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 347 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 348 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 349 | vndk: { |
| 350 | enabled: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 351 | }, |
| 352 | nocrt: true, |
| 353 | target: { |
| 354 | vendor: { |
| 355 | cflags: ["-DTEST"], |
| 356 | }, |
| 357 | product: { |
| 358 | cflags: ["-DTEST"], |
| 359 | }, |
| 360 | }, |
| 361 | } |
| 362 | |
| 363 | cc_library { |
| 364 | name: "libvndk_sp", |
| 365 | vendor_available: true, |
| 366 | vndk: { |
| 367 | enabled: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 368 | support_system_process: true, |
| 369 | }, |
| 370 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 371 | suffix: "-x", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | cc_library { |
| 375 | name: "libvndk_sp_private", |
| 376 | vendor_available: false, |
| 377 | vndk: { |
| 378 | enabled: true, |
| 379 | support_system_process: true, |
| 380 | }, |
| 381 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 382 | target: { |
| 383 | vendor: { |
| 384 | suffix: "-x", |
| 385 | }, |
| 386 | }, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 387 | } |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 388 | |
| 389 | cc_library { |
| 390 | name: "libvndk_sp_product_private", |
| 391 | vendor_available: false, |
| 392 | product_available: false, |
| 393 | vndk: { |
| 394 | enabled: true, |
| 395 | support_system_process: true, |
| 396 | }, |
| 397 | nocrt: true, |
| 398 | target: { |
| 399 | vendor: { |
| 400 | suffix: "-x", |
| 401 | }, |
| 402 | product: { |
| 403 | suffix: "-x", |
| 404 | }, |
| 405 | }, |
| 406 | } |
| 407 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 408 | vndk_libraries_txt { |
| 409 | name: "llndk.libraries.txt", |
| 410 | } |
| 411 | vndk_libraries_txt { |
| 412 | name: "vndkcore.libraries.txt", |
| 413 | } |
| 414 | vndk_libraries_txt { |
| 415 | name: "vndksp.libraries.txt", |
| 416 | } |
| 417 | vndk_libraries_txt { |
| 418 | name: "vndkprivate.libraries.txt", |
| 419 | } |
| 420 | vndk_libraries_txt { |
| 421 | name: "vndkcorevariant.libraries.txt", |
| 422 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 423 | ` |
| 424 | |
| 425 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 426 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 427 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 428 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 429 | |
| 430 | ctx := testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 431 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 432 | // subdir == "" because VNDK libs are not supposed to be installed separately. |
| 433 | // They are installed as part of VNDK APEX instead. |
| 434 | checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant) |
| 435 | checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 436 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant) |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 437 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant) |
| 438 | checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 439 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 440 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 441 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant) |
| 442 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 443 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 444 | // Check VNDK snapshot output. |
| 445 | |
| 446 | snapshotDir := "vndk-snapshot" |
| 447 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 448 | |
| 449 | vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 450 | "arm64", "armv8-a")) |
| 451 | vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 452 | "arm", "armv7-a-neon")) |
| 453 | |
| 454 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") |
| 455 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") |
| 456 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") |
| 457 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") |
| 458 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 459 | variant := "android_vendor.VER_arm64_armv8-a_shared" |
| 460 | variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 461 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 462 | snapshotSingleton := ctx.SingletonForTests("vndk-snapshot") |
| 463 | |
| 464 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant) |
| 465 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 466 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant) |
| 467 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 468 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) |
| 469 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 470 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 471 | snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 472 | checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "") |
| 473 | checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "") |
| 474 | checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "") |
| 475 | checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "") |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 476 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 477 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 478 | "LLNDK: libc.so", |
| 479 | "LLNDK: libdl.so", |
| 480 | "LLNDK: libft2.so", |
| 481 | "LLNDK: libm.so", |
| 482 | "VNDK-SP: libc++.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 483 | "VNDK-SP: libvndk_sp-x.so", |
| 484 | "VNDK-SP: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 485 | "VNDK-SP: libvndk_sp_product_private-x.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 486 | "VNDK-core: libvndk-private.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 487 | "VNDK-core: libvndk.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 488 | "VNDK-core: libvndk_product.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 489 | "VNDK-private: libft2.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 490 | "VNDK-private: libvndk-private.so", |
| 491 | "VNDK-private: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 492 | "VNDK-private: libvndk_sp_product_private-x.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 493 | }) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 494 | 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^] | 495 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"}) |
| 496 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"}) |
| 497 | 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] | 498 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) |
| 499 | } |
| 500 | |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 501 | func TestVndkWithHostSupported(t *testing.T) { |
| 502 | ctx := testCc(t, ` |
| 503 | cc_library { |
| 504 | name: "libvndk_host_supported", |
| 505 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 506 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 507 | vndk: { |
| 508 | enabled: true, |
| 509 | }, |
| 510 | host_supported: true, |
| 511 | } |
| 512 | |
| 513 | cc_library { |
| 514 | name: "libvndk_host_supported_but_disabled_on_device", |
| 515 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 516 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 517 | vndk: { |
| 518 | enabled: true, |
| 519 | }, |
| 520 | host_supported: true, |
| 521 | enabled: false, |
| 522 | target: { |
| 523 | host: { |
| 524 | enabled: true, |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | vndk_libraries_txt { |
| 530 | name: "vndkcore.libraries.txt", |
| 531 | } |
| 532 | `) |
| 533 | |
| 534 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"}) |
| 535 | } |
| 536 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 537 | func TestVndkLibrariesTxtAndroidMk(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 538 | bp := ` |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 539 | vndk_libraries_txt { |
| 540 | name: "llndk.libraries.txt", |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 541 | }` |
| 542 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 543 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 544 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 545 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 546 | |
| 547 | module := ctx.ModuleForTests("llndk.libraries.txt", "") |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 548 | entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0] |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 549 | assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"}) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | func TestVndkUsingCoreVariant(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 553 | bp := ` |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 554 | cc_library { |
| 555 | name: "libvndk", |
| 556 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 557 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 558 | vndk: { |
| 559 | enabled: true, |
| 560 | }, |
| 561 | nocrt: true, |
| 562 | } |
| 563 | |
| 564 | cc_library { |
| 565 | name: "libvndk_sp", |
| 566 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 567 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 568 | vndk: { |
| 569 | enabled: true, |
| 570 | support_system_process: true, |
| 571 | }, |
| 572 | nocrt: true, |
| 573 | } |
| 574 | |
| 575 | cc_library { |
| 576 | name: "libvndk2", |
| 577 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 578 | product_available: false, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 579 | vndk: { |
| 580 | enabled: true, |
| 581 | }, |
| 582 | nocrt: true, |
| 583 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 584 | |
| 585 | vndk_libraries_txt { |
| 586 | name: "vndkcorevariant.libraries.txt", |
| 587 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 588 | ` |
| 589 | |
| 590 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 591 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 592 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 593 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 594 | |
| 595 | setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"}) |
| 596 | |
| 597 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 598 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 599 | 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] | 600 | } |
| 601 | |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 602 | func TestDataLibs(t *testing.T) { |
| 603 | bp := ` |
| 604 | cc_test_library { |
| 605 | name: "test_lib", |
| 606 | srcs: ["test_lib.cpp"], |
| 607 | gtest: false, |
| 608 | } |
| 609 | |
| 610 | cc_test { |
| 611 | name: "main_test", |
| 612 | data_libs: ["test_lib"], |
| 613 | gtest: false, |
| 614 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 615 | ` |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 616 | |
| 617 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 618 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 619 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 620 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 621 | |
| 622 | ctx := testCcWithConfig(t, config) |
| 623 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 624 | testBinary := module.(*Module).linker.(*testBinary) |
| 625 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 626 | if err != nil { |
| 627 | t.Errorf("Expected cc_test to produce output files, error: %s", err) |
| 628 | return |
| 629 | } |
| 630 | if len(outputFiles) != 1 { |
| 631 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 632 | return |
| 633 | } |
| 634 | if len(testBinary.dataPaths()) != 1 { |
| 635 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 636 | return |
| 637 | } |
| 638 | |
| 639 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 640 | testBinaryPath := testBinary.dataPaths()[0].SrcPath.String() |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 641 | |
| 642 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 643 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 644 | return |
| 645 | } |
| 646 | if !strings.HasSuffix(testBinaryPath, "/test_lib.so") { |
| 647 | t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath) |
| 648 | return |
| 649 | } |
| 650 | } |
| 651 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 652 | func TestDataLibsRelativeInstallPath(t *testing.T) { |
| 653 | bp := ` |
| 654 | cc_test_library { |
| 655 | name: "test_lib", |
| 656 | srcs: ["test_lib.cpp"], |
| 657 | relative_install_path: "foo/bar/baz", |
| 658 | gtest: false, |
| 659 | } |
| 660 | |
| 661 | cc_test { |
| 662 | name: "main_test", |
| 663 | data_libs: ["test_lib"], |
| 664 | gtest: false, |
| 665 | } |
| 666 | ` |
| 667 | |
| 668 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 669 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 670 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 671 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 672 | |
| 673 | ctx := testCcWithConfig(t, config) |
| 674 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 675 | testBinary := module.(*Module).linker.(*testBinary) |
| 676 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 677 | if err != nil { |
| 678 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 679 | } |
| 680 | if len(outputFiles) != 1 { |
| 681 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 682 | } |
| 683 | if len(testBinary.dataPaths()) != 1 { |
| 684 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 685 | } |
| 686 | |
| 687 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 688 | |
| 689 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 690 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 691 | } |
| 692 | entries := android.AndroidMkEntriesForTest(t, config, "", module)[0] |
| 693 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 694 | 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] | 695 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 699 | func TestVndkWhenVndkVersionIsNotSet(t *testing.T) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 700 | ctx := testCcNoVndk(t, ` |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 701 | cc_library { |
| 702 | name: "libvndk", |
| 703 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 704 | product_available: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 705 | vndk: { |
| 706 | enabled: true, |
| 707 | }, |
| 708 | nocrt: true, |
| 709 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 710 | `) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 711 | |
| 712 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 713 | "LLNDK: libc.so", |
| 714 | "LLNDK: libdl.so", |
| 715 | "LLNDK: libft2.so", |
| 716 | "LLNDK: libm.so", |
| 717 | "VNDK-SP: libc++.so", |
| 718 | "VNDK-core: libvndk.so", |
| 719 | "VNDK-private: libft2.so", |
| 720 | }) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 721 | } |
| 722 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 723 | func TestVndkModuleError(t *testing.T) { |
| 724 | // Check the error message for vendor_available and product_available properties. |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 725 | testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", ` |
| 726 | cc_library { |
| 727 | name: "libvndk", |
| 728 | vndk: { |
| 729 | enabled: true, |
| 730 | }, |
| 731 | nocrt: true, |
| 732 | } |
| 733 | `) |
| 734 | |
| 735 | testCcErrorProductVndk(t, "vndk: vendor_available must be set to either true or false when `vndk: {enabled: true}`", ` |
| 736 | cc_library { |
| 737 | name: "libvndk", |
| 738 | product_available: true, |
| 739 | vndk: { |
| 740 | enabled: true, |
| 741 | }, |
| 742 | nocrt: true, |
| 743 | } |
| 744 | `) |
| 745 | |
| 746 | testCcErrorProductVndk(t, "product_available: may not have different value than `vendor_available` for a VNDK", ` |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 747 | cc_library { |
| 748 | name: "libvndk", |
| 749 | vendor_available: true, |
| 750 | product_available: false, |
| 751 | vndk: { |
| 752 | enabled: true, |
| 753 | }, |
| 754 | nocrt: true, |
| 755 | } |
| 756 | `) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 757 | |
| 758 | testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", ` |
| 759 | cc_library { |
| 760 | name: "libvndkprop", |
| 761 | vendor_available: true, |
| 762 | product_available: true, |
| 763 | vndk: { |
| 764 | enabled: true, |
| 765 | }, |
| 766 | nocrt: true, |
| 767 | target: { |
| 768 | vendor: { |
| 769 | cflags: ["-DTEST",], |
| 770 | }, |
| 771 | }, |
| 772 | } |
| 773 | `) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 774 | } |
| 775 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 776 | func TestVndkDepError(t *testing.T) { |
| 777 | // Check whether an error is emitted when a VNDK lib depends on a system lib. |
| 778 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 779 | cc_library { |
| 780 | name: "libvndk", |
| 781 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 782 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 783 | vndk: { |
| 784 | enabled: true, |
| 785 | }, |
| 786 | shared_libs: ["libfwk"], // Cause error |
| 787 | nocrt: true, |
| 788 | } |
| 789 | |
| 790 | cc_library { |
| 791 | name: "libfwk", |
| 792 | nocrt: true, |
| 793 | } |
| 794 | `) |
| 795 | |
| 796 | // Check whether an error is emitted when a VNDK lib depends on a vendor lib. |
| 797 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 798 | cc_library { |
| 799 | name: "libvndk", |
| 800 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 801 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 802 | vndk: { |
| 803 | enabled: true, |
| 804 | }, |
| 805 | shared_libs: ["libvendor"], // Cause error |
| 806 | nocrt: true, |
| 807 | } |
| 808 | |
| 809 | cc_library { |
| 810 | name: "libvendor", |
| 811 | vendor: true, |
| 812 | nocrt: true, |
| 813 | } |
| 814 | `) |
| 815 | |
| 816 | // Check whether an error is emitted when a VNDK-SP lib depends on a system lib. |
| 817 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 818 | cc_library { |
| 819 | name: "libvndk_sp", |
| 820 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 821 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 822 | vndk: { |
| 823 | enabled: true, |
| 824 | support_system_process: true, |
| 825 | }, |
| 826 | shared_libs: ["libfwk"], // Cause error |
| 827 | nocrt: true, |
| 828 | } |
| 829 | |
| 830 | cc_library { |
| 831 | name: "libfwk", |
| 832 | nocrt: true, |
| 833 | } |
| 834 | `) |
| 835 | |
| 836 | // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib. |
| 837 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 838 | cc_library { |
| 839 | name: "libvndk_sp", |
| 840 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 841 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 842 | vndk: { |
| 843 | enabled: true, |
| 844 | support_system_process: true, |
| 845 | }, |
| 846 | shared_libs: ["libvendor"], // Cause error |
| 847 | nocrt: true, |
| 848 | } |
| 849 | |
| 850 | cc_library { |
| 851 | name: "libvendor", |
| 852 | vendor: true, |
| 853 | nocrt: true, |
| 854 | } |
| 855 | `) |
| 856 | |
| 857 | // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib. |
| 858 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 859 | cc_library { |
| 860 | name: "libvndk_sp", |
| 861 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 862 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 863 | vndk: { |
| 864 | enabled: true, |
| 865 | support_system_process: true, |
| 866 | }, |
| 867 | shared_libs: ["libvndk"], // Cause error |
| 868 | nocrt: true, |
| 869 | } |
| 870 | |
| 871 | cc_library { |
| 872 | name: "libvndk", |
| 873 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 874 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 875 | vndk: { |
| 876 | enabled: true, |
| 877 | }, |
| 878 | nocrt: true, |
| 879 | } |
| 880 | `) |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 881 | |
| 882 | // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib. |
| 883 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 884 | cc_library { |
| 885 | name: "libvndk", |
| 886 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 887 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 888 | vndk: { |
| 889 | enabled: true, |
| 890 | }, |
| 891 | shared_libs: ["libnonvndk"], |
| 892 | nocrt: true, |
| 893 | } |
| 894 | |
| 895 | cc_library { |
| 896 | name: "libnonvndk", |
| 897 | vendor_available: true, |
| 898 | nocrt: true, |
| 899 | } |
| 900 | `) |
| 901 | |
| 902 | // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib. |
| 903 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 904 | cc_library { |
| 905 | name: "libvndkprivate", |
| 906 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 907 | product_available: false, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 908 | vndk: { |
| 909 | enabled: true, |
| 910 | }, |
| 911 | shared_libs: ["libnonvndk"], |
| 912 | nocrt: true, |
| 913 | } |
| 914 | |
| 915 | cc_library { |
| 916 | name: "libnonvndk", |
| 917 | vendor_available: true, |
| 918 | nocrt: true, |
| 919 | } |
| 920 | `) |
| 921 | |
| 922 | // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib. |
| 923 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 924 | cc_library { |
| 925 | name: "libvndksp", |
| 926 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 927 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 928 | vndk: { |
| 929 | enabled: true, |
| 930 | support_system_process: true, |
| 931 | }, |
| 932 | shared_libs: ["libnonvndk"], |
| 933 | nocrt: true, |
| 934 | } |
| 935 | |
| 936 | cc_library { |
| 937 | name: "libnonvndk", |
| 938 | vendor_available: true, |
| 939 | nocrt: true, |
| 940 | } |
| 941 | `) |
| 942 | |
| 943 | // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib. |
| 944 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 945 | cc_library { |
| 946 | name: "libvndkspprivate", |
| 947 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 948 | product_available: false, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 949 | vndk: { |
| 950 | enabled: true, |
| 951 | support_system_process: true, |
| 952 | }, |
| 953 | shared_libs: ["libnonvndk"], |
| 954 | nocrt: true, |
| 955 | } |
| 956 | |
| 957 | cc_library { |
| 958 | name: "libnonvndk", |
| 959 | vendor_available: true, |
| 960 | nocrt: true, |
| 961 | } |
| 962 | `) |
| 963 | } |
| 964 | |
| 965 | func TestDoubleLoadbleDep(t *testing.T) { |
| 966 | // okay to link : LLNDK -> double_loadable VNDK |
| 967 | testCc(t, ` |
| 968 | cc_library { |
| 969 | name: "libllndk", |
| 970 | shared_libs: ["libdoubleloadable"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 971 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 975 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 976 | symbol_file: "", |
| 977 | } |
| 978 | |
| 979 | cc_library { |
| 980 | name: "libdoubleloadable", |
| 981 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 982 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 983 | vndk: { |
| 984 | enabled: true, |
| 985 | }, |
| 986 | double_loadable: true, |
| 987 | } |
| 988 | `) |
| 989 | // okay to link : LLNDK -> VNDK-SP |
| 990 | testCc(t, ` |
| 991 | cc_library { |
| 992 | name: "libllndk", |
| 993 | shared_libs: ["libvndksp"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 994 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 998 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 999 | symbol_file: "", |
| 1000 | } |
| 1001 | |
| 1002 | cc_library { |
| 1003 | name: "libvndksp", |
| 1004 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1005 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1006 | vndk: { |
| 1007 | enabled: true, |
| 1008 | support_system_process: true, |
| 1009 | }, |
| 1010 | } |
| 1011 | `) |
| 1012 | // okay to link : double_loadable -> double_loadable |
| 1013 | testCc(t, ` |
| 1014 | cc_library { |
| 1015 | name: "libdoubleloadable1", |
| 1016 | shared_libs: ["libdoubleloadable2"], |
| 1017 | vendor_available: true, |
| 1018 | double_loadable: true, |
| 1019 | } |
| 1020 | |
| 1021 | cc_library { |
| 1022 | name: "libdoubleloadable2", |
| 1023 | vendor_available: true, |
| 1024 | double_loadable: true, |
| 1025 | } |
| 1026 | `) |
| 1027 | // okay to link : double_loadable VNDK -> double_loadable VNDK private |
| 1028 | testCc(t, ` |
| 1029 | cc_library { |
| 1030 | name: "libdoubleloadable", |
| 1031 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1032 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1033 | vndk: { |
| 1034 | enabled: true, |
| 1035 | }, |
| 1036 | double_loadable: true, |
| 1037 | shared_libs: ["libnondoubleloadable"], |
| 1038 | } |
| 1039 | |
| 1040 | cc_library { |
| 1041 | name: "libnondoubleloadable", |
| 1042 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1043 | product_available: false, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1044 | vndk: { |
| 1045 | enabled: true, |
| 1046 | }, |
| 1047 | double_loadable: true, |
| 1048 | } |
| 1049 | `) |
| 1050 | // okay to link : LLNDK -> core-only -> vendor_available & double_loadable |
| 1051 | testCc(t, ` |
| 1052 | cc_library { |
| 1053 | name: "libllndk", |
| 1054 | shared_libs: ["libcoreonly"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1055 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1059 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1060 | symbol_file: "", |
| 1061 | } |
| 1062 | |
| 1063 | cc_library { |
| 1064 | name: "libcoreonly", |
| 1065 | shared_libs: ["libvendoravailable"], |
| 1066 | } |
| 1067 | |
| 1068 | // indirect dependency of LLNDK |
| 1069 | cc_library { |
| 1070 | name: "libvendoravailable", |
| 1071 | vendor_available: true, |
| 1072 | double_loadable: true, |
| 1073 | } |
| 1074 | `) |
| 1075 | } |
| 1076 | |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1077 | func TestVendorSnapshotCapture(t *testing.T) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1078 | bp := ` |
| 1079 | cc_library { |
| 1080 | name: "libvndk", |
| 1081 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1082 | product_available: true, |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1083 | vndk: { |
| 1084 | enabled: true, |
| 1085 | }, |
| 1086 | nocrt: true, |
| 1087 | } |
| 1088 | |
| 1089 | cc_library { |
| 1090 | name: "libvendor", |
| 1091 | vendor: true, |
| 1092 | nocrt: true, |
| 1093 | } |
| 1094 | |
| 1095 | cc_library { |
| 1096 | name: "libvendor_available", |
| 1097 | vendor_available: true, |
| 1098 | nocrt: true, |
| 1099 | } |
| 1100 | |
| 1101 | cc_library_headers { |
| 1102 | name: "libvendor_headers", |
| 1103 | vendor_available: true, |
| 1104 | nocrt: true, |
| 1105 | } |
| 1106 | |
| 1107 | cc_binary { |
| 1108 | name: "vendor_bin", |
| 1109 | vendor: true, |
| 1110 | nocrt: true, |
| 1111 | } |
| 1112 | |
| 1113 | cc_binary { |
| 1114 | name: "vendor_available_bin", |
| 1115 | vendor_available: true, |
| 1116 | nocrt: true, |
| 1117 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1118 | |
| 1119 | toolchain_library { |
| 1120 | name: "libb", |
| 1121 | vendor_available: true, |
| 1122 | src: "libb.a", |
| 1123 | } |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 1124 | |
| 1125 | cc_object { |
| 1126 | name: "obj", |
| 1127 | vendor_available: true, |
| 1128 | } |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1129 | |
| 1130 | cc_library { |
| 1131 | name: "libllndk", |
| 1132 | llndk_stubs: "libllndk.llndk", |
| 1133 | } |
| 1134 | |
| 1135 | llndk_library { |
| 1136 | name: "libllndk.llndk", |
| 1137 | symbol_file: "", |
| 1138 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1139 | ` |
| 1140 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1141 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1142 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1143 | ctx := testCcWithConfig(t, config) |
| 1144 | |
| 1145 | // Check Vendor snapshot output. |
| 1146 | |
| 1147 | snapshotDir := "vendor-snapshot" |
| 1148 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1149 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 1150 | |
| 1151 | var jsonFiles []string |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1152 | |
| 1153 | for _, arch := range [][]string{ |
| 1154 | []string{"arm64", "armv8-a"}, |
| 1155 | []string{"arm", "armv7-a-neon"}, |
| 1156 | } { |
| 1157 | archType := arch[0] |
| 1158 | archVariant := arch[1] |
| 1159 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1160 | |
| 1161 | // For shared libraries, only non-VNDK vendor_available modules are captured |
| 1162 | sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) |
| 1163 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1164 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 1165 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) |
| 1166 | jsonFiles = append(jsonFiles, |
| 1167 | filepath.Join(sharedDir, "libvendor.so.json"), |
| 1168 | filepath.Join(sharedDir, "libvendor_available.so.json")) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1169 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1170 | // LLNDK modules are not captured |
| 1171 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant) |
| 1172 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1173 | // 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] | 1174 | // Also cfi variants are captured, except for prebuilts like toolchain_library |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1175 | staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1176 | staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1177 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1178 | checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) |
| 1179 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1180 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1181 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1182 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1183 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1184 | checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1185 | jsonFiles = append(jsonFiles, |
| 1186 | filepath.Join(staticDir, "libb.a.json"), |
| 1187 | filepath.Join(staticDir, "libvndk.a.json"), |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1188 | filepath.Join(staticDir, "libvndk.cfi.a.json"), |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1189 | filepath.Join(staticDir, "libvendor.a.json"), |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1190 | filepath.Join(staticDir, "libvendor.cfi.a.json"), |
| 1191 | filepath.Join(staticDir, "libvendor_available.a.json"), |
| 1192 | filepath.Join(staticDir, "libvendor_available.cfi.a.json")) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1193 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1194 | // For binary executables, all vendor:true and vendor_available modules are captured. |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1195 | if archType == "arm64" { |
| 1196 | binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) |
| 1197 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1198 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant) |
| 1199 | checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) |
| 1200 | jsonFiles = append(jsonFiles, |
| 1201 | filepath.Join(binaryDir, "vendor_bin.json"), |
| 1202 | filepath.Join(binaryDir, "vendor_available_bin.json")) |
| 1203 | } |
| 1204 | |
| 1205 | // For header libraries, all vendor:true and vendor_available modules are captured. |
| 1206 | headerDir := filepath.Join(snapshotVariantPath, archDir, "header") |
| 1207 | jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json")) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 1208 | |
| 1209 | // For object modules, all vendor:true and vendor_available modules are captured. |
| 1210 | objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) |
| 1211 | objectDir := filepath.Join(snapshotVariantPath, archDir, "object") |
| 1212 | checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) |
| 1213 | jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | for _, jsonFile := range jsonFiles { |
| 1217 | // verify all json files exist |
| 1218 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1219 | t.Errorf("%q expected but not found", jsonFile) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1224 | func TestVendorSnapshotUse(t *testing.T) { |
| 1225 | frameworkBp := ` |
| 1226 | cc_library { |
| 1227 | name: "libvndk", |
| 1228 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1229 | product_available: true, |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1230 | vndk: { |
| 1231 | enabled: true, |
| 1232 | }, |
| 1233 | nocrt: true, |
| 1234 | compile_multilib: "64", |
| 1235 | } |
| 1236 | |
| 1237 | cc_library { |
| 1238 | name: "libvendor", |
| 1239 | vendor: true, |
| 1240 | nocrt: true, |
| 1241 | no_libcrt: true, |
| 1242 | stl: "none", |
| 1243 | system_shared_libs: [], |
| 1244 | compile_multilib: "64", |
| 1245 | } |
| 1246 | |
| 1247 | cc_binary { |
| 1248 | name: "bin", |
| 1249 | vendor: true, |
| 1250 | nocrt: true, |
| 1251 | no_libcrt: true, |
| 1252 | stl: "none", |
| 1253 | system_shared_libs: [], |
| 1254 | compile_multilib: "64", |
| 1255 | } |
| 1256 | ` |
| 1257 | |
| 1258 | vndkBp := ` |
| 1259 | vndk_prebuilt_shared { |
| 1260 | name: "libvndk", |
| 1261 | version: "BOARD", |
| 1262 | target_arch: "arm64", |
| 1263 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1264 | product_available: true, |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1265 | vndk: { |
| 1266 | enabled: true, |
| 1267 | }, |
| 1268 | arch: { |
| 1269 | arm64: { |
| 1270 | srcs: ["libvndk.so"], |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1271 | export_include_dirs: ["include/libvndk"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1272 | }, |
| 1273 | }, |
| 1274 | } |
| 1275 | ` |
| 1276 | |
| 1277 | vendorProprietaryBp := ` |
| 1278 | cc_library { |
| 1279 | name: "libvendor_without_snapshot", |
| 1280 | vendor: true, |
| 1281 | nocrt: true, |
| 1282 | no_libcrt: true, |
| 1283 | stl: "none", |
| 1284 | system_shared_libs: [], |
| 1285 | compile_multilib: "64", |
| 1286 | } |
| 1287 | |
| 1288 | cc_library_shared { |
| 1289 | name: "libclient", |
| 1290 | vendor: true, |
| 1291 | nocrt: true, |
| 1292 | no_libcrt: true, |
| 1293 | stl: "none", |
| 1294 | system_shared_libs: [], |
| 1295 | shared_libs: ["libvndk"], |
| 1296 | static_libs: ["libvendor", "libvendor_without_snapshot"], |
| 1297 | compile_multilib: "64", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1298 | srcs: ["client.cpp"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | cc_binary { |
| 1302 | name: "bin_without_snapshot", |
| 1303 | vendor: true, |
| 1304 | nocrt: true, |
| 1305 | no_libcrt: true, |
| 1306 | stl: "none", |
| 1307 | system_shared_libs: [], |
| 1308 | static_libs: ["libvndk"], |
| 1309 | compile_multilib: "64", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1310 | srcs: ["bin.cpp"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | vendor_snapshot_static { |
| 1314 | name: "libvndk", |
| 1315 | version: "BOARD", |
| 1316 | target_arch: "arm64", |
| 1317 | vendor: true, |
| 1318 | arch: { |
| 1319 | arm64: { |
| 1320 | src: "libvndk.a", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1321 | export_include_dirs: ["include/libvndk"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1322 | }, |
| 1323 | }, |
| 1324 | } |
| 1325 | |
| 1326 | vendor_snapshot_shared { |
| 1327 | name: "libvendor", |
| 1328 | version: "BOARD", |
| 1329 | target_arch: "arm64", |
| 1330 | vendor: true, |
| 1331 | arch: { |
| 1332 | arm64: { |
| 1333 | src: "libvendor.so", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1334 | export_include_dirs: ["include/libvendor"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1335 | }, |
| 1336 | }, |
| 1337 | } |
| 1338 | |
| 1339 | vendor_snapshot_static { |
| 1340 | name: "libvendor", |
| 1341 | version: "BOARD", |
| 1342 | target_arch: "arm64", |
| 1343 | vendor: true, |
| 1344 | arch: { |
| 1345 | arm64: { |
| 1346 | src: "libvendor.a", |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1347 | export_include_dirs: ["include/libvendor"], |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1348 | }, |
| 1349 | }, |
| 1350 | } |
| 1351 | |
| 1352 | vendor_snapshot_binary { |
| 1353 | name: "bin", |
| 1354 | version: "BOARD", |
| 1355 | target_arch: "arm64", |
| 1356 | vendor: true, |
| 1357 | arch: { |
| 1358 | arm64: { |
| 1359 | src: "bin", |
| 1360 | }, |
| 1361 | }, |
| 1362 | } |
| 1363 | ` |
| 1364 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1365 | |
| 1366 | mockFS := map[string][]byte{ |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1367 | "deps/Android.bp": []byte(depsBp), |
| 1368 | "framework/Android.bp": []byte(frameworkBp), |
| 1369 | "vendor/Android.bp": []byte(vendorProprietaryBp), |
| 1370 | "vendor/bin": nil, |
| 1371 | "vendor/bin.cpp": nil, |
| 1372 | "vendor/client.cpp": nil, |
| 1373 | "vendor/include/libvndk/a.h": nil, |
| 1374 | "vendor/include/libvendor/b.h": nil, |
| 1375 | "vendor/libvndk.a": nil, |
| 1376 | "vendor/libvendor.a": nil, |
| 1377 | "vendor/libvendor.so": nil, |
| 1378 | "vndk/Android.bp": []byte(vndkBp), |
| 1379 | "vndk/include/libvndk/a.h": nil, |
| 1380 | "vndk/libvndk.so": nil, |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1384 | config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD") |
| 1385 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1386 | ctx := CreateTestContext(config) |
| 1387 | ctx.Register() |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1388 | |
| 1389 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"}) |
| 1390 | android.FailIfErrored(t, errs) |
| 1391 | _, errs = ctx.PrepareBuildActions(config) |
| 1392 | android.FailIfErrored(t, errs) |
| 1393 | |
| 1394 | sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared" |
| 1395 | staticVariant := "android_vendor.BOARD_arm64_armv8-a_static" |
| 1396 | binaryVariant := "android_vendor.BOARD_arm64_armv8-a" |
| 1397 | |
| 1398 | // 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] | 1399 | libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"] |
| 1400 | for _, includeFlags := range []string{ |
| 1401 | "-Ivndk/include/libvndk", // libvndk |
| 1402 | "-Ivendor/include/libvendor", // libvendor |
| 1403 | } { |
| 1404 | if !strings.Contains(libclientCcFlags, includeFlags) { |
| 1405 | t.Errorf("flags for libclient must contain %#v, but was %#v.", |
| 1406 | includeFlags, libclientCcFlags) |
| 1407 | } |
| 1408 | } |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1409 | |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1410 | libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"] |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1411 | for _, input := range [][]string{ |
| 1412 | []string{sharedVariant, "libvndk.vndk.BOARD.arm64"}, |
| 1413 | []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"}, |
| 1414 | []string{staticVariant, "libvendor_without_snapshot"}, |
| 1415 | } { |
| 1416 | outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */) |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1417 | if !strings.Contains(libclientLdFlags, outputPaths[0].String()) { |
| 1418 | 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] | 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64 |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1423 | binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"] |
| 1424 | if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") { |
| 1425 | t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.", |
| 1426 | "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags) |
| 1427 | } |
| 1428 | |
| 1429 | binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"] |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1430 | libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"}) |
Inseob Kim | 67be732 | 2020-10-19 10:15:28 +0900 | [diff] [blame] | 1431 | if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) { |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1432 | 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] | 1433 | libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags) |
Inseob Kim | 5f58ff7 | 2020-09-07 19:53:31 +0900 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64 |
| 1437 | ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so") |
| 1438 | |
| 1439 | // libvendor_without_snapshot.so is installed by libvendor_without_snapshot |
| 1440 | ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so") |
| 1441 | |
| 1442 | // bin is installed by bin.vendor_binary.BOARD.arm64 |
| 1443 | ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin") |
| 1444 | |
| 1445 | // bin_without_snapshot is installed by bin_without_snapshot |
| 1446 | ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot") |
| 1447 | |
| 1448 | // libvendor and bin don't have vendor.BOARD variant |
| 1449 | libvendorVariants := ctx.ModuleVariantsForTests("libvendor") |
| 1450 | if inList(sharedVariant, libvendorVariants) { |
| 1451 | t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant) |
| 1452 | } |
| 1453 | |
| 1454 | binVariants := ctx.ModuleVariantsForTests("bin") |
| 1455 | if inList(binaryVariant, binVariants) { |
| 1456 | t.Errorf("bin must not have variant %#v, but it does", sharedVariant) |
| 1457 | } |
| 1458 | } |
| 1459 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1460 | func TestVendorSnapshotSanitizer(t *testing.T) { |
| 1461 | bp := ` |
| 1462 | vendor_snapshot_static { |
| 1463 | name: "libsnapshot", |
| 1464 | vendor: true, |
| 1465 | target_arch: "arm64", |
| 1466 | version: "BOARD", |
| 1467 | arch: { |
| 1468 | arm64: { |
| 1469 | src: "libsnapshot.a", |
| 1470 | cfi: { |
| 1471 | src: "libsnapshot.cfi.a", |
| 1472 | } |
| 1473 | }, |
| 1474 | }, |
| 1475 | } |
| 1476 | ` |
| 1477 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1478 | config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD") |
| 1479 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1480 | ctx := testCcWithConfig(t, config) |
| 1481 | |
| 1482 | // Check non-cfi and cfi variant. |
| 1483 | staticVariant := "android_vendor.BOARD_arm64_armv8-a_static" |
| 1484 | staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi" |
| 1485 | |
| 1486 | staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module) |
| 1487 | assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a") |
| 1488 | |
| 1489 | staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module) |
| 1490 | assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a") |
| 1491 | } |
| 1492 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1493 | func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) { |
| 1494 | t.Helper() |
| 1495 | if c.ExcludeFromVendorSnapshot() != expected { |
| 1496 | t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected) |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | func TestVendorSnapshotExclude(t *testing.T) { |
| 1501 | |
| 1502 | // This test verifies that the exclude_from_vendor_snapshot property |
| 1503 | // makes its way from the Android.bp source file into the module data |
| 1504 | // structure. It also verifies that modules are correctly included or |
| 1505 | // excluded in the vendor snapshot based on their path (framework or |
| 1506 | // vendor) and the exclude_from_vendor_snapshot property. |
| 1507 | |
| 1508 | frameworkBp := ` |
| 1509 | cc_library_shared { |
| 1510 | name: "libinclude", |
| 1511 | srcs: ["src/include.cpp"], |
| 1512 | vendor_available: true, |
| 1513 | } |
| 1514 | cc_library_shared { |
| 1515 | name: "libexclude", |
| 1516 | srcs: ["src/exclude.cpp"], |
| 1517 | vendor: true, |
| 1518 | exclude_from_vendor_snapshot: true, |
| 1519 | } |
| 1520 | ` |
| 1521 | |
| 1522 | vendorProprietaryBp := ` |
| 1523 | cc_library_shared { |
| 1524 | name: "libvendor", |
| 1525 | srcs: ["vendor.cpp"], |
| 1526 | vendor: true, |
| 1527 | } |
| 1528 | ` |
| 1529 | |
| 1530 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1531 | |
| 1532 | mockFS := map[string][]byte{ |
| 1533 | "deps/Android.bp": []byte(depsBp), |
| 1534 | "framework/Android.bp": []byte(frameworkBp), |
| 1535 | "framework/include.cpp": nil, |
| 1536 | "framework/exclude.cpp": nil, |
| 1537 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1538 | "device/vendor.cpp": nil, |
| 1539 | } |
| 1540 | |
| 1541 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1542 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1543 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1544 | ctx := CreateTestContext(config) |
| 1545 | ctx.Register() |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1546 | |
| 1547 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"}) |
| 1548 | android.FailIfErrored(t, errs) |
| 1549 | _, errs = ctx.PrepareBuildActions(config) |
| 1550 | android.FailIfErrored(t, errs) |
| 1551 | |
| 1552 | // Test an include and exclude framework module. |
| 1553 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false) |
| 1554 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false) |
| 1555 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true) |
| 1556 | |
| 1557 | // A vendor module is excluded, but by its path, not the |
| 1558 | // exclude_from_vendor_snapshot property. |
| 1559 | assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false) |
| 1560 | |
| 1561 | // Verify the content of the vendor snapshot. |
| 1562 | |
| 1563 | snapshotDir := "vendor-snapshot" |
| 1564 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 1565 | snapshotSingleton := ctx.SingletonForTests("vendor-snapshot") |
| 1566 | |
| 1567 | var includeJsonFiles []string |
| 1568 | var excludeJsonFiles []string |
| 1569 | |
| 1570 | for _, arch := range [][]string{ |
| 1571 | []string{"arm64", "armv8-a"}, |
| 1572 | []string{"arm", "armv7-a-neon"}, |
| 1573 | } { |
| 1574 | archType := arch[0] |
| 1575 | archVariant := arch[1] |
| 1576 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1577 | |
| 1578 | sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) |
| 1579 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1580 | |
| 1581 | // Included modules |
| 1582 | checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) |
| 1583 | includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) |
| 1584 | |
| 1585 | // Excluded modules |
| 1586 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) |
| 1587 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json")) |
| 1588 | checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant) |
| 1589 | excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json")) |
| 1590 | } |
| 1591 | |
| 1592 | // Verify that each json file for an included module has a rule. |
| 1593 | for _, jsonFile := range includeJsonFiles { |
| 1594 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1595 | t.Errorf("include json file %q not found", jsonFile) |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | // Verify that each json file for an excluded module has no rule. |
| 1600 | for _, jsonFile := range excludeJsonFiles { |
| 1601 | if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil { |
| 1602 | t.Errorf("exclude json file %q found", jsonFile) |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) { |
| 1608 | |
| 1609 | // This test verifies that using the exclude_from_vendor_snapshot |
| 1610 | // property on a module in a vendor proprietary path generates an |
| 1611 | // error. These modules are already excluded, so we prohibit using the |
| 1612 | // property in this way, which could add to confusion. |
| 1613 | |
| 1614 | vendorProprietaryBp := ` |
| 1615 | cc_library_shared { |
| 1616 | name: "libvendor", |
| 1617 | srcs: ["vendor.cpp"], |
| 1618 | vendor: true, |
| 1619 | exclude_from_vendor_snapshot: true, |
| 1620 | } |
| 1621 | ` |
| 1622 | |
| 1623 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1624 | |
| 1625 | mockFS := map[string][]byte{ |
| 1626 | "deps/Android.bp": []byte(depsBp), |
| 1627 | "device/Android.bp": []byte(vendorProprietaryBp), |
| 1628 | "device/vendor.cpp": nil, |
| 1629 | } |
| 1630 | |
| 1631 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1632 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1633 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1634 | ctx := CreateTestContext(config) |
| 1635 | ctx.Register() |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1636 | |
| 1637 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"}) |
| 1638 | android.FailIfErrored(t, errs) |
| 1639 | |
| 1640 | _, errs = ctx.PrepareBuildActions(config) |
| 1641 | android.CheckErrorsAgainstExpectations(t, errs, []string{ |
| 1642 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1643 | `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] | 1644 | `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`, |
| 1645 | `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] | 1646 | }) |
| 1647 | } |
| 1648 | |
| 1649 | func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) { |
| 1650 | |
| 1651 | // This test verifies that using the exclude_from_vendor_snapshot |
| 1652 | // property on a module that is vendor available generates an error. A |
| 1653 | // vendor available module must be captured in the vendor snapshot and |
| 1654 | // must not built from source when building the vendor image against |
| 1655 | // the vendor snapshot. |
| 1656 | |
| 1657 | frameworkBp := ` |
| 1658 | cc_library_shared { |
| 1659 | name: "libinclude", |
| 1660 | srcs: ["src/include.cpp"], |
| 1661 | vendor_available: true, |
| 1662 | exclude_from_vendor_snapshot: true, |
| 1663 | } |
| 1664 | ` |
| 1665 | |
| 1666 | depsBp := GatherRequiredDepsForTest(android.Android) |
| 1667 | |
| 1668 | mockFS := map[string][]byte{ |
| 1669 | "deps/Android.bp": []byte(depsBp), |
| 1670 | "framework/Android.bp": []byte(frameworkBp), |
| 1671 | "framework/include.cpp": nil, |
| 1672 | } |
| 1673 | |
| 1674 | config := TestConfig(buildDir, android.Android, nil, "", mockFS) |
| 1675 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1676 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1677 | ctx := CreateTestContext(config) |
| 1678 | ctx.Register() |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1679 | |
| 1680 | _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"}) |
| 1681 | android.FailIfErrored(t, errs) |
| 1682 | |
| 1683 | _, errs = ctx.PrepareBuildActions(config) |
| 1684 | android.CheckErrorsAgainstExpectations(t, errs, []string{ |
| 1685 | `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1686 | `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1687 | `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1688 | `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`, |
| 1689 | }) |
| 1690 | } |
| 1691 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 1692 | func TestRecoverySnapshotCapture(t *testing.T) { |
| 1693 | bp := ` |
| 1694 | cc_library { |
| 1695 | name: "libvndk", |
| 1696 | vendor_available: true, |
| 1697 | recovery_available: true, |
| 1698 | product_available: true, |
| 1699 | vndk: { |
| 1700 | enabled: true, |
| 1701 | }, |
| 1702 | nocrt: true, |
| 1703 | } |
| 1704 | |
| 1705 | cc_library { |
| 1706 | name: "librecovery", |
| 1707 | recovery: true, |
| 1708 | nocrt: true, |
| 1709 | } |
| 1710 | |
| 1711 | cc_library { |
| 1712 | name: "librecovery_available", |
| 1713 | recovery_available: true, |
| 1714 | nocrt: true, |
| 1715 | } |
| 1716 | |
| 1717 | cc_library_headers { |
| 1718 | name: "librecovery_headers", |
| 1719 | recovery_available: true, |
| 1720 | nocrt: true, |
| 1721 | } |
| 1722 | |
| 1723 | cc_binary { |
| 1724 | name: "recovery_bin", |
| 1725 | recovery: true, |
| 1726 | nocrt: true, |
| 1727 | } |
| 1728 | |
| 1729 | cc_binary { |
| 1730 | name: "recovery_available_bin", |
| 1731 | recovery_available: true, |
| 1732 | nocrt: true, |
| 1733 | } |
| 1734 | |
| 1735 | toolchain_library { |
| 1736 | name: "libb", |
| 1737 | recovery_available: true, |
| 1738 | src: "libb.a", |
| 1739 | } |
| 1740 | |
| 1741 | cc_object { |
| 1742 | name: "obj", |
| 1743 | recovery_available: true, |
| 1744 | } |
| 1745 | ` |
| 1746 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 1747 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 1748 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 1749 | ctx := testCcWithConfig(t, config) |
| 1750 | |
| 1751 | // Check Recovery snapshot output. |
| 1752 | |
| 1753 | snapshotDir := "recovery-snapshot" |
| 1754 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") |
| 1755 | snapshotSingleton := ctx.SingletonForTests("recovery-snapshot") |
| 1756 | |
| 1757 | var jsonFiles []string |
| 1758 | |
| 1759 | for _, arch := range [][]string{ |
| 1760 | []string{"arm64", "armv8-a"}, |
| 1761 | } { |
| 1762 | archType := arch[0] |
| 1763 | archVariant := arch[1] |
| 1764 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) |
| 1765 | |
| 1766 | // For shared libraries, only recovery_available modules are captured. |
| 1767 | sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) |
| 1768 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") |
| 1769 | checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant) |
| 1770 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) |
| 1771 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) |
| 1772 | jsonFiles = append(jsonFiles, |
| 1773 | filepath.Join(sharedDir, "libvndk.so.json"), |
| 1774 | filepath.Join(sharedDir, "librecovery.so.json"), |
| 1775 | filepath.Join(sharedDir, "librecovery_available.so.json")) |
| 1776 | |
| 1777 | // For static libraries, all recovery:true and recovery_available modules are captured. |
| 1778 | staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant) |
| 1779 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") |
| 1780 | checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant) |
| 1781 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant) |
| 1782 | checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant) |
| 1783 | jsonFiles = append(jsonFiles, |
| 1784 | filepath.Join(staticDir, "libb.a.json"), |
| 1785 | filepath.Join(staticDir, "librecovery.a.json"), |
| 1786 | filepath.Join(staticDir, "librecovery_available.a.json")) |
| 1787 | |
| 1788 | // For binary executables, all recovery:true and recovery_available modules are captured. |
| 1789 | if archType == "arm64" { |
| 1790 | binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) |
| 1791 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") |
| 1792 | checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant) |
| 1793 | checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant) |
| 1794 | jsonFiles = append(jsonFiles, |
| 1795 | filepath.Join(binaryDir, "recovery_bin.json"), |
| 1796 | filepath.Join(binaryDir, "recovery_available_bin.json")) |
| 1797 | } |
| 1798 | |
| 1799 | // For header libraries, all vendor:true and vendor_available modules are captured. |
| 1800 | headerDir := filepath.Join(snapshotVariantPath, archDir, "header") |
| 1801 | jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json")) |
| 1802 | |
| 1803 | // For object modules, all vendor:true and vendor_available modules are captured. |
| 1804 | objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant) |
| 1805 | objectDir := filepath.Join(snapshotVariantPath, archDir, "object") |
| 1806 | checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant) |
| 1807 | jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json")) |
| 1808 | } |
| 1809 | |
| 1810 | for _, jsonFile := range jsonFiles { |
| 1811 | // verify all json files exist |
| 1812 | if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil { |
| 1813 | t.Errorf("%q expected but not found", jsonFile) |
| 1814 | } |
| 1815 | } |
| 1816 | } |
| 1817 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1818 | func TestDoubleLoadableDepError(t *testing.T) { |
| 1819 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 1820 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1821 | cc_library { |
| 1822 | name: "libllndk", |
| 1823 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1824 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1828 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1829 | symbol_file: "", |
| 1830 | } |
| 1831 | |
| 1832 | cc_library { |
| 1833 | name: "libnondoubleloadable", |
| 1834 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1835 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1836 | vndk: { |
| 1837 | enabled: true, |
| 1838 | }, |
| 1839 | } |
| 1840 | `) |
| 1841 | |
| 1842 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 1843 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1844 | cc_library { |
| 1845 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 1846 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1847 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1848 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1852 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1853 | symbol_file: "", |
| 1854 | } |
| 1855 | |
| 1856 | cc_library { |
| 1857 | name: "libnondoubleloadable", |
| 1858 | vendor_available: true, |
| 1859 | } |
| 1860 | `) |
| 1861 | |
| 1862 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib. |
| 1863 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1864 | cc_library { |
| 1865 | name: "libdoubleloadable", |
| 1866 | vendor_available: true, |
| 1867 | double_loadable: true, |
| 1868 | shared_libs: ["libnondoubleloadable"], |
| 1869 | } |
| 1870 | |
| 1871 | cc_library { |
| 1872 | name: "libnondoubleloadable", |
| 1873 | vendor_available: true, |
| 1874 | } |
| 1875 | `) |
| 1876 | |
| 1877 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib. |
| 1878 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1879 | cc_library { |
| 1880 | name: "libdoubleloadable", |
| 1881 | vendor_available: true, |
| 1882 | double_loadable: true, |
| 1883 | shared_libs: ["libnondoubleloadable"], |
| 1884 | } |
| 1885 | |
| 1886 | cc_library { |
| 1887 | name: "libnondoubleloadable", |
| 1888 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1889 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1890 | vndk: { |
| 1891 | enabled: true, |
| 1892 | }, |
| 1893 | } |
| 1894 | `) |
| 1895 | |
| 1896 | // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib. |
| 1897 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1898 | cc_library { |
| 1899 | name: "libdoubleloadable", |
| 1900 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1901 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1902 | vndk: { |
| 1903 | enabled: true, |
| 1904 | }, |
| 1905 | double_loadable: true, |
| 1906 | shared_libs: ["libnondoubleloadable"], |
| 1907 | } |
| 1908 | |
| 1909 | cc_library { |
| 1910 | name: "libnondoubleloadable", |
| 1911 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1912 | product_available: false, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1913 | vndk: { |
| 1914 | enabled: true, |
| 1915 | }, |
| 1916 | } |
| 1917 | `) |
| 1918 | |
| 1919 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 1920 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1921 | cc_library { |
| 1922 | name: "libllndk", |
| 1923 | shared_libs: ["libcoreonly"], |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1924 | llndk_stubs: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1928 | name: "libllndk.llndk", |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1929 | symbol_file: "", |
| 1930 | } |
| 1931 | |
| 1932 | cc_library { |
| 1933 | name: "libcoreonly", |
| 1934 | shared_libs: ["libvendoravailable"], |
| 1935 | } |
| 1936 | |
| 1937 | // indirect dependency of LLNDK |
| 1938 | cc_library { |
| 1939 | name: "libvendoravailable", |
| 1940 | vendor_available: true, |
| 1941 | } |
| 1942 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1943 | } |
| 1944 | |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1945 | func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) { |
| 1946 | testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", ` |
| 1947 | cc_library { |
| 1948 | name: "libvndksp", |
| 1949 | shared_libs: ["libanothervndksp"], |
| 1950 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1951 | product_available: true, |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1952 | vndk: { |
| 1953 | enabled: true, |
| 1954 | support_system_process: true, |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | cc_library { |
| 1959 | name: "libllndk", |
| 1960 | shared_libs: ["libanothervndksp"], |
| 1961 | } |
| 1962 | |
| 1963 | llndk_library { |
| 1964 | name: "libllndk", |
| 1965 | symbol_file: "", |
| 1966 | } |
| 1967 | |
| 1968 | cc_library { |
| 1969 | name: "libanothervndksp", |
| 1970 | vendor_available: true, |
| 1971 | } |
| 1972 | `) |
| 1973 | } |
| 1974 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1975 | func TestVndkExt(t *testing.T) { |
| 1976 | // This test checks the VNDK-Ext properties. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1977 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1978 | cc_library { |
| 1979 | name: "libvndk", |
| 1980 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1981 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1982 | vndk: { |
| 1983 | enabled: true, |
| 1984 | }, |
| 1985 | nocrt: true, |
| 1986 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1987 | cc_library { |
| 1988 | name: "libvndk2", |
| 1989 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1990 | product_available: true, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1991 | vndk: { |
| 1992 | enabled: true, |
| 1993 | }, |
| 1994 | target: { |
| 1995 | vendor: { |
| 1996 | suffix: "-suffix", |
| 1997 | }, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1998 | product: { |
| 1999 | suffix: "-suffix", |
| 2000 | }, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2001 | }, |
| 2002 | nocrt: true, |
| 2003 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2004 | |
| 2005 | cc_library { |
| 2006 | name: "libvndk_ext", |
| 2007 | vendor: true, |
| 2008 | vndk: { |
| 2009 | enabled: true, |
| 2010 | extends: "libvndk", |
| 2011 | }, |
| 2012 | nocrt: true, |
| 2013 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2014 | |
| 2015 | cc_library { |
| 2016 | name: "libvndk2_ext", |
| 2017 | vendor: true, |
| 2018 | vndk: { |
| 2019 | enabled: true, |
| 2020 | extends: "libvndk2", |
| 2021 | }, |
| 2022 | nocrt: true, |
| 2023 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2024 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2025 | cc_library { |
| 2026 | name: "libvndk_ext_product", |
| 2027 | product_specific: true, |
| 2028 | vndk: { |
| 2029 | enabled: true, |
| 2030 | extends: "libvndk", |
| 2031 | }, |
| 2032 | nocrt: true, |
| 2033 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 2034 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2035 | cc_library { |
| 2036 | name: "libvndk2_ext_product", |
| 2037 | product_specific: true, |
| 2038 | vndk: { |
| 2039 | enabled: true, |
| 2040 | extends: "libvndk2", |
| 2041 | }, |
| 2042 | nocrt: true, |
| 2043 | } |
| 2044 | ` |
| 2045 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2046 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2047 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2048 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2049 | |
| 2050 | ctx := testCcWithConfig(t, config) |
| 2051 | |
| 2052 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) |
| 2053 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) |
| 2054 | |
| 2055 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 2056 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") |
| 2057 | |
| 2058 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) |
| 2059 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2060 | } |
| 2061 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2062 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2063 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. |
| 2064 | ctx := testCcNoVndk(t, ` |
| 2065 | cc_library { |
| 2066 | name: "libvndk", |
| 2067 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2068 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2069 | vndk: { |
| 2070 | enabled: true, |
| 2071 | }, |
| 2072 | nocrt: true, |
| 2073 | } |
| 2074 | |
| 2075 | cc_library { |
| 2076 | name: "libvndk_ext", |
| 2077 | vendor: true, |
| 2078 | vndk: { |
| 2079 | enabled: true, |
| 2080 | extends: "libvndk", |
| 2081 | }, |
| 2082 | nocrt: true, |
| 2083 | } |
| 2084 | `) |
| 2085 | |
| 2086 | // Ensures that the core variant of "libvndk_ext" can be found. |
| 2087 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) |
| 2088 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 2089 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) |
| 2090 | } |
| 2091 | } |
| 2092 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2093 | func TestVndkExtWithoutProductVndkVersion(t *testing.T) { |
| 2094 | // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set. |
| 2095 | ctx := testCc(t, ` |
| 2096 | cc_library { |
| 2097 | name: "libvndk", |
| 2098 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2099 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2100 | vndk: { |
| 2101 | enabled: true, |
| 2102 | }, |
| 2103 | nocrt: true, |
| 2104 | } |
| 2105 | |
| 2106 | cc_library { |
| 2107 | name: "libvndk_ext_product", |
| 2108 | product_specific: true, |
| 2109 | vndk: { |
| 2110 | enabled: true, |
| 2111 | extends: "libvndk", |
| 2112 | }, |
| 2113 | nocrt: true, |
| 2114 | } |
| 2115 | `) |
| 2116 | |
| 2117 | // Ensures that the core variant of "libvndk_ext_product" can be found. |
| 2118 | mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module) |
| 2119 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { |
| 2120 | t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends) |
| 2121 | } |
| 2122 | } |
| 2123 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2124 | func TestVndkExtError(t *testing.T) { |
| 2125 | // 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] | 2126 | 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] | 2127 | cc_library { |
| 2128 | name: "libvndk", |
| 2129 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2130 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2131 | vndk: { |
| 2132 | enabled: true, |
| 2133 | }, |
| 2134 | nocrt: true, |
| 2135 | } |
| 2136 | |
| 2137 | cc_library { |
| 2138 | name: "libvndk_ext", |
| 2139 | vndk: { |
| 2140 | enabled: true, |
| 2141 | extends: "libvndk", |
| 2142 | }, |
| 2143 | nocrt: true, |
| 2144 | } |
| 2145 | `) |
| 2146 | |
| 2147 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 2148 | cc_library { |
| 2149 | name: "libvndk", |
| 2150 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2151 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2152 | vndk: { |
| 2153 | enabled: true, |
| 2154 | }, |
| 2155 | nocrt: true, |
| 2156 | } |
| 2157 | |
| 2158 | cc_library { |
| 2159 | name: "libvndk_ext", |
| 2160 | vendor: true, |
| 2161 | vndk: { |
| 2162 | enabled: true, |
| 2163 | }, |
| 2164 | nocrt: true, |
| 2165 | } |
| 2166 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2167 | |
| 2168 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 2169 | cc_library { |
| 2170 | name: "libvndk", |
| 2171 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2172 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2173 | vndk: { |
| 2174 | enabled: true, |
| 2175 | }, |
| 2176 | nocrt: true, |
| 2177 | } |
| 2178 | |
| 2179 | cc_library { |
| 2180 | name: "libvndk_ext_product", |
| 2181 | product_specific: true, |
| 2182 | vndk: { |
| 2183 | enabled: true, |
| 2184 | }, |
| 2185 | nocrt: true, |
| 2186 | } |
| 2187 | `) |
| 2188 | |
| 2189 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` |
| 2190 | cc_library { |
| 2191 | name: "libvndk", |
| 2192 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2193 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2194 | vndk: { |
| 2195 | enabled: true, |
| 2196 | }, |
| 2197 | nocrt: true, |
| 2198 | } |
| 2199 | |
| 2200 | cc_library { |
| 2201 | name: "libvndk_ext_product", |
| 2202 | product_specific: true, |
| 2203 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2204 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2205 | vndk: { |
| 2206 | enabled: true, |
| 2207 | extends: "libvndk", |
| 2208 | }, |
| 2209 | nocrt: true, |
| 2210 | } |
| 2211 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
| 2215 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 2216 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 2217 | cc_library { |
| 2218 | name: "libvndk", |
| 2219 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2220 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2221 | vndk: { |
| 2222 | enabled: true, |
| 2223 | }, |
| 2224 | nocrt: true, |
| 2225 | } |
| 2226 | |
| 2227 | cc_library { |
| 2228 | name: "libvndk_sp_ext", |
| 2229 | vendor: true, |
| 2230 | vndk: { |
| 2231 | enabled: true, |
| 2232 | extends: "libvndk", |
| 2233 | support_system_process: true, |
| 2234 | }, |
| 2235 | nocrt: true, |
| 2236 | } |
| 2237 | `) |
| 2238 | |
| 2239 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 2240 | cc_library { |
| 2241 | name: "libvndk_sp", |
| 2242 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2243 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2244 | vndk: { |
| 2245 | enabled: true, |
| 2246 | support_system_process: true, |
| 2247 | }, |
| 2248 | nocrt: true, |
| 2249 | } |
| 2250 | |
| 2251 | cc_library { |
| 2252 | name: "libvndk_ext", |
| 2253 | vendor: true, |
| 2254 | vndk: { |
| 2255 | enabled: true, |
| 2256 | extends: "libvndk_sp", |
| 2257 | }, |
| 2258 | nocrt: true, |
| 2259 | } |
| 2260 | `) |
| 2261 | } |
| 2262 | |
| 2263 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2264 | // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2265 | // with `vendor_available: false`. |
| 2266 | testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` |
| 2267 | cc_library { |
| 2268 | name: "libvndk", |
| 2269 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2270 | product_available: false, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2271 | vndk: { |
| 2272 | enabled: true, |
| 2273 | }, |
| 2274 | nocrt: true, |
| 2275 | } |
| 2276 | |
| 2277 | cc_library { |
| 2278 | name: "libvndk_ext", |
| 2279 | vendor: true, |
| 2280 | vndk: { |
| 2281 | enabled: true, |
| 2282 | extends: "libvndk", |
| 2283 | }, |
| 2284 | nocrt: true, |
| 2285 | } |
| 2286 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2287 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 2288 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which does not have `product_available: true`", ` |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2289 | cc_library { |
| 2290 | name: "libvndk", |
| 2291 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2292 | product_available: false, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2293 | vndk: { |
| 2294 | enabled: true, |
| 2295 | }, |
| 2296 | nocrt: true, |
| 2297 | } |
| 2298 | |
| 2299 | cc_library { |
| 2300 | name: "libvndk_ext_product", |
| 2301 | product_specific: true, |
| 2302 | vndk: { |
| 2303 | enabled: true, |
| 2304 | extends: "libvndk", |
| 2305 | }, |
| 2306 | nocrt: true, |
| 2307 | } |
| 2308 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2309 | } |
| 2310 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2311 | func TestVendorModuleUseVndkExt(t *testing.T) { |
| 2312 | // 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] | 2313 | testCc(t, ` |
| 2314 | cc_library { |
| 2315 | name: "libvndk", |
| 2316 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2317 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2318 | vndk: { |
| 2319 | enabled: true, |
| 2320 | }, |
| 2321 | nocrt: true, |
| 2322 | } |
| 2323 | |
| 2324 | cc_library { |
| 2325 | name: "libvndk_ext", |
| 2326 | vendor: true, |
| 2327 | vndk: { |
| 2328 | enabled: true, |
| 2329 | extends: "libvndk", |
| 2330 | }, |
| 2331 | nocrt: true, |
| 2332 | } |
| 2333 | |
| 2334 | cc_library { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2335 | name: "libvndk_sp", |
| 2336 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2337 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2338 | vndk: { |
| 2339 | enabled: true, |
| 2340 | support_system_process: true, |
| 2341 | }, |
| 2342 | nocrt: true, |
| 2343 | } |
| 2344 | |
| 2345 | cc_library { |
| 2346 | name: "libvndk_sp_ext", |
| 2347 | vendor: true, |
| 2348 | vndk: { |
| 2349 | enabled: true, |
| 2350 | extends: "libvndk_sp", |
| 2351 | support_system_process: true, |
| 2352 | }, |
| 2353 | nocrt: true, |
| 2354 | } |
| 2355 | |
| 2356 | cc_library { |
| 2357 | name: "libvendor", |
| 2358 | vendor: true, |
| 2359 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 2360 | nocrt: true, |
| 2361 | } |
| 2362 | `) |
| 2363 | } |
| 2364 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2365 | func TestVndkExtUseVendorLib(t *testing.T) { |
| 2366 | // 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] | 2367 | testCc(t, ` |
| 2368 | cc_library { |
| 2369 | name: "libvndk", |
| 2370 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2371 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2372 | vndk: { |
| 2373 | enabled: true, |
| 2374 | }, |
| 2375 | nocrt: true, |
| 2376 | } |
| 2377 | |
| 2378 | cc_library { |
| 2379 | name: "libvndk_ext", |
| 2380 | vendor: true, |
| 2381 | vndk: { |
| 2382 | enabled: true, |
| 2383 | extends: "libvndk", |
| 2384 | }, |
| 2385 | shared_libs: ["libvendor"], |
| 2386 | nocrt: true, |
| 2387 | } |
| 2388 | |
| 2389 | cc_library { |
| 2390 | name: "libvendor", |
| 2391 | vendor: true, |
| 2392 | nocrt: true, |
| 2393 | } |
| 2394 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2395 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2396 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 2397 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2398 | cc_library { |
| 2399 | name: "libvndk_sp", |
| 2400 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2401 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2402 | vndk: { |
| 2403 | enabled: true, |
| 2404 | support_system_process: true, |
| 2405 | }, |
| 2406 | nocrt: true, |
| 2407 | } |
| 2408 | |
| 2409 | cc_library { |
| 2410 | name: "libvndk_sp_ext", |
| 2411 | vendor: true, |
| 2412 | vndk: { |
| 2413 | enabled: true, |
| 2414 | extends: "libvndk_sp", |
| 2415 | support_system_process: true, |
| 2416 | }, |
| 2417 | shared_libs: ["libvendor"], // Cause an error |
| 2418 | nocrt: true, |
| 2419 | } |
| 2420 | |
| 2421 | cc_library { |
| 2422 | name: "libvendor", |
| 2423 | vendor: true, |
| 2424 | nocrt: true, |
| 2425 | } |
| 2426 | `) |
| 2427 | } |
| 2428 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2429 | func TestProductVndkExtDependency(t *testing.T) { |
| 2430 | bp := ` |
| 2431 | cc_library { |
| 2432 | name: "libvndk", |
| 2433 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2434 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2435 | vndk: { |
| 2436 | enabled: true, |
| 2437 | }, |
| 2438 | nocrt: true, |
| 2439 | } |
| 2440 | |
| 2441 | cc_library { |
| 2442 | name: "libvndk_ext_product", |
| 2443 | product_specific: true, |
| 2444 | vndk: { |
| 2445 | enabled: true, |
| 2446 | extends: "libvndk", |
| 2447 | }, |
| 2448 | shared_libs: ["libproduct_for_vndklibs"], |
| 2449 | nocrt: true, |
| 2450 | } |
| 2451 | |
| 2452 | cc_library { |
| 2453 | name: "libvndk_sp", |
| 2454 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2455 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 2456 | vndk: { |
| 2457 | enabled: true, |
| 2458 | support_system_process: true, |
| 2459 | }, |
| 2460 | nocrt: true, |
| 2461 | } |
| 2462 | |
| 2463 | cc_library { |
| 2464 | name: "libvndk_sp_ext_product", |
| 2465 | product_specific: true, |
| 2466 | vndk: { |
| 2467 | enabled: true, |
| 2468 | extends: "libvndk_sp", |
| 2469 | support_system_process: true, |
| 2470 | }, |
| 2471 | shared_libs: ["libproduct_for_vndklibs"], |
| 2472 | nocrt: true, |
| 2473 | } |
| 2474 | |
| 2475 | cc_library { |
| 2476 | name: "libproduct", |
| 2477 | product_specific: true, |
| 2478 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], |
| 2479 | nocrt: true, |
| 2480 | } |
| 2481 | |
| 2482 | cc_library { |
| 2483 | name: "libproduct_for_vndklibs", |
| 2484 | product_specific: true, |
| 2485 | nocrt: true, |
| 2486 | } |
| 2487 | ` |
| 2488 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2489 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2490 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2491 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2492 | |
| 2493 | testCcWithConfig(t, config) |
| 2494 | } |
| 2495 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2496 | func TestVndkSpExtUseVndkError(t *testing.T) { |
| 2497 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 2498 | // library. |
| 2499 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 2500 | cc_library { |
| 2501 | name: "libvndk", |
| 2502 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2503 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2504 | vndk: { |
| 2505 | enabled: true, |
| 2506 | }, |
| 2507 | nocrt: true, |
| 2508 | } |
| 2509 | |
| 2510 | cc_library { |
| 2511 | name: "libvndk_sp", |
| 2512 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2513 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2514 | vndk: { |
| 2515 | enabled: true, |
| 2516 | support_system_process: true, |
| 2517 | }, |
| 2518 | nocrt: true, |
| 2519 | } |
| 2520 | |
| 2521 | cc_library { |
| 2522 | name: "libvndk_sp_ext", |
| 2523 | vendor: true, |
| 2524 | vndk: { |
| 2525 | enabled: true, |
| 2526 | extends: "libvndk_sp", |
| 2527 | support_system_process: true, |
| 2528 | }, |
| 2529 | shared_libs: ["libvndk"], // Cause an error |
| 2530 | nocrt: true, |
| 2531 | } |
| 2532 | `) |
| 2533 | |
| 2534 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 2535 | // library. |
| 2536 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 2537 | cc_library { |
| 2538 | name: "libvndk", |
| 2539 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2540 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2541 | vndk: { |
| 2542 | enabled: true, |
| 2543 | }, |
| 2544 | nocrt: true, |
| 2545 | } |
| 2546 | |
| 2547 | cc_library { |
| 2548 | name: "libvndk_ext", |
| 2549 | vendor: true, |
| 2550 | vndk: { |
| 2551 | enabled: true, |
| 2552 | extends: "libvndk", |
| 2553 | }, |
| 2554 | nocrt: true, |
| 2555 | } |
| 2556 | |
| 2557 | cc_library { |
| 2558 | name: "libvndk_sp", |
| 2559 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2560 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 2561 | vndk: { |
| 2562 | enabled: true, |
| 2563 | support_system_process: true, |
| 2564 | }, |
| 2565 | nocrt: true, |
| 2566 | } |
| 2567 | |
| 2568 | cc_library { |
| 2569 | name: "libvndk_sp_ext", |
| 2570 | vendor: true, |
| 2571 | vndk: { |
| 2572 | enabled: true, |
| 2573 | extends: "libvndk_sp", |
| 2574 | support_system_process: true, |
| 2575 | }, |
| 2576 | shared_libs: ["libvndk_ext"], // Cause an error |
| 2577 | nocrt: true, |
| 2578 | } |
| 2579 | `) |
| 2580 | } |
| 2581 | |
| 2582 | func TestVndkUseVndkExtError(t *testing.T) { |
| 2583 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 2584 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2585 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 2586 | cc_library { |
| 2587 | name: "libvndk", |
| 2588 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2589 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2590 | vndk: { |
| 2591 | enabled: true, |
| 2592 | }, |
| 2593 | nocrt: true, |
| 2594 | } |
| 2595 | |
| 2596 | cc_library { |
| 2597 | name: "libvndk_ext", |
| 2598 | vendor: true, |
| 2599 | vndk: { |
| 2600 | enabled: true, |
| 2601 | extends: "libvndk", |
| 2602 | }, |
| 2603 | nocrt: true, |
| 2604 | } |
| 2605 | |
| 2606 | cc_library { |
| 2607 | name: "libvndk2", |
| 2608 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2609 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2610 | vndk: { |
| 2611 | enabled: true, |
| 2612 | }, |
| 2613 | shared_libs: ["libvndk_ext"], |
| 2614 | nocrt: true, |
| 2615 | } |
| 2616 | `) |
| 2617 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 2618 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2619 | cc_library { |
| 2620 | name: "libvndk", |
| 2621 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2622 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2623 | vndk: { |
| 2624 | enabled: true, |
| 2625 | }, |
| 2626 | nocrt: true, |
| 2627 | } |
| 2628 | |
| 2629 | cc_library { |
| 2630 | name: "libvndk_ext", |
| 2631 | vendor: true, |
| 2632 | vndk: { |
| 2633 | enabled: true, |
| 2634 | extends: "libvndk", |
| 2635 | }, |
| 2636 | nocrt: true, |
| 2637 | } |
| 2638 | |
| 2639 | cc_library { |
| 2640 | name: "libvndk2", |
| 2641 | vendor_available: true, |
| 2642 | vndk: { |
| 2643 | enabled: true, |
| 2644 | }, |
| 2645 | target: { |
| 2646 | vendor: { |
| 2647 | shared_libs: ["libvndk_ext"], |
| 2648 | }, |
| 2649 | }, |
| 2650 | nocrt: true, |
| 2651 | } |
| 2652 | `) |
| 2653 | |
| 2654 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 2655 | cc_library { |
| 2656 | name: "libvndk_sp", |
| 2657 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2658 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2659 | vndk: { |
| 2660 | enabled: true, |
| 2661 | support_system_process: true, |
| 2662 | }, |
| 2663 | nocrt: true, |
| 2664 | } |
| 2665 | |
| 2666 | cc_library { |
| 2667 | name: "libvndk_sp_ext", |
| 2668 | vendor: true, |
| 2669 | vndk: { |
| 2670 | enabled: true, |
| 2671 | extends: "libvndk_sp", |
| 2672 | support_system_process: true, |
| 2673 | }, |
| 2674 | nocrt: true, |
| 2675 | } |
| 2676 | |
| 2677 | cc_library { |
| 2678 | name: "libvndk_sp_2", |
| 2679 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2680 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2681 | vndk: { |
| 2682 | enabled: true, |
| 2683 | support_system_process: true, |
| 2684 | }, |
| 2685 | shared_libs: ["libvndk_sp_ext"], |
| 2686 | nocrt: true, |
| 2687 | } |
| 2688 | `) |
| 2689 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 2690 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2691 | cc_library { |
| 2692 | name: "libvndk_sp", |
| 2693 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2694 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2695 | vndk: { |
| 2696 | enabled: true, |
| 2697 | }, |
| 2698 | nocrt: true, |
| 2699 | } |
| 2700 | |
| 2701 | cc_library { |
| 2702 | name: "libvndk_sp_ext", |
| 2703 | vendor: true, |
| 2704 | vndk: { |
| 2705 | enabled: true, |
| 2706 | extends: "libvndk_sp", |
| 2707 | }, |
| 2708 | nocrt: true, |
| 2709 | } |
| 2710 | |
| 2711 | cc_library { |
| 2712 | name: "libvndk_sp2", |
| 2713 | vendor_available: true, |
| 2714 | vndk: { |
| 2715 | enabled: true, |
| 2716 | }, |
| 2717 | target: { |
| 2718 | vendor: { |
| 2719 | shared_libs: ["libvndk_sp_ext"], |
| 2720 | }, |
| 2721 | }, |
| 2722 | nocrt: true, |
| 2723 | } |
| 2724 | `) |
| 2725 | } |
| 2726 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2727 | func TestEnforceProductVndkVersion(t *testing.T) { |
| 2728 | bp := ` |
| 2729 | cc_library { |
| 2730 | name: "libllndk", |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2731 | llndk_stubs: "libllndk.llndk", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2732 | } |
| 2733 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2734 | name: "libllndk.llndk", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2735 | symbol_file: "", |
| 2736 | } |
| 2737 | cc_library { |
| 2738 | name: "libvndk", |
| 2739 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2740 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2741 | vndk: { |
| 2742 | enabled: true, |
| 2743 | }, |
| 2744 | nocrt: true, |
| 2745 | } |
| 2746 | cc_library { |
| 2747 | name: "libvndk_sp", |
| 2748 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2749 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2750 | vndk: { |
| 2751 | enabled: true, |
| 2752 | support_system_process: true, |
| 2753 | }, |
| 2754 | nocrt: true, |
| 2755 | } |
| 2756 | cc_library { |
| 2757 | name: "libva", |
| 2758 | vendor_available: true, |
| 2759 | nocrt: true, |
| 2760 | } |
| 2761 | cc_library { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2762 | name: "libpa", |
| 2763 | product_available: true, |
| 2764 | nocrt: true, |
| 2765 | } |
| 2766 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 2767 | name: "libboth_available", |
| 2768 | vendor_available: true, |
| 2769 | product_available: true, |
| 2770 | nocrt: true, |
| 2771 | target: { |
| 2772 | vendor: { |
| 2773 | suffix: "-vendor", |
| 2774 | }, |
| 2775 | product: { |
| 2776 | suffix: "-product", |
| 2777 | }, |
| 2778 | } |
| 2779 | } |
| 2780 | cc_library { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2781 | name: "libproduct_va", |
| 2782 | product_specific: true, |
| 2783 | vendor_available: true, |
| 2784 | nocrt: true, |
| 2785 | } |
| 2786 | cc_library { |
| 2787 | name: "libprod", |
| 2788 | product_specific: true, |
| 2789 | shared_libs: [ |
| 2790 | "libllndk", |
| 2791 | "libvndk", |
| 2792 | "libvndk_sp", |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2793 | "libpa", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 2794 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2795 | "libproduct_va", |
| 2796 | ], |
| 2797 | nocrt: true, |
| 2798 | } |
| 2799 | cc_library { |
| 2800 | name: "libvendor", |
| 2801 | vendor: true, |
| 2802 | shared_libs: [ |
| 2803 | "libllndk", |
| 2804 | "libvndk", |
| 2805 | "libvndk_sp", |
| 2806 | "libva", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 2807 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2808 | "libproduct_va", |
| 2809 | ], |
| 2810 | nocrt: true, |
| 2811 | } |
| 2812 | ` |
| 2813 | |
| 2814 | config := TestConfig(buildDir, android.Android, nil, bp, nil) |
| 2815 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
| 2816 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") |
| 2817 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") |
| 2818 | |
| 2819 | ctx := testCcWithConfig(t, config) |
| 2820 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 2821 | checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant) |
| 2822 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 2823 | |
| 2824 | mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module) |
| 2825 | assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so") |
| 2826 | |
| 2827 | mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module) |
| 2828 | assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
| 2832 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2833 | cc_library { |
| 2834 | name: "libprod", |
| 2835 | product_specific: true, |
| 2836 | shared_libs: [ |
| 2837 | "libvendor", |
| 2838 | ], |
| 2839 | nocrt: true, |
| 2840 | } |
| 2841 | cc_library { |
| 2842 | name: "libvendor", |
| 2843 | vendor: true, |
| 2844 | nocrt: true, |
| 2845 | } |
| 2846 | `) |
| 2847 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2848 | cc_library { |
| 2849 | name: "libprod", |
| 2850 | product_specific: true, |
| 2851 | shared_libs: [ |
| 2852 | "libsystem", |
| 2853 | ], |
| 2854 | nocrt: true, |
| 2855 | } |
| 2856 | cc_library { |
| 2857 | name: "libsystem", |
| 2858 | nocrt: true, |
| 2859 | } |
| 2860 | `) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame^] | 2861 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2862 | cc_library { |
| 2863 | name: "libprod", |
| 2864 | product_specific: true, |
| 2865 | shared_libs: [ |
| 2866 | "libva", |
| 2867 | ], |
| 2868 | nocrt: true, |
| 2869 | } |
| 2870 | cc_library { |
| 2871 | name: "libva", |
| 2872 | vendor_available: true, |
| 2873 | nocrt: true, |
| 2874 | } |
| 2875 | `) |
| 2876 | testCcErrorProductVndk(t, "product module that is not VNDK should not link to \".*\" which is marked as `product_available: false`", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2877 | cc_library { |
| 2878 | name: "libprod", |
| 2879 | product_specific: true, |
| 2880 | shared_libs: [ |
| 2881 | "libvndk_private", |
| 2882 | ], |
| 2883 | nocrt: true, |
| 2884 | } |
| 2885 | cc_library { |
| 2886 | name: "libvndk_private", |
| 2887 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2888 | product_available: false, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2889 | vndk: { |
| 2890 | enabled: true, |
| 2891 | }, |
| 2892 | nocrt: true, |
| 2893 | } |
| 2894 | `) |
| 2895 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` |
| 2896 | cc_library { |
| 2897 | name: "libprod", |
| 2898 | product_specific: true, |
| 2899 | shared_libs: [ |
| 2900 | "libsystem_ext", |
| 2901 | ], |
| 2902 | nocrt: true, |
| 2903 | } |
| 2904 | cc_library { |
| 2905 | name: "libsystem_ext", |
| 2906 | system_ext_specific: true, |
| 2907 | nocrt: true, |
| 2908 | } |
| 2909 | `) |
| 2910 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 2911 | cc_library { |
| 2912 | name: "libsystem", |
| 2913 | shared_libs: [ |
| 2914 | "libproduct_va", |
| 2915 | ], |
| 2916 | nocrt: true, |
| 2917 | } |
| 2918 | cc_library { |
| 2919 | name: "libproduct_va", |
| 2920 | product_specific: true, |
| 2921 | vendor_available: true, |
| 2922 | nocrt: true, |
| 2923 | } |
| 2924 | `) |
| 2925 | } |
| 2926 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2927 | func TestMakeLinkType(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2928 | bp := ` |
| 2929 | cc_library { |
| 2930 | name: "libvndk", |
| 2931 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2932 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2933 | vndk: { |
| 2934 | enabled: true, |
| 2935 | }, |
| 2936 | } |
| 2937 | cc_library { |
| 2938 | name: "libvndksp", |
| 2939 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2940 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2941 | vndk: { |
| 2942 | enabled: true, |
| 2943 | support_system_process: true, |
| 2944 | }, |
| 2945 | } |
| 2946 | cc_library { |
| 2947 | name: "libvndkprivate", |
| 2948 | vendor_available: false, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2949 | product_available: false, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2950 | vndk: { |
| 2951 | enabled: true, |
| 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 | } |