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