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