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