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