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" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 23 | "runtime" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 24 | "strings" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 25 | "testing" |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 26 | |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 27 | "android/soong/aidl_library" |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 28 | "android/soong/android" |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 29 | "android/soong/bazel/cquery" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 32 | func init() { |
| 33 | registerTestMutators(android.InitRegistrationContext) |
| 34 | } |
| 35 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 36 | func TestMain(m *testing.M) { |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 37 | os.Exit(m.Run()) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 38 | } |
| 39 | |
Paul Duffin | 2e6f90e | 2021-03-22 23:20:25 +0000 | [diff] [blame] | 40 | var prepareForCcTest = android.GroupFixturePreparers( |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 41 | PrepareForTestWithCcIncludeVndk, |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 42 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 43 | variables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 44 | variables.Platform_vndk_version = StringPtr("29") |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 45 | }), |
| 46 | ) |
| 47 | |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 48 | var ccLibInApex = "cc_lib_in_apex" |
| 49 | var apexVariationName = "apex28" |
| 50 | var apexVersion = "28" |
| 51 | |
| 52 | func registerTestMutators(ctx android.RegistrationContext) { |
| 53 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 54 | ctx.BottomUp("apex", testApexMutator).Parallel() |
| 55 | ctx.BottomUp("mixed_builds_prep", mixedBuildsPrepareMutator).Parallel() |
| 56 | }) |
| 57 | } |
| 58 | |
| 59 | func mixedBuildsPrepareMutator(ctx android.BottomUpMutatorContext) { |
| 60 | if m := ctx.Module(); m.Enabled() { |
| 61 | if mixedBuildMod, ok := m.(android.MixedBuildBuildable); ok { |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 62 | if mixedBuildMod.IsMixedBuildSupported(ctx) && android.MixedBuildsEnabled(ctx) == android.MixedBuildEnabled { |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 63 | mixedBuildMod.QueueBazelCall(ctx) |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func testApexMutator(mctx android.BottomUpMutatorContext) { |
| 70 | modules := mctx.CreateVariations(apexVariationName) |
| 71 | apexInfo := android.ApexInfo{ |
| 72 | ApexVariationName: apexVariationName, |
| 73 | MinSdkVersion: android.ApiLevelForTest(apexVersion), |
| 74 | } |
| 75 | mctx.SetVariationProvider(modules[0], android.ApexInfoProvider, apexInfo) |
| 76 | } |
| 77 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 78 | // testCcWithConfig runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 79 | // |
| 80 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 81 | // |
| 82 | // deprecated |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 83 | func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext { |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 84 | t.Helper() |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 85 | result := prepareForCcTest.RunTestWithConfig(t, config) |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 86 | return result.TestContext |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 87 | } |
| 88 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 89 | // testCc runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 90 | // |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 91 | // 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] | 92 | // easier to customize the test behavior. |
| 93 | // |
| 94 | // 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] | 95 | // 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] | 96 | // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify |
| 97 | // that it did not change the test behavior unexpectedly. |
| 98 | // |
| 99 | // deprecated |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 100 | func testCc(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 101 | t.Helper() |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 102 | result := prepareForCcTest.RunTestWithBp(t, bp) |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 103 | return result.TestContext |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 104 | } |
| 105 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 106 | // testCcErrorWithConfig runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 107 | // |
| 108 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 109 | // |
| 110 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 111 | func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 112 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 113 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 114 | prepareForCcTest. |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 115 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 116 | RunTestWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 117 | } |
| 118 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 119 | // testCcError runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 120 | // |
| 121 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 122 | // |
| 123 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 124 | func testCcError(t *testing.T, pattern string, bp string) { |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 125 | t.Helper() |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 126 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 127 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 128 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 129 | testCcErrorWithConfig(t, pattern, config) |
| 130 | return |
| 131 | } |
| 132 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 133 | // testCcErrorProductVndk runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 134 | // |
| 135 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 136 | // |
| 137 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 138 | func testCcErrorProductVndk(t *testing.T, pattern string, bp string) { |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 139 | t.Helper() |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 140 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 141 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 142 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 143 | testCcErrorWithConfig(t, pattern, config) |
| 144 | return |
| 145 | } |
| 146 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 147 | const ( |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 148 | coreVariant = "android_arm64_armv8-a_shared" |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 149 | vendorVariant = "android_vendor.29_arm64_armv8-a_shared" |
| 150 | productVariant = "android_product.29_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 151 | recoveryVariant = "android_recovery_arm64_armv8-a_shared" |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 152 | ) |
| 153 | |
Paul Duffin | db462dd | 2021-03-21 22:01:55 +0000 | [diff] [blame] | 154 | // Test that the PrepareForTestWithCcDefaultModules provides all the files that it uses by |
| 155 | // running it in a fixture that requires all source files to exist. |
| 156 | func TestPrepareForTestWithCcDefaultModules(t *testing.T) { |
| 157 | android.GroupFixturePreparers( |
| 158 | PrepareForTestWithCcDefaultModules, |
| 159 | android.PrepareForTestDisallowNonExistentPaths, |
| 160 | ).RunTest(t) |
| 161 | } |
| 162 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 163 | func TestVendorSrc(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 164 | t.Parallel() |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 165 | ctx := testCc(t, ` |
| 166 | cc_library { |
| 167 | name: "libTest", |
| 168 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 169 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 170 | nocrt: true, |
| 171 | system_shared_libs: [], |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 172 | vendor_available: true, |
| 173 | target: { |
| 174 | vendor: { |
| 175 | srcs: ["bar.c"], |
| 176 | }, |
| 177 | }, |
| 178 | } |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 179 | `) |
| 180 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 181 | ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld") |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 182 | var objs []string |
| 183 | for _, o := range ld.Inputs { |
| 184 | objs = append(objs, o.Base()) |
| 185 | } |
Colin Cross | 95d33fe | 2018-01-03 13:40:46 -0800 | [diff] [blame] | 186 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 187 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 188 | } |
| 189 | } |
| 190 | |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 191 | func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) { |
| 192 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) |
| 193 | partitionDefined := false |
| 194 | checkPartition := func(specific bool, partition string) { |
| 195 | if specific { |
| 196 | if expected != partition && !partitionDefined { |
| 197 | // The variant is installed to the 'partition' |
| 198 | t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition) |
| 199 | } |
| 200 | partitionDefined = true |
| 201 | } else { |
| 202 | // The variant is not installed to the 'partition' |
| 203 | if expected == partition { |
| 204 | t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition) |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | socSpecific := func(m *Module) bool { |
| 209 | return m.SocSpecific() || m.socSpecificModuleContext() |
| 210 | } |
| 211 | deviceSpecific := func(m *Module) bool { |
| 212 | return m.DeviceSpecific() || m.deviceSpecificModuleContext() |
| 213 | } |
| 214 | productSpecific := func(m *Module) bool { |
| 215 | return m.ProductSpecific() || m.productSpecificModuleContext() |
| 216 | } |
| 217 | systemExtSpecific := func(m *Module) bool { |
| 218 | return m.SystemExtSpecific() |
| 219 | } |
| 220 | checkPartition(socSpecific(mod), "vendor") |
| 221 | checkPartition(deviceSpecific(mod), "odm") |
| 222 | checkPartition(productSpecific(mod), "product") |
| 223 | checkPartition(systemExtSpecific(mod), "system_ext") |
| 224 | if !partitionDefined && expected != "system" { |
| 225 | t.Errorf("%s variant of %q is expected to be installed to %s partition,"+ |
| 226 | " but installed to system partition", variant, name, expected) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | func TestInstallPartition(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 231 | t.Parallel() |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 232 | t.Helper() |
| 233 | ctx := prepareForCcTest.RunTestWithBp(t, ` |
| 234 | cc_library { |
| 235 | name: "libsystem", |
| 236 | } |
| 237 | cc_library { |
| 238 | name: "libsystem_ext", |
| 239 | system_ext_specific: true, |
| 240 | } |
| 241 | cc_library { |
| 242 | name: "libproduct", |
| 243 | product_specific: true, |
| 244 | } |
| 245 | cc_library { |
| 246 | name: "libvendor", |
| 247 | vendor: true, |
| 248 | } |
| 249 | cc_library { |
| 250 | name: "libodm", |
| 251 | device_specific: true, |
| 252 | } |
| 253 | cc_library { |
| 254 | name: "liball_available", |
| 255 | vendor_available: true, |
| 256 | product_available: true, |
| 257 | } |
| 258 | cc_library { |
| 259 | name: "libsystem_ext_all_available", |
| 260 | system_ext_specific: true, |
| 261 | vendor_available: true, |
| 262 | product_available: true, |
| 263 | } |
| 264 | cc_library { |
| 265 | name: "liball_available_odm", |
| 266 | odm_available: true, |
| 267 | product_available: true, |
| 268 | } |
| 269 | cc_library { |
| 270 | name: "libproduct_vendoravailable", |
| 271 | product_specific: true, |
| 272 | vendor_available: true, |
| 273 | } |
| 274 | cc_library { |
| 275 | name: "libproduct_odmavailable", |
| 276 | product_specific: true, |
| 277 | odm_available: true, |
| 278 | } |
| 279 | `).TestContext |
| 280 | |
| 281 | checkInstallPartition(t, ctx, "libsystem", coreVariant, "system") |
| 282 | checkInstallPartition(t, ctx, "libsystem_ext", coreVariant, "system_ext") |
| 283 | checkInstallPartition(t, ctx, "libproduct", productVariant, "product") |
| 284 | checkInstallPartition(t, ctx, "libvendor", vendorVariant, "vendor") |
| 285 | checkInstallPartition(t, ctx, "libodm", vendorVariant, "odm") |
| 286 | |
| 287 | checkInstallPartition(t, ctx, "liball_available", coreVariant, "system") |
| 288 | checkInstallPartition(t, ctx, "liball_available", productVariant, "product") |
| 289 | checkInstallPartition(t, ctx, "liball_available", vendorVariant, "vendor") |
| 290 | |
| 291 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", coreVariant, "system_ext") |
| 292 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", productVariant, "product") |
| 293 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", vendorVariant, "vendor") |
| 294 | |
| 295 | checkInstallPartition(t, ctx, "liball_available_odm", coreVariant, "system") |
| 296 | checkInstallPartition(t, ctx, "liball_available_odm", productVariant, "product") |
| 297 | checkInstallPartition(t, ctx, "liball_available_odm", vendorVariant, "odm") |
| 298 | |
| 299 | checkInstallPartition(t, ctx, "libproduct_vendoravailable", productVariant, "product") |
| 300 | checkInstallPartition(t, ctx, "libproduct_vendoravailable", vendorVariant, "vendor") |
| 301 | |
| 302 | checkInstallPartition(t, ctx, "libproduct_odmavailable", productVariant, "product") |
| 303 | checkInstallPartition(t, ctx, "libproduct_odmavailable", vendorVariant, "odm") |
| 304 | } |
| 305 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 306 | func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 307 | isVndkSp bool, extends string, variant string) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 308 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 309 | t.Helper() |
| 310 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 311 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 312 | |
| 313 | // Check library properties. |
| 314 | lib, ok := mod.compiler.(*libraryDecorator) |
| 315 | if !ok { |
| 316 | t.Errorf("%q must have libraryDecorator", name) |
| 317 | } else if lib.baseInstaller.subDir != subDir { |
| 318 | t.Errorf("%q must use %q as subdir but it is using %q", name, subDir, |
| 319 | lib.baseInstaller.subDir) |
| 320 | } |
| 321 | |
| 322 | // Check VNDK properties. |
| 323 | if mod.vndkdep == nil { |
| 324 | t.Fatalf("%q must have `vndkdep`", name) |
| 325 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 326 | if !mod.IsVndk() { |
| 327 | t.Errorf("%q IsVndk() must equal to true", name) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 328 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 329 | if mod.IsVndkSp() != isVndkSp { |
| 330 | t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | // Check VNDK extension properties. |
| 334 | isVndkExt := extends != "" |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 335 | if mod.IsVndkExt() != isVndkExt { |
| 336 | t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends { |
| 340 | t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends) |
| 341 | } |
| 342 | } |
| 343 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 344 | func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) { |
| 345 | t.Helper() |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 346 | content := android.ContentFromFileRuleForTests(t, params) |
| 347 | actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' }) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 348 | assertArrayString(t, actual, expected) |
| 349 | } |
| 350 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 351 | func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) { |
| 352 | t.Helper() |
| 353 | vndkSnapshot := ctx.SingletonForTests("vndk-snapshot") |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 354 | checkWriteFileOutput(t, vndkSnapshot.Output(output), expected) |
| 355 | } |
| 356 | |
| 357 | func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) { |
| 358 | t.Helper() |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 359 | got := ctx.ModuleForTests(module, "android_common").Module().(*vndkLibrariesTxt).fileNames |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 360 | assertArrayString(t, got, expected) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 361 | } |
| 362 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 363 | func TestVndk(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 364 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 365 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 366 | cc_library { |
| 367 | name: "libvndk", |
| 368 | vendor_available: true, |
| 369 | vndk: { |
| 370 | enabled: true, |
| 371 | }, |
| 372 | nocrt: true, |
| 373 | } |
| 374 | |
| 375 | cc_library { |
| 376 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 377 | vendor_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 378 | vndk: { |
| 379 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 380 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 381 | }, |
| 382 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 383 | stem: "libvndk-private", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 387 | name: "libvndk_product", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 388 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 389 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 390 | vndk: { |
| 391 | enabled: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 392 | }, |
| 393 | nocrt: true, |
| 394 | target: { |
| 395 | vendor: { |
| 396 | cflags: ["-DTEST"], |
| 397 | }, |
| 398 | product: { |
| 399 | cflags: ["-DTEST"], |
| 400 | }, |
| 401 | }, |
| 402 | } |
| 403 | |
| 404 | cc_library { |
| 405 | name: "libvndk_sp", |
| 406 | vendor_available: true, |
| 407 | vndk: { |
| 408 | enabled: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 409 | support_system_process: true, |
| 410 | }, |
| 411 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 412 | suffix: "-x", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | cc_library { |
| 416 | name: "libvndk_sp_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 417 | vendor_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 418 | vndk: { |
| 419 | enabled: true, |
| 420 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 421 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 422 | }, |
| 423 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 424 | target: { |
| 425 | vendor: { |
| 426 | suffix: "-x", |
| 427 | }, |
| 428 | }, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 429 | } |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 430 | |
| 431 | cc_library { |
| 432 | name: "libvndk_sp_product_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 433 | vendor_available: true, |
| 434 | product_available: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 435 | vndk: { |
| 436 | enabled: true, |
| 437 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 438 | private: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 439 | }, |
| 440 | nocrt: true, |
| 441 | target: { |
| 442 | vendor: { |
| 443 | suffix: "-x", |
| 444 | }, |
| 445 | product: { |
| 446 | suffix: "-x", |
| 447 | }, |
| 448 | }, |
| 449 | } |
| 450 | |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 451 | cc_library { |
| 452 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 453 | llndk: { |
| 454 | symbol_file: "libllndk.map.txt", |
| 455 | export_llndk_headers: ["libllndk_headers"], |
| 456 | } |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 457 | } |
| 458 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 459 | cc_library { |
| 460 | name: "libclang_rt.hwasan-llndk", |
| 461 | llndk: { |
| 462 | symbol_file: "libclang_rt.hwasan.map.txt", |
| 463 | } |
| 464 | } |
| 465 | |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 466 | cc_library_headers { |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 467 | name: "libllndk_headers", |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 468 | llndk: { |
| 469 | llndk_headers: true, |
| 470 | }, |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 471 | export_include_dirs: ["include"], |
| 472 | } |
| 473 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 474 | llndk_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 475 | name: "llndk.libraries.txt", |
| 476 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 477 | vndkcore_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 478 | name: "vndkcore.libraries.txt", |
| 479 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 480 | vndksp_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 481 | name: "vndksp.libraries.txt", |
| 482 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 483 | vndkprivate_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 484 | name: "vndkprivate.libraries.txt", |
| 485 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 486 | vndkproduct_libraries_txt { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 487 | name: "vndkproduct.libraries.txt", |
| 488 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 489 | vndkcorevariant_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 490 | name: "vndkcorevariant.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 491 | insert_vndk_version: false, |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 492 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 493 | ` |
| 494 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 495 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 496 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 497 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 498 | |
| 499 | ctx := testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 500 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 501 | // subdir == "" because VNDK libs are not supposed to be installed separately. |
| 502 | // They are installed as part of VNDK APEX instead. |
| 503 | checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant) |
| 504 | checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 505 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant) |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 506 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant) |
| 507 | checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 508 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 509 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 510 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant) |
| 511 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 512 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 513 | // Check VNDK snapshot output. |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 514 | snapshotDir := "vndk-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 515 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 516 | |
| 517 | vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 518 | "arm64", "armv8-a")) |
| 519 | vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 520 | "arm", "armv7-a-neon")) |
| 521 | |
| 522 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") |
| 523 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 524 | llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub") |
| 525 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 526 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") |
| 527 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 528 | llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 529 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 530 | variant := "android_vendor.29_arm64_armv8-a_shared" |
| 531 | variant2nd := "android_vendor.29_arm_armv7-a-neon_shared" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 532 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 533 | snapshotSingleton := ctx.SingletonForTests("vndk-snapshot") |
| 534 | |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 535 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant) |
| 536 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) |
| 537 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant) |
| 538 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd) |
| 539 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) |
| 540 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) |
| 541 | CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant) |
| 542 | CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 543 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 544 | snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 545 | CheckSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "android_common") |
| 546 | CheckSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "android_common") |
| 547 | CheckSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "android_common") |
| 548 | CheckSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "android_common") |
| 549 | 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] | 550 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 551 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 552 | "LLNDK: libc.so", |
| 553 | "LLNDK: libdl.so", |
| 554 | "LLNDK: libft2.so", |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 555 | "LLNDK: libllndk.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 556 | "LLNDK: libm.so", |
| 557 | "VNDK-SP: libc++.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 558 | "VNDK-SP: libvndk_sp-x.so", |
| 559 | "VNDK-SP: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 560 | "VNDK-SP: libvndk_sp_product_private-x.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 561 | "VNDK-core: libvndk-private.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 562 | "VNDK-core: libvndk.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 563 | "VNDK-core: libvndk_product.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 564 | "VNDK-private: libft2.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 565 | "VNDK-private: libvndk-private.so", |
| 566 | "VNDK-private: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 567 | "VNDK-private: libvndk_sp_product_private-x.so", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 568 | "VNDK-product: libc++.so", |
| 569 | "VNDK-product: libvndk_product.so", |
| 570 | "VNDK-product: libvndk_sp_product_private-x.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 571 | }) |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 572 | 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] | 573 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"}) |
| 574 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"}) |
| 575 | 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] | 576 | 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] | 577 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) |
| 578 | } |
| 579 | |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 580 | func TestVndkWithHostSupported(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 581 | t.Parallel() |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 582 | ctx := testCc(t, ` |
| 583 | cc_library { |
| 584 | name: "libvndk_host_supported", |
| 585 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 586 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 587 | vndk: { |
| 588 | enabled: true, |
| 589 | }, |
| 590 | host_supported: true, |
| 591 | } |
| 592 | |
| 593 | cc_library { |
| 594 | name: "libvndk_host_supported_but_disabled_on_device", |
| 595 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 596 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 597 | vndk: { |
| 598 | enabled: true, |
| 599 | }, |
| 600 | host_supported: true, |
| 601 | enabled: false, |
| 602 | target: { |
| 603 | host: { |
| 604 | enabled: true, |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 609 | vndkcore_libraries_txt { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 610 | name: "vndkcore.libraries.txt", |
| 611 | } |
| 612 | `) |
| 613 | |
| 614 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"}) |
| 615 | } |
| 616 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 617 | func TestVndkLibrariesTxtAndroidMk(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 618 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 619 | bp := ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 620 | llndk_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 621 | name: "llndk.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 622 | insert_vndk_version: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 623 | }` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 624 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 625 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 626 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 627 | config.TestProductVariables.KeepVndk = BoolPtr(true) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 628 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 629 | |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 630 | module := ctx.ModuleForTests("llndk.libraries.txt", "android_common") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 631 | entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0] |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 632 | assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"}) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | func TestVndkUsingCoreVariant(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 636 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 637 | bp := ` |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 638 | cc_library { |
| 639 | name: "libvndk", |
| 640 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 641 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 642 | vndk: { |
| 643 | enabled: true, |
| 644 | }, |
| 645 | nocrt: true, |
| 646 | } |
| 647 | |
| 648 | cc_library { |
| 649 | name: "libvndk_sp", |
| 650 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 651 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 652 | vndk: { |
| 653 | enabled: true, |
| 654 | support_system_process: true, |
| 655 | }, |
| 656 | nocrt: true, |
| 657 | } |
| 658 | |
| 659 | cc_library { |
| 660 | name: "libvndk2", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 661 | vendor_available: true, |
| 662 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 663 | vndk: { |
| 664 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 665 | private: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 666 | }, |
| 667 | nocrt: true, |
| 668 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 669 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 670 | vndkcorevariant_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 671 | name: "vndkcorevariant.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 672 | insert_vndk_version: false, |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 673 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 674 | ` |
| 675 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 676 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 677 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 678 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 679 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 680 | |
| 681 | setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"}) |
| 682 | |
| 683 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 684 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 685 | 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] | 686 | } |
| 687 | |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 688 | func TestDataLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 689 | t.Parallel() |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 690 | bp := ` |
| 691 | cc_test_library { |
| 692 | name: "test_lib", |
| 693 | srcs: ["test_lib.cpp"], |
| 694 | gtest: false, |
| 695 | } |
| 696 | |
| 697 | cc_test { |
| 698 | name: "main_test", |
| 699 | data_libs: ["test_lib"], |
| 700 | gtest: false, |
| 701 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 702 | ` |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 703 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 704 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 705 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 706 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 707 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 708 | |
| 709 | ctx := testCcWithConfig(t, config) |
| 710 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 711 | testBinary := module.(*Module).linker.(*testBinary) |
| 712 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 713 | if err != nil { |
| 714 | t.Errorf("Expected cc_test to produce output files, error: %s", err) |
| 715 | return |
| 716 | } |
| 717 | if len(outputFiles) != 1 { |
| 718 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 719 | return |
| 720 | } |
| 721 | if len(testBinary.dataPaths()) != 1 { |
| 722 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 723 | return |
| 724 | } |
| 725 | |
| 726 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 727 | testBinaryPath := testBinary.dataPaths()[0].SrcPath.String() |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 728 | |
| 729 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 730 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 731 | return |
| 732 | } |
| 733 | if !strings.HasSuffix(testBinaryPath, "/test_lib.so") { |
| 734 | t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath) |
| 735 | return |
| 736 | } |
| 737 | } |
| 738 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 739 | func TestDataLibsRelativeInstallPath(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 740 | t.Parallel() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 741 | bp := ` |
| 742 | cc_test_library { |
| 743 | name: "test_lib", |
| 744 | srcs: ["test_lib.cpp"], |
| 745 | relative_install_path: "foo/bar/baz", |
| 746 | gtest: false, |
| 747 | } |
| 748 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 749 | cc_binary { |
| 750 | name: "test_bin", |
| 751 | relative_install_path: "foo/bar/baz", |
| 752 | compile_multilib: "both", |
| 753 | } |
| 754 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 755 | cc_test { |
| 756 | name: "main_test", |
| 757 | data_libs: ["test_lib"], |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 758 | data_bins: ["test_bin"], |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 759 | gtest: false, |
| 760 | } |
| 761 | ` |
| 762 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 763 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 764 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 765 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 766 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 767 | |
| 768 | ctx := testCcWithConfig(t, config) |
| 769 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 770 | testBinary := module.(*Module).linker.(*testBinary) |
| 771 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 772 | if err != nil { |
| 773 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 774 | } |
| 775 | if len(outputFiles) != 1 { |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 776 | t.Fatalf("expected exactly one output file. output files: [%s]", outputFiles) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 777 | } |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 778 | if len(testBinary.dataPaths()) != 2 { |
| 779 | 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] | 780 | } |
| 781 | |
| 782 | outputPath := outputFiles[0].String() |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 783 | |
| 784 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 785 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 786 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 787 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 788 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 789 | 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] | 790 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 791 | } |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 792 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][1], ":test_bin:foo/bar/baz") { |
| 793 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_bin:foo/bar/baz`,"+ |
| 794 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][1]) |
| 795 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 796 | } |
| 797 | |
Trevor Radcliffe | f389cb4 | 2022-03-24 21:06:14 +0000 | [diff] [blame] | 798 | func TestTestBinaryTestSuites(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 799 | t.Parallel() |
Trevor Radcliffe | f389cb4 | 2022-03-24 21:06:14 +0000 | [diff] [blame] | 800 | bp := ` |
| 801 | cc_test { |
| 802 | name: "main_test", |
| 803 | srcs: ["main_test.cpp"], |
| 804 | test_suites: [ |
| 805 | "suite_1", |
| 806 | "suite_2", |
| 807 | ], |
| 808 | gtest: false, |
| 809 | } |
| 810 | ` |
| 811 | |
| 812 | ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext |
| 813 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 814 | |
| 815 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
| 816 | compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"] |
| 817 | if len(compatEntries) != 2 { |
| 818 | t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries)) |
| 819 | } |
| 820 | if compatEntries[0] != "suite_1" { |
| 821 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+ |
| 822 | " but was '%s'", compatEntries[0]) |
| 823 | } |
| 824 | if compatEntries[1] != "suite_2" { |
| 825 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+ |
| 826 | " but was '%s'", compatEntries[1]) |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | func TestTestLibraryTestSuites(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 831 | t.Parallel() |
Trevor Radcliffe | f389cb4 | 2022-03-24 21:06:14 +0000 | [diff] [blame] | 832 | bp := ` |
| 833 | cc_test_library { |
| 834 | name: "main_test_lib", |
| 835 | srcs: ["main_test_lib.cpp"], |
| 836 | test_suites: [ |
| 837 | "suite_1", |
| 838 | "suite_2", |
| 839 | ], |
| 840 | gtest: false, |
| 841 | } |
| 842 | ` |
| 843 | |
| 844 | ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext |
| 845 | module := ctx.ModuleForTests("main_test_lib", "android_arm_armv7-a-neon_shared").Module() |
| 846 | |
| 847 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
| 848 | compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"] |
| 849 | if len(compatEntries) != 2 { |
| 850 | t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries)) |
| 851 | } |
| 852 | if compatEntries[0] != "suite_1" { |
| 853 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+ |
| 854 | " but was '%s'", compatEntries[0]) |
| 855 | } |
| 856 | if compatEntries[1] != "suite_2" { |
| 857 | t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+ |
| 858 | " but was '%s'", compatEntries[1]) |
| 859 | } |
| 860 | } |
| 861 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 862 | func TestVndkModuleError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 863 | t.Parallel() |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 864 | // Check the error message for vendor_available and product_available properties. |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 865 | 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] | 866 | cc_library { |
| 867 | name: "libvndk", |
| 868 | vndk: { |
| 869 | enabled: true, |
| 870 | }, |
| 871 | nocrt: true, |
| 872 | } |
| 873 | `) |
| 874 | |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 875 | 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] | 876 | cc_library { |
| 877 | name: "libvndk", |
| 878 | product_available: true, |
| 879 | vndk: { |
| 880 | enabled: true, |
| 881 | }, |
| 882 | nocrt: true, |
| 883 | } |
| 884 | `) |
| 885 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 886 | testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", ` |
| 887 | cc_library { |
| 888 | name: "libvndkprop", |
| 889 | vendor_available: true, |
| 890 | product_available: true, |
| 891 | vndk: { |
| 892 | enabled: true, |
| 893 | }, |
| 894 | nocrt: true, |
| 895 | target: { |
| 896 | vendor: { |
| 897 | cflags: ["-DTEST",], |
| 898 | }, |
| 899 | }, |
| 900 | } |
| 901 | `) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 902 | } |
| 903 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 904 | func TestVndkDepError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 905 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 906 | // Check whether an error is emitted when a VNDK lib depends on a system lib. |
| 907 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 908 | cc_library { |
| 909 | name: "libvndk", |
| 910 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 911 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 912 | vndk: { |
| 913 | enabled: true, |
| 914 | }, |
| 915 | shared_libs: ["libfwk"], // Cause error |
| 916 | nocrt: true, |
| 917 | } |
| 918 | |
| 919 | cc_library { |
| 920 | name: "libfwk", |
| 921 | nocrt: true, |
| 922 | } |
| 923 | `) |
| 924 | |
| 925 | // Check whether an error is emitted when a VNDK lib depends on a vendor lib. |
| 926 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 927 | cc_library { |
| 928 | name: "libvndk", |
| 929 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 930 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 931 | vndk: { |
| 932 | enabled: true, |
| 933 | }, |
| 934 | shared_libs: ["libvendor"], // Cause error |
| 935 | nocrt: true, |
| 936 | } |
| 937 | |
| 938 | cc_library { |
| 939 | name: "libvendor", |
| 940 | vendor: true, |
| 941 | nocrt: true, |
| 942 | } |
| 943 | `) |
| 944 | |
| 945 | // Check whether an error is emitted when a VNDK-SP lib depends on a system lib. |
| 946 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 947 | cc_library { |
| 948 | name: "libvndk_sp", |
| 949 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 950 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 951 | vndk: { |
| 952 | enabled: true, |
| 953 | support_system_process: true, |
| 954 | }, |
| 955 | shared_libs: ["libfwk"], // Cause error |
| 956 | nocrt: true, |
| 957 | } |
| 958 | |
| 959 | cc_library { |
| 960 | name: "libfwk", |
| 961 | nocrt: true, |
| 962 | } |
| 963 | `) |
| 964 | |
| 965 | // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib. |
| 966 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 967 | cc_library { |
| 968 | name: "libvndk_sp", |
| 969 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 970 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 971 | vndk: { |
| 972 | enabled: true, |
| 973 | support_system_process: true, |
| 974 | }, |
| 975 | shared_libs: ["libvendor"], // Cause error |
| 976 | nocrt: true, |
| 977 | } |
| 978 | |
| 979 | cc_library { |
| 980 | name: "libvendor", |
| 981 | vendor: true, |
| 982 | nocrt: true, |
| 983 | } |
| 984 | `) |
| 985 | |
| 986 | // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib. |
| 987 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 988 | cc_library { |
| 989 | name: "libvndk_sp", |
| 990 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 991 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 992 | vndk: { |
| 993 | enabled: true, |
| 994 | support_system_process: true, |
| 995 | }, |
| 996 | shared_libs: ["libvndk"], // Cause error |
| 997 | nocrt: true, |
| 998 | } |
| 999 | |
| 1000 | cc_library { |
| 1001 | name: "libvndk", |
| 1002 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1003 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1004 | vndk: { |
| 1005 | enabled: true, |
| 1006 | }, |
| 1007 | nocrt: true, |
| 1008 | } |
| 1009 | `) |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1010 | |
| 1011 | // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib. |
| 1012 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1013 | cc_library { |
| 1014 | name: "libvndk", |
| 1015 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1016 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1017 | vndk: { |
| 1018 | enabled: true, |
| 1019 | }, |
| 1020 | shared_libs: ["libnonvndk"], |
| 1021 | nocrt: true, |
| 1022 | } |
| 1023 | |
| 1024 | cc_library { |
| 1025 | name: "libnonvndk", |
| 1026 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame^] | 1027 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1028 | nocrt: true, |
| 1029 | } |
| 1030 | `) |
| 1031 | |
| 1032 | // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib. |
| 1033 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1034 | cc_library { |
| 1035 | name: "libvndkprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1036 | vendor_available: true, |
| 1037 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1038 | vndk: { |
| 1039 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1040 | private: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1041 | }, |
| 1042 | shared_libs: ["libnonvndk"], |
| 1043 | nocrt: true, |
| 1044 | } |
| 1045 | |
| 1046 | cc_library { |
| 1047 | name: "libnonvndk", |
| 1048 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame^] | 1049 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1050 | nocrt: true, |
| 1051 | } |
| 1052 | `) |
| 1053 | |
| 1054 | // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib. |
| 1055 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1056 | cc_library { |
| 1057 | name: "libvndksp", |
| 1058 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1059 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1060 | vndk: { |
| 1061 | enabled: true, |
| 1062 | support_system_process: true, |
| 1063 | }, |
| 1064 | shared_libs: ["libnonvndk"], |
| 1065 | nocrt: true, |
| 1066 | } |
| 1067 | |
| 1068 | cc_library { |
| 1069 | name: "libnonvndk", |
| 1070 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame^] | 1071 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1072 | nocrt: true, |
| 1073 | } |
| 1074 | `) |
| 1075 | |
| 1076 | // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib. |
| 1077 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1078 | cc_library { |
| 1079 | name: "libvndkspprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1080 | vendor_available: true, |
| 1081 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1082 | vndk: { |
| 1083 | enabled: true, |
| 1084 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1085 | private: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1086 | }, |
| 1087 | shared_libs: ["libnonvndk"], |
| 1088 | nocrt: true, |
| 1089 | } |
| 1090 | |
| 1091 | cc_library { |
| 1092 | name: "libnonvndk", |
| 1093 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame^] | 1094 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1095 | nocrt: true, |
| 1096 | } |
| 1097 | `) |
| 1098 | } |
| 1099 | |
| 1100 | func TestDoubleLoadbleDep(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1101 | t.Parallel() |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1102 | // okay to link : LLNDK -> double_loadable VNDK |
| 1103 | testCc(t, ` |
| 1104 | cc_library { |
| 1105 | name: "libllndk", |
| 1106 | shared_libs: ["libdoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1107 | llndk: { |
| 1108 | symbol_file: "libllndk.map.txt", |
| 1109 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | cc_library { |
| 1113 | name: "libdoubleloadable", |
| 1114 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1115 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1116 | vndk: { |
| 1117 | enabled: true, |
| 1118 | }, |
| 1119 | double_loadable: true, |
| 1120 | } |
| 1121 | `) |
| 1122 | // okay to link : LLNDK -> VNDK-SP |
| 1123 | testCc(t, ` |
| 1124 | cc_library { |
| 1125 | name: "libllndk", |
| 1126 | shared_libs: ["libvndksp"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1127 | llndk: { |
| 1128 | symbol_file: "libllndk.map.txt", |
| 1129 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | cc_library { |
| 1133 | name: "libvndksp", |
| 1134 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1135 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1136 | vndk: { |
| 1137 | enabled: true, |
| 1138 | support_system_process: true, |
| 1139 | }, |
| 1140 | } |
| 1141 | `) |
| 1142 | // okay to link : double_loadable -> double_loadable |
| 1143 | testCc(t, ` |
| 1144 | cc_library { |
| 1145 | name: "libdoubleloadable1", |
| 1146 | shared_libs: ["libdoubleloadable2"], |
| 1147 | vendor_available: true, |
| 1148 | double_loadable: true, |
| 1149 | } |
| 1150 | |
| 1151 | cc_library { |
| 1152 | name: "libdoubleloadable2", |
| 1153 | vendor_available: true, |
| 1154 | double_loadable: true, |
| 1155 | } |
| 1156 | `) |
| 1157 | // okay to link : double_loadable VNDK -> double_loadable VNDK private |
| 1158 | testCc(t, ` |
| 1159 | cc_library { |
| 1160 | name: "libdoubleloadable", |
| 1161 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1162 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1163 | vndk: { |
| 1164 | enabled: true, |
| 1165 | }, |
| 1166 | double_loadable: true, |
| 1167 | shared_libs: ["libnondoubleloadable"], |
| 1168 | } |
| 1169 | |
| 1170 | cc_library { |
| 1171 | name: "libnondoubleloadable", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1172 | vendor_available: true, |
| 1173 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1174 | vndk: { |
| 1175 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1176 | private: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1177 | }, |
| 1178 | double_loadable: true, |
| 1179 | } |
| 1180 | `) |
| 1181 | // okay to link : LLNDK -> core-only -> vendor_available & double_loadable |
| 1182 | testCc(t, ` |
| 1183 | cc_library { |
| 1184 | name: "libllndk", |
| 1185 | shared_libs: ["libcoreonly"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1186 | llndk: { |
| 1187 | symbol_file: "libllndk.map.txt", |
| 1188 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | cc_library { |
| 1192 | name: "libcoreonly", |
| 1193 | shared_libs: ["libvendoravailable"], |
| 1194 | } |
| 1195 | |
| 1196 | // indirect dependency of LLNDK |
| 1197 | cc_library { |
| 1198 | name: "libvendoravailable", |
| 1199 | vendor_available: true, |
| 1200 | double_loadable: true, |
| 1201 | } |
| 1202 | `) |
| 1203 | } |
| 1204 | |
| 1205 | func TestDoubleLoadableDepError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1206 | t.Parallel() |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1207 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. |
| 1208 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1209 | cc_library { |
| 1210 | name: "libllndk", |
| 1211 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1212 | llndk: { |
| 1213 | symbol_file: "libllndk.map.txt", |
| 1214 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | cc_library { |
| 1218 | name: "libnondoubleloadable", |
| 1219 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1220 | product_available: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1221 | vndk: { |
| 1222 | enabled: true, |
| 1223 | }, |
| 1224 | } |
| 1225 | `) |
| 1226 | |
| 1227 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. |
| 1228 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1229 | cc_library { |
| 1230 | name: "libllndk", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 1231 | no_libcrt: true, |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1232 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1233 | llndk: { |
| 1234 | symbol_file: "libllndk.map.txt", |
| 1235 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | cc_library { |
| 1239 | name: "libnondoubleloadable", |
| 1240 | vendor_available: true, |
| 1241 | } |
| 1242 | `) |
| 1243 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1244 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. |
| 1245 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` |
| 1246 | cc_library { |
| 1247 | name: "libllndk", |
| 1248 | shared_libs: ["libcoreonly"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1249 | llndk: { |
| 1250 | symbol_file: "libllndk.map.txt", |
| 1251 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | cc_library { |
| 1255 | name: "libcoreonly", |
| 1256 | shared_libs: ["libvendoravailable"], |
| 1257 | } |
| 1258 | |
| 1259 | // indirect dependency of LLNDK |
| 1260 | cc_library { |
| 1261 | name: "libvendoravailable", |
| 1262 | vendor_available: true, |
| 1263 | } |
| 1264 | `) |
Jiyong Park | 0474e1f | 2021-01-14 14:26:06 +0900 | [diff] [blame] | 1265 | |
| 1266 | // The error is not from 'client' but from 'libllndk' |
| 1267 | testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", ` |
| 1268 | cc_library { |
| 1269 | name: "client", |
| 1270 | vendor_available: true, |
| 1271 | double_loadable: true, |
| 1272 | shared_libs: ["libllndk"], |
| 1273 | } |
| 1274 | cc_library { |
| 1275 | name: "libllndk", |
| 1276 | shared_libs: ["libnondoubleloadable"], |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1277 | llndk: { |
| 1278 | symbol_file: "libllndk.map.txt", |
| 1279 | } |
Jiyong Park | 0474e1f | 2021-01-14 14:26:06 +0900 | [diff] [blame] | 1280 | } |
| 1281 | cc_library { |
| 1282 | name: "libnondoubleloadable", |
| 1283 | vendor_available: true, |
| 1284 | } |
| 1285 | `) |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1286 | } |
| 1287 | |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1288 | func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1289 | t.Parallel() |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1290 | testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", ` |
| 1291 | cc_library { |
| 1292 | name: "libvndksp", |
| 1293 | shared_libs: ["libanothervndksp"], |
| 1294 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1295 | product_available: true, |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1296 | vndk: { |
| 1297 | enabled: true, |
| 1298 | support_system_process: true, |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | cc_library { |
| 1303 | name: "libllndk", |
| 1304 | shared_libs: ["libanothervndksp"], |
| 1305 | } |
| 1306 | |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1307 | cc_library { |
| 1308 | name: "libanothervndksp", |
| 1309 | vendor_available: true, |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame^] | 1310 | product_available: true, |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 1311 | } |
| 1312 | `) |
| 1313 | } |
| 1314 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1315 | func TestVndkExt(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1316 | t.Parallel() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1317 | // This test checks the VNDK-Ext properties. |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1318 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1319 | cc_library { |
| 1320 | name: "libvndk", |
| 1321 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1322 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1323 | vndk: { |
| 1324 | enabled: true, |
| 1325 | }, |
| 1326 | nocrt: true, |
| 1327 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1328 | cc_library { |
| 1329 | name: "libvndk2", |
| 1330 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1331 | product_available: true, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1332 | vndk: { |
| 1333 | enabled: true, |
| 1334 | }, |
| 1335 | target: { |
| 1336 | vendor: { |
| 1337 | suffix: "-suffix", |
| 1338 | }, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1339 | product: { |
| 1340 | suffix: "-suffix", |
| 1341 | }, |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1342 | }, |
| 1343 | nocrt: true, |
| 1344 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1345 | |
| 1346 | cc_library { |
| 1347 | name: "libvndk_ext", |
| 1348 | vendor: true, |
| 1349 | vndk: { |
| 1350 | enabled: true, |
| 1351 | extends: "libvndk", |
| 1352 | }, |
| 1353 | nocrt: true, |
| 1354 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1355 | |
| 1356 | cc_library { |
| 1357 | name: "libvndk2_ext", |
| 1358 | vendor: true, |
| 1359 | vndk: { |
| 1360 | enabled: true, |
| 1361 | extends: "libvndk2", |
| 1362 | }, |
| 1363 | nocrt: true, |
| 1364 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1365 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1366 | cc_library { |
| 1367 | name: "libvndk_ext_product", |
| 1368 | product_specific: true, |
| 1369 | vndk: { |
| 1370 | enabled: true, |
| 1371 | extends: "libvndk", |
| 1372 | }, |
| 1373 | nocrt: true, |
| 1374 | } |
Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1375 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1376 | cc_library { |
| 1377 | name: "libvndk2_ext_product", |
| 1378 | product_specific: true, |
| 1379 | vndk: { |
| 1380 | enabled: true, |
| 1381 | extends: "libvndk2", |
| 1382 | }, |
| 1383 | nocrt: true, |
| 1384 | } |
| 1385 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1386 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1387 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1388 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1389 | |
| 1390 | ctx := testCcWithConfig(t, config) |
| 1391 | |
| 1392 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) |
| 1393 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) |
| 1394 | |
| 1395 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) |
| 1396 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") |
| 1397 | |
| 1398 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) |
| 1399 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1400 | } |
| 1401 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1402 | func TestVndkExtError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1403 | t.Parallel() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1404 | // 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] | 1405 | 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] | 1406 | cc_library { |
| 1407 | name: "libvndk", |
| 1408 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1409 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1410 | vndk: { |
| 1411 | enabled: true, |
| 1412 | }, |
| 1413 | nocrt: true, |
| 1414 | } |
| 1415 | |
| 1416 | cc_library { |
| 1417 | name: "libvndk_ext", |
| 1418 | vndk: { |
| 1419 | enabled: true, |
| 1420 | extends: "libvndk", |
| 1421 | }, |
| 1422 | nocrt: true, |
| 1423 | } |
| 1424 | `) |
| 1425 | |
| 1426 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1427 | cc_library { |
| 1428 | name: "libvndk", |
| 1429 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1430 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1431 | vndk: { |
| 1432 | enabled: true, |
| 1433 | }, |
| 1434 | nocrt: true, |
| 1435 | } |
| 1436 | |
| 1437 | cc_library { |
| 1438 | name: "libvndk_ext", |
| 1439 | vendor: true, |
| 1440 | vndk: { |
| 1441 | enabled: true, |
| 1442 | }, |
| 1443 | nocrt: true, |
| 1444 | } |
| 1445 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1446 | |
| 1447 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` |
| 1448 | cc_library { |
| 1449 | name: "libvndk", |
| 1450 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1451 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1452 | vndk: { |
| 1453 | enabled: true, |
| 1454 | }, |
| 1455 | nocrt: true, |
| 1456 | } |
| 1457 | |
| 1458 | cc_library { |
| 1459 | name: "libvndk_ext_product", |
| 1460 | product_specific: true, |
| 1461 | vndk: { |
| 1462 | enabled: true, |
| 1463 | }, |
| 1464 | nocrt: true, |
| 1465 | } |
| 1466 | `) |
| 1467 | |
| 1468 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` |
| 1469 | cc_library { |
| 1470 | name: "libvndk", |
| 1471 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1472 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1473 | vndk: { |
| 1474 | enabled: true, |
| 1475 | }, |
| 1476 | nocrt: true, |
| 1477 | } |
| 1478 | |
| 1479 | cc_library { |
| 1480 | name: "libvndk_ext_product", |
| 1481 | product_specific: true, |
| 1482 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1483 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1484 | vndk: { |
| 1485 | enabled: true, |
| 1486 | extends: "libvndk", |
| 1487 | }, |
| 1488 | nocrt: true, |
| 1489 | } |
| 1490 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1494 | t.Parallel() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1495 | // This test ensures an error is emitted for inconsistent support_system_process. |
| 1496 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1497 | cc_library { |
| 1498 | name: "libvndk", |
| 1499 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1500 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1501 | vndk: { |
| 1502 | enabled: true, |
| 1503 | }, |
| 1504 | nocrt: true, |
| 1505 | } |
| 1506 | |
| 1507 | cc_library { |
| 1508 | name: "libvndk_sp_ext", |
| 1509 | vendor: true, |
| 1510 | vndk: { |
| 1511 | enabled: true, |
| 1512 | extends: "libvndk", |
| 1513 | support_system_process: true, |
| 1514 | }, |
| 1515 | nocrt: true, |
| 1516 | } |
| 1517 | `) |
| 1518 | |
| 1519 | testCcError(t, "module \".*\" with mismatched support_system_process", ` |
| 1520 | cc_library { |
| 1521 | name: "libvndk_sp", |
| 1522 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1523 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1524 | vndk: { |
| 1525 | enabled: true, |
| 1526 | support_system_process: true, |
| 1527 | }, |
| 1528 | nocrt: true, |
| 1529 | } |
| 1530 | |
| 1531 | cc_library { |
| 1532 | name: "libvndk_ext", |
| 1533 | vendor: true, |
| 1534 | vndk: { |
| 1535 | enabled: true, |
| 1536 | extends: "libvndk_sp", |
| 1537 | }, |
| 1538 | nocrt: true, |
| 1539 | } |
| 1540 | `) |
| 1541 | } |
| 1542 | |
| 1543 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1544 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1545 | // 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] | 1546 | // with `private: true`. |
| 1547 | testCcError(t, "`extends` refers module \".*\" which has `private: true`", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1548 | cc_library { |
| 1549 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1550 | vendor_available: true, |
| 1551 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1552 | vndk: { |
| 1553 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1554 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1555 | }, |
| 1556 | nocrt: true, |
| 1557 | } |
| 1558 | |
| 1559 | cc_library { |
| 1560 | name: "libvndk_ext", |
| 1561 | vendor: true, |
| 1562 | vndk: { |
| 1563 | enabled: true, |
| 1564 | extends: "libvndk", |
| 1565 | }, |
| 1566 | nocrt: true, |
| 1567 | } |
| 1568 | `) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1569 | |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1570 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", ` |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1571 | cc_library { |
| 1572 | name: "libvndk", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1573 | vendor_available: true, |
| 1574 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1575 | vndk: { |
| 1576 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 1577 | private: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1578 | }, |
| 1579 | nocrt: true, |
| 1580 | } |
| 1581 | |
| 1582 | cc_library { |
| 1583 | name: "libvndk_ext_product", |
| 1584 | product_specific: true, |
| 1585 | vndk: { |
| 1586 | enabled: true, |
| 1587 | extends: "libvndk", |
| 1588 | }, |
| 1589 | nocrt: true, |
| 1590 | } |
| 1591 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1592 | } |
| 1593 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1594 | func TestVendorModuleUseVndkExt(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1595 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1596 | // 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] | 1597 | testCc(t, ` |
| 1598 | cc_library { |
| 1599 | name: "libvndk", |
| 1600 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1601 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1602 | vndk: { |
| 1603 | enabled: true, |
| 1604 | }, |
| 1605 | nocrt: true, |
| 1606 | } |
| 1607 | |
| 1608 | cc_library { |
| 1609 | name: "libvndk_ext", |
| 1610 | vendor: true, |
| 1611 | vndk: { |
| 1612 | enabled: true, |
| 1613 | extends: "libvndk", |
| 1614 | }, |
| 1615 | nocrt: true, |
| 1616 | } |
| 1617 | |
| 1618 | cc_library { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1619 | name: "libvndk_sp", |
| 1620 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1621 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1622 | vndk: { |
| 1623 | enabled: true, |
| 1624 | support_system_process: true, |
| 1625 | }, |
| 1626 | nocrt: true, |
| 1627 | } |
| 1628 | |
| 1629 | cc_library { |
| 1630 | name: "libvndk_sp_ext", |
| 1631 | vendor: true, |
| 1632 | vndk: { |
| 1633 | enabled: true, |
| 1634 | extends: "libvndk_sp", |
| 1635 | support_system_process: true, |
| 1636 | }, |
| 1637 | nocrt: true, |
| 1638 | } |
| 1639 | |
| 1640 | cc_library { |
| 1641 | name: "libvendor", |
| 1642 | vendor: true, |
| 1643 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], |
| 1644 | nocrt: true, |
| 1645 | } |
| 1646 | `) |
| 1647 | } |
| 1648 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1649 | func TestVndkExtUseVendorLib(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1650 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1651 | // 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] | 1652 | testCc(t, ` |
| 1653 | cc_library { |
| 1654 | name: "libvndk", |
| 1655 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1656 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1657 | vndk: { |
| 1658 | enabled: true, |
| 1659 | }, |
| 1660 | nocrt: true, |
| 1661 | } |
| 1662 | |
| 1663 | cc_library { |
| 1664 | name: "libvndk_ext", |
| 1665 | vendor: true, |
| 1666 | vndk: { |
| 1667 | enabled: true, |
| 1668 | extends: "libvndk", |
| 1669 | }, |
| 1670 | shared_libs: ["libvendor"], |
| 1671 | nocrt: true, |
| 1672 | } |
| 1673 | |
| 1674 | cc_library { |
| 1675 | name: "libvendor", |
| 1676 | vendor: true, |
| 1677 | nocrt: true, |
| 1678 | } |
| 1679 | `) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1680 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1681 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. |
| 1682 | testCc(t, ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1683 | cc_library { |
| 1684 | name: "libvndk_sp", |
| 1685 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1686 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1687 | vndk: { |
| 1688 | enabled: true, |
| 1689 | support_system_process: true, |
| 1690 | }, |
| 1691 | nocrt: true, |
| 1692 | } |
| 1693 | |
| 1694 | cc_library { |
| 1695 | name: "libvndk_sp_ext", |
| 1696 | vendor: true, |
| 1697 | vndk: { |
| 1698 | enabled: true, |
| 1699 | extends: "libvndk_sp", |
| 1700 | support_system_process: true, |
| 1701 | }, |
| 1702 | shared_libs: ["libvendor"], // Cause an error |
| 1703 | nocrt: true, |
| 1704 | } |
| 1705 | |
| 1706 | cc_library { |
| 1707 | name: "libvendor", |
| 1708 | vendor: true, |
| 1709 | nocrt: true, |
| 1710 | } |
| 1711 | `) |
| 1712 | } |
| 1713 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1714 | func TestProductVndkExtDependency(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1715 | t.Parallel() |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1716 | bp := ` |
| 1717 | cc_library { |
| 1718 | name: "libvndk", |
| 1719 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1720 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1721 | vndk: { |
| 1722 | enabled: true, |
| 1723 | }, |
| 1724 | nocrt: true, |
| 1725 | } |
| 1726 | |
| 1727 | cc_library { |
| 1728 | name: "libvndk_ext_product", |
| 1729 | product_specific: true, |
| 1730 | vndk: { |
| 1731 | enabled: true, |
| 1732 | extends: "libvndk", |
| 1733 | }, |
| 1734 | shared_libs: ["libproduct_for_vndklibs"], |
| 1735 | nocrt: true, |
| 1736 | } |
| 1737 | |
| 1738 | cc_library { |
| 1739 | name: "libvndk_sp", |
| 1740 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1741 | product_available: true, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1742 | vndk: { |
| 1743 | enabled: true, |
| 1744 | support_system_process: true, |
| 1745 | }, |
| 1746 | nocrt: true, |
| 1747 | } |
| 1748 | |
| 1749 | cc_library { |
| 1750 | name: "libvndk_sp_ext_product", |
| 1751 | product_specific: true, |
| 1752 | vndk: { |
| 1753 | enabled: true, |
| 1754 | extends: "libvndk_sp", |
| 1755 | support_system_process: true, |
| 1756 | }, |
| 1757 | shared_libs: ["libproduct_for_vndklibs"], |
| 1758 | nocrt: true, |
| 1759 | } |
| 1760 | |
| 1761 | cc_library { |
| 1762 | name: "libproduct", |
| 1763 | product_specific: true, |
| 1764 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], |
| 1765 | nocrt: true, |
| 1766 | } |
| 1767 | |
| 1768 | cc_library { |
| 1769 | name: "libproduct_for_vndklibs", |
| 1770 | product_specific: true, |
| 1771 | nocrt: true, |
| 1772 | } |
| 1773 | ` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 1774 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1775 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 1776 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1777 | |
| 1778 | testCcWithConfig(t, config) |
| 1779 | } |
| 1780 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1781 | func TestVndkSpExtUseVndkError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1782 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1783 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK |
| 1784 | // library. |
| 1785 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1786 | cc_library { |
| 1787 | name: "libvndk", |
| 1788 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1789 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1790 | vndk: { |
| 1791 | enabled: true, |
| 1792 | }, |
| 1793 | nocrt: true, |
| 1794 | } |
| 1795 | |
| 1796 | cc_library { |
| 1797 | name: "libvndk_sp", |
| 1798 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1799 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1800 | vndk: { |
| 1801 | enabled: true, |
| 1802 | support_system_process: true, |
| 1803 | }, |
| 1804 | nocrt: true, |
| 1805 | } |
| 1806 | |
| 1807 | cc_library { |
| 1808 | name: "libvndk_sp_ext", |
| 1809 | vendor: true, |
| 1810 | vndk: { |
| 1811 | enabled: true, |
| 1812 | extends: "libvndk_sp", |
| 1813 | support_system_process: true, |
| 1814 | }, |
| 1815 | shared_libs: ["libvndk"], // Cause an error |
| 1816 | nocrt: true, |
| 1817 | } |
| 1818 | `) |
| 1819 | |
| 1820 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext |
| 1821 | // library. |
| 1822 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
| 1823 | cc_library { |
| 1824 | name: "libvndk", |
| 1825 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1826 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1827 | vndk: { |
| 1828 | enabled: true, |
| 1829 | }, |
| 1830 | nocrt: true, |
| 1831 | } |
| 1832 | |
| 1833 | cc_library { |
| 1834 | name: "libvndk_ext", |
| 1835 | vendor: true, |
| 1836 | vndk: { |
| 1837 | enabled: true, |
| 1838 | extends: "libvndk", |
| 1839 | }, |
| 1840 | nocrt: true, |
| 1841 | } |
| 1842 | |
| 1843 | cc_library { |
| 1844 | name: "libvndk_sp", |
| 1845 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1846 | product_available: true, |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1847 | vndk: { |
| 1848 | enabled: true, |
| 1849 | support_system_process: true, |
| 1850 | }, |
| 1851 | nocrt: true, |
| 1852 | } |
| 1853 | |
| 1854 | cc_library { |
| 1855 | name: "libvndk_sp_ext", |
| 1856 | vendor: true, |
| 1857 | vndk: { |
| 1858 | enabled: true, |
| 1859 | extends: "libvndk_sp", |
| 1860 | support_system_process: true, |
| 1861 | }, |
| 1862 | shared_libs: ["libvndk_ext"], // Cause an error |
| 1863 | nocrt: true, |
| 1864 | } |
| 1865 | `) |
| 1866 | } |
| 1867 | |
| 1868 | func TestVndkUseVndkExtError(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1869 | t.Parallel() |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1870 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a |
| 1871 | // VNDK-Ext/VNDK-SP-Ext library. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1872 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1873 | cc_library { |
| 1874 | name: "libvndk", |
| 1875 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1876 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1877 | vndk: { |
| 1878 | enabled: true, |
| 1879 | }, |
| 1880 | nocrt: true, |
| 1881 | } |
| 1882 | |
| 1883 | cc_library { |
| 1884 | name: "libvndk_ext", |
| 1885 | vendor: true, |
| 1886 | vndk: { |
| 1887 | enabled: true, |
| 1888 | extends: "libvndk", |
| 1889 | }, |
| 1890 | nocrt: true, |
| 1891 | } |
| 1892 | |
| 1893 | cc_library { |
| 1894 | name: "libvndk2", |
| 1895 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1896 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1897 | vndk: { |
| 1898 | enabled: true, |
| 1899 | }, |
| 1900 | shared_libs: ["libvndk_ext"], |
| 1901 | nocrt: true, |
| 1902 | } |
| 1903 | `) |
| 1904 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1905 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1906 | cc_library { |
| 1907 | name: "libvndk", |
| 1908 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1909 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1910 | vndk: { |
| 1911 | enabled: true, |
| 1912 | }, |
| 1913 | nocrt: true, |
| 1914 | } |
| 1915 | |
| 1916 | cc_library { |
| 1917 | name: "libvndk_ext", |
| 1918 | vendor: true, |
| 1919 | vndk: { |
| 1920 | enabled: true, |
| 1921 | extends: "libvndk", |
| 1922 | }, |
| 1923 | nocrt: true, |
| 1924 | } |
| 1925 | |
| 1926 | cc_library { |
| 1927 | name: "libvndk2", |
| 1928 | vendor_available: true, |
| 1929 | vndk: { |
| 1930 | enabled: true, |
| 1931 | }, |
| 1932 | target: { |
| 1933 | vendor: { |
| 1934 | shared_libs: ["libvndk_ext"], |
| 1935 | }, |
| 1936 | }, |
| 1937 | nocrt: true, |
| 1938 | } |
| 1939 | `) |
| 1940 | |
| 1941 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` |
| 1942 | cc_library { |
| 1943 | name: "libvndk_sp", |
| 1944 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1945 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1946 | vndk: { |
| 1947 | enabled: true, |
| 1948 | support_system_process: true, |
| 1949 | }, |
| 1950 | nocrt: true, |
| 1951 | } |
| 1952 | |
| 1953 | cc_library { |
| 1954 | name: "libvndk_sp_ext", |
| 1955 | vendor: true, |
| 1956 | vndk: { |
| 1957 | enabled: true, |
| 1958 | extends: "libvndk_sp", |
| 1959 | support_system_process: true, |
| 1960 | }, |
| 1961 | nocrt: true, |
| 1962 | } |
| 1963 | |
| 1964 | cc_library { |
| 1965 | name: "libvndk_sp_2", |
| 1966 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1967 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1968 | vndk: { |
| 1969 | enabled: true, |
| 1970 | support_system_process: true, |
| 1971 | }, |
| 1972 | shared_libs: ["libvndk_sp_ext"], |
| 1973 | nocrt: true, |
| 1974 | } |
| 1975 | `) |
| 1976 | |
Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1977 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1978 | cc_library { |
| 1979 | name: "libvndk_sp", |
| 1980 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 1981 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1982 | vndk: { |
| 1983 | enabled: true, |
| 1984 | }, |
| 1985 | nocrt: true, |
| 1986 | } |
| 1987 | |
| 1988 | cc_library { |
| 1989 | name: "libvndk_sp_ext", |
| 1990 | vendor: true, |
| 1991 | vndk: { |
| 1992 | enabled: true, |
| 1993 | extends: "libvndk_sp", |
| 1994 | }, |
| 1995 | nocrt: true, |
| 1996 | } |
| 1997 | |
| 1998 | cc_library { |
| 1999 | name: "libvndk_sp2", |
| 2000 | vendor_available: true, |
| 2001 | vndk: { |
| 2002 | enabled: true, |
| 2003 | }, |
| 2004 | target: { |
| 2005 | vendor: { |
| 2006 | shared_libs: ["libvndk_sp_ext"], |
| 2007 | }, |
| 2008 | }, |
| 2009 | nocrt: true, |
| 2010 | } |
| 2011 | `) |
| 2012 | } |
| 2013 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2014 | func TestEnforceProductVndkVersion(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2015 | t.Parallel() |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2016 | bp := ` |
| 2017 | cc_library { |
| 2018 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2019 | llndk: { |
| 2020 | symbol_file: "libllndk.map.txt", |
| 2021 | } |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2022 | } |
| 2023 | cc_library { |
| 2024 | name: "libvndk", |
| 2025 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2026 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2027 | vndk: { |
| 2028 | enabled: true, |
| 2029 | }, |
| 2030 | nocrt: true, |
| 2031 | } |
| 2032 | cc_library { |
| 2033 | name: "libvndk_sp", |
| 2034 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2035 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2036 | vndk: { |
| 2037 | enabled: true, |
| 2038 | support_system_process: true, |
| 2039 | }, |
| 2040 | nocrt: true, |
| 2041 | } |
| 2042 | cc_library { |
| 2043 | name: "libva", |
| 2044 | vendor_available: true, |
| 2045 | nocrt: true, |
| 2046 | } |
| 2047 | cc_library { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2048 | name: "libpa", |
| 2049 | product_available: true, |
| 2050 | nocrt: true, |
| 2051 | } |
| 2052 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2053 | name: "libboth_available", |
| 2054 | vendor_available: true, |
| 2055 | product_available: true, |
| 2056 | nocrt: true, |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2057 | srcs: ["foo.c"], |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2058 | target: { |
| 2059 | vendor: { |
| 2060 | suffix: "-vendor", |
| 2061 | }, |
| 2062 | product: { |
| 2063 | suffix: "-product", |
| 2064 | }, |
| 2065 | } |
| 2066 | } |
| 2067 | cc_library { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2068 | name: "libproduct_va", |
| 2069 | product_specific: true, |
| 2070 | vendor_available: true, |
| 2071 | nocrt: true, |
| 2072 | } |
| 2073 | cc_library { |
| 2074 | name: "libprod", |
| 2075 | product_specific: true, |
| 2076 | shared_libs: [ |
| 2077 | "libllndk", |
| 2078 | "libvndk", |
| 2079 | "libvndk_sp", |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2080 | "libpa", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2081 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2082 | "libproduct_va", |
| 2083 | ], |
| 2084 | nocrt: true, |
| 2085 | } |
| 2086 | cc_library { |
| 2087 | name: "libvendor", |
| 2088 | vendor: true, |
| 2089 | shared_libs: [ |
| 2090 | "libllndk", |
| 2091 | "libvndk", |
| 2092 | "libvndk_sp", |
| 2093 | "libva", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2094 | "libboth_available", |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2095 | "libproduct_va", |
| 2096 | ], |
| 2097 | nocrt: true, |
| 2098 | } |
| 2099 | ` |
| 2100 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 2101 | ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2102 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 2103 | checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant) |
| 2104 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2105 | |
| 2106 | mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module) |
| 2107 | assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so") |
| 2108 | |
| 2109 | mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module) |
| 2110 | assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so") |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2111 | |
| 2112 | ensureStringContains := func(t *testing.T, str string, substr string) { |
| 2113 | t.Helper() |
| 2114 | if !strings.Contains(str, substr) { |
| 2115 | t.Errorf("%q is not found in %v", substr, str) |
| 2116 | } |
| 2117 | } |
| 2118 | ensureStringNotContains := func(t *testing.T, str string, substr string) { |
| 2119 | t.Helper() |
| 2120 | if strings.Contains(str, substr) { |
| 2121 | t.Errorf("%q is found in %v", substr, str) |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | // _static variant is used since _shared reuses *.o from the static variant |
| 2126 | vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1)) |
| 2127 | product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1)) |
| 2128 | |
| 2129 | vendor_cflags := vendor_static.Rule("cc").Args["cFlags"] |
| 2130 | ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__") |
| 2131 | ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__") |
| 2132 | ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__") |
| 2133 | |
| 2134 | product_cflags := product_static.Rule("cc").Args["cFlags"] |
| 2135 | ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__") |
| 2136 | ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__") |
| 2137 | ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2141 | t.Parallel() |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2142 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2143 | cc_library { |
| 2144 | name: "libprod", |
| 2145 | product_specific: true, |
| 2146 | shared_libs: [ |
| 2147 | "libvendor", |
| 2148 | ], |
| 2149 | nocrt: true, |
| 2150 | } |
| 2151 | cc_library { |
| 2152 | name: "libvendor", |
| 2153 | vendor: true, |
| 2154 | nocrt: true, |
| 2155 | } |
| 2156 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2157 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2158 | cc_library { |
| 2159 | name: "libprod", |
| 2160 | product_specific: true, |
| 2161 | shared_libs: [ |
| 2162 | "libsystem", |
| 2163 | ], |
| 2164 | nocrt: true, |
| 2165 | } |
| 2166 | cc_library { |
| 2167 | name: "libsystem", |
| 2168 | nocrt: true, |
| 2169 | } |
| 2170 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2171 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2172 | cc_library { |
| 2173 | name: "libprod", |
| 2174 | product_specific: true, |
| 2175 | shared_libs: [ |
| 2176 | "libva", |
| 2177 | ], |
| 2178 | nocrt: true, |
| 2179 | } |
| 2180 | cc_library { |
| 2181 | name: "libva", |
| 2182 | vendor_available: true, |
| 2183 | nocrt: true, |
| 2184 | } |
| 2185 | `) |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2186 | 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] | 2187 | cc_library { |
| 2188 | name: "libprod", |
| 2189 | product_specific: true, |
| 2190 | shared_libs: [ |
| 2191 | "libvndk_private", |
| 2192 | ], |
| 2193 | nocrt: true, |
| 2194 | } |
| 2195 | cc_library { |
| 2196 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2197 | vendor_available: true, |
| 2198 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2199 | vndk: { |
| 2200 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2201 | private: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2202 | }, |
| 2203 | nocrt: true, |
| 2204 | } |
| 2205 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2206 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2207 | cc_library { |
| 2208 | name: "libprod", |
| 2209 | product_specific: true, |
| 2210 | shared_libs: [ |
| 2211 | "libsystem_ext", |
| 2212 | ], |
| 2213 | nocrt: true, |
| 2214 | } |
| 2215 | cc_library { |
| 2216 | name: "libsystem_ext", |
| 2217 | system_ext_specific: true, |
| 2218 | nocrt: true, |
| 2219 | } |
| 2220 | `) |
| 2221 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 2222 | cc_library { |
| 2223 | name: "libsystem", |
| 2224 | shared_libs: [ |
| 2225 | "libproduct_va", |
| 2226 | ], |
| 2227 | nocrt: true, |
| 2228 | } |
| 2229 | cc_library { |
| 2230 | name: "libproduct_va", |
| 2231 | product_specific: true, |
| 2232 | vendor_available: true, |
| 2233 | nocrt: true, |
| 2234 | } |
| 2235 | `) |
| 2236 | } |
| 2237 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2238 | func TestMakeLinkType(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2239 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2240 | bp := ` |
| 2241 | cc_library { |
| 2242 | name: "libvndk", |
| 2243 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2244 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2245 | vndk: { |
| 2246 | enabled: true, |
| 2247 | }, |
| 2248 | } |
| 2249 | cc_library { |
| 2250 | name: "libvndksp", |
| 2251 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2252 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2253 | vndk: { |
| 2254 | enabled: true, |
| 2255 | support_system_process: true, |
| 2256 | }, |
| 2257 | } |
| 2258 | cc_library { |
| 2259 | name: "libvndkprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2260 | vendor_available: true, |
| 2261 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2262 | vndk: { |
| 2263 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2264 | private: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2265 | }, |
| 2266 | } |
| 2267 | cc_library { |
| 2268 | name: "libvendor", |
| 2269 | vendor: true, |
| 2270 | } |
| 2271 | cc_library { |
| 2272 | name: "libvndkext", |
| 2273 | vendor: true, |
| 2274 | vndk: { |
| 2275 | enabled: true, |
| 2276 | extends: "libvndk", |
| 2277 | }, |
| 2278 | } |
| 2279 | vndk_prebuilt_shared { |
| 2280 | name: "prevndk", |
| 2281 | version: "27", |
| 2282 | target_arch: "arm", |
| 2283 | binder32bit: true, |
| 2284 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2285 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2286 | vndk: { |
| 2287 | enabled: true, |
| 2288 | }, |
| 2289 | arch: { |
| 2290 | arm: { |
| 2291 | srcs: ["liba.so"], |
| 2292 | }, |
| 2293 | }, |
| 2294 | } |
| 2295 | cc_library { |
| 2296 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2297 | llndk: { |
| 2298 | symbol_file: "libllndk.map.txt", |
| 2299 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2300 | } |
| 2301 | cc_library { |
| 2302 | name: "libllndkprivate", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2303 | llndk: { |
| 2304 | symbol_file: "libllndkprivate.map.txt", |
| 2305 | private: true, |
| 2306 | } |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | llndk_libraries_txt { |
| 2310 | name: "llndk.libraries.txt", |
| 2311 | } |
| 2312 | vndkcore_libraries_txt { |
| 2313 | name: "vndkcore.libraries.txt", |
| 2314 | } |
| 2315 | vndksp_libraries_txt { |
| 2316 | name: "vndksp.libraries.txt", |
| 2317 | } |
| 2318 | vndkprivate_libraries_txt { |
| 2319 | name: "vndkprivate.libraries.txt", |
| 2320 | } |
| 2321 | vndkcorevariant_libraries_txt { |
| 2322 | name: "vndkcorevariant.libraries.txt", |
| 2323 | insert_vndk_version: false, |
| 2324 | } |
| 2325 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2326 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 2327 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2328 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2329 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2330 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2331 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2332 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2333 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", |
| 2334 | []string{"libvndk.so", "libvndkprivate.so"}) |
| 2335 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", |
| 2336 | []string{"libc++.so", "libvndksp.so"}) |
| 2337 | checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", |
| 2338 | []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"}) |
| 2339 | checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", |
| 2340 | []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2341 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2342 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2343 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2344 | tests := []struct { |
| 2345 | variant string |
| 2346 | name string |
| 2347 | expected string |
| 2348 | }{ |
| 2349 | {vendorVariant, "libvndk", "native:vndk"}, |
| 2350 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 2351 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 2352 | {vendorVariant, "libvendor", "native:vendor"}, |
| 2353 | {vendorVariant, "libvndkext", "native:vendor"}, |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2354 | {vendorVariant, "libllndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2355 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2356 | {coreVariant, "libvndk", "native:platform"}, |
| 2357 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 2358 | {coreVariant, "libllndk", "native:platform"}, |
| 2359 | } |
| 2360 | for _, test := range tests { |
| 2361 | t.Run(test.name, func(t *testing.T) { |
| 2362 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 2363 | assertString(t, module.makeLinkType, test.expected) |
| 2364 | }) |
| 2365 | } |
| 2366 | } |
| 2367 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2368 | var staticLinkDepOrderTestCases = []struct { |
| 2369 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2370 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2371 | inStatic string |
| 2372 | |
| 2373 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2374 | // It models the dependencies declared in an Android.bp file. |
| 2375 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2376 | |
| 2377 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2378 | // The keys of allOrdered specify which modules we would like to check. |
| 2379 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 2380 | // dependencies) for each module to test |
| 2381 | allOrdered string |
| 2382 | |
| 2383 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2384 | // The keys of outOrdered specify which modules we would like to check. |
| 2385 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 2386 | // for each module to test. |
| 2387 | outOrdered string |
| 2388 | }{ |
| 2389 | // Simple tests |
| 2390 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2391 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2392 | outOrdered: "", |
| 2393 | }, |
| 2394 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2395 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2396 | outOrdered: "a:", |
| 2397 | }, |
| 2398 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2399 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2400 | outOrdered: "a:b; b:", |
| 2401 | }, |
| 2402 | // Tests of reordering |
| 2403 | { |
| 2404 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2405 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2406 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 2407 | }, |
| 2408 | { |
| 2409 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2410 | 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] | 2411 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 2412 | }, |
| 2413 | { |
| 2414 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2415 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2416 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 2417 | }, |
| 2418 | { |
| 2419 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2420 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2421 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 2422 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 2423 | }, |
| 2424 | { |
| 2425 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2426 | 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] | 2427 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2428 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2429 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2430 | // shared dependencies |
| 2431 | { |
| 2432 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 2433 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 2434 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 2435 | // a shared dependency on b, that that shows up in allOrdered. |
| 2436 | inShared: "c:b", |
| 2437 | allOrdered: "c:b", |
| 2438 | outOrdered: "c:", |
| 2439 | }, |
| 2440 | { |
| 2441 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 2442 | // the second phase of the above test would look like |
| 2443 | inStatic: "a:b,c; c:b", |
| 2444 | allOrdered: "a:c,b; c:b", |
| 2445 | outOrdered: "a:c,b; c:b", |
| 2446 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2447 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 2448 | // to dictate an order |
| 2449 | { |
| 2450 | // 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] | 2451 | 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] | 2452 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 2453 | }, |
| 2454 | { |
| 2455 | // 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] | 2456 | 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] | 2457 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 2458 | }, |
| 2459 | // Tests involving duplicate dependencies |
| 2460 | { |
| 2461 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2462 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2463 | outOrdered: "a:c,b", |
| 2464 | }, |
| 2465 | { |
| 2466 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2467 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2468 | outOrdered: "a:d,c,b", |
| 2469 | }, |
| 2470 | // Tests to confirm the nonexistence of infinite loops. |
| 2471 | // These cases should never happen, so as long as the test terminates and the |
| 2472 | // result is deterministic then that should be fine. |
| 2473 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2474 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2475 | outOrdered: "a:a", |
| 2476 | }, |
| 2477 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2478 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2479 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 2480 | outOrdered: "a:b; b:c; c:a", |
| 2481 | }, |
| 2482 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2483 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2484 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 2485 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 2486 | }, |
| 2487 | } |
| 2488 | |
| 2489 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 2490 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 2491 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 2492 | strippedText := strings.Replace(text, " ", "", -1) |
| 2493 | if len(strippedText) < 1 { |
| 2494 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 2495 | } |
| 2496 | allDeps = make(map[android.Path][]android.Path, 0) |
| 2497 | |
| 2498 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 2499 | moduleTexts := strings.Split(strippedText, ";") |
| 2500 | |
| 2501 | outputForModuleName := func(moduleName string) android.Path { |
| 2502 | return android.PathForTesting(moduleName) |
| 2503 | } |
| 2504 | |
| 2505 | for _, moduleText := range moduleTexts { |
| 2506 | // convert from "a:b,c" to ["a", "b,c"] |
| 2507 | components := strings.Split(moduleText, ":") |
| 2508 | if len(components) != 2 { |
| 2509 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 2510 | } |
| 2511 | moduleName := components[0] |
| 2512 | moduleOutput := outputForModuleName(moduleName) |
| 2513 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 2514 | |
| 2515 | depString := components[1] |
| 2516 | // convert from "b,c" to ["b", "c"] |
| 2517 | depNames := strings.Split(depString, ",") |
| 2518 | if len(depString) < 1 { |
| 2519 | depNames = []string{} |
| 2520 | } |
| 2521 | var deps []android.Path |
| 2522 | for _, depName := range depNames { |
| 2523 | deps = append(deps, outputForModuleName(depName)) |
| 2524 | } |
| 2525 | allDeps[moduleOutput] = deps |
| 2526 | } |
| 2527 | return modulesInOrder, allDeps |
| 2528 | } |
| 2529 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2530 | func TestStaticLibDepReordering(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2531 | t.Parallel() |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2532 | ctx := testCc(t, ` |
| 2533 | cc_library { |
| 2534 | name: "a", |
| 2535 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2536 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2537 | } |
| 2538 | cc_library { |
| 2539 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2540 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2541 | } |
| 2542 | cc_library { |
| 2543 | name: "c", |
| 2544 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2545 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2546 | } |
| 2547 | cc_library { |
| 2548 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2549 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | `) |
| 2553 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2554 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2555 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 2556 | actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). |
| 2557 | TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 2558 | expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2559 | |
| 2560 | if !reflect.DeepEqual(actual, expected) { |
| 2561 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2562 | "\nactual: %v"+ |
| 2563 | "\nexpected: %v", |
| 2564 | actual, |
| 2565 | expected, |
| 2566 | ) |
| 2567 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2568 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2569 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2570 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2571 | t.Parallel() |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2572 | ctx := testCc(t, ` |
| 2573 | cc_library { |
| 2574 | name: "a", |
| 2575 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2576 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2577 | } |
| 2578 | cc_library { |
| 2579 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2580 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2581 | } |
| 2582 | cc_library { |
| 2583 | name: "c", |
| 2584 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2585 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | `) |
| 2589 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2590 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2591 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 2592 | actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). |
| 2593 | TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 2594 | expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"}) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2595 | |
| 2596 | if !reflect.DeepEqual(actual, expected) { |
| 2597 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 2598 | "\nactual: %v"+ |
| 2599 | "\nexpected: %v", |
| 2600 | actual, |
| 2601 | expected, |
| 2602 | ) |
| 2603 | } |
| 2604 | } |
| 2605 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2606 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 2607 | t.Helper() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2608 | if !reflect.DeepEqual(actual, expected) { |
| 2609 | t.Errorf(message+ |
| 2610 | "\nactual: %v"+ |
| 2611 | "\nexpected: %v", |
| 2612 | actual, |
| 2613 | expected, |
| 2614 | ) |
| 2615 | } |
| 2616 | } |
| 2617 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2618 | func TestLlndkLibrary(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2619 | t.Parallel() |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2620 | result := prepareForCcTest.RunTestWithBp(t, ` |
| 2621 | cc_library { |
| 2622 | name: "libllndk", |
| 2623 | stubs: { versions: ["1", "2"] }, |
| 2624 | llndk: { |
| 2625 | symbol_file: "libllndk.map.txt", |
| 2626 | }, |
| 2627 | export_include_dirs: ["include"], |
| 2628 | } |
| 2629 | |
| 2630 | cc_prebuilt_library_shared { |
| 2631 | name: "libllndkprebuilt", |
| 2632 | stubs: { versions: ["1", "2"] }, |
| 2633 | llndk: { |
| 2634 | symbol_file: "libllndkprebuilt.map.txt", |
| 2635 | }, |
| 2636 | } |
| 2637 | |
| 2638 | cc_library { |
| 2639 | name: "libllndk_with_external_headers", |
| 2640 | stubs: { versions: ["1", "2"] }, |
| 2641 | llndk: { |
| 2642 | symbol_file: "libllndk.map.txt", |
| 2643 | export_llndk_headers: ["libexternal_llndk_headers"], |
| 2644 | }, |
| 2645 | header_libs: ["libexternal_headers"], |
| 2646 | export_header_lib_headers: ["libexternal_headers"], |
| 2647 | } |
| 2648 | cc_library_headers { |
| 2649 | name: "libexternal_headers", |
| 2650 | export_include_dirs: ["include"], |
| 2651 | vendor_available: true, |
| 2652 | } |
| 2653 | cc_library_headers { |
| 2654 | name: "libexternal_llndk_headers", |
| 2655 | export_include_dirs: ["include_llndk"], |
| 2656 | llndk: { |
| 2657 | symbol_file: "libllndk.map.txt", |
| 2658 | }, |
| 2659 | vendor_available: true, |
| 2660 | } |
| 2661 | |
| 2662 | cc_library { |
| 2663 | name: "libllndk_with_override_headers", |
| 2664 | stubs: { versions: ["1", "2"] }, |
| 2665 | llndk: { |
| 2666 | symbol_file: "libllndk.map.txt", |
| 2667 | override_export_include_dirs: ["include_llndk"], |
| 2668 | }, |
| 2669 | export_include_dirs: ["include"], |
| 2670 | } |
| 2671 | `) |
| 2672 | actual := result.ModuleVariantsForTests("libllndk") |
| 2673 | for i := 0; i < len(actual); i++ { |
| 2674 | if !strings.HasPrefix(actual[i], "android_vendor.29_") { |
| 2675 | actual = append(actual[:i], actual[i+1:]...) |
| 2676 | i-- |
| 2677 | } |
| 2678 | } |
| 2679 | expected := []string{ |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2680 | "android_vendor.29_arm64_armv8-a_shared_current", |
| 2681 | "android_vendor.29_arm64_armv8-a_shared", |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2682 | "android_vendor.29_arm_armv7-a-neon_shared_current", |
| 2683 | "android_vendor.29_arm_armv7-a-neon_shared", |
| 2684 | } |
| 2685 | android.AssertArrayString(t, "variants for llndk stubs", expected, actual) |
| 2686 | |
| 2687 | params := result.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub") |
| 2688 | android.AssertSame(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"]) |
| 2689 | |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2690 | checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) { |
| 2691 | t.Helper() |
| 2692 | m := result.ModuleForTests(module, variant).Module() |
| 2693 | f := result.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) |
| 2694 | android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]", |
| 2695 | expectedDirs, f.IncludeDirs) |
| 2696 | } |
| 2697 | |
| 2698 | checkExportedIncludeDirs("libllndk", "android_arm64_armv8-a_shared", "include") |
| 2699 | checkExportedIncludeDirs("libllndk", "android_vendor.29_arm64_armv8-a_shared", "include") |
| 2700 | checkExportedIncludeDirs("libllndk_with_external_headers", "android_arm64_armv8-a_shared", "include") |
| 2701 | checkExportedIncludeDirs("libllndk_with_external_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk") |
| 2702 | checkExportedIncludeDirs("libllndk_with_override_headers", "android_arm64_armv8-a_shared", "include") |
| 2703 | checkExportedIncludeDirs("libllndk_with_override_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk") |
| 2704 | } |
| 2705 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2706 | func TestLlndkHeaders(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2707 | t.Parallel() |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2708 | ctx := testCc(t, ` |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2709 | cc_library_headers { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2710 | name: "libllndk_headers", |
| 2711 | export_include_dirs: ["my_include"], |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2712 | llndk: { |
| 2713 | llndk_headers: true, |
| 2714 | }, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2715 | } |
| 2716 | cc_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2717 | name: "libllndk", |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2718 | llndk: { |
| 2719 | symbol_file: "libllndk.map.txt", |
| 2720 | export_llndk_headers: ["libllndk_headers"], |
| 2721 | } |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | cc_library { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2725 | name: "libvendor", |
| 2726 | shared_libs: ["libllndk"], |
| 2727 | vendor: true, |
| 2728 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2729 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2730 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2731 | } |
| 2732 | `) |
| 2733 | |
| 2734 | // _static variant is used since _shared reuses *.o from the static variant |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2735 | 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] | 2736 | cflags := cc.Args["cFlags"] |
| 2737 | if !strings.Contains(cflags, "-Imy_include") { |
| 2738 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 2739 | } |
| 2740 | } |
| 2741 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2742 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 2743 | actual := module.Properties.AndroidMkRuntimeLibs |
| 2744 | if !reflect.DeepEqual(actual, expected) { |
| 2745 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 2746 | "\nactual: %v"+ |
| 2747 | "\nexpected: %v", |
| 2748 | actual, |
| 2749 | expected, |
| 2750 | ) |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | const runtimeLibAndroidBp = ` |
| 2755 | cc_library { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2756 | name: "liball_available", |
| 2757 | vendor_available: true, |
| 2758 | product_available: true, |
| 2759 | no_libcrt : true, |
| 2760 | nocrt : true, |
| 2761 | system_shared_libs : [], |
| 2762 | } |
| 2763 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2764 | name: "libvendor_available1", |
| 2765 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2766 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2767 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2768 | nocrt : true, |
| 2769 | system_shared_libs : [], |
| 2770 | } |
| 2771 | cc_library { |
| 2772 | name: "libvendor_available2", |
| 2773 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2774 | runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2775 | target: { |
| 2776 | vendor: { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2777 | exclude_runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2778 | } |
| 2779 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2780 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2781 | nocrt : true, |
| 2782 | system_shared_libs : [], |
| 2783 | } |
| 2784 | cc_library { |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2785 | name: "libproduct_vendor", |
| 2786 | product_specific: true, |
| 2787 | vendor_available: true, |
| 2788 | no_libcrt : true, |
| 2789 | nocrt : true, |
| 2790 | system_shared_libs : [], |
| 2791 | } |
| 2792 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2793 | name: "libcore", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2794 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2795 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2796 | nocrt : true, |
| 2797 | system_shared_libs : [], |
| 2798 | } |
| 2799 | cc_library { |
| 2800 | name: "libvendor1", |
| 2801 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2802 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2803 | nocrt : true, |
| 2804 | system_shared_libs : [], |
| 2805 | } |
| 2806 | cc_library { |
| 2807 | name: "libvendor2", |
| 2808 | vendor: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2809 | runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"], |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2810 | no_libcrt : true, |
| 2811 | nocrt : true, |
| 2812 | system_shared_libs : [], |
| 2813 | } |
| 2814 | cc_library { |
| 2815 | name: "libproduct_available1", |
| 2816 | product_available: true, |
| 2817 | runtime_libs: ["liball_available"], |
| 2818 | no_libcrt : true, |
| 2819 | nocrt : true, |
| 2820 | system_shared_libs : [], |
| 2821 | } |
| 2822 | cc_library { |
| 2823 | name: "libproduct1", |
| 2824 | product_specific: true, |
| 2825 | no_libcrt : true, |
| 2826 | nocrt : true, |
| 2827 | system_shared_libs : [], |
| 2828 | } |
| 2829 | cc_library { |
| 2830 | name: "libproduct2", |
| 2831 | product_specific: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2832 | runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2833 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2834 | nocrt : true, |
| 2835 | system_shared_libs : [], |
| 2836 | } |
| 2837 | ` |
| 2838 | |
| 2839 | func TestRuntimeLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2840 | t.Parallel() |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2841 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2842 | |
| 2843 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2844 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2845 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2846 | module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2847 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
| 2848 | |
| 2849 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2850 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2851 | |
| 2852 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2853 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2854 | |
| 2855 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 2856 | // and vendor variants. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2857 | variant = "android_vendor.29_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.vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2861 | |
| 2862 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2863 | checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2864 | |
| 2865 | // runtime_libs for product variants have '.product' suffixes if the modules have both core |
| 2866 | // and product variants. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2867 | variant = "android_product.29_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2868 | |
| 2869 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2870 | checkRuntimeLibs(t, []string{"liball_available.product"}, module) |
| 2871 | |
| 2872 | module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) |
Justin Yun | d00f5ca | 2021-02-03 19:43:02 +0900 | [diff] [blame] | 2873 | checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | func TestExcludeRuntimeLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2877 | t.Parallel() |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2878 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2879 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2880 | variant := "android_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2881 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2882 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2883 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2884 | variant = "android_vendor.29_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2885 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2886 | checkRuntimeLibs(t, nil, module) |
| 2887 | } |
| 2888 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2889 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2890 | t.Helper() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2891 | actual := module.Properties.AndroidMkStaticLibs |
| 2892 | if !reflect.DeepEqual(actual, expected) { |
| 2893 | t.Errorf("incorrect static_libs"+ |
| 2894 | "\nactual: %v"+ |
| 2895 | "\nexpected: %v", |
| 2896 | actual, |
| 2897 | expected, |
| 2898 | ) |
| 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | const staticLibAndroidBp = ` |
| 2903 | cc_library { |
| 2904 | name: "lib1", |
| 2905 | } |
| 2906 | cc_library { |
| 2907 | name: "lib2", |
| 2908 | static_libs: ["lib1"], |
| 2909 | } |
| 2910 | ` |
| 2911 | |
| 2912 | func TestStaticLibDepExport(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2913 | t.Parallel() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2914 | ctx := testCc(t, staticLibAndroidBp) |
| 2915 | |
| 2916 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2917 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2918 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 2919 | checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2920 | |
| 2921 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2922 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2923 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 2924 | // libc++_static is linked additionally. |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 2925 | checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2926 | } |
| 2927 | |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 2928 | func TestLibDepAndroidMkExportInMixedBuilds(t *testing.T) { |
| 2929 | bp := ` |
| 2930 | cc_library { |
| 2931 | name: "static_dep", |
| 2932 | } |
| 2933 | cc_library { |
| 2934 | name: "whole_static_dep", |
| 2935 | } |
| 2936 | cc_library { |
| 2937 | name: "shared_dep", |
| 2938 | } |
| 2939 | cc_library { |
| 2940 | name: "lib", |
| 2941 | bazel_module: { label: "//:lib" }, |
| 2942 | static_libs: ["static_dep"], |
| 2943 | whole_static_libs: ["whole_static_dep"], |
| 2944 | shared_libs: ["shared_dep"], |
| 2945 | } |
| 2946 | cc_test { |
| 2947 | name: "test", |
| 2948 | bazel_module: { label: "//:test" }, |
| 2949 | static_libs: ["static_dep"], |
| 2950 | whole_static_libs: ["whole_static_dep"], |
| 2951 | shared_libs: ["shared_dep"], |
| 2952 | gtest: false, |
Sam Delmerico | ef69d47 | 2023-04-18 17:32:43 -0400 | [diff] [blame] | 2953 | sanitize: { |
| 2954 | // cc_test modules default to memtag_heap: true, |
| 2955 | // but this adds extra dependencies that we don't care about |
| 2956 | never: true, |
| 2957 | } |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 2958 | } |
| 2959 | cc_binary { |
| 2960 | name: "binary", |
| 2961 | bazel_module: { label: "//:binary" }, |
| 2962 | static_libs: ["static_dep"], |
| 2963 | whole_static_libs: ["whole_static_dep"], |
| 2964 | shared_libs: ["shared_dep"], |
| 2965 | } |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 2966 | cc_library_headers { |
| 2967 | name: "lib_headers", |
| 2968 | bazel_module: { label: "//:lib_headers" }, |
| 2969 | static_libs: ["static_dep"], |
| 2970 | whole_static_libs: ["whole_static_dep"], |
| 2971 | shared_libs: ["shared_dep"], |
| 2972 | } |
| 2973 | cc_prebuilt_library { |
| 2974 | name: "lib_prebuilt", |
| 2975 | bazel_module: { label: "//:lib_prebuilt" }, |
| 2976 | static_libs: ["static_dep"], |
| 2977 | whole_static_libs: ["whole_static_dep"], |
| 2978 | shared_libs: ["shared_dep"], |
| 2979 | } |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 2980 | ` |
| 2981 | |
| 2982 | testCases := []struct { |
| 2983 | name string |
| 2984 | moduleName string |
| 2985 | variant string |
| 2986 | androidMkInfo cquery.CcAndroidMkInfo |
| 2987 | }{ |
| 2988 | { |
| 2989 | name: "shared lib", |
| 2990 | moduleName: "lib", |
| 2991 | variant: "android_arm64_armv8-a_shared", |
| 2992 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 2993 | LocalStaticLibs: []string{"static_dep"}, |
| 2994 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 2995 | LocalSharedLibs: []string{"shared_dep"}, |
| 2996 | }, |
| 2997 | }, |
| 2998 | { |
| 2999 | name: "static lib", |
| 3000 | moduleName: "lib", |
| 3001 | variant: "android_arm64_armv8-a_static", |
| 3002 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3003 | LocalStaticLibs: []string{"static_dep"}, |
| 3004 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3005 | LocalSharedLibs: []string{"shared_dep"}, |
| 3006 | }, |
| 3007 | }, |
| 3008 | { |
| 3009 | name: "cc_test arm64", |
| 3010 | moduleName: "test", |
| 3011 | variant: "android_arm64_armv8-a", |
| 3012 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3013 | LocalStaticLibs: []string{"static_dep"}, |
| 3014 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3015 | LocalSharedLibs: []string{"shared_dep"}, |
| 3016 | }, |
| 3017 | }, |
| 3018 | { |
| 3019 | name: "cc_test arm", |
| 3020 | moduleName: "test", |
| 3021 | variant: "android_arm_armv7-a-neon", |
| 3022 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3023 | LocalStaticLibs: []string{"static_dep"}, |
| 3024 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3025 | LocalSharedLibs: []string{"shared_dep"}, |
| 3026 | }, |
| 3027 | }, |
| 3028 | { |
| 3029 | name: "cc_binary", |
| 3030 | moduleName: "binary", |
| 3031 | variant: "android_arm64_armv8-a", |
| 3032 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3033 | LocalStaticLibs: []string{"static_dep"}, |
| 3034 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3035 | LocalSharedLibs: []string{"shared_dep"}, |
| 3036 | }, |
| 3037 | }, |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3038 | { |
| 3039 | name: "cc_library_headers", |
| 3040 | moduleName: "lib_headers", |
| 3041 | variant: "android_arm64_armv8-a", |
| 3042 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3043 | LocalStaticLibs: []string{"static_dep"}, |
| 3044 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3045 | LocalSharedLibs: []string{"shared_dep"}, |
| 3046 | }, |
| 3047 | }, |
| 3048 | { |
| 3049 | name: "prebuilt lib static", |
| 3050 | moduleName: "lib_prebuilt", |
| 3051 | variant: "android_arm64_armv8-a_static", |
| 3052 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3053 | LocalStaticLibs: []string{"static_dep"}, |
| 3054 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3055 | LocalSharedLibs: []string{"shared_dep"}, |
| 3056 | }, |
| 3057 | }, |
| 3058 | { |
| 3059 | name: "prebuilt lib shared", |
| 3060 | moduleName: "lib_prebuilt", |
| 3061 | variant: "android_arm64_armv8-a_shared", |
| 3062 | androidMkInfo: cquery.CcAndroidMkInfo{ |
| 3063 | LocalStaticLibs: []string{"static_dep"}, |
| 3064 | LocalWholeStaticLibs: []string{"whole_static_dep"}, |
| 3065 | LocalSharedLibs: []string{"shared_dep"}, |
| 3066 | }, |
| 3067 | }, |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | outputBaseDir := "out/bazel" |
| 3071 | for _, tc := range testCases { |
| 3072 | t.Run(tc.name, func(t *testing.T) { |
| 3073 | result := android.GroupFixturePreparers( |
| 3074 | prepareForCcTest, |
| 3075 | android.FixtureModifyConfig(func(config android.Config) { |
| 3076 | config.BazelContext = android.MockBazelContext{ |
| 3077 | OutputBaseDir: outputBaseDir, |
| 3078 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 3079 | "//:lib": cquery.CcInfo{ |
| 3080 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3081 | RootDynamicLibraries: []string{""}, |
| 3082 | }, |
| 3083 | "//:lib_bp2build_cc_library_static": cquery.CcInfo{ |
| 3084 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3085 | RootStaticArchives: []string{""}, |
| 3086 | }, |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3087 | "//:lib_headers": cquery.CcInfo{ |
| 3088 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3089 | OutputFiles: []string{""}, |
| 3090 | }, |
| 3091 | "//:lib_prebuilt": cquery.CcInfo{ |
| 3092 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3093 | }, |
| 3094 | "//:lib_prebuilt_bp2build_cc_library_static": cquery.CcInfo{ |
| 3095 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3096 | }, |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3097 | }, |
| 3098 | LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{ |
Jingwen Chen | 6ee23ad | 2023-07-24 14:56:28 +0000 | [diff] [blame] | 3099 | "//:test__tf_internal": cquery.CcUnstrippedInfo{ |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3100 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3101 | }, |
| 3102 | "//:binary": cquery.CcUnstrippedInfo{ |
| 3103 | CcAndroidMkInfo: tc.androidMkInfo, |
| 3104 | }, |
| 3105 | }, |
| 3106 | } |
| 3107 | }), |
| 3108 | ).RunTestWithBp(t, bp) |
| 3109 | ctx := result.TestContext |
| 3110 | |
| 3111 | module := ctx.ModuleForTests(tc.moduleName, tc.variant).Module().(*Module) |
| 3112 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3113 | if !reflect.DeepEqual(module.Properties.AndroidMkStaticLibs, tc.androidMkInfo.LocalStaticLibs) { |
| 3114 | t.Errorf("incorrect static_libs"+ |
| 3115 | "\nactual: %v"+ |
| 3116 | "\nexpected: %v", |
| 3117 | module.Properties.AndroidMkStaticLibs, |
| 3118 | tc.androidMkInfo.LocalStaticLibs, |
| 3119 | ) |
| 3120 | } |
| 3121 | staticDepsDiffer, missingStaticDeps, additionalStaticDeps := android.ListSetDifference( |
| 3122 | entries.EntryMap["LOCAL_STATIC_LIBRARIES"], |
| 3123 | tc.androidMkInfo.LocalStaticLibs, |
| 3124 | ) |
| 3125 | if staticDepsDiffer { |
| 3126 | t.Errorf( |
| 3127 | "expected LOCAL_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q", |
| 3128 | tc.androidMkInfo.LocalStaticLibs, |
| 3129 | entries.EntryMap["LOCAL_STATIC_LIBRARIES"], |
| 3130 | missingStaticDeps, |
| 3131 | additionalStaticDeps, |
| 3132 | ) |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3133 | } |
| 3134 | |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3135 | if !reflect.DeepEqual(module.Properties.AndroidMkWholeStaticLibs, tc.androidMkInfo.LocalWholeStaticLibs) { |
| 3136 | t.Errorf("expected module.Properties.AndroidMkWholeStaticLibs to be %q, but was %q", |
| 3137 | tc.androidMkInfo.LocalWholeStaticLibs, |
| 3138 | module.Properties.AndroidMkWholeStaticLibs, |
| 3139 | ) |
| 3140 | } |
| 3141 | wholeStaticDepsDiffer, missingWholeStaticDeps, additionalWholeStaticDeps := android.ListSetDifference( |
| 3142 | entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"], |
| 3143 | tc.androidMkInfo.LocalWholeStaticLibs, |
| 3144 | ) |
| 3145 | if wholeStaticDepsDiffer { |
| 3146 | t.Errorf( |
| 3147 | "expected LOCAL_WHOLE_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q", |
| 3148 | tc.androidMkInfo.LocalWholeStaticLibs, |
| 3149 | entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"], |
| 3150 | missingWholeStaticDeps, |
| 3151 | additionalWholeStaticDeps, |
| 3152 | ) |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3153 | } |
| 3154 | |
Sam Delmerico | 5fb794a | 2023-01-27 16:01:37 -0500 | [diff] [blame] | 3155 | if !reflect.DeepEqual(module.Properties.AndroidMkSharedLibs, tc.androidMkInfo.LocalSharedLibs) { |
| 3156 | t.Errorf("incorrect shared_libs"+ |
| 3157 | "\nactual: %v"+ |
| 3158 | "\nexpected: %v", |
| 3159 | module.Properties.AndroidMkSharedLibs, |
| 3160 | tc.androidMkInfo.LocalSharedLibs, |
| 3161 | ) |
| 3162 | } |
| 3163 | sharedDepsDiffer, missingSharedDeps, additionalSharedDeps := android.ListSetDifference( |
| 3164 | entries.EntryMap["LOCAL_SHARED_LIBRARIES"], |
| 3165 | tc.androidMkInfo.LocalSharedLibs, |
| 3166 | ) |
| 3167 | if sharedDepsDiffer { |
| 3168 | t.Errorf( |
| 3169 | "expected LOCAL_SHARED_LIBRARIES to be %q but was %q; missing %q; extra %q", |
| 3170 | tc.androidMkInfo.LocalSharedLibs, |
| 3171 | entries.EntryMap["LOCAL_SHARED_LIBRARIES"], |
| 3172 | missingSharedDeps, |
| 3173 | additionalSharedDeps, |
| 3174 | ) |
Sam Delmerico | 4e115cc | 2023-01-19 15:36:52 -0500 | [diff] [blame] | 3175 | } |
| 3176 | }) |
| 3177 | } |
| 3178 | } |
| 3179 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3180 | var compilerFlagsTestCases = []struct { |
| 3181 | in string |
| 3182 | out bool |
| 3183 | }{ |
| 3184 | { |
| 3185 | in: "a", |
| 3186 | out: false, |
| 3187 | }, |
| 3188 | { |
| 3189 | in: "-a", |
| 3190 | out: true, |
| 3191 | }, |
| 3192 | { |
| 3193 | in: "-Ipath/to/something", |
| 3194 | out: false, |
| 3195 | }, |
| 3196 | { |
| 3197 | in: "-isystempath/to/something", |
| 3198 | out: false, |
| 3199 | }, |
| 3200 | { |
| 3201 | in: "--coverage", |
| 3202 | out: false, |
| 3203 | }, |
| 3204 | { |
| 3205 | in: "-include a/b", |
| 3206 | out: true, |
| 3207 | }, |
| 3208 | { |
| 3209 | in: "-include a/b c/d", |
| 3210 | out: false, |
| 3211 | }, |
| 3212 | { |
| 3213 | in: "-DMACRO", |
| 3214 | out: true, |
| 3215 | }, |
| 3216 | { |
| 3217 | in: "-DMAC RO", |
| 3218 | out: false, |
| 3219 | }, |
| 3220 | { |
| 3221 | in: "-a -b", |
| 3222 | out: false, |
| 3223 | }, |
| 3224 | { |
| 3225 | in: "-DMACRO=definition", |
| 3226 | out: true, |
| 3227 | }, |
| 3228 | { |
| 3229 | in: "-DMACRO=defi nition", |
| 3230 | out: true, // TODO(jiyong): this should be false |
| 3231 | }, |
| 3232 | { |
| 3233 | in: "-DMACRO(x)=x + 1", |
| 3234 | out: true, |
| 3235 | }, |
| 3236 | { |
| 3237 | in: "-DMACRO=\"defi nition\"", |
| 3238 | out: true, |
| 3239 | }, |
| 3240 | } |
| 3241 | |
| 3242 | type mockContext struct { |
| 3243 | BaseModuleContext |
| 3244 | result bool |
| 3245 | } |
| 3246 | |
| 3247 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 3248 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 3249 | ctx.result = false |
| 3250 | } |
| 3251 | |
| 3252 | func TestCompilerFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3253 | t.Parallel() |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3254 | for _, testCase := range compilerFlagsTestCases { |
| 3255 | ctx := &mockContext{result: true} |
| 3256 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 3257 | if ctx.result != testCase.out { |
| 3258 | t.Errorf("incorrect output:") |
| 3259 | t.Errorf(" input: %#v", testCase.in) |
| 3260 | t.Errorf(" expected: %#v", testCase.out) |
| 3261 | t.Errorf(" got: %#v", ctx.result) |
| 3262 | } |
| 3263 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3264 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3265 | |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3266 | func TestRecovery(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3267 | t.Parallel() |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3268 | ctx := testCc(t, ` |
| 3269 | cc_library_shared { |
| 3270 | name: "librecovery", |
| 3271 | recovery: true, |
| 3272 | } |
| 3273 | cc_library_shared { |
| 3274 | name: "librecovery32", |
| 3275 | recovery: true, |
| 3276 | compile_multilib:"32", |
| 3277 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3278 | cc_library_shared { |
| 3279 | name: "libHalInRecovery", |
| 3280 | recovery_available: true, |
| 3281 | vendor: true, |
| 3282 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3283 | `) |
| 3284 | |
| 3285 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3286 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3287 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 3288 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 3289 | } |
| 3290 | |
| 3291 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 3292 | if android.InList(arm64, variants) { |
| 3293 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 3294 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3295 | |
| 3296 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 3297 | if !recoveryModule.Platform() { |
| 3298 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 3299 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3300 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3301 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3302 | func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3303 | t.Parallel() |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3304 | bp := ` |
| 3305 | cc_prebuilt_test_library_shared { |
| 3306 | name: "test_lib", |
| 3307 | relative_install_path: "foo/bar/baz", |
| 3308 | srcs: ["srcpath/dontusethispath/baz.so"], |
| 3309 | } |
| 3310 | |
| 3311 | cc_test { |
| 3312 | name: "main_test", |
| 3313 | data_libs: ["test_lib"], |
| 3314 | gtest: false, |
| 3315 | } |
| 3316 | ` |
| 3317 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 3318 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3319 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3320 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3321 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 3322 | |
| 3323 | ctx := testCcWithConfig(t, config) |
| 3324 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 3325 | testBinary := module.(*Module).linker.(*testBinary) |
| 3326 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 3327 | if err != nil { |
| 3328 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 3329 | } |
| 3330 | if len(outputFiles) != 1 { |
| 3331 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 3332 | } |
| 3333 | if len(testBinary.dataPaths()) != 1 { |
| 3334 | t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) |
| 3335 | } |
| 3336 | |
| 3337 | outputPath := outputFiles[0].String() |
| 3338 | |
| 3339 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 3340 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 3341 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3342 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3343 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 3344 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ |
| 3345 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
| 3346 | } |
| 3347 | } |
| 3348 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3349 | func TestVersionedStubs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3350 | t.Parallel() |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3351 | ctx := testCc(t, ` |
| 3352 | cc_library_shared { |
| 3353 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3354 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3355 | stubs: { |
| 3356 | symbol_file: "foo.map.txt", |
| 3357 | versions: ["1", "2", "3"], |
| 3358 | }, |
| 3359 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3360 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3361 | cc_library_shared { |
| 3362 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3363 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3364 | shared_libs: ["libFoo#1"], |
| 3365 | }`) |
| 3366 | |
| 3367 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3368 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3369 | "android_arm64_armv8-a_shared", |
| 3370 | "android_arm64_armv8-a_shared_1", |
| 3371 | "android_arm64_armv8-a_shared_2", |
| 3372 | "android_arm64_armv8-a_shared_3", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 3373 | "android_arm64_armv8-a_shared_current", |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3374 | "android_arm_armv7-a-neon_shared", |
| 3375 | "android_arm_armv7-a-neon_shared_1", |
| 3376 | "android_arm_armv7-a-neon_shared_2", |
| 3377 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 3378 | "android_arm_armv7-a-neon_shared_current", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3379 | } |
| 3380 | variantsMismatch := false |
| 3381 | if len(variants) != len(expectedVariants) { |
| 3382 | variantsMismatch = true |
| 3383 | } else { |
| 3384 | for _, v := range expectedVariants { |
| 3385 | if !inList(v, variants) { |
| 3386 | variantsMismatch = false |
| 3387 | } |
| 3388 | } |
| 3389 | } |
| 3390 | if variantsMismatch { |
| 3391 | t.Errorf("variants of libFoo expected:\n") |
| 3392 | for _, v := range expectedVariants { |
| 3393 | t.Errorf("%q\n", v) |
| 3394 | } |
| 3395 | t.Errorf(", but got:\n") |
| 3396 | for _, v := range variants { |
| 3397 | t.Errorf("%q\n", v) |
| 3398 | } |
| 3399 | } |
| 3400 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3401 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3402 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3403 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3404 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 3405 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 3406 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3407 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3408 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3409 | cFlags := libBarCompileRule.Args["cFlags"] |
| 3410 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 3411 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 3412 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 3413 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3414 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3415 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 3416 | func TestStubsForLibraryInMultipleApexes(t *testing.T) { |
| 3417 | t.Parallel() |
| 3418 | ctx := testCc(t, ` |
| 3419 | cc_library_shared { |
| 3420 | name: "libFoo", |
| 3421 | srcs: ["foo.c"], |
| 3422 | stubs: { |
| 3423 | symbol_file: "foo.map.txt", |
| 3424 | versions: ["current"], |
| 3425 | }, |
| 3426 | apex_available: ["bar", "a1"], |
| 3427 | } |
| 3428 | |
| 3429 | cc_library_shared { |
| 3430 | name: "libBar", |
| 3431 | srcs: ["bar.c"], |
| 3432 | shared_libs: ["libFoo"], |
| 3433 | apex_available: ["a1"], |
| 3434 | } |
| 3435 | |
| 3436 | cc_library_shared { |
| 3437 | name: "libA1", |
| 3438 | srcs: ["a1.c"], |
| 3439 | shared_libs: ["libFoo"], |
| 3440 | apex_available: ["a1"], |
| 3441 | } |
| 3442 | |
| 3443 | cc_library_shared { |
| 3444 | name: "libBarA1", |
| 3445 | srcs: ["bara1.c"], |
| 3446 | shared_libs: ["libFoo"], |
| 3447 | apex_available: ["bar", "a1"], |
| 3448 | } |
| 3449 | |
| 3450 | cc_library_shared { |
| 3451 | name: "libAnyApex", |
| 3452 | srcs: ["anyApex.c"], |
| 3453 | shared_libs: ["libFoo"], |
| 3454 | apex_available: ["//apex_available:anyapex"], |
| 3455 | } |
| 3456 | |
| 3457 | cc_library_shared { |
| 3458 | name: "libBaz", |
| 3459 | srcs: ["baz.c"], |
| 3460 | shared_libs: ["libFoo"], |
| 3461 | apex_available: ["baz"], |
| 3462 | } |
| 3463 | |
| 3464 | cc_library_shared { |
| 3465 | name: "libQux", |
| 3466 | srcs: ["qux.c"], |
| 3467 | shared_libs: ["libFoo"], |
| 3468 | apex_available: ["qux", "bar"], |
| 3469 | }`) |
| 3470 | |
| 3471 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3472 | expectedVariants := []string{ |
| 3473 | "android_arm64_armv8-a_shared", |
| 3474 | "android_arm64_armv8-a_shared_current", |
| 3475 | "android_arm_armv7-a-neon_shared", |
| 3476 | "android_arm_armv7-a-neon_shared_current", |
| 3477 | } |
| 3478 | variantsMismatch := false |
| 3479 | if len(variants) != len(expectedVariants) { |
| 3480 | variantsMismatch = true |
| 3481 | } else { |
| 3482 | for _, v := range expectedVariants { |
| 3483 | if !inList(v, variants) { |
| 3484 | variantsMismatch = false |
| 3485 | } |
| 3486 | } |
| 3487 | } |
| 3488 | if variantsMismatch { |
| 3489 | t.Errorf("variants of libFoo expected:\n") |
| 3490 | for _, v := range expectedVariants { |
| 3491 | t.Errorf("%q\n", v) |
| 3492 | } |
| 3493 | t.Errorf(", but got:\n") |
| 3494 | for _, v := range variants { |
| 3495 | t.Errorf("%q\n", v) |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | linkAgainstFoo := []string{"libBarA1"} |
| 3500 | linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"} |
| 3501 | |
| 3502 | libFooPath := "libFoo/android_arm64_armv8-a_shared/libFoo.so" |
| 3503 | for _, lib := range linkAgainstFoo { |
| 3504 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3505 | libFlags := libLinkRule.Args["libFlags"] |
| 3506 | if !strings.Contains(libFlags, libFooPath) { |
| 3507 | t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags) |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | libFooStubPath := "libFoo/android_arm64_armv8-a_shared_current/libFoo.so" |
| 3512 | for _, lib := range linkAgainstFooStubs { |
| 3513 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3514 | libFlags := libLinkRule.Args["libFlags"] |
| 3515 | if !strings.Contains(libFlags, libFooStubPath) { |
| 3516 | t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags) |
| 3517 | } |
| 3518 | } |
| 3519 | } |
| 3520 | |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 3521 | func TestMixedBuildUsesStubs(t *testing.T) { |
Sam Delmerico | 75dbca2 | 2023-04-20 13:13:25 +0000 | [diff] [blame] | 3522 | t.Parallel() |
| 3523 | bp := ` |
| 3524 | cc_library_shared { |
| 3525 | name: "libFoo", |
| 3526 | bazel_module: { label: "//:libFoo" }, |
| 3527 | srcs: ["foo.c"], |
| 3528 | stubs: { |
| 3529 | symbol_file: "foo.map.txt", |
| 3530 | versions: ["current"], |
| 3531 | }, |
| 3532 | apex_available: ["bar", "a1"], |
| 3533 | } |
| 3534 | |
| 3535 | cc_library_shared { |
| 3536 | name: "libBar", |
| 3537 | srcs: ["bar.c"], |
| 3538 | shared_libs: ["libFoo"], |
| 3539 | apex_available: ["a1"], |
| 3540 | } |
| 3541 | |
| 3542 | cc_library_shared { |
| 3543 | name: "libA1", |
| 3544 | srcs: ["a1.c"], |
| 3545 | shared_libs: ["libFoo"], |
| 3546 | apex_available: ["a1"], |
| 3547 | } |
| 3548 | |
| 3549 | cc_library_shared { |
| 3550 | name: "libBarA1", |
| 3551 | srcs: ["bara1.c"], |
| 3552 | shared_libs: ["libFoo"], |
| 3553 | apex_available: ["bar", "a1"], |
| 3554 | } |
| 3555 | |
| 3556 | cc_library_shared { |
| 3557 | name: "libAnyApex", |
| 3558 | srcs: ["anyApex.c"], |
| 3559 | shared_libs: ["libFoo"], |
| 3560 | apex_available: ["//apex_available:anyapex"], |
| 3561 | } |
| 3562 | |
| 3563 | cc_library_shared { |
| 3564 | name: "libBaz", |
| 3565 | srcs: ["baz.c"], |
| 3566 | shared_libs: ["libFoo"], |
| 3567 | apex_available: ["baz"], |
| 3568 | } |
| 3569 | |
| 3570 | cc_library_shared { |
| 3571 | name: "libQux", |
| 3572 | srcs: ["qux.c"], |
| 3573 | shared_libs: ["libFoo"], |
| 3574 | apex_available: ["qux", "bar"], |
| 3575 | }` |
| 3576 | |
| 3577 | result := android.GroupFixturePreparers( |
| 3578 | prepareForCcTest, |
| 3579 | android.FixtureModifyConfig(func(config android.Config) { |
| 3580 | config.BazelContext = android.MockBazelContext{ |
| 3581 | OutputBaseDir: "out/bazel", |
| 3582 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 3583 | "//:libFoo": { |
| 3584 | RootDynamicLibraries: []string{"libFoo.so"}, |
| 3585 | }, |
| 3586 | "//:libFoo_stub_libs-current": { |
| 3587 | RootDynamicLibraries: []string{"libFoo_stub_libs-current.so"}, |
| 3588 | }, |
| 3589 | }, |
| 3590 | } |
| 3591 | }), |
| 3592 | ).RunTestWithBp(t, bp) |
| 3593 | ctx := result.TestContext |
| 3594 | |
| 3595 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3596 | expectedVariants := []string{ |
| 3597 | "android_arm64_armv8-a_shared", |
| 3598 | "android_arm64_armv8-a_shared_current", |
| 3599 | "android_arm_armv7-a-neon_shared", |
| 3600 | "android_arm_armv7-a-neon_shared_current", |
| 3601 | } |
| 3602 | variantsMismatch := false |
| 3603 | if len(variants) != len(expectedVariants) { |
| 3604 | variantsMismatch = true |
| 3605 | } else { |
| 3606 | for _, v := range expectedVariants { |
| 3607 | if !inList(v, variants) { |
| 3608 | variantsMismatch = false |
| 3609 | } |
| 3610 | } |
| 3611 | } |
| 3612 | if variantsMismatch { |
| 3613 | t.Errorf("variants of libFoo expected:\n") |
| 3614 | for _, v := range expectedVariants { |
| 3615 | t.Errorf("%q\n", v) |
| 3616 | } |
| 3617 | t.Errorf(", but got:\n") |
| 3618 | for _, v := range variants { |
| 3619 | t.Errorf("%q\n", v) |
| 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | linkAgainstFoo := []string{"libBarA1"} |
| 3624 | linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"} |
| 3625 | |
| 3626 | libFooPath := "out/bazel/execroot/__main__/libFoo.so" |
| 3627 | for _, lib := range linkAgainstFoo { |
| 3628 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3629 | libFlags := libLinkRule.Args["libFlags"] |
| 3630 | if !strings.Contains(libFlags, libFooPath) { |
| 3631 | t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags) |
| 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | libFooStubPath := "out/bazel/execroot/__main__/libFoo_stub_libs-current.so" |
| 3636 | for _, lib := range linkAgainstFooStubs { |
| 3637 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3638 | libFlags := libLinkRule.Args["libFlags"] |
| 3639 | if !strings.Contains(libFlags, libFooStubPath) { |
| 3640 | t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags) |
| 3641 | } |
| 3642 | } |
| 3643 | } |
| 3644 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3645 | func TestVersioningMacro(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3646 | t.Parallel() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3647 | for _, tc := range []struct{ moduleName, expected string }{ |
| 3648 | {"libc", "__LIBC_API__"}, |
| 3649 | {"libfoo", "__LIBFOO_API__"}, |
| 3650 | {"libfoo@1", "__LIBFOO_1_API__"}, |
| 3651 | {"libfoo-v1", "__LIBFOO_V1_API__"}, |
| 3652 | {"libfoo.v1", "__LIBFOO_V1_API__"}, |
| 3653 | } { |
| 3654 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) |
| 3655 | } |
| 3656 | } |
| 3657 | |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3658 | func pathsToBase(paths android.Paths) []string { |
| 3659 | var ret []string |
| 3660 | for _, p := range paths { |
| 3661 | ret = append(ret, p.Base()) |
| 3662 | } |
| 3663 | return ret |
| 3664 | } |
| 3665 | |
| 3666 | func TestStaticLibArchiveArgs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3667 | t.Parallel() |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3668 | ctx := testCc(t, ` |
| 3669 | cc_library_static { |
| 3670 | name: "foo", |
| 3671 | srcs: ["foo.c"], |
| 3672 | } |
| 3673 | |
| 3674 | cc_library_static { |
| 3675 | name: "bar", |
| 3676 | srcs: ["bar.c"], |
| 3677 | } |
| 3678 | |
| 3679 | cc_library_shared { |
| 3680 | name: "qux", |
| 3681 | srcs: ["qux.c"], |
| 3682 | } |
| 3683 | |
| 3684 | cc_library_static { |
| 3685 | name: "baz", |
| 3686 | srcs: ["baz.c"], |
| 3687 | static_libs: ["foo"], |
| 3688 | shared_libs: ["qux"], |
| 3689 | whole_static_libs: ["bar"], |
| 3690 | }`) |
| 3691 | |
| 3692 | variant := "android_arm64_armv8-a_static" |
| 3693 | arRule := ctx.ModuleForTests("baz", variant).Rule("ar") |
| 3694 | |
| 3695 | // For static libraries, the object files of a whole static dep are included in the archive |
| 3696 | // directly |
| 3697 | if g, w := pathsToBase(arRule.Inputs), []string{"bar.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3698 | t.Errorf("Expected input objects %q, got %q", w, g) |
| 3699 | } |
| 3700 | |
| 3701 | // non whole static dependencies are not linked into the archive |
| 3702 | if len(arRule.Implicits) > 0 { |
| 3703 | t.Errorf("Expected 0 additional deps, got %q", arRule.Implicits) |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | func TestSharedLibLinkingArgs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3708 | t.Parallel() |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3709 | ctx := testCc(t, ` |
| 3710 | cc_library_static { |
| 3711 | name: "foo", |
| 3712 | srcs: ["foo.c"], |
| 3713 | } |
| 3714 | |
| 3715 | cc_library_static { |
| 3716 | name: "bar", |
| 3717 | srcs: ["bar.c"], |
| 3718 | } |
| 3719 | |
| 3720 | cc_library_shared { |
| 3721 | name: "qux", |
| 3722 | srcs: ["qux.c"], |
| 3723 | } |
| 3724 | |
| 3725 | cc_library_shared { |
| 3726 | name: "baz", |
| 3727 | srcs: ["baz.c"], |
| 3728 | static_libs: ["foo"], |
| 3729 | shared_libs: ["qux"], |
| 3730 | whole_static_libs: ["bar"], |
| 3731 | }`) |
| 3732 | |
| 3733 | variant := "android_arm64_armv8-a_shared" |
| 3734 | linkRule := ctx.ModuleForTests("baz", variant).Rule("ld") |
| 3735 | libFlags := linkRule.Args["libFlags"] |
| 3736 | // When dynamically linking, we expect static dependencies to be found on the command line |
| 3737 | if expected := "foo.a"; !strings.Contains(libFlags, expected) { |
| 3738 | t.Errorf("Static lib %q was not found in %q", expected, libFlags) |
| 3739 | } |
| 3740 | // When dynamically linking, we expect whole static dependencies to be found on the command line |
| 3741 | if expected := "bar.a"; !strings.Contains(libFlags, expected) { |
| 3742 | t.Errorf("Static lib %q was not found in %q", expected, libFlags) |
| 3743 | } |
| 3744 | |
| 3745 | // When dynamically linking, we expect shared dependencies to be found on the command line |
| 3746 | if expected := "qux.so"; !strings.Contains(libFlags, expected) { |
| 3747 | t.Errorf("Shared lib %q was not found in %q", expected, libFlags) |
| 3748 | } |
| 3749 | |
| 3750 | // We should only have the objects from the shared library srcs, not the whole static dependencies |
| 3751 | if g, w := pathsToBase(linkRule.Inputs), []string{"baz.o"}; !reflect.DeepEqual(w, g) { |
| 3752 | t.Errorf("Expected input objects %q, got %q", w, g) |
| 3753 | } |
| 3754 | } |
| 3755 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3756 | func TestStaticExecutable(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3757 | t.Parallel() |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3758 | ctx := testCc(t, ` |
| 3759 | cc_binary { |
| 3760 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 3761 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3762 | static_executable: true, |
| 3763 | }`) |
| 3764 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3765 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3766 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 3767 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 3768 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3769 | for _, lib := range systemStaticLibs { |
| 3770 | if !strings.Contains(libFlags, lib) { |
| 3771 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 3772 | } |
| 3773 | } |
| 3774 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 3775 | for _, lib := range systemSharedLibs { |
| 3776 | if strings.Contains(libFlags, lib) { |
| 3777 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 3778 | } |
| 3779 | } |
| 3780 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3781 | |
| 3782 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3783 | t.Parallel() |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3784 | ctx := testCc(t, ` |
| 3785 | cc_binary { |
| 3786 | name: "mybin", |
| 3787 | srcs: ["foo.c"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3788 | static_libs: ["libfooC", "libfooB"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3789 | static_executable: true, |
| 3790 | stl: "none", |
| 3791 | } |
| 3792 | |
| 3793 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3794 | name: "libfooB", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3795 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3796 | shared_libs: ["libfooC"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3797 | stl: "none", |
| 3798 | } |
| 3799 | |
| 3800 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3801 | name: "libfooC", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3802 | srcs: ["foo.c"], |
| 3803 | stl: "none", |
| 3804 | stubs: { |
| 3805 | versions: ["1"], |
| 3806 | }, |
| 3807 | }`) |
| 3808 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3809 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld") |
| 3810 | actual := mybin.Implicits[:2] |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 3811 | expected := GetOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3812 | |
| 3813 | if !reflect.DeepEqual(actual, expected) { |
| 3814 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 3815 | "\nactual: %v"+ |
| 3816 | "\nexpected: %v", |
| 3817 | actual, |
| 3818 | expected, |
| 3819 | ) |
| 3820 | } |
| 3821 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3822 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3823 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3824 | t.Parallel() |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3825 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 3826 | cc_library { |
| 3827 | name: "libA", |
| 3828 | srcs: ["foo.c"], |
| 3829 | shared_libs: ["libB"], |
| 3830 | stl: "none", |
| 3831 | } |
| 3832 | |
| 3833 | cc_library { |
| 3834 | name: "libB", |
| 3835 | srcs: ["foo.c"], |
| 3836 | enabled: false, |
| 3837 | stl: "none", |
| 3838 | } |
| 3839 | `) |
| 3840 | } |
| 3841 | |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3842 | func VerifyAFLFuzzTargetVariant(t *testing.T, variant string) { |
| 3843 | bp := ` |
| 3844 | cc_fuzz { |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3845 | name: "test_afl_fuzz_target", |
| 3846 | srcs: ["foo.c"], |
| 3847 | host_supported: true, |
| 3848 | static_libs: [ |
| 3849 | "afl_fuzz_static_lib", |
| 3850 | ], |
| 3851 | shared_libs: [ |
| 3852 | "afl_fuzz_shared_lib", |
| 3853 | ], |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3854 | fuzzing_frameworks: { |
| 3855 | afl: true, |
| 3856 | libfuzzer: false, |
| 3857 | }, |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3858 | } |
| 3859 | cc_library { |
| 3860 | name: "afl_fuzz_static_lib", |
| 3861 | host_supported: true, |
| 3862 | srcs: ["static_file.c"], |
| 3863 | } |
| 3864 | cc_library { |
| 3865 | name: "libfuzzer_only_static_lib", |
| 3866 | host_supported: true, |
| 3867 | srcs: ["static_file.c"], |
| 3868 | } |
| 3869 | cc_library { |
| 3870 | name: "afl_fuzz_shared_lib", |
| 3871 | host_supported: true, |
| 3872 | srcs: ["shared_file.c"], |
| 3873 | static_libs: [ |
| 3874 | "second_static_lib", |
| 3875 | ], |
| 3876 | } |
| 3877 | cc_library_headers { |
| 3878 | name: "libafl_headers", |
| 3879 | vendor_available: true, |
| 3880 | host_supported: true, |
| 3881 | export_include_dirs: [ |
| 3882 | "include", |
| 3883 | "instrumentation", |
| 3884 | ], |
| 3885 | } |
| 3886 | cc_object { |
| 3887 | name: "afl-compiler-rt", |
| 3888 | vendor_available: true, |
| 3889 | host_supported: true, |
| 3890 | cflags: [ |
| 3891 | "-fPIC", |
| 3892 | ], |
| 3893 | srcs: [ |
| 3894 | "instrumentation/afl-compiler-rt.o.c", |
| 3895 | ], |
| 3896 | } |
| 3897 | cc_library { |
| 3898 | name: "second_static_lib", |
| 3899 | host_supported: true, |
| 3900 | srcs: ["second_file.c"], |
| 3901 | } |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3902 | cc_object { |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3903 | name: "aflpp_driver", |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3904 | host_supported: true, |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3905 | srcs: [ |
| 3906 | "aflpp_driver.c", |
| 3907 | ], |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3908 | }` |
| 3909 | |
| 3910 | testEnv := map[string]string{ |
| 3911 | "FUZZ_FRAMEWORK": "AFL", |
| 3912 | } |
| 3913 | |
| 3914 | ctx := android.GroupFixturePreparers(prepareForCcTest, android.FixtureMergeEnv(testEnv)).RunTestWithBp(t, bp) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3915 | |
| 3916 | checkPcGuardFlag := func( |
| 3917 | modName string, variantName string, shouldHave bool) { |
| 3918 | cc := ctx.ModuleForTests(modName, variantName).Rule("cc") |
| 3919 | |
| 3920 | cFlags, ok := cc.Args["cFlags"] |
| 3921 | if !ok { |
| 3922 | t.Errorf("Could not find cFlags for module %s and variant %s", |
| 3923 | modName, variantName) |
| 3924 | } |
| 3925 | |
| 3926 | if strings.Contains( |
| 3927 | cFlags, "-fsanitize-coverage=trace-pc-guard") != shouldHave { |
| 3928 | t.Errorf("Flag was found: %t. Expected to find flag: %t. "+ |
| 3929 | "Test failed for module %s and variant %s", |
| 3930 | !shouldHave, shouldHave, modName, variantName) |
| 3931 | } |
| 3932 | } |
| 3933 | |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3934 | moduleName := "test_afl_fuzz_target" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3935 | checkPcGuardFlag(moduleName, variant+"_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3936 | |
| 3937 | moduleName = "afl_fuzz_static_lib" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3938 | checkPcGuardFlag(moduleName, variant+"_static", false) |
| 3939 | checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3940 | |
| 3941 | moduleName = "second_static_lib" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3942 | checkPcGuardFlag(moduleName, variant+"_static", false) |
| 3943 | checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3944 | |
| 3945 | ctx.ModuleForTests("afl_fuzz_shared_lib", |
| 3946 | "android_arm64_armv8-a_shared").Rule("cc") |
| 3947 | ctx.ModuleForTests("afl_fuzz_shared_lib", |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3948 | "android_arm64_armv8-a_shared_fuzzer").Rule("cc") |
| 3949 | } |
| 3950 | |
| 3951 | func TestAFLFuzzTargetForDevice(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3952 | t.Parallel() |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3953 | VerifyAFLFuzzTargetVariant(t, "android_arm64_armv8-a") |
| 3954 | } |
| 3955 | |
| 3956 | func TestAFLFuzzTargetForLinuxHost(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3957 | t.Parallel() |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3958 | if runtime.GOOS != "linux" { |
| 3959 | t.Skip("requires linux") |
| 3960 | } |
| 3961 | |
| 3962 | VerifyAFLFuzzTargetVariant(t, "linux_glibc_x86_64") |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3963 | } |
| 3964 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3965 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 3966 | // correctly. |
| 3967 | func TestFuzzTarget(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3968 | t.Parallel() |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3969 | ctx := testCc(t, ` |
| 3970 | cc_fuzz { |
| 3971 | name: "fuzz_smoke_test", |
| 3972 | srcs: ["foo.c"], |
| 3973 | }`) |
| 3974 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 3975 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3976 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 3977 | } |
| 3978 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3979 | func assertString(t *testing.T, got, expected string) { |
| 3980 | t.Helper() |
| 3981 | if got != expected { |
| 3982 | t.Errorf("expected %q got %q", expected, got) |
| 3983 | } |
| 3984 | } |
| 3985 | |
| 3986 | func assertArrayString(t *testing.T, got, expected []string) { |
| 3987 | t.Helper() |
| 3988 | if len(got) != len(expected) { |
| 3989 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 3990 | return |
| 3991 | } |
| 3992 | for i := range got { |
| 3993 | if got[i] != expected[i] { |
| 3994 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 3995 | i, expected[i], expected, got[i], got) |
| 3996 | return |
| 3997 | } |
| 3998 | } |
| 3999 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4000 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 4001 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 4002 | t.Helper() |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 4003 | assertArrayString(t, android.SortedKeys(m), expected) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 4004 | } |
| 4005 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4006 | func TestDefaults(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4007 | t.Parallel() |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4008 | ctx := testCc(t, ` |
| 4009 | cc_defaults { |
| 4010 | name: "defaults", |
| 4011 | srcs: ["foo.c"], |
| 4012 | static: { |
| 4013 | srcs: ["bar.c"], |
| 4014 | }, |
| 4015 | shared: { |
| 4016 | srcs: ["baz.c"], |
| 4017 | }, |
Liz Kammer | 3cf5211 | 2021-03-31 15:42:03 -0400 | [diff] [blame] | 4018 | bazel_module: { |
| 4019 | bp2build_available: true, |
| 4020 | }, |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | cc_library_static { |
| 4024 | name: "libstatic", |
| 4025 | defaults: ["defaults"], |
| 4026 | } |
| 4027 | |
| 4028 | cc_library_shared { |
| 4029 | name: "libshared", |
| 4030 | defaults: ["defaults"], |
| 4031 | } |
| 4032 | |
| 4033 | cc_library { |
| 4034 | name: "libboth", |
| 4035 | defaults: ["defaults"], |
| 4036 | } |
| 4037 | |
| 4038 | cc_binary { |
| 4039 | name: "binary", |
| 4040 | defaults: ["defaults"], |
| 4041 | }`) |
| 4042 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4043 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4044 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 4045 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 4046 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4047 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4048 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 4049 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 4050 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4051 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4052 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 4053 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 4054 | } |
| 4055 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4056 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4057 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 4058 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 4059 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4060 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 4061 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 4062 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 4063 | } |
| 4064 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4065 | |
| 4066 | func TestProductVariableDefaults(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4067 | t.Parallel() |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4068 | bp := ` |
| 4069 | cc_defaults { |
| 4070 | name: "libfoo_defaults", |
| 4071 | srcs: ["foo.c"], |
| 4072 | cppflags: ["-DFOO"], |
| 4073 | product_variables: { |
| 4074 | debuggable: { |
| 4075 | cppflags: ["-DBAR"], |
| 4076 | }, |
| 4077 | }, |
| 4078 | } |
| 4079 | |
| 4080 | cc_library { |
| 4081 | name: "libfoo", |
| 4082 | defaults: ["libfoo_defaults"], |
| 4083 | } |
| 4084 | ` |
| 4085 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 4086 | result := android.GroupFixturePreparers( |
| 4087 | prepareForCcTest, |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4088 | android.PrepareForTestWithVariables, |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4089 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4090 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4091 | variables.Debuggable = BoolPtr(true) |
| 4092 | }), |
| 4093 | ).RunTestWithBp(t, bp) |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4094 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4095 | libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module) |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4096 | android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR") |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 4097 | } |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4098 | |
| 4099 | func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { |
| 4100 | t.Parallel() |
| 4101 | bp := ` |
| 4102 | cc_library_static { |
| 4103 | name: "libfoo", |
| 4104 | srcs: ["foo.c"], |
| 4105 | whole_static_libs: ["libbar"], |
| 4106 | } |
| 4107 | |
| 4108 | cc_library_static { |
| 4109 | name: "libbar", |
| 4110 | whole_static_libs: ["libmissing"], |
| 4111 | } |
| 4112 | ` |
| 4113 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 4114 | result := android.GroupFixturePreparers( |
| 4115 | prepareForCcTest, |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4116 | android.PrepareForTestWithAllowMissingDependencies, |
| 4117 | ).RunTestWithBp(t, bp) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4118 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4119 | libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a") |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4120 | android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4121 | |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4122 | android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing") |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4123 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 4124 | libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a") |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 4125 | android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String()) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 4126 | } |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 4127 | |
| 4128 | func TestInstallSharedLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4129 | t.Parallel() |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 4130 | bp := ` |
| 4131 | cc_binary { |
| 4132 | name: "bin", |
| 4133 | host_supported: true, |
| 4134 | shared_libs: ["libshared"], |
| 4135 | runtime_libs: ["libruntime"], |
| 4136 | srcs: [":gen"], |
| 4137 | } |
| 4138 | |
| 4139 | cc_library_shared { |
| 4140 | name: "libshared", |
| 4141 | host_supported: true, |
| 4142 | shared_libs: ["libtransitive"], |
| 4143 | } |
| 4144 | |
| 4145 | cc_library_shared { |
| 4146 | name: "libtransitive", |
| 4147 | host_supported: true, |
| 4148 | } |
| 4149 | |
| 4150 | cc_library_shared { |
| 4151 | name: "libruntime", |
| 4152 | host_supported: true, |
| 4153 | } |
| 4154 | |
| 4155 | cc_binary_host { |
| 4156 | name: "tool", |
| 4157 | srcs: ["foo.cpp"], |
| 4158 | } |
| 4159 | |
| 4160 | genrule { |
| 4161 | name: "gen", |
| 4162 | tools: ["tool"], |
| 4163 | out: ["gen.cpp"], |
| 4164 | cmd: "$(location tool) $(out)", |
| 4165 | } |
| 4166 | ` |
| 4167 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 4168 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 4169 | ctx := testCcWithConfig(t, config) |
| 4170 | |
| 4171 | hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install") |
| 4172 | hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4173 | hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4174 | hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install") |
| 4175 | hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install") |
| 4176 | |
| 4177 | if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) { |
| 4178 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4179 | } |
| 4180 | |
| 4181 | if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 4182 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4183 | } |
| 4184 | |
| 4185 | if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 4186 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4187 | } |
| 4188 | |
| 4189 | if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) { |
| 4190 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 4191 | } |
| 4192 | |
| 4193 | if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 4194 | t.Errorf("expected no host bin dependency %q, got %q", w, g) |
| 4195 | } |
| 4196 | |
| 4197 | deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install") |
| 4198 | deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install") |
| 4199 | deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install") |
| 4200 | deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install") |
| 4201 | |
| 4202 | if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) { |
| 4203 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4204 | } |
| 4205 | |
| 4206 | if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 4207 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4208 | } |
| 4209 | |
| 4210 | if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 4211 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4212 | } |
| 4213 | |
| 4214 | if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) { |
| 4215 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 4216 | } |
| 4217 | |
| 4218 | if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 4219 | t.Errorf("expected no device bin dependency %q, got %q", w, g) |
| 4220 | } |
| 4221 | |
| 4222 | } |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 4223 | |
| 4224 | func TestStubsLibReexportsHeaders(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4225 | t.Parallel() |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 4226 | ctx := testCc(t, ` |
| 4227 | cc_library_shared { |
| 4228 | name: "libclient", |
| 4229 | srcs: ["foo.c"], |
| 4230 | shared_libs: ["libfoo#1"], |
| 4231 | } |
| 4232 | |
| 4233 | cc_library_shared { |
| 4234 | name: "libfoo", |
| 4235 | srcs: ["foo.c"], |
| 4236 | shared_libs: ["libbar"], |
| 4237 | export_shared_lib_headers: ["libbar"], |
| 4238 | stubs: { |
| 4239 | symbol_file: "foo.map.txt", |
| 4240 | versions: ["1", "2", "3"], |
| 4241 | }, |
| 4242 | } |
| 4243 | |
| 4244 | cc_library_shared { |
| 4245 | name: "libbar", |
| 4246 | export_include_dirs: ["include/libbar"], |
| 4247 | srcs: ["foo.c"], |
| 4248 | }`) |
| 4249 | |
| 4250 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4251 | |
| 4252 | if !strings.Contains(cFlags, "-Iinclude/libbar") { |
| 4253 | t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags) |
| 4254 | } |
| 4255 | } |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 4256 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4257 | func TestAidlLibraryWithHeaders(t *testing.T) { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4258 | t.Parallel() |
| 4259 | ctx := android.GroupFixturePreparers( |
| 4260 | prepareForCcTest, |
| 4261 | aidl_library.PrepareForTestWithAidlLibrary, |
| 4262 | android.MockFS{ |
| 4263 | "package_bar/Android.bp": []byte(` |
| 4264 | aidl_library { |
| 4265 | name: "bar", |
| 4266 | srcs: ["x/y/Bar.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4267 | hdrs: ["x/HeaderBar.aidl"], |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4268 | strip_import_prefix: "x", |
| 4269 | } |
| 4270 | `)}.AddToFixture(), |
| 4271 | android.MockFS{ |
| 4272 | "package_foo/Android.bp": []byte(` |
| 4273 | aidl_library { |
| 4274 | name: "foo", |
| 4275 | srcs: ["a/b/Foo.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4276 | hdrs: ["a/HeaderFoo.aidl"], |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4277 | strip_import_prefix: "a", |
| 4278 | deps: ["bar"], |
| 4279 | } |
| 4280 | cc_library { |
| 4281 | name: "libfoo", |
| 4282 | aidl: { |
| 4283 | libs: ["foo"], |
| 4284 | } |
| 4285 | } |
| 4286 | `), |
| 4287 | }.AddToFixture(), |
| 4288 | ).RunTest(t).TestContext |
| 4289 | |
| 4290 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4291 | |
| 4292 | android.AssertPathsRelativeToTopEquals( |
| 4293 | t, |
| 4294 | "aidl headers", |
| 4295 | []string{ |
| 4296 | "package_bar/x/HeaderBar.aidl", |
| 4297 | "package_foo/a/HeaderFoo.aidl", |
| 4298 | "package_foo/a/b/Foo.aidl", |
| 4299 | "out/soong/.intermediates/package_foo/libfoo/android_arm64_armv8-a_static/gen/aidl_library.sbox.textproto", |
| 4300 | }, |
| 4301 | libfoo.Rule("aidl_library").Implicits, |
| 4302 | ) |
| 4303 | |
| 4304 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl_library.sbox.textproto")) |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4305 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4306 | |
| 4307 | expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x" |
| 4308 | if !strings.Contains(aidlCommand, expectedAidlFlags) { |
| 4309 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlags) |
| 4310 | } |
| 4311 | |
| 4312 | outputs := strings.Join(libfoo.AllOutputs(), " ") |
| 4313 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4314 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BpFoo.h") |
| 4315 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BnFoo.h") |
| 4316 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/Foo.h") |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4317 | android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp") |
| 4318 | // Confirm that the aidl header doesn't get compiled to cpp and h files |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4319 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BpBar.h") |
| 4320 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BnBar.h") |
| 4321 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/Bar.h") |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4322 | android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp") |
| 4323 | } |
| 4324 | |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 4325 | func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4326 | t.Parallel() |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4327 | ctx := android.GroupFixturePreparers( |
| 4328 | prepareForCcTest, |
| 4329 | aidl_library.PrepareForTestWithAidlLibrary, |
| 4330 | ).RunTestWithBp(t, ` |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 4331 | cc_library { |
| 4332 | name: "libfoo", |
| 4333 | srcs: ["a/Foo.aidl"], |
| 4334 | aidl: { flags: ["-Werror"], }, |
| 4335 | } |
| 4336 | `) |
| 4337 | |
| 4338 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
| 4339 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) |
| 4340 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4341 | expectedAidlFlag := "-Werror" |
| 4342 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 4343 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 4344 | } |
| 4345 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 4346 | |
Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 4347 | func TestAidlFlagsWithMinSdkVersion(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4348 | t.Parallel() |
Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 4349 | for _, tc := range []struct { |
| 4350 | name string |
| 4351 | sdkVersion string |
| 4352 | variant string |
| 4353 | expected string |
| 4354 | }{ |
| 4355 | { |
| 4356 | name: "default is current", |
| 4357 | sdkVersion: "", |
| 4358 | variant: "android_arm64_armv8-a_static", |
| 4359 | expected: "platform_apis", |
| 4360 | }, |
| 4361 | { |
| 4362 | name: "use sdk_version", |
| 4363 | sdkVersion: `sdk_version: "29"`, |
| 4364 | variant: "android_arm64_armv8-a_static", |
| 4365 | expected: "platform_apis", |
| 4366 | }, |
| 4367 | { |
| 4368 | name: "use sdk_version(sdk variant)", |
| 4369 | sdkVersion: `sdk_version: "29"`, |
| 4370 | variant: "android_arm64_armv8-a_sdk_static", |
| 4371 | expected: "29", |
| 4372 | }, |
| 4373 | { |
| 4374 | name: "use min_sdk_version", |
| 4375 | sdkVersion: `min_sdk_version: "29"`, |
| 4376 | variant: "android_arm64_armv8-a_static", |
| 4377 | expected: "29", |
| 4378 | }, |
| 4379 | } { |
| 4380 | t.Run(tc.name, func(t *testing.T) { |
| 4381 | ctx := testCc(t, ` |
| 4382 | cc_library { |
| 4383 | name: "libfoo", |
| 4384 | stl: "none", |
| 4385 | srcs: ["a/Foo.aidl"], |
| 4386 | `+tc.sdkVersion+` |
| 4387 | } |
| 4388 | `) |
| 4389 | libfoo := ctx.ModuleForTests("libfoo", tc.variant) |
| 4390 | manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) |
| 4391 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4392 | expectedAidlFlag := "--min_sdk_version=" + tc.expected |
| 4393 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 4394 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 4395 | } |
| 4396 | }) |
| 4397 | } |
| 4398 | } |
| 4399 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4400 | func TestInvalidAidlProp(t *testing.T) { |
| 4401 | t.Parallel() |
| 4402 | |
| 4403 | testCases := []struct { |
| 4404 | description string |
| 4405 | bp string |
| 4406 | }{ |
| 4407 | { |
| 4408 | description: "Invalid use of aidl.libs and aidl.include_dirs", |
| 4409 | bp: ` |
| 4410 | cc_library { |
| 4411 | name: "foo", |
| 4412 | aidl: { |
| 4413 | libs: ["foo_aidl"], |
| 4414 | include_dirs: ["bar/include"], |
| 4415 | } |
| 4416 | } |
| 4417 | `, |
| 4418 | }, |
| 4419 | { |
| 4420 | description: "Invalid use of aidl.libs and aidl.local_include_dirs", |
| 4421 | bp: ` |
| 4422 | cc_library { |
| 4423 | name: "foo", |
| 4424 | aidl: { |
| 4425 | libs: ["foo_aidl"], |
| 4426 | local_include_dirs: ["include"], |
| 4427 | } |
| 4428 | } |
| 4429 | `, |
| 4430 | }, |
| 4431 | } |
| 4432 | |
| 4433 | for _, testCase := range testCases { |
| 4434 | t.Run(testCase.description, func(t *testing.T) { |
| 4435 | bp := ` |
| 4436 | aidl_library { |
| 4437 | name: "foo_aidl", |
| 4438 | srcs: ["Foo.aidl"], |
| 4439 | } ` + testCase.bp |
| 4440 | android.GroupFixturePreparers( |
| 4441 | prepareForCcTest, |
| 4442 | aidl_library.PrepareForTestWithAidlLibrary. |
| 4443 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("For aidl headers, please only use aidl.libs prop")), |
| 4444 | ).RunTestWithBp(t, bp) |
| 4445 | }) |
| 4446 | } |
| 4447 | } |
| 4448 | |
Jiyong Park | a008fb0 | 2021-03-16 17:15:53 +0900 | [diff] [blame] | 4449 | func TestMinSdkVersionInClangTriple(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4450 | t.Parallel() |
Jiyong Park | a008fb0 | 2021-03-16 17:15:53 +0900 | [diff] [blame] | 4451 | ctx := testCc(t, ` |
| 4452 | cc_library_shared { |
| 4453 | name: "libfoo", |
| 4454 | srcs: ["foo.c"], |
| 4455 | min_sdk_version: "29", |
| 4456 | }`) |
| 4457 | |
| 4458 | cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4459 | android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29") |
| 4460 | } |
| 4461 | |
Vinh Tran | f192474 | 2022-06-24 16:40:11 -0400 | [diff] [blame] | 4462 | func TestNonDigitMinSdkVersionInClangTriple(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4463 | t.Parallel() |
Vinh Tran | f192474 | 2022-06-24 16:40:11 -0400 | [diff] [blame] | 4464 | bp := ` |
| 4465 | cc_library_shared { |
| 4466 | name: "libfoo", |
| 4467 | srcs: ["foo.c"], |
| 4468 | min_sdk_version: "S", |
| 4469 | } |
| 4470 | ` |
| 4471 | result := android.GroupFixturePreparers( |
| 4472 | prepareForCcTest, |
| 4473 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4474 | variables.Platform_version_active_codenames = []string{"UpsideDownCake", "Tiramisu"} |
| 4475 | }), |
| 4476 | ).RunTestWithBp(t, bp) |
| 4477 | ctx := result.TestContext |
| 4478 | cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4479 | android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android31") |
| 4480 | } |
| 4481 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4482 | func TestIncludeDirsExporting(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4483 | t.Parallel() |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4484 | |
| 4485 | // Trim spaces from the beginning, end and immediately after any newline characters. Leaves |
| 4486 | // embedded newline characters alone. |
| 4487 | trimIndentingSpaces := func(s string) string { |
| 4488 | return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1")) |
| 4489 | } |
| 4490 | |
| 4491 | checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) { |
| 4492 | t.Helper() |
| 4493 | expected = trimIndentingSpaces(expected) |
| 4494 | actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n")) |
| 4495 | if expected != actual { |
| 4496 | t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual) |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo) |
| 4501 | |
| 4502 | checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) { |
| 4503 | t.Helper() |
| 4504 | exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo) |
| 4505 | name := module.Name() |
| 4506 | |
| 4507 | for _, checker := range checkers { |
| 4508 | checker(t, name, exported) |
| 4509 | } |
| 4510 | } |
| 4511 | |
| 4512 | expectedIncludeDirs := func(expectedPaths string) exportedChecker { |
| 4513 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4514 | t.Helper() |
| 4515 | checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs) |
| 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker { |
| 4520 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4521 | t.Helper() |
| 4522 | checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs) |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | expectedGeneratedHeaders := func(expectedPaths string) exportedChecker { |
| 4527 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4528 | t.Helper() |
| 4529 | checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders) |
| 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker { |
| 4534 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4535 | t.Helper() |
| 4536 | checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps) |
| 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | genRuleModules := ` |
| 4541 | genrule { |
| 4542 | name: "genrule_foo", |
| 4543 | cmd: "generate-foo", |
| 4544 | out: [ |
| 4545 | "generated_headers/foo/generated_header.h", |
| 4546 | ], |
| 4547 | export_include_dirs: [ |
| 4548 | "generated_headers", |
| 4549 | ], |
| 4550 | } |
| 4551 | |
| 4552 | genrule { |
| 4553 | name: "genrule_bar", |
| 4554 | cmd: "generate-bar", |
| 4555 | out: [ |
| 4556 | "generated_headers/bar/generated_header.h", |
| 4557 | ], |
| 4558 | export_include_dirs: [ |
| 4559 | "generated_headers", |
| 4560 | ], |
| 4561 | } |
| 4562 | ` |
| 4563 | |
| 4564 | t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) { |
| 4565 | ctx := testCc(t, genRuleModules+` |
| 4566 | cc_library { |
| 4567 | name: "libfoo", |
| 4568 | srcs: ["foo.c"], |
| 4569 | export_include_dirs: ["foo/standard"], |
| 4570 | export_system_include_dirs: ["foo/system"], |
| 4571 | generated_headers: ["genrule_foo"], |
| 4572 | export_generated_headers: ["genrule_foo"], |
| 4573 | } |
| 4574 | |
| 4575 | cc_library { |
| 4576 | name: "libbar", |
| 4577 | srcs: ["bar.c"], |
| 4578 | shared_libs: ["libfoo"], |
| 4579 | export_include_dirs: ["bar/standard"], |
| 4580 | export_system_include_dirs: ["bar/system"], |
| 4581 | generated_headers: ["genrule_bar"], |
| 4582 | export_generated_headers: ["genrule_bar"], |
| 4583 | } |
| 4584 | `) |
| 4585 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4586 | checkIncludeDirs(t, ctx, foo, |
| 4587 | expectedIncludeDirs(` |
| 4588 | foo/standard |
| 4589 | .intermediates/genrule_foo/gen/generated_headers |
| 4590 | `), |
| 4591 | expectedSystemIncludeDirs(`foo/system`), |
| 4592 | expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4593 | expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4594 | ) |
| 4595 | |
| 4596 | bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() |
| 4597 | checkIncludeDirs(t, ctx, bar, |
| 4598 | expectedIncludeDirs(` |
| 4599 | bar/standard |
| 4600 | .intermediates/genrule_bar/gen/generated_headers |
| 4601 | `), |
| 4602 | expectedSystemIncludeDirs(`bar/system`), |
| 4603 | expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`), |
| 4604 | expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`), |
| 4605 | ) |
| 4606 | }) |
| 4607 | |
| 4608 | t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) { |
| 4609 | ctx := testCc(t, genRuleModules+` |
| 4610 | cc_library { |
| 4611 | name: "libfoo", |
| 4612 | srcs: ["foo.c"], |
| 4613 | export_include_dirs: ["foo/standard"], |
| 4614 | export_system_include_dirs: ["foo/system"], |
| 4615 | generated_headers: ["genrule_foo"], |
| 4616 | export_generated_headers: ["genrule_foo"], |
| 4617 | } |
| 4618 | |
| 4619 | cc_library { |
| 4620 | name: "libbar", |
| 4621 | srcs: ["bar.c"], |
| 4622 | whole_static_libs: ["libfoo"], |
| 4623 | export_include_dirs: ["bar/standard"], |
| 4624 | export_system_include_dirs: ["bar/system"], |
| 4625 | generated_headers: ["genrule_bar"], |
| 4626 | export_generated_headers: ["genrule_bar"], |
| 4627 | } |
| 4628 | `) |
| 4629 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4630 | checkIncludeDirs(t, ctx, foo, |
| 4631 | expectedIncludeDirs(` |
| 4632 | foo/standard |
| 4633 | .intermediates/genrule_foo/gen/generated_headers |
| 4634 | `), |
| 4635 | expectedSystemIncludeDirs(`foo/system`), |
| 4636 | expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4637 | expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4638 | ) |
| 4639 | |
| 4640 | bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() |
| 4641 | checkIncludeDirs(t, ctx, bar, |
| 4642 | expectedIncludeDirs(` |
| 4643 | bar/standard |
| 4644 | foo/standard |
| 4645 | .intermediates/genrule_foo/gen/generated_headers |
| 4646 | .intermediates/genrule_bar/gen/generated_headers |
| 4647 | `), |
| 4648 | expectedSystemIncludeDirs(` |
| 4649 | bar/system |
| 4650 | foo/system |
| 4651 | `), |
| 4652 | expectedGeneratedHeaders(` |
| 4653 | .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h |
| 4654 | .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h |
| 4655 | `), |
| 4656 | expectedOrderOnlyDeps(` |
| 4657 | .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h |
| 4658 | .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h |
| 4659 | `), |
| 4660 | ) |
| 4661 | }) |
| 4662 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4663 | t.Run("ensure only aidl headers are exported", func(t *testing.T) { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4664 | ctx := android.GroupFixturePreparers( |
| 4665 | prepareForCcTest, |
| 4666 | aidl_library.PrepareForTestWithAidlLibrary, |
| 4667 | ).RunTestWithBp(t, ` |
| 4668 | aidl_library { |
| 4669 | name: "libfoo_aidl", |
| 4670 | srcs: ["x/y/Bar.aidl"], |
| 4671 | strip_import_prefix: "x", |
| 4672 | } |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4673 | cc_library_shared { |
| 4674 | name: "libfoo", |
| 4675 | srcs: [ |
| 4676 | "foo.c", |
| 4677 | "b.aidl", |
| 4678 | "a.proto", |
| 4679 | ], |
| 4680 | aidl: { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4681 | libs: ["libfoo_aidl"], |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4682 | export_aidl_headers: true, |
| 4683 | } |
| 4684 | } |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4685 | `).TestContext |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4686 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4687 | checkIncludeDirs(t, ctx, foo, |
| 4688 | expectedIncludeDirs(` |
| 4689 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4690 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4691 | `), |
| 4692 | expectedSystemIncludeDirs(``), |
| 4693 | expectedGeneratedHeaders(` |
| 4694 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h |
| 4695 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h |
| 4696 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4697 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h |
| 4698 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h |
| 4699 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4700 | `), |
| 4701 | expectedOrderOnlyDeps(` |
| 4702 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h |
| 4703 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h |
| 4704 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4705 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h |
| 4706 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h |
| 4707 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4708 | `), |
| 4709 | ) |
| 4710 | }) |
| 4711 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4712 | t.Run("ensure only proto headers are exported", func(t *testing.T) { |
| 4713 | ctx := testCc(t, genRuleModules+` |
| 4714 | cc_library_shared { |
| 4715 | name: "libfoo", |
| 4716 | srcs: [ |
| 4717 | "foo.c", |
| 4718 | "b.aidl", |
| 4719 | "a.proto", |
| 4720 | ], |
| 4721 | proto: { |
| 4722 | export_proto_headers: true, |
| 4723 | } |
| 4724 | } |
| 4725 | `) |
| 4726 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4727 | checkIncludeDirs(t, ctx, foo, |
| 4728 | expectedIncludeDirs(` |
| 4729 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto |
| 4730 | `), |
| 4731 | expectedSystemIncludeDirs(``), |
| 4732 | expectedGeneratedHeaders(` |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4733 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h |
| 4734 | `), |
| 4735 | expectedOrderOnlyDeps(` |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4736 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h |
| 4737 | `), |
| 4738 | ) |
| 4739 | }) |
| 4740 | |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 4741 | t.Run("ensure only sysprop headers are exported", func(t *testing.T) { |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4742 | ctx := testCc(t, genRuleModules+` |
| 4743 | cc_library_shared { |
| 4744 | name: "libfoo", |
| 4745 | srcs: [ |
| 4746 | "foo.c", |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4747 | "path/to/a.sysprop", |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4748 | "b.aidl", |
| 4749 | "a.proto", |
| 4750 | ], |
| 4751 | } |
| 4752 | `) |
| 4753 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4754 | checkIncludeDirs(t, ctx, foo, |
| 4755 | expectedIncludeDirs(` |
| 4756 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include |
| 4757 | `), |
| 4758 | expectedSystemIncludeDirs(``), |
| 4759 | expectedGeneratedHeaders(` |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4760 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/path/to/a.sysprop.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4761 | `), |
| 4762 | expectedOrderOnlyDeps(` |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4763 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/path/to/a.sysprop.h |
| 4764 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/path/to/a.sysprop.h |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4765 | `), |
| 4766 | ) |
| 4767 | }) |
| 4768 | } |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4769 | |
| 4770 | func TestIncludeDirectoryOrdering(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4771 | t.Parallel() |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4772 | baseExpectedFlags := []string{ |
| 4773 | "${config.ArmThumbCflags}", |
| 4774 | "${config.ArmCflags}", |
| 4775 | "${config.CommonGlobalCflags}", |
| 4776 | "${config.DeviceGlobalCflags}", |
| 4777 | "${config.ExternalCflags}", |
| 4778 | "${config.ArmToolchainCflags}", |
| 4779 | "${config.ArmArmv7ANeonCflags}", |
| 4780 | "${config.ArmGenericCflags}", |
| 4781 | "-target", |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4782 | "armv7a-linux-androideabi21", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | expectedIncludes := []string{ |
| 4786 | "external/foo/android_arm_export_include_dirs", |
| 4787 | "external/foo/lib32_export_include_dirs", |
| 4788 | "external/foo/arm_export_include_dirs", |
| 4789 | "external/foo/android_export_include_dirs", |
| 4790 | "external/foo/linux_export_include_dirs", |
| 4791 | "external/foo/export_include_dirs", |
| 4792 | "external/foo/android_arm_local_include_dirs", |
| 4793 | "external/foo/lib32_local_include_dirs", |
| 4794 | "external/foo/arm_local_include_dirs", |
| 4795 | "external/foo/android_local_include_dirs", |
| 4796 | "external/foo/linux_local_include_dirs", |
| 4797 | "external/foo/local_include_dirs", |
| 4798 | "external/foo", |
| 4799 | "external/foo/libheader1", |
| 4800 | "external/foo/libheader2", |
| 4801 | "external/foo/libwhole1", |
| 4802 | "external/foo/libwhole2", |
| 4803 | "external/foo/libstatic1", |
| 4804 | "external/foo/libstatic2", |
| 4805 | "external/foo/libshared1", |
| 4806 | "external/foo/libshared2", |
| 4807 | "external/foo/liblinux", |
| 4808 | "external/foo/libandroid", |
| 4809 | "external/foo/libarm", |
| 4810 | "external/foo/lib32", |
| 4811 | "external/foo/libandroid_arm", |
| 4812 | "defaults/cc/common/ndk_libc++_shared", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"} |
| 4816 | cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"} |
| 4817 | |
Elliott Hughes | ed4a27b | 2022-05-18 13:15:00 -0700 | [diff] [blame] | 4818 | cflags := []string{"-Werror", "-std=candcpp"} |
Elliott Hughes | fb294e3 | 2023-06-14 10:42:45 -0700 | [diff] [blame] | 4819 | cstd := []string{"-std=gnu17", "-std=conly"} |
Liz Kammer | 9dc6577 | 2021-12-16 11:38:50 -0500 | [diff] [blame] | 4820 | cppstd := []string{"-std=gnu++17", "-std=cpp", "-fno-rtti"} |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4821 | |
| 4822 | lastIncludes := []string{ |
| 4823 | "out/soong/ndk/sysroot/usr/include", |
| 4824 | "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi", |
| 4825 | } |
| 4826 | |
| 4827 | combineSlices := func(slices ...[]string) []string { |
| 4828 | var ret []string |
| 4829 | for _, s := range slices { |
| 4830 | ret = append(ret, s...) |
| 4831 | } |
| 4832 | return ret |
| 4833 | } |
| 4834 | |
| 4835 | testCases := []struct { |
| 4836 | name string |
| 4837 | src string |
| 4838 | expected []string |
| 4839 | }{ |
| 4840 | { |
| 4841 | name: "c", |
| 4842 | src: "foo.c", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4843 | 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] | 4844 | }, |
| 4845 | { |
| 4846 | name: "cc", |
| 4847 | src: "foo.cc", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4848 | 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] | 4849 | }, |
| 4850 | { |
| 4851 | name: "assemble", |
| 4852 | src: "foo.s", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4853 | expected: combineSlices(baseExpectedFlags, []string{"${config.CommonGlobalAsflags}"}, expectedIncludes, lastIncludes), |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4854 | }, |
| 4855 | } |
| 4856 | |
| 4857 | for _, tc := range testCases { |
| 4858 | t.Run(tc.name, func(t *testing.T) { |
| 4859 | bp := fmt.Sprintf(` |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4860 | cc_library { |
| 4861 | name: "libfoo", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4862 | srcs: ["%s"], |
Liz Kammer | 9dc6577 | 2021-12-16 11:38:50 -0500 | [diff] [blame] | 4863 | cflags: ["-std=candcpp"], |
| 4864 | conlyflags: ["-std=conly"], |
| 4865 | cppflags: ["-std=cpp"], |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4866 | local_include_dirs: ["local_include_dirs"], |
| 4867 | export_include_dirs: ["export_include_dirs"], |
| 4868 | export_system_include_dirs: ["export_system_include_dirs"], |
| 4869 | static_libs: ["libstatic1", "libstatic2"], |
| 4870 | whole_static_libs: ["libwhole1", "libwhole2"], |
| 4871 | shared_libs: ["libshared1", "libshared2"], |
| 4872 | header_libs: ["libheader1", "libheader2"], |
| 4873 | target: { |
| 4874 | android: { |
| 4875 | shared_libs: ["libandroid"], |
| 4876 | local_include_dirs: ["android_local_include_dirs"], |
| 4877 | export_include_dirs: ["android_export_include_dirs"], |
| 4878 | }, |
| 4879 | android_arm: { |
| 4880 | shared_libs: ["libandroid_arm"], |
| 4881 | local_include_dirs: ["android_arm_local_include_dirs"], |
| 4882 | export_include_dirs: ["android_arm_export_include_dirs"], |
| 4883 | }, |
| 4884 | linux: { |
| 4885 | shared_libs: ["liblinux"], |
| 4886 | local_include_dirs: ["linux_local_include_dirs"], |
| 4887 | export_include_dirs: ["linux_export_include_dirs"], |
| 4888 | }, |
| 4889 | }, |
| 4890 | multilib: { |
| 4891 | lib32: { |
| 4892 | shared_libs: ["lib32"], |
| 4893 | local_include_dirs: ["lib32_local_include_dirs"], |
| 4894 | export_include_dirs: ["lib32_export_include_dirs"], |
| 4895 | }, |
| 4896 | }, |
| 4897 | arch: { |
| 4898 | arm: { |
| 4899 | shared_libs: ["libarm"], |
| 4900 | local_include_dirs: ["arm_local_include_dirs"], |
| 4901 | export_include_dirs: ["arm_export_include_dirs"], |
| 4902 | }, |
| 4903 | }, |
| 4904 | stl: "libc++", |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4905 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | cc_library_headers { |
| 4909 | name: "libheader1", |
| 4910 | export_include_dirs: ["libheader1"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4911 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4912 | stl: "none", |
| 4913 | } |
| 4914 | |
| 4915 | cc_library_headers { |
| 4916 | name: "libheader2", |
| 4917 | export_include_dirs: ["libheader2"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4918 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4919 | stl: "none", |
| 4920 | } |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4921 | `, tc.src) |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4922 | |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4923 | libs := []string{ |
| 4924 | "libstatic1", |
| 4925 | "libstatic2", |
| 4926 | "libwhole1", |
| 4927 | "libwhole2", |
| 4928 | "libshared1", |
| 4929 | "libshared2", |
| 4930 | "libandroid", |
| 4931 | "libandroid_arm", |
| 4932 | "liblinux", |
| 4933 | "lib32", |
| 4934 | "libarm", |
| 4935 | } |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4936 | |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4937 | for _, lib := range libs { |
| 4938 | bp += fmt.Sprintf(` |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4939 | cc_library { |
| 4940 | name: "%s", |
| 4941 | export_include_dirs: ["%s"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4942 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4943 | stl: "none", |
| 4944 | } |
| 4945 | `, lib, lib) |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | ctx := android.GroupFixturePreparers( |
| 4949 | PrepareForIntegrationTestWithCc, |
| 4950 | android.FixtureAddTextFile("external/foo/Android.bp", bp), |
| 4951 | ).RunTest(t) |
| 4952 | // Use the arm variant instead of the arm64 variant so that it gets headers from |
| 4953 | // ndk_libandroid_support to test LateStaticLibs. |
| 4954 | cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"] |
| 4955 | |
| 4956 | var includes []string |
| 4957 | flags := strings.Split(cflags, " ") |
| 4958 | for _, flag := range flags { |
| 4959 | if strings.HasPrefix(flag, "-I") { |
| 4960 | includes = append(includes, strings.TrimPrefix(flag, "-I")) |
| 4961 | } else if flag == "-isystem" { |
| 4962 | // skip isystem, include next |
| 4963 | } else if len(flag) > 0 { |
| 4964 | includes = append(includes, flag) |
| 4965 | } |
| 4966 | } |
| 4967 | |
| 4968 | android.AssertArrayString(t, "includes", tc.expected, includes) |
| 4969 | }) |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4972 | } |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 4973 | |
zijunzhao | 933e380 | 2023-01-12 07:26:20 +0000 | [diff] [blame] | 4974 | func TestAddnoOverride64GlobalCflags(t *testing.T) { |
| 4975 | t.Parallel() |
| 4976 | ctx := testCc(t, ` |
| 4977 | cc_library_shared { |
| 4978 | name: "libclient", |
| 4979 | srcs: ["foo.c"], |
| 4980 | shared_libs: ["libfoo#1"], |
| 4981 | } |
| 4982 | |
| 4983 | cc_library_shared { |
| 4984 | name: "libfoo", |
| 4985 | srcs: ["foo.c"], |
| 4986 | shared_libs: ["libbar"], |
| 4987 | export_shared_lib_headers: ["libbar"], |
| 4988 | stubs: { |
| 4989 | symbol_file: "foo.map.txt", |
| 4990 | versions: ["1", "2", "3"], |
| 4991 | }, |
| 4992 | } |
| 4993 | |
| 4994 | cc_library_shared { |
| 4995 | name: "libbar", |
| 4996 | export_include_dirs: ["include/libbar"], |
| 4997 | srcs: ["foo.c"], |
| 4998 | }`) |
| 4999 | |
| 5000 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 5001 | |
| 5002 | if !strings.Contains(cFlags, "${config.NoOverride64GlobalCflags}") { |
| 5003 | t.Errorf("expected %q in cflags, got %q", "${config.NoOverride64GlobalCflags}", cFlags) |
| 5004 | } |
| 5005 | } |
| 5006 | |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 5007 | func TestCcBuildBrokenClangProperty(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 5008 | t.Parallel() |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 5009 | tests := []struct { |
| 5010 | name string |
| 5011 | clang bool |
| 5012 | BuildBrokenClangProperty bool |
| 5013 | err string |
| 5014 | }{ |
| 5015 | { |
| 5016 | name: "error when clang is set to false", |
| 5017 | clang: false, |
| 5018 | err: "is no longer supported", |
| 5019 | }, |
| 5020 | { |
| 5021 | name: "error when clang is set to true", |
| 5022 | clang: true, |
| 5023 | err: "property is deprecated, see Changes.md", |
| 5024 | }, |
| 5025 | { |
| 5026 | name: "no error when BuildBrokenClangProperty is explicitly set to true", |
| 5027 | clang: true, |
| 5028 | BuildBrokenClangProperty: true, |
| 5029 | }, |
| 5030 | } |
| 5031 | |
| 5032 | for _, test := range tests { |
| 5033 | t.Run(test.name, func(t *testing.T) { |
| 5034 | bp := fmt.Sprintf(` |
| 5035 | cc_library { |
| 5036 | name: "foo", |
| 5037 | clang: %t, |
| 5038 | }`, test.clang) |
| 5039 | |
| 5040 | if test.err == "" { |
| 5041 | android.GroupFixturePreparers( |
| 5042 | prepareForCcTest, |
| 5043 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5044 | if test.BuildBrokenClangProperty { |
| 5045 | variables.BuildBrokenClangProperty = test.BuildBrokenClangProperty |
| 5046 | } |
| 5047 | }), |
| 5048 | ).RunTestWithBp(t, bp) |
| 5049 | } else { |
| 5050 | prepareForCcTest. |
| 5051 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 5052 | RunTestWithBp(t, bp) |
| 5053 | } |
| 5054 | }) |
| 5055 | } |
| 5056 | } |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 5057 | |
| 5058 | func TestCcBuildBrokenClangAsFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 5059 | t.Parallel() |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 5060 | tests := []struct { |
| 5061 | name string |
| 5062 | clangAsFlags []string |
| 5063 | BuildBrokenClangAsFlags bool |
| 5064 | err string |
| 5065 | }{ |
| 5066 | { |
| 5067 | name: "error when clang_asflags is set", |
| 5068 | clangAsFlags: []string{"-a", "-b"}, |
| 5069 | err: "clang_asflags: property is deprecated", |
| 5070 | }, |
| 5071 | { |
| 5072 | name: "no error when BuildBrokenClangAsFlags is explicitly set to true", |
| 5073 | clangAsFlags: []string{"-a", "-b"}, |
| 5074 | BuildBrokenClangAsFlags: true, |
| 5075 | }, |
| 5076 | } |
| 5077 | |
| 5078 | for _, test := range tests { |
| 5079 | t.Run(test.name, func(t *testing.T) { |
| 5080 | bp := fmt.Sprintf(` |
| 5081 | cc_library { |
| 5082 | name: "foo", |
| 5083 | clang_asflags: %s, |
| 5084 | }`, `["`+strings.Join(test.clangAsFlags, `","`)+`"]`) |
| 5085 | |
| 5086 | if test.err == "" { |
| 5087 | android.GroupFixturePreparers( |
| 5088 | prepareForCcTest, |
| 5089 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5090 | if test.BuildBrokenClangAsFlags { |
| 5091 | variables.BuildBrokenClangAsFlags = test.BuildBrokenClangAsFlags |
| 5092 | } |
| 5093 | }), |
| 5094 | ).RunTestWithBp(t, bp) |
| 5095 | } else { |
| 5096 | prepareForCcTest. |
| 5097 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 5098 | RunTestWithBp(t, bp) |
| 5099 | } |
| 5100 | }) |
| 5101 | } |
| 5102 | } |
| 5103 | |
| 5104 | func TestCcBuildBrokenClangCFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 5105 | t.Parallel() |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 5106 | tests := []struct { |
| 5107 | name string |
| 5108 | clangCFlags []string |
| 5109 | BuildBrokenClangCFlags bool |
| 5110 | err string |
| 5111 | }{ |
| 5112 | { |
| 5113 | name: "error when clang_cflags is set", |
| 5114 | clangCFlags: []string{"-a", "-b"}, |
| 5115 | err: "clang_cflags: property is deprecated", |
| 5116 | }, |
| 5117 | { |
| 5118 | name: "no error when BuildBrokenClangCFlags is explicitly set to true", |
| 5119 | clangCFlags: []string{"-a", "-b"}, |
| 5120 | BuildBrokenClangCFlags: true, |
| 5121 | }, |
| 5122 | } |
| 5123 | |
| 5124 | for _, test := range tests { |
| 5125 | t.Run(test.name, func(t *testing.T) { |
| 5126 | bp := fmt.Sprintf(` |
| 5127 | cc_library { |
| 5128 | name: "foo", |
| 5129 | clang_cflags: %s, |
| 5130 | }`, `["`+strings.Join(test.clangCFlags, `","`)+`"]`) |
| 5131 | |
| 5132 | if test.err == "" { |
| 5133 | android.GroupFixturePreparers( |
| 5134 | prepareForCcTest, |
| 5135 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5136 | if test.BuildBrokenClangCFlags { |
| 5137 | variables.BuildBrokenClangCFlags = test.BuildBrokenClangCFlags |
| 5138 | } |
| 5139 | }), |
| 5140 | ).RunTestWithBp(t, bp) |
| 5141 | } else { |
| 5142 | prepareForCcTest. |
| 5143 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 5144 | RunTestWithBp(t, bp) |
| 5145 | } |
| 5146 | }) |
| 5147 | } |
| 5148 | } |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 5149 | |
| 5150 | func TestDclaLibraryInApex(t *testing.T) { |
| 5151 | t.Parallel() |
| 5152 | bp := ` |
| 5153 | cc_library_shared { |
| 5154 | name: "cc_lib_in_apex", |
| 5155 | srcs: ["foo.cc"], |
| 5156 | apex_available: ["myapex"], |
| 5157 | bazel_module: { label: "//foo/bar:bar" }, |
| 5158 | }` |
| 5159 | label := "//foo/bar:bar" |
| 5160 | arch64 := "arm64_armv8-a" |
| 5161 | arch32 := "arm_armv7-a-neon" |
| 5162 | apexCfgKey := android.ApexConfigKey{ |
| 5163 | WithinApex: true, |
| 5164 | ApexSdkVersion: "28", |
| 5165 | } |
| 5166 | |
| 5167 | result := android.GroupFixturePreparers( |
| 5168 | prepareForCcTest, |
| 5169 | android.FixtureRegisterWithContext(registerTestMutators), |
| 5170 | android.FixtureModifyConfig(func(config android.Config) { |
| 5171 | config.BazelContext = android.MockBazelContext{ |
| 5172 | OutputBaseDir: "outputbase", |
| 5173 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 5174 | android.BuildMockBazelContextResultKey(label, arch32, android.Android, apexCfgKey): cquery.CcInfo{ |
| 5175 | RootDynamicLibraries: []string{"foo.so"}, |
| 5176 | }, |
| 5177 | android.BuildMockBazelContextResultKey(label, arch64, android.Android, apexCfgKey): cquery.CcInfo{ |
| 5178 | RootDynamicLibraries: []string{"foo.so"}, |
| 5179 | }, |
| 5180 | }, |
| 5181 | BazelRequests: make(map[string]bool), |
| 5182 | } |
| 5183 | }), |
| 5184 | ).RunTestWithBp(t, bp) |
| 5185 | ctx := result.TestContext |
| 5186 | |
| 5187 | // Test if the bazel request is queued correctly |
| 5188 | key := android.BuildMockBazelContextRequestKey(label, cquery.GetCcInfo, arch32, android.Android, apexCfgKey) |
| 5189 | if !ctx.Config().BazelContext.(android.MockBazelContext).BazelRequests[key] { |
| 5190 | t.Errorf("Bazel request was not queued: %s", key) |
| 5191 | } |
| 5192 | |
| 5193 | sharedFoo := ctx.ModuleForTests(ccLibInApex, "android_arm_armv7-a-neon_shared_"+apexVariationName).Module() |
| 5194 | producer := sharedFoo.(android.OutputFileProducer) |
| 5195 | outputFiles, err := producer.OutputFiles("") |
| 5196 | if err != nil { |
| 5197 | t.Errorf("Unexpected error getting cc_object outputfiles %s", err) |
| 5198 | } |
| 5199 | expectedOutputFiles := []string{"outputbase/execroot/__main__/foo.so"} |
| 5200 | android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings()) |
| 5201 | } |
Sam Delmerico | ef69d47 | 2023-04-18 17:32:43 -0400 | [diff] [blame] | 5202 | |
| 5203 | func TestDisableSanitizerVariantsInMixedBuilds(t *testing.T) { |
| 5204 | t.Parallel() |
| 5205 | bp := ` |
| 5206 | cc_library_static { |
| 5207 | name: "foo_ubsan_minimal", |
| 5208 | srcs: ["foo.cc"], |
| 5209 | bazel_module: { label: "//foo_ubsan_minimal" }, |
| 5210 | sanitize: { |
| 5211 | all_undefined: true, |
| 5212 | integer_overflow: true, |
| 5213 | }, |
| 5214 | } |
| 5215 | cc_library_static { |
| 5216 | name: "foo", |
| 5217 | srcs: ["foo.cc"], |
| 5218 | bazel_module: { label: "//foo" }, |
| 5219 | sanitize: { |
| 5220 | address: true, |
| 5221 | hwaddress: true, |
| 5222 | fuzzer: true, |
| 5223 | integer_overflow: true, |
| 5224 | scs: true, |
| 5225 | }, |
| 5226 | } |
| 5227 | cc_library_static { |
| 5228 | name: "foo_tsan", |
| 5229 | srcs: ["foo.cc"], |
| 5230 | bazel_module: { label: "//foo_tsan" }, |
| 5231 | sanitize: { |
| 5232 | thread: true, |
| 5233 | }, |
| 5234 | } |
| 5235 | cc_library_static { |
| 5236 | name: "foo_cfi", |
| 5237 | srcs: ["foo.cc"], |
| 5238 | bazel_module: { label: "//foo_cfi" }, |
| 5239 | sanitize: { |
| 5240 | cfi: true, |
| 5241 | }, |
| 5242 | } |
| 5243 | cc_library_static { |
| 5244 | name: "foo_memtag_stack", |
| 5245 | srcs: ["foo.cc"], |
| 5246 | bazel_module: { label: "//foo_memtag_stack" }, |
| 5247 | sanitize: { |
| 5248 | memtag_stack: true, |
| 5249 | }, |
| 5250 | } |
| 5251 | cc_library_static { |
| 5252 | name: "foo_memtag_heap", |
| 5253 | srcs: ["foo.cc"], |
| 5254 | bazel_module: { label: "//foo_memtag_heap" }, |
| 5255 | sanitize: { |
| 5256 | memtag_heap: true, |
| 5257 | }, |
| 5258 | } |
| 5259 | cc_library_static { |
| 5260 | name: "foo_safestack", |
| 5261 | srcs: ["foo.cc"], |
| 5262 | bazel_module: { label: "//foo_safestack" }, |
| 5263 | sanitize: { |
| 5264 | safestack: true, |
| 5265 | }, |
| 5266 | } |
| 5267 | cc_library_static { |
| 5268 | name: "foo_scudo", |
| 5269 | srcs: ["foo.cc"], |
| 5270 | bazel_module: { label: "//foo_scudo" }, |
| 5271 | sanitize: { |
| 5272 | scudo: true, |
| 5273 | }, |
| 5274 | } |
| 5275 | ` |
| 5276 | testcases := []struct { |
| 5277 | name string |
| 5278 | variant string |
| 5279 | expectedOutputPaths []string |
| 5280 | }{ |
| 5281 | { |
| 5282 | name: "foo_ubsan_minimal", |
| 5283 | variant: "android_arm64_armv8-a_static_apex28", |
| 5284 | expectedOutputPaths: []string{ |
| 5285 | "outputbase/execroot/__main__/foo_ubsan_minimal.a", |
| 5286 | }, |
| 5287 | }, |
| 5288 | { |
| 5289 | name: "foo", |
| 5290 | variant: "android_arm64_armv8-a_static_apex28", |
| 5291 | expectedOutputPaths: []string{ |
| 5292 | "outputbase/execroot/__main__/foo.a", |
| 5293 | }, |
| 5294 | }, |
| 5295 | { |
| 5296 | name: "foo", |
| 5297 | variant: "android_arm_armv7-a-neon_static_asan_apex28", |
| 5298 | expectedOutputPaths: []string{ |
| 5299 | "out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_apex28/foo.a", |
| 5300 | }, |
| 5301 | }, |
| 5302 | { |
| 5303 | name: "foo", |
| 5304 | variant: "android_arm64_armv8-a_static_hwasan_apex28", |
| 5305 | expectedOutputPaths: []string{ |
| 5306 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_apex28/foo.a", |
| 5307 | }, |
| 5308 | }, |
| 5309 | { |
| 5310 | name: "foo", |
| 5311 | variant: "android_arm64_armv8-a_static_fuzzer_apex28", |
| 5312 | expectedOutputPaths: []string{ |
| 5313 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_fuzzer_apex28/foo.a", |
| 5314 | }, |
| 5315 | }, |
| 5316 | { |
| 5317 | name: "foo", |
| 5318 | variant: "android_arm_armv7-a-neon_static_asan_fuzzer_apex28", |
| 5319 | expectedOutputPaths: []string{ |
| 5320 | "out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_fuzzer_apex28/foo.a", |
| 5321 | }, |
| 5322 | }, |
| 5323 | { |
| 5324 | name: "foo", |
| 5325 | variant: "android_arm64_armv8-a_static_hwasan_fuzzer_apex28", |
| 5326 | expectedOutputPaths: []string{ |
| 5327 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_fuzzer_apex28/foo.a", |
| 5328 | }, |
| 5329 | }, |
| 5330 | { |
| 5331 | name: "foo", |
| 5332 | variant: "android_arm64_armv8-a_static_scs_apex28", |
| 5333 | expectedOutputPaths: []string{ |
| 5334 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_scs_apex28/foo.a", |
| 5335 | }, |
| 5336 | }, |
| 5337 | { |
| 5338 | name: "foo", |
| 5339 | variant: "android_arm64_armv8-a_static_hwasan_scs_apex28", |
| 5340 | expectedOutputPaths: []string{ |
| 5341 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_apex28/foo.a", |
| 5342 | }, |
| 5343 | }, |
| 5344 | { |
| 5345 | name: "foo", |
| 5346 | variant: "android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28", |
| 5347 | expectedOutputPaths: []string{ |
| 5348 | "out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28/foo.a", |
| 5349 | }, |
| 5350 | }, |
| 5351 | { |
| 5352 | name: "foo_tsan", |
| 5353 | variant: "android_arm64_armv8-a_static_apex28", |
| 5354 | expectedOutputPaths: []string{ |
| 5355 | "outputbase/execroot/__main__/foo_tsan.a", |
| 5356 | }, |
| 5357 | }, |
| 5358 | { |
| 5359 | name: "foo_tsan", |
| 5360 | variant: "android_arm64_armv8-a_static_tsan_apex28", |
| 5361 | expectedOutputPaths: []string{ |
| 5362 | "out/soong/.intermediates/foo_tsan/android_arm64_armv8-a_static_tsan_apex28/foo_tsan.a", |
| 5363 | }, |
| 5364 | }, |
| 5365 | { |
| 5366 | name: "foo_cfi", |
| 5367 | variant: "android_arm64_armv8-a_static_apex28", |
| 5368 | expectedOutputPaths: []string{ |
| 5369 | "outputbase/execroot/__main__/foo_cfi.a", |
| 5370 | }, |
| 5371 | }, |
| 5372 | { |
| 5373 | name: "foo_cfi", |
| 5374 | variant: "android_arm64_armv8-a_static_cfi_apex28", |
| 5375 | expectedOutputPaths: []string{ |
Yu Liu | 95497dc | 2023-05-25 11:15:07 -0700 | [diff] [blame] | 5376 | "outputbase/execroot/__main__/foo_cfi.a", |
Sam Delmerico | ef69d47 | 2023-04-18 17:32:43 -0400 | [diff] [blame] | 5377 | }, |
| 5378 | }, |
| 5379 | { |
| 5380 | name: "foo_memtag_stack", |
| 5381 | variant: "android_arm64_armv8-a_static_apex28", |
| 5382 | expectedOutputPaths: []string{ |
| 5383 | "out/soong/.intermediates/foo_memtag_stack/android_arm64_armv8-a_static_apex28/foo_memtag_stack.a", |
| 5384 | }, |
| 5385 | }, |
| 5386 | { |
| 5387 | name: "foo_memtag_heap", |
| 5388 | variant: "android_arm64_armv8-a_static_apex28", |
| 5389 | expectedOutputPaths: []string{ |
| 5390 | "out/soong/.intermediates/foo_memtag_heap/android_arm64_armv8-a_static_apex28/foo_memtag_heap.a", |
| 5391 | }, |
| 5392 | }, |
| 5393 | { |
| 5394 | name: "foo_safestack", |
| 5395 | variant: "android_arm64_armv8-a_static_apex28", |
| 5396 | expectedOutputPaths: []string{ |
| 5397 | "out/soong/.intermediates/foo_safestack/android_arm64_armv8-a_static_apex28/foo_safestack.a", |
| 5398 | }, |
| 5399 | }, |
| 5400 | { |
| 5401 | name: "foo_scudo", |
| 5402 | variant: "android_arm64_armv8-a_static_apex28", |
| 5403 | expectedOutputPaths: []string{ |
| 5404 | "out/soong/.intermediates/foo_scudo/android_arm64_armv8-a_static_apex28/foo_scudo.a", |
| 5405 | }, |
| 5406 | }, |
| 5407 | } |
| 5408 | |
| 5409 | ctx := android.GroupFixturePreparers( |
| 5410 | prepareForCcTest, |
| 5411 | prepareForAsanTest, |
| 5412 | android.FixtureRegisterWithContext(registerTestMutators), |
| 5413 | android.FixtureModifyConfig(func(config android.Config) { |
| 5414 | config.BazelContext = android.MockBazelContext{ |
| 5415 | OutputBaseDir: "outputbase", |
| 5416 | LabelToCcInfo: map[string]cquery.CcInfo{ |
| 5417 | "//foo_ubsan_minimal": { |
| 5418 | RootStaticArchives: []string{"foo_ubsan_minimal.a"}, |
| 5419 | }, |
| 5420 | "//foo": { |
| 5421 | RootStaticArchives: []string{"foo.a"}, |
| 5422 | }, |
| 5423 | "//foo_tsan": { |
| 5424 | RootStaticArchives: []string{"foo_tsan.a"}, |
| 5425 | }, |
| 5426 | "//foo_cfi": { |
| 5427 | RootStaticArchives: []string{"foo_cfi.a"}, |
| 5428 | }, |
| 5429 | "//foo_memtag_stack": { |
| 5430 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5431 | }, |
| 5432 | "//foo_memtag_heap": { |
| 5433 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5434 | }, |
| 5435 | "//foo_safestack": { |
| 5436 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5437 | }, |
| 5438 | "//foo_scudo": { |
| 5439 | RootStaticArchives: []string{"INVALID_ARCHIVE.a"}, |
| 5440 | }, |
| 5441 | }, |
| 5442 | } |
| 5443 | }), |
| 5444 | ).RunTestWithBp(t, bp).TestContext |
| 5445 | |
| 5446 | for _, tc := range testcases { |
| 5447 | fooMod := ctx.ModuleForTests(tc.name, tc.variant).Module() |
| 5448 | outputFiles, err := fooMod.(android.OutputFileProducer).OutputFiles("") |
| 5449 | if err != nil { |
| 5450 | t.Errorf("Unexpected error getting cc_object outputfiles %s", err) |
| 5451 | } |
| 5452 | android.AssertPathsRelativeToTopEquals(t, "output files", tc.expectedOutputPaths, outputFiles) |
| 5453 | } |
| 5454 | } |