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