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" |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 29 | |
| 30 | "github.com/google/blueprint" |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 31 | ) |
| 32 | |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 33 | func init() { |
| 34 | registerTestMutators(android.InitRegistrationContext) |
| 35 | } |
| 36 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 37 | func TestMain(m *testing.M) { |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 38 | os.Exit(m.Run()) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 39 | } |
| 40 | |
Paul Duffin | 2e6f90e | 2021-03-22 23:20:25 +0000 | [diff] [blame] | 41 | var prepareForCcTest = android.GroupFixturePreparers( |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 42 | PrepareForTestWithCcIncludeVndk, |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 43 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
Justin Yun | 41cbb5e | 2023-11-29 17:58:16 +0900 | [diff] [blame] | 44 | variables.VendorApiLevel = StringPtr("202404") |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 45 | variables.DeviceVndkVersion = StringPtr("current") |
Yi-Yo Chiang | 88960aa | 2024-01-19 15:02:29 +0800 | [diff] [blame] | 46 | variables.KeepVndk = BoolPtr(true) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 47 | variables.Platform_vndk_version = StringPtr("29") |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 48 | }), |
| 49 | ) |
| 50 | |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 51 | // TODO(b/316829758) Update prepareForCcTest with this configuration and remove prepareForCcTestWithoutVndk |
| 52 | var prepareForCcTestWithoutVndk = android.GroupFixturePreparers( |
| 53 | PrepareForIntegrationTestWithCc, |
| 54 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 55 | variables.VendorApiLevel = StringPtr("202404") |
| 56 | }), |
| 57 | ) |
| 58 | |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 59 | var apexVariationName = "apex28" |
| 60 | var apexVersion = "28" |
| 61 | |
| 62 | func registerTestMutators(ctx android.RegistrationContext) { |
| 63 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 64 | ctx.BottomUp("apex", testApexMutator).Parallel() |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 65 | }) |
| 66 | } |
| 67 | |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 68 | func testApexMutator(mctx android.BottomUpMutatorContext) { |
| 69 | modules := mctx.CreateVariations(apexVariationName) |
| 70 | apexInfo := android.ApexInfo{ |
| 71 | ApexVariationName: apexVariationName, |
| 72 | MinSdkVersion: android.ApiLevelForTest(apexVersion), |
| 73 | } |
| 74 | mctx.SetVariationProvider(modules[0], android.ApexInfoProvider, apexInfo) |
| 75 | } |
| 76 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 77 | // testCcWithConfig runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 78 | // |
| 79 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 80 | // |
| 81 | // deprecated |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 82 | func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext { |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 83 | t.Helper() |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 84 | result := prepareForCcTest.RunTestWithConfig(t, config) |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 85 | return result.TestContext |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 86 | } |
| 87 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 88 | // testCc runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 89 | // |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 90 | // 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] | 91 | // easier to customize the test behavior. |
| 92 | // |
| 93 | // 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] | 94 | // 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] | 95 | // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify |
| 96 | // that it did not change the test behavior unexpectedly. |
| 97 | // |
| 98 | // deprecated |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 99 | func testCc(t *testing.T, bp string) *android.TestContext { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 100 | t.Helper() |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 101 | result := prepareForCcTest.RunTestWithBp(t, bp) |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 102 | return result.TestContext |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 103 | } |
| 104 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 105 | // testCcErrorWithConfig runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 106 | // |
| 107 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 108 | // |
| 109 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 110 | func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 111 | t.Helper() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 112 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 113 | prepareForCcTest. |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 114 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 115 | RunTestWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 116 | } |
| 117 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 118 | // testCcError runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 119 | // |
| 120 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 121 | // |
| 122 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 123 | func testCcError(t *testing.T, pattern string, bp string) { |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 124 | t.Helper() |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 125 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 126 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 127 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 128 | testCcErrorWithConfig(t, pattern, config) |
| 129 | return |
| 130 | } |
| 131 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 132 | // testCcErrorProductVndk runs tests using the prepareForCcTest |
Paul Duffin | 02a3d65 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 133 | // |
| 134 | // See testCc for an explanation as to how to stop using this deprecated method. |
| 135 | // |
| 136 | // deprecated |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 137 | func testCcErrorProductVndk(t *testing.T, pattern string, bp string) { |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 138 | t.Helper() |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 139 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 140 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 141 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 142 | testCcErrorWithConfig(t, pattern, config) |
| 143 | return |
| 144 | } |
| 145 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 146 | const ( |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 147 | coreVariant = "android_arm64_armv8-a_shared" |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 148 | vendorVariant = "android_vendor.29_arm64_armv8-a_shared" |
| 149 | productVariant = "android_product.29_arm64_armv8-a_shared" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 150 | recoveryVariant = "android_recovery_arm64_armv8-a_shared" |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 151 | ) |
| 152 | |
Paul Duffin | db462dd | 2021-03-21 22:01:55 +0000 | [diff] [blame] | 153 | // Test that the PrepareForTestWithCcDefaultModules provides all the files that it uses by |
| 154 | // running it in a fixture that requires all source files to exist. |
| 155 | func TestPrepareForTestWithCcDefaultModules(t *testing.T) { |
| 156 | android.GroupFixturePreparers( |
| 157 | PrepareForTestWithCcDefaultModules, |
| 158 | android.PrepareForTestDisallowNonExistentPaths, |
| 159 | ).RunTest(t) |
| 160 | } |
| 161 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 162 | func TestVendorSrc(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 163 | t.Parallel() |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 164 | ctx := testCc(t, ` |
| 165 | cc_library { |
| 166 | name: "libTest", |
| 167 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 168 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 169 | nocrt: true, |
| 170 | system_shared_libs: [], |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 171 | vendor_available: true, |
| 172 | target: { |
| 173 | vendor: { |
| 174 | srcs: ["bar.c"], |
| 175 | }, |
| 176 | }, |
| 177 | } |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 178 | `) |
| 179 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 180 | ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld") |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 181 | var objs []string |
| 182 | for _, o := range ld.Inputs { |
| 183 | objs = append(objs, o.Base()) |
| 184 | } |
Colin Cross | 95d33fe | 2018-01-03 13:40:46 -0800 | [diff] [blame] | 185 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 186 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) |
| 187 | } |
| 188 | } |
| 189 | |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 190 | func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) { |
| 191 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) |
| 192 | partitionDefined := false |
| 193 | checkPartition := func(specific bool, partition string) { |
| 194 | if specific { |
| 195 | if expected != partition && !partitionDefined { |
| 196 | // The variant is installed to the 'partition' |
| 197 | t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition) |
| 198 | } |
| 199 | partitionDefined = true |
| 200 | } else { |
| 201 | // The variant is not installed to the 'partition' |
| 202 | if expected == partition { |
| 203 | t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition) |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | socSpecific := func(m *Module) bool { |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 208 | return m.SocSpecific() || m.InstallInVendor() |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 209 | } |
| 210 | deviceSpecific := func(m *Module) bool { |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 211 | return m.DeviceSpecific() || m.InstallInOdm() |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 212 | } |
| 213 | productSpecific := func(m *Module) bool { |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 214 | return m.ProductSpecific() || m.InstallInProduct() |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 215 | } |
| 216 | systemExtSpecific := func(m *Module) bool { |
| 217 | return m.SystemExtSpecific() |
| 218 | } |
| 219 | checkPartition(socSpecific(mod), "vendor") |
| 220 | checkPartition(deviceSpecific(mod), "odm") |
| 221 | checkPartition(productSpecific(mod), "product") |
| 222 | checkPartition(systemExtSpecific(mod), "system_ext") |
| 223 | if !partitionDefined && expected != "system" { |
| 224 | t.Errorf("%s variant of %q is expected to be installed to %s partition,"+ |
| 225 | " but installed to system partition", variant, name, expected) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | func TestInstallPartition(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 230 | t.Parallel() |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 231 | t.Helper() |
| 232 | ctx := prepareForCcTest.RunTestWithBp(t, ` |
| 233 | cc_library { |
| 234 | name: "libsystem", |
| 235 | } |
| 236 | cc_library { |
| 237 | name: "libsystem_ext", |
| 238 | system_ext_specific: true, |
| 239 | } |
| 240 | cc_library { |
| 241 | name: "libproduct", |
| 242 | product_specific: true, |
| 243 | } |
| 244 | cc_library { |
| 245 | name: "libvendor", |
| 246 | vendor: true, |
| 247 | } |
| 248 | cc_library { |
| 249 | name: "libodm", |
| 250 | device_specific: true, |
| 251 | } |
| 252 | cc_library { |
| 253 | name: "liball_available", |
| 254 | vendor_available: true, |
| 255 | product_available: true, |
| 256 | } |
| 257 | cc_library { |
| 258 | name: "libsystem_ext_all_available", |
| 259 | system_ext_specific: true, |
| 260 | vendor_available: true, |
| 261 | product_available: true, |
| 262 | } |
| 263 | cc_library { |
| 264 | name: "liball_available_odm", |
| 265 | odm_available: true, |
| 266 | product_available: true, |
| 267 | } |
| 268 | cc_library { |
| 269 | name: "libproduct_vendoravailable", |
| 270 | product_specific: true, |
| 271 | vendor_available: true, |
| 272 | } |
| 273 | cc_library { |
| 274 | name: "libproduct_odmavailable", |
| 275 | product_specific: true, |
| 276 | odm_available: true, |
| 277 | } |
| 278 | `).TestContext |
| 279 | |
| 280 | checkInstallPartition(t, ctx, "libsystem", coreVariant, "system") |
| 281 | checkInstallPartition(t, ctx, "libsystem_ext", coreVariant, "system_ext") |
| 282 | checkInstallPartition(t, ctx, "libproduct", productVariant, "product") |
| 283 | checkInstallPartition(t, ctx, "libvendor", vendorVariant, "vendor") |
| 284 | checkInstallPartition(t, ctx, "libodm", vendorVariant, "odm") |
| 285 | |
| 286 | checkInstallPartition(t, ctx, "liball_available", coreVariant, "system") |
| 287 | checkInstallPartition(t, ctx, "liball_available", productVariant, "product") |
| 288 | checkInstallPartition(t, ctx, "liball_available", vendorVariant, "vendor") |
| 289 | |
| 290 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", coreVariant, "system_ext") |
| 291 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", productVariant, "product") |
| 292 | checkInstallPartition(t, ctx, "libsystem_ext_all_available", vendorVariant, "vendor") |
| 293 | |
| 294 | checkInstallPartition(t, ctx, "liball_available_odm", coreVariant, "system") |
| 295 | checkInstallPartition(t, ctx, "liball_available_odm", productVariant, "product") |
| 296 | checkInstallPartition(t, ctx, "liball_available_odm", vendorVariant, "odm") |
| 297 | |
| 298 | checkInstallPartition(t, ctx, "libproduct_vendoravailable", productVariant, "product") |
| 299 | checkInstallPartition(t, ctx, "libproduct_vendoravailable", vendorVariant, "vendor") |
| 300 | |
| 301 | checkInstallPartition(t, ctx, "libproduct_odmavailable", productVariant, "product") |
| 302 | checkInstallPartition(t, ctx, "libproduct_odmavailable", vendorVariant, "odm") |
| 303 | } |
| 304 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 305 | func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string, |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 306 | isVndkSp bool, extends string, variant string) { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 307 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 308 | t.Helper() |
| 309 | |
Justin Yun | 0ecf0b2 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 310 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 311 | |
| 312 | // Check library properties. |
| 313 | lib, ok := mod.compiler.(*libraryDecorator) |
| 314 | if !ok { |
| 315 | t.Errorf("%q must have libraryDecorator", name) |
| 316 | } else if lib.baseInstaller.subDir != subDir { |
| 317 | t.Errorf("%q must use %q as subdir but it is using %q", name, subDir, |
| 318 | lib.baseInstaller.subDir) |
| 319 | } |
| 320 | |
| 321 | // Check VNDK properties. |
| 322 | if mod.vndkdep == nil { |
| 323 | t.Fatalf("%q must have `vndkdep`", name) |
| 324 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 325 | if !mod.IsVndk() { |
| 326 | t.Errorf("%q IsVndk() must equal to true", name) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 327 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 328 | if mod.IsVndkSp() != isVndkSp { |
| 329 | t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // Check VNDK extension properties. |
| 333 | isVndkExt := extends != "" |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 334 | if mod.IsVndkExt() != isVndkExt { |
| 335 | t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends { |
| 339 | t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends) |
| 340 | } |
| 341 | } |
| 342 | |
Colin Cross | f61d03d | 2023-11-02 16:56:39 -0700 | [diff] [blame] | 343 | func checkWriteFileOutput(t *testing.T, ctx *android.TestContext, params android.TestingBuildParams, expected []string) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 344 | t.Helper() |
Colin Cross | f61d03d | 2023-11-02 16:56:39 -0700 | [diff] [blame] | 345 | content := android.ContentFromFileRuleForTests(t, ctx, params) |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 346 | actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' }) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 347 | assertArrayString(t, actual, expected) |
| 348 | } |
| 349 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 350 | func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) { |
| 351 | t.Helper() |
| 352 | vndkSnapshot := ctx.SingletonForTests("vndk-snapshot") |
Colin Cross | f61d03d | 2023-11-02 16:56:39 -0700 | [diff] [blame] | 353 | checkWriteFileOutput(t, ctx, vndkSnapshot.Output(output), expected) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) { |
| 357 | t.Helper() |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 358 | got := ctx.ModuleForTests(module, "android_common").Module().(*vndkLibrariesTxt).fileNames |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 359 | assertArrayString(t, got, expected) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 360 | } |
| 361 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 362 | func TestVndk(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 363 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 364 | bp := ` |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 365 | cc_library { |
| 366 | name: "libvndk", |
| 367 | vendor_available: true, |
| 368 | vndk: { |
| 369 | enabled: true, |
| 370 | }, |
| 371 | nocrt: true, |
| 372 | } |
| 373 | |
| 374 | cc_library { |
| 375 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 376 | vendor_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 377 | vndk: { |
| 378 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 379 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 380 | }, |
| 381 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 382 | stem: "libvndk-private", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | cc_library { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 386 | name: "libvndk_product", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 387 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 388 | product_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 389 | vndk: { |
| 390 | enabled: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 391 | }, |
| 392 | nocrt: true, |
| 393 | target: { |
| 394 | vendor: { |
| 395 | cflags: ["-DTEST"], |
| 396 | }, |
| 397 | product: { |
| 398 | cflags: ["-DTEST"], |
| 399 | }, |
| 400 | }, |
| 401 | } |
| 402 | |
| 403 | cc_library { |
| 404 | name: "libvndk_sp", |
| 405 | vendor_available: true, |
| 406 | vndk: { |
| 407 | enabled: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 408 | support_system_process: true, |
| 409 | }, |
| 410 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 411 | suffix: "-x", |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | cc_library { |
| 415 | name: "libvndk_sp_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 416 | vendor_available: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 417 | vndk: { |
| 418 | enabled: true, |
| 419 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 420 | private: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 421 | }, |
| 422 | nocrt: true, |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 423 | target: { |
| 424 | vendor: { |
| 425 | suffix: "-x", |
| 426 | }, |
| 427 | }, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 428 | } |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 429 | |
| 430 | cc_library { |
| 431 | name: "libvndk_sp_product_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 432 | vendor_available: true, |
| 433 | product_available: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 434 | vndk: { |
| 435 | enabled: true, |
| 436 | support_system_process: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 437 | private: true, |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 438 | }, |
| 439 | nocrt: true, |
| 440 | target: { |
| 441 | vendor: { |
| 442 | suffix: "-x", |
| 443 | }, |
| 444 | product: { |
| 445 | suffix: "-x", |
| 446 | }, |
| 447 | }, |
| 448 | } |
| 449 | |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 450 | cc_library { |
| 451 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 452 | llndk: { |
| 453 | symbol_file: "libllndk.map.txt", |
| 454 | export_llndk_headers: ["libllndk_headers"], |
| 455 | } |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 456 | } |
| 457 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 458 | cc_library { |
| 459 | name: "libclang_rt.hwasan-llndk", |
| 460 | llndk: { |
| 461 | symbol_file: "libclang_rt.hwasan.map.txt", |
| 462 | } |
| 463 | } |
| 464 | |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 465 | cc_library_headers { |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 466 | name: "libllndk_headers", |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 467 | llndk: { |
| 468 | llndk_headers: true, |
| 469 | }, |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 470 | export_include_dirs: ["include"], |
| 471 | } |
| 472 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 473 | llndk_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 474 | name: "llndk.libraries.txt", |
| 475 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 476 | vndkcore_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 477 | name: "vndkcore.libraries.txt", |
| 478 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 479 | vndksp_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 480 | name: "vndksp.libraries.txt", |
| 481 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 482 | vndkprivate_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 483 | name: "vndkprivate.libraries.txt", |
| 484 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 485 | vndkproduct_libraries_txt { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 486 | name: "vndkproduct.libraries.txt", |
| 487 | } |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 488 | vndkcorevariant_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 489 | name: "vndkcorevariant.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 490 | insert_vndk_version: false, |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 491 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 492 | ` |
| 493 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 494 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 495 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 496 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 497 | |
| 498 | ctx := testCcWithConfig(t, config) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 499 | |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 500 | // subdir == "" because VNDK libs are not supposed to be installed separately. |
| 501 | // They are installed as part of VNDK APEX instead. |
| 502 | checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant) |
| 503 | checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 504 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant) |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 505 | checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant) |
| 506 | checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant) |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 507 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 508 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 509 | checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant) |
| 510 | checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 511 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 512 | // Check VNDK snapshot output. |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 513 | snapshotDir := "vndk-snapshot" |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 514 | snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 515 | |
| 516 | vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 517 | "arm64", "armv8-a")) |
| 518 | vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", |
| 519 | "arm", "armv7-a-neon")) |
| 520 | |
| 521 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") |
| 522 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 523 | llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub") |
| 524 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 525 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") |
| 526 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 527 | llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 528 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 529 | variant := "android_vendor.29_arm64_armv8-a_shared" |
| 530 | variant2nd := "android_vendor.29_arm_armv7-a-neon_shared" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 531 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 532 | snapshotSingleton := ctx.SingletonForTests("vndk-snapshot") |
| 533 | |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 534 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant) |
| 535 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) |
| 536 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant) |
| 537 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd) |
| 538 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) |
| 539 | CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) |
| 540 | CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant) |
| 541 | CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 542 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 543 | snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 544 | CheckSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "android_common") |
| 545 | CheckSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "android_common") |
| 546 | CheckSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "android_common") |
| 547 | CheckSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "android_common") |
| 548 | 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] | 549 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 550 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ |
| 551 | "LLNDK: libc.so", |
| 552 | "LLNDK: libdl.so", |
| 553 | "LLNDK: libft2.so", |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 554 | "LLNDK: libllndk.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 555 | "LLNDK: libm.so", |
| 556 | "VNDK-SP: libc++.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 557 | "VNDK-SP: libvndk_sp-x.so", |
| 558 | "VNDK-SP: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 559 | "VNDK-SP: libvndk_sp_product_private-x.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 560 | "VNDK-core: libvndk-private.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 561 | "VNDK-core: libvndk.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 562 | "VNDK-core: libvndk_product.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 563 | "VNDK-private: libft2.so", |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 564 | "VNDK-private: libvndk-private.so", |
| 565 | "VNDK-private: libvndk_sp_private-x.so", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 566 | "VNDK-private: libvndk_sp_product_private-x.so", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 567 | "VNDK-product: libc++.so", |
| 568 | "VNDK-product: libvndk_product.so", |
| 569 | "VNDK-product: libvndk_sp_product_private-x.so", |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 570 | }) |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 571 | 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] | 572 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"}) |
| 573 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"}) |
| 574 | 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] | 575 | 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] | 576 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) |
| 577 | } |
| 578 | |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 579 | func TestVndkWithHostSupported(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 580 | t.Parallel() |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 581 | ctx := testCc(t, ` |
| 582 | cc_library { |
| 583 | name: "libvndk_host_supported", |
| 584 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 585 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 586 | vndk: { |
| 587 | enabled: true, |
| 588 | }, |
| 589 | host_supported: true, |
| 590 | } |
| 591 | |
| 592 | cc_library { |
| 593 | name: "libvndk_host_supported_but_disabled_on_device", |
| 594 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 595 | product_available: true, |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 596 | vndk: { |
| 597 | enabled: true, |
| 598 | }, |
| 599 | host_supported: true, |
| 600 | enabled: false, |
| 601 | target: { |
| 602 | host: { |
| 603 | enabled: true, |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 608 | vndkcore_libraries_txt { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 609 | name: "vndkcore.libraries.txt", |
| 610 | } |
| 611 | `) |
| 612 | |
| 613 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"}) |
| 614 | } |
| 615 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 616 | func TestVndkLibrariesTxtAndroidMk(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 617 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 618 | bp := ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 619 | llndk_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 620 | name: "llndk.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 621 | insert_vndk_version: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 622 | }` |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 623 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 624 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 625 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 626 | config.TestProductVariables.KeepVndk = BoolPtr(true) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 627 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 628 | |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 629 | module := ctx.ModuleForTests("llndk.libraries.txt", "android_common") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 630 | entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0] |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 631 | assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"}) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | func TestVndkUsingCoreVariant(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 635 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 636 | bp := ` |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 637 | cc_library { |
| 638 | name: "libvndk", |
| 639 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 640 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 641 | vndk: { |
| 642 | enabled: true, |
| 643 | }, |
| 644 | nocrt: true, |
| 645 | } |
| 646 | |
| 647 | cc_library { |
| 648 | name: "libvndk_sp", |
| 649 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 650 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 651 | vndk: { |
| 652 | enabled: true, |
| 653 | support_system_process: true, |
| 654 | }, |
| 655 | nocrt: true, |
| 656 | } |
| 657 | |
| 658 | cc_library { |
| 659 | name: "libvndk2", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 660 | vendor_available: true, |
| 661 | product_available: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 662 | vndk: { |
| 663 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 664 | private: true, |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 665 | }, |
| 666 | nocrt: true, |
| 667 | } |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 668 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 669 | vndkcorevariant_libraries_txt { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 670 | name: "vndkcorevariant.libraries.txt", |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 671 | insert_vndk_version: false, |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 672 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 673 | ` |
| 674 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 675 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 676 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 677 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 678 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
Kiyoung Kim | 03b6cba | 2023-10-06 14:12:43 +0900 | [diff] [blame] | 679 | config.TestProductVariables.KeepVndk = BoolPtr(true) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 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 { |
Colin Cross | 7e2e794 | 2023-11-16 12:56:02 -0800 | [diff] [blame] | 722 | t.Errorf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths()) |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 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 { |
Colin Cross | 7e2e794 | 2023-11-16 12:56:02 -0800 | [diff] [blame] | 779 | t.Fatalf("expected exactly one test data file. test data files: [%v]", 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__") |
Justin Yun | 41cbb5e | 2023-11-29 17:58:16 +0900 | [diff] [blame] | 2133 | ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR_API__=202404") |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2134 | |
| 2135 | product_cflags := product_static.Rule("cc").Args["cFlags"] |
| 2136 | ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__") |
| 2137 | ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__") |
| 2138 | ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__") |
Justin Yun | 41cbb5e | 2023-11-29 17:58:16 +0900 | [diff] [blame] | 2139 | ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR_API__=202404") |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | func TestEnforceProductVndkVersionErrors(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2143 | t.Parallel() |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2144 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2145 | cc_library { |
| 2146 | name: "libprod", |
| 2147 | product_specific: true, |
| 2148 | shared_libs: [ |
| 2149 | "libvendor", |
| 2150 | ], |
| 2151 | nocrt: true, |
| 2152 | } |
| 2153 | cc_library { |
| 2154 | name: "libvendor", |
| 2155 | vendor: true, |
| 2156 | nocrt: true, |
| 2157 | } |
| 2158 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2159 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2160 | cc_library { |
| 2161 | name: "libprod", |
| 2162 | product_specific: true, |
| 2163 | shared_libs: [ |
| 2164 | "libsystem", |
| 2165 | ], |
| 2166 | nocrt: true, |
| 2167 | } |
| 2168 | cc_library { |
| 2169 | name: "libsystem", |
| 2170 | nocrt: true, |
| 2171 | } |
| 2172 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2173 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 2174 | cc_library { |
| 2175 | name: "libprod", |
| 2176 | product_specific: true, |
| 2177 | shared_libs: [ |
| 2178 | "libva", |
| 2179 | ], |
| 2180 | nocrt: true, |
| 2181 | } |
| 2182 | cc_library { |
| 2183 | name: "libva", |
| 2184 | vendor_available: true, |
| 2185 | nocrt: true, |
| 2186 | } |
| 2187 | `) |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2188 | 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] | 2189 | cc_library { |
| 2190 | name: "libprod", |
| 2191 | product_specific: true, |
| 2192 | shared_libs: [ |
| 2193 | "libvndk_private", |
| 2194 | ], |
| 2195 | nocrt: true, |
| 2196 | } |
| 2197 | cc_library { |
| 2198 | name: "libvndk_private", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2199 | vendor_available: true, |
| 2200 | product_available: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2201 | vndk: { |
| 2202 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2203 | private: true, |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2204 | }, |
| 2205 | nocrt: true, |
| 2206 | } |
| 2207 | `) |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2208 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", ` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2209 | cc_library { |
| 2210 | name: "libprod", |
| 2211 | product_specific: true, |
| 2212 | shared_libs: [ |
| 2213 | "libsystem_ext", |
| 2214 | ], |
| 2215 | nocrt: true, |
| 2216 | } |
| 2217 | cc_library { |
| 2218 | name: "libsystem_ext", |
| 2219 | system_ext_specific: true, |
| 2220 | nocrt: true, |
| 2221 | } |
| 2222 | `) |
| 2223 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` |
| 2224 | cc_library { |
| 2225 | name: "libsystem", |
| 2226 | shared_libs: [ |
| 2227 | "libproduct_va", |
| 2228 | ], |
| 2229 | nocrt: true, |
| 2230 | } |
| 2231 | cc_library { |
| 2232 | name: "libproduct_va", |
| 2233 | product_specific: true, |
| 2234 | vendor_available: true, |
| 2235 | nocrt: true, |
| 2236 | } |
| 2237 | `) |
| 2238 | } |
| 2239 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2240 | func TestMakeLinkType(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2241 | t.Parallel() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2242 | bp := ` |
| 2243 | cc_library { |
| 2244 | name: "libvndk", |
| 2245 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2246 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2247 | vndk: { |
| 2248 | enabled: true, |
| 2249 | }, |
| 2250 | } |
| 2251 | cc_library { |
| 2252 | name: "libvndksp", |
| 2253 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2254 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2255 | vndk: { |
| 2256 | enabled: true, |
| 2257 | support_system_process: true, |
| 2258 | }, |
| 2259 | } |
| 2260 | cc_library { |
| 2261 | name: "libvndkprivate", |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2262 | vendor_available: true, |
| 2263 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2264 | vndk: { |
| 2265 | enabled: true, |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 2266 | private: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2267 | }, |
| 2268 | } |
| 2269 | cc_library { |
| 2270 | name: "libvendor", |
| 2271 | vendor: true, |
| 2272 | } |
| 2273 | cc_library { |
| 2274 | name: "libvndkext", |
| 2275 | vendor: true, |
| 2276 | vndk: { |
| 2277 | enabled: true, |
| 2278 | extends: "libvndk", |
| 2279 | }, |
| 2280 | } |
| 2281 | vndk_prebuilt_shared { |
| 2282 | name: "prevndk", |
| 2283 | version: "27", |
| 2284 | target_arch: "arm", |
| 2285 | binder32bit: true, |
| 2286 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2287 | product_available: true, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2288 | vndk: { |
| 2289 | enabled: true, |
| 2290 | }, |
| 2291 | arch: { |
| 2292 | arm: { |
| 2293 | srcs: ["liba.so"], |
| 2294 | }, |
| 2295 | }, |
| 2296 | } |
| 2297 | cc_library { |
| 2298 | name: "libllndk", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2299 | llndk: { |
| 2300 | symbol_file: "libllndk.map.txt", |
| 2301 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2302 | } |
| 2303 | cc_library { |
| 2304 | name: "libllndkprivate", |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 2305 | llndk: { |
| 2306 | symbol_file: "libllndkprivate.map.txt", |
| 2307 | private: true, |
| 2308 | } |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | llndk_libraries_txt { |
| 2312 | name: "llndk.libraries.txt", |
| 2313 | } |
| 2314 | vndkcore_libraries_txt { |
| 2315 | name: "vndkcore.libraries.txt", |
| 2316 | } |
| 2317 | vndksp_libraries_txt { |
| 2318 | name: "vndksp.libraries.txt", |
| 2319 | } |
| 2320 | vndkprivate_libraries_txt { |
| 2321 | name: "vndkprivate.libraries.txt", |
| 2322 | } |
| 2323 | vndkcorevariant_libraries_txt { |
| 2324 | name: "vndkcorevariant.libraries.txt", |
| 2325 | insert_vndk_version: false, |
| 2326 | } |
| 2327 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2328 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 2329 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2330 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2331 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2332 | // native:vndk |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 2333 | ctx := testCcWithConfig(t, config) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2334 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 2335 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", |
| 2336 | []string{"libvndk.so", "libvndkprivate.so"}) |
| 2337 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", |
| 2338 | []string{"libc++.so", "libvndksp.so"}) |
| 2339 | checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", |
| 2340 | []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"}) |
| 2341 | checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", |
| 2342 | []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"}) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2343 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2344 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2345 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2346 | tests := []struct { |
| 2347 | variant string |
| 2348 | name string |
| 2349 | expected string |
| 2350 | }{ |
| 2351 | {vendorVariant, "libvndk", "native:vndk"}, |
| 2352 | {vendorVariant, "libvndksp", "native:vndk"}, |
| 2353 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, |
| 2354 | {vendorVariant, "libvendor", "native:vendor"}, |
| 2355 | {vendorVariant, "libvndkext", "native:vendor"}, |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 2356 | {vendorVariant, "libllndk", "native:vndk"}, |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 2357 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2358 | {coreVariant, "libvndk", "native:platform"}, |
| 2359 | {coreVariant, "libvndkprivate", "native:platform"}, |
| 2360 | {coreVariant, "libllndk", "native:platform"}, |
| 2361 | } |
| 2362 | for _, test := range tests { |
| 2363 | t.Run(test.name, func(t *testing.T) { |
| 2364 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) |
| 2365 | assertString(t, module.makeLinkType, test.expected) |
| 2366 | }) |
| 2367 | } |
| 2368 | } |
| 2369 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2370 | var staticLinkDepOrderTestCases = []struct { |
| 2371 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2372 | // It models the dependencies declared in an Android.bp file. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2373 | inStatic string |
| 2374 | |
| 2375 | // This is a string representation of a map[moduleName][]moduleDependency . |
| 2376 | // It models the dependencies declared in an Android.bp file. |
| 2377 | inShared string |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2378 | |
| 2379 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2380 | // The keys of allOrdered specify which modules we would like to check. |
| 2381 | // The values of allOrdered specify the expected result (of the transitive closure of all |
| 2382 | // dependencies) for each module to test |
| 2383 | allOrdered string |
| 2384 | |
| 2385 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . |
| 2386 | // The keys of outOrdered specify which modules we would like to check. |
| 2387 | // The values of outOrdered specify the expected result (of the ordered linker command line) |
| 2388 | // for each module to test. |
| 2389 | outOrdered string |
| 2390 | }{ |
| 2391 | // Simple tests |
| 2392 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2393 | inStatic: "", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2394 | outOrdered: "", |
| 2395 | }, |
| 2396 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2397 | inStatic: "a:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2398 | outOrdered: "a:", |
| 2399 | }, |
| 2400 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2401 | inStatic: "a:b; b:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2402 | outOrdered: "a:b; b:", |
| 2403 | }, |
| 2404 | // Tests of reordering |
| 2405 | { |
| 2406 | // diamond example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2407 | inStatic: "a:d,b,c; b:d; c:d; d:", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2408 | outOrdered: "a:b,c,d; b:d; c:d; d:", |
| 2409 | }, |
| 2410 | { |
| 2411 | // somewhat real example |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2412 | 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] | 2413 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", |
| 2414 | }, |
| 2415 | { |
| 2416 | // multiple reorderings |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2417 | inStatic: "a:b,c,d,e; d:b; e:c", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2418 | outOrdered: "a:d,b,e,c; d:b; e:c", |
| 2419 | }, |
| 2420 | { |
| 2421 | // should reorder without adding new transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2422 | inStatic: "bin:lib2,lib1; lib1:lib2,liboptional", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2423 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", |
| 2424 | outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional", |
| 2425 | }, |
| 2426 | { |
| 2427 | // multiple levels of dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2428 | 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] | 2429 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2430 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", |
| 2431 | }, |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2432 | // shared dependencies |
| 2433 | { |
| 2434 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. |
| 2435 | // So, we don't actually have to check that a shared dependency of c will change the order |
| 2436 | // of a library that depends statically on b and on c. We only need to check that if c has |
| 2437 | // a shared dependency on b, that that shows up in allOrdered. |
| 2438 | inShared: "c:b", |
| 2439 | allOrdered: "c:b", |
| 2440 | outOrdered: "c:", |
| 2441 | }, |
| 2442 | { |
| 2443 | // This test doesn't actually include any shared dependencies but it's a reminder of what |
| 2444 | // the second phase of the above test would look like |
| 2445 | inStatic: "a:b,c; c:b", |
| 2446 | allOrdered: "a:c,b; c:b", |
| 2447 | outOrdered: "a:c,b; c:b", |
| 2448 | }, |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2449 | // tiebreakers for when two modules specifying different orderings and there is no dependency |
| 2450 | // to dictate an order |
| 2451 | { |
| 2452 | // 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] | 2453 | 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] | 2454 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", |
| 2455 | }, |
| 2456 | { |
| 2457 | // 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] | 2458 | 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] | 2459 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e", |
| 2460 | }, |
| 2461 | // Tests involving duplicate dependencies |
| 2462 | { |
| 2463 | // simple duplicate |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2464 | inStatic: "a:b,c,c,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2465 | outOrdered: "a:c,b", |
| 2466 | }, |
| 2467 | { |
| 2468 | // duplicates with reordering |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2469 | inStatic: "a:b,c,d,c; c:b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2470 | outOrdered: "a:d,c,b", |
| 2471 | }, |
| 2472 | // Tests to confirm the nonexistence of infinite loops. |
| 2473 | // These cases should never happen, so as long as the test terminates and the |
| 2474 | // result is deterministic then that should be fine. |
| 2475 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2476 | inStatic: "a:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2477 | outOrdered: "a:a", |
| 2478 | }, |
| 2479 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2480 | inStatic: "a:b; b:c; c:a", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2481 | allOrdered: "a:b,c; b:c,a; c:a,b", |
| 2482 | outOrdered: "a:b; b:c; c:a", |
| 2483 | }, |
| 2484 | { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2485 | inStatic: "a:b,c; b:c,a; c:a,b", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2486 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", |
| 2487 | outOrdered: "a:c,b; b:a,c; c:b,a", |
| 2488 | }, |
| 2489 | } |
| 2490 | |
| 2491 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) |
| 2492 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { |
| 2493 | // convert from "a:b,c; d:e" to "a:b,c;d:e" |
| 2494 | strippedText := strings.Replace(text, " ", "", -1) |
| 2495 | if len(strippedText) < 1 { |
| 2496 | return []android.Path{}, make(map[android.Path][]android.Path, 0) |
| 2497 | } |
| 2498 | allDeps = make(map[android.Path][]android.Path, 0) |
| 2499 | |
| 2500 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] |
| 2501 | moduleTexts := strings.Split(strippedText, ";") |
| 2502 | |
| 2503 | outputForModuleName := func(moduleName string) android.Path { |
| 2504 | return android.PathForTesting(moduleName) |
| 2505 | } |
| 2506 | |
| 2507 | for _, moduleText := range moduleTexts { |
| 2508 | // convert from "a:b,c" to ["a", "b,c"] |
| 2509 | components := strings.Split(moduleText, ":") |
| 2510 | if len(components) != 2 { |
| 2511 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) |
| 2512 | } |
| 2513 | moduleName := components[0] |
| 2514 | moduleOutput := outputForModuleName(moduleName) |
| 2515 | modulesInOrder = append(modulesInOrder, moduleOutput) |
| 2516 | |
| 2517 | depString := components[1] |
| 2518 | // convert from "b,c" to ["b", "c"] |
| 2519 | depNames := strings.Split(depString, ",") |
| 2520 | if len(depString) < 1 { |
| 2521 | depNames = []string{} |
| 2522 | } |
| 2523 | var deps []android.Path |
| 2524 | for _, depName := range depNames { |
| 2525 | deps = append(deps, outputForModuleName(depName)) |
| 2526 | } |
| 2527 | allDeps[moduleOutput] = deps |
| 2528 | } |
| 2529 | return modulesInOrder, allDeps |
| 2530 | } |
| 2531 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2532 | func TestStaticLibDepReordering(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2533 | t.Parallel() |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2534 | ctx := testCc(t, ` |
| 2535 | cc_library { |
| 2536 | name: "a", |
| 2537 | static_libs: ["b", "c", "d"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2538 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2539 | } |
| 2540 | cc_library { |
| 2541 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2542 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2543 | } |
| 2544 | cc_library { |
| 2545 | name: "c", |
| 2546 | static_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2547 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2548 | } |
| 2549 | cc_library { |
| 2550 | name: "d", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2551 | stl: "none", |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | `) |
| 2555 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2556 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2557 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 2558 | staticLibInfo, _ := android.SingletonModuleProvider(ctx, moduleA, StaticLibraryInfoProvider) |
| 2559 | actual := android.Paths(staticLibInfo.TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 2560 | expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2561 | |
| 2562 | if !reflect.DeepEqual(actual, expected) { |
| 2563 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 2564 | "\nactual: %v"+ |
| 2565 | "\nexpected: %v", |
| 2566 | actual, |
| 2567 | expected, |
| 2568 | ) |
| 2569 | } |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2570 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2571 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2572 | func TestStaticLibDepReorderingWithShared(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2573 | t.Parallel() |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2574 | ctx := testCc(t, ` |
| 2575 | cc_library { |
| 2576 | name: "a", |
| 2577 | static_libs: ["b", "c"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2578 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2579 | } |
| 2580 | cc_library { |
| 2581 | name: "b", |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2582 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2583 | } |
| 2584 | cc_library { |
| 2585 | name: "c", |
| 2586 | shared_libs: ["b"], |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2587 | stl: "none", |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | `) |
| 2591 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2592 | variant := "android_arm64_armv8-a_static" |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2593 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 2594 | staticLibInfo, _ := android.SingletonModuleProvider(ctx, moduleA, StaticLibraryInfoProvider) |
| 2595 | actual := android.Paths(staticLibInfo.TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 2596 | expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"}) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2597 | |
| 2598 | if !reflect.DeepEqual(actual, expected) { |
| 2599 | t.Errorf("staticDeps orderings did not account for shared libs"+ |
| 2600 | "\nactual: %v"+ |
| 2601 | "\nexpected: %v", |
| 2602 | actual, |
| 2603 | expected, |
| 2604 | ) |
| 2605 | } |
| 2606 | } |
| 2607 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2608 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 2609 | t.Helper() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2610 | if !reflect.DeepEqual(actual, expected) { |
| 2611 | t.Errorf(message+ |
| 2612 | "\nactual: %v"+ |
| 2613 | "\nexpected: %v", |
| 2614 | actual, |
| 2615 | expected, |
| 2616 | ) |
| 2617 | } |
| 2618 | } |
| 2619 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2620 | func TestLlndkLibrary(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2621 | t.Parallel() |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2622 | result := prepareForCcTest.RunTestWithBp(t, ` |
| 2623 | cc_library { |
| 2624 | name: "libllndk", |
| 2625 | stubs: { versions: ["1", "2"] }, |
| 2626 | llndk: { |
| 2627 | symbol_file: "libllndk.map.txt", |
| 2628 | }, |
| 2629 | export_include_dirs: ["include"], |
| 2630 | } |
| 2631 | |
| 2632 | cc_prebuilt_library_shared { |
| 2633 | name: "libllndkprebuilt", |
| 2634 | stubs: { versions: ["1", "2"] }, |
| 2635 | llndk: { |
| 2636 | symbol_file: "libllndkprebuilt.map.txt", |
| 2637 | }, |
| 2638 | } |
| 2639 | |
| 2640 | cc_library { |
| 2641 | name: "libllndk_with_external_headers", |
| 2642 | stubs: { versions: ["1", "2"] }, |
| 2643 | llndk: { |
| 2644 | symbol_file: "libllndk.map.txt", |
| 2645 | export_llndk_headers: ["libexternal_llndk_headers"], |
| 2646 | }, |
| 2647 | header_libs: ["libexternal_headers"], |
| 2648 | export_header_lib_headers: ["libexternal_headers"], |
| 2649 | } |
| 2650 | cc_library_headers { |
| 2651 | name: "libexternal_headers", |
| 2652 | export_include_dirs: ["include"], |
| 2653 | vendor_available: true, |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 2654 | product_available: true, |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2655 | } |
| 2656 | cc_library_headers { |
| 2657 | name: "libexternal_llndk_headers", |
| 2658 | export_include_dirs: ["include_llndk"], |
| 2659 | llndk: { |
| 2660 | symbol_file: "libllndk.map.txt", |
| 2661 | }, |
| 2662 | vendor_available: true, |
| 2663 | } |
| 2664 | |
| 2665 | cc_library { |
| 2666 | name: "libllndk_with_override_headers", |
| 2667 | stubs: { versions: ["1", "2"] }, |
| 2668 | llndk: { |
| 2669 | symbol_file: "libllndk.map.txt", |
| 2670 | override_export_include_dirs: ["include_llndk"], |
| 2671 | }, |
| 2672 | export_include_dirs: ["include"], |
| 2673 | } |
| 2674 | `) |
| 2675 | actual := result.ModuleVariantsForTests("libllndk") |
| 2676 | for i := 0; i < len(actual); i++ { |
| 2677 | if !strings.HasPrefix(actual[i], "android_vendor.29_") { |
| 2678 | actual = append(actual[:i], actual[i+1:]...) |
| 2679 | i-- |
| 2680 | } |
| 2681 | } |
| 2682 | expected := []string{ |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2683 | "android_vendor.29_arm64_armv8-a_shared_current", |
| 2684 | "android_vendor.29_arm64_armv8-a_shared", |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2685 | "android_vendor.29_arm_armv7-a-neon_shared_current", |
| 2686 | "android_vendor.29_arm_armv7-a-neon_shared", |
| 2687 | } |
| 2688 | android.AssertArrayString(t, "variants for llndk stubs", expected, actual) |
| 2689 | |
| 2690 | params := result.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub") |
Jooyung Han | 33eb615 | 2024-03-11 15:46:48 +0900 | [diff] [blame^] | 2691 | android.AssertSame(t, "use Vendor API level for default stubs", "202404", params.Args["apiLevel"]) |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2692 | |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2693 | checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) { |
| 2694 | t.Helper() |
| 2695 | m := result.ModuleForTests(module, variant).Module() |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 2696 | f, _ := android.SingletonModuleProvider(result, m, FlagExporterInfoProvider) |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 2697 | android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]", |
| 2698 | expectedDirs, f.IncludeDirs) |
| 2699 | } |
| 2700 | |
| 2701 | checkExportedIncludeDirs("libllndk", "android_arm64_armv8-a_shared", "include") |
| 2702 | checkExportedIncludeDirs("libllndk", "android_vendor.29_arm64_armv8-a_shared", "include") |
| 2703 | checkExportedIncludeDirs("libllndk_with_external_headers", "android_arm64_armv8-a_shared", "include") |
| 2704 | checkExportedIncludeDirs("libllndk_with_external_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk") |
| 2705 | checkExportedIncludeDirs("libllndk_with_override_headers", "android_arm64_armv8-a_shared", "include") |
| 2706 | checkExportedIncludeDirs("libllndk_with_override_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk") |
| 2707 | } |
| 2708 | |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2709 | func TestLlndkHeaders(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2710 | t.Parallel() |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2711 | ctx := testCc(t, ` |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2712 | cc_library_headers { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2713 | name: "libllndk_headers", |
| 2714 | export_include_dirs: ["my_include"], |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2715 | llndk: { |
| 2716 | llndk_headers: true, |
| 2717 | }, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2718 | } |
| 2719 | cc_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2720 | name: "libllndk", |
Colin Cross | 627280f | 2021-04-26 16:53:58 -0700 | [diff] [blame] | 2721 | llndk: { |
| 2722 | symbol_file: "libllndk.map.txt", |
| 2723 | export_llndk_headers: ["libllndk_headers"], |
| 2724 | } |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | cc_library { |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2728 | name: "libvendor", |
| 2729 | shared_libs: ["libllndk"], |
| 2730 | vendor: true, |
| 2731 | srcs: ["foo.c"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2732 | no_libcrt: true, |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2733 | nocrt: true, |
Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2734 | } |
| 2735 | `) |
| 2736 | |
| 2737 | // _static variant is used since _shared reuses *.o from the static variant |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2738 | 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] | 2739 | cflags := cc.Args["cFlags"] |
| 2740 | if !strings.Contains(cflags, "-Imy_include") { |
| 2741 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) |
| 2742 | } |
| 2743 | } |
| 2744 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2745 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { |
| 2746 | actual := module.Properties.AndroidMkRuntimeLibs |
| 2747 | if !reflect.DeepEqual(actual, expected) { |
| 2748 | t.Errorf("incorrect runtime_libs for shared libs"+ |
| 2749 | "\nactual: %v"+ |
| 2750 | "\nexpected: %v", |
| 2751 | actual, |
| 2752 | expected, |
| 2753 | ) |
| 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | const runtimeLibAndroidBp = ` |
| 2758 | cc_library { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2759 | name: "liball_available", |
| 2760 | vendor_available: true, |
| 2761 | product_available: true, |
| 2762 | no_libcrt : true, |
| 2763 | nocrt : true, |
| 2764 | system_shared_libs : [], |
| 2765 | } |
| 2766 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2767 | name: "libvendor_available1", |
| 2768 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2769 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2770 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2771 | nocrt : true, |
| 2772 | system_shared_libs : [], |
| 2773 | } |
| 2774 | cc_library { |
| 2775 | name: "libvendor_available2", |
| 2776 | vendor_available: true, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2777 | runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2778 | target: { |
| 2779 | vendor: { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2780 | exclude_runtime_libs: ["liball_available"], |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2781 | } |
| 2782 | }, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2783 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2784 | nocrt : true, |
| 2785 | system_shared_libs : [], |
| 2786 | } |
| 2787 | cc_library { |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2788 | name: "libproduct_vendor", |
| 2789 | product_specific: true, |
| 2790 | vendor_available: true, |
| 2791 | no_libcrt : true, |
| 2792 | nocrt : true, |
| 2793 | system_shared_libs : [], |
| 2794 | } |
| 2795 | cc_library { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2796 | name: "libcore", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2797 | runtime_libs: ["liball_available"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2798 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2799 | nocrt : true, |
| 2800 | system_shared_libs : [], |
| 2801 | } |
| 2802 | cc_library { |
| 2803 | name: "libvendor1", |
| 2804 | vendor: true, |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2805 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2806 | nocrt : true, |
| 2807 | system_shared_libs : [], |
| 2808 | } |
| 2809 | cc_library { |
| 2810 | name: "libvendor2", |
| 2811 | vendor: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2812 | runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"], |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2813 | no_libcrt : true, |
| 2814 | nocrt : true, |
| 2815 | system_shared_libs : [], |
| 2816 | } |
| 2817 | cc_library { |
| 2818 | name: "libproduct_available1", |
| 2819 | product_available: true, |
| 2820 | runtime_libs: ["liball_available"], |
| 2821 | no_libcrt : true, |
| 2822 | nocrt : true, |
| 2823 | system_shared_libs : [], |
| 2824 | } |
| 2825 | cc_library { |
| 2826 | name: "libproduct1", |
| 2827 | product_specific: true, |
| 2828 | no_libcrt : true, |
| 2829 | nocrt : true, |
| 2830 | system_shared_libs : [], |
| 2831 | } |
| 2832 | cc_library { |
| 2833 | name: "libproduct2", |
| 2834 | product_specific: true, |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2835 | runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"], |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2836 | no_libcrt : true, |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2837 | nocrt : true, |
| 2838 | system_shared_libs : [], |
| 2839 | } |
| 2840 | ` |
| 2841 | |
| 2842 | func TestRuntimeLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2843 | t.Parallel() |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2844 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2845 | |
| 2846 | // runtime_libs for core variants use the module names without suffixes. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2847 | variant := "android_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2848 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2849 | module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2850 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
| 2851 | |
| 2852 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2853 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2854 | |
| 2855 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2856 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2857 | |
| 2858 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core |
| 2859 | // and vendor variants. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2860 | variant = "android_vendor.29_arm64_armv8-a_shared" |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2861 | |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2862 | module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module) |
| 2863 | checkRuntimeLibs(t, []string{"liball_available.vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2864 | |
| 2865 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 2866 | checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module) |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2867 | |
| 2868 | // runtime_libs for product variants have '.product' suffixes if the modules have both core |
| 2869 | // and product variants. |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2870 | variant = "android_product.29_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2871 | |
| 2872 | module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module) |
| 2873 | checkRuntimeLibs(t, []string{"liball_available.product"}, module) |
| 2874 | |
| 2875 | module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module) |
Justin Yun | d00f5ca | 2021-02-03 19:43:02 +0900 | [diff] [blame] | 2876 | checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | func TestExcludeRuntimeLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2880 | t.Parallel() |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2881 | ctx := testCc(t, runtimeLibAndroidBp) |
| 2882 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2883 | variant := "android_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2884 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
| 2885 | checkRuntimeLibs(t, []string{"liball_available"}, module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2886 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2887 | variant = "android_vendor.29_arm64_armv8-a_shared" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 2888 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2889 | checkRuntimeLibs(t, nil, module) |
| 2890 | } |
| 2891 | |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2892 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2893 | t.Helper() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2894 | actual := module.Properties.AndroidMkStaticLibs |
| 2895 | if !reflect.DeepEqual(actual, expected) { |
| 2896 | t.Errorf("incorrect static_libs"+ |
| 2897 | "\nactual: %v"+ |
| 2898 | "\nexpected: %v", |
| 2899 | actual, |
| 2900 | expected, |
| 2901 | ) |
| 2902 | } |
| 2903 | } |
| 2904 | |
| 2905 | const staticLibAndroidBp = ` |
| 2906 | cc_library { |
| 2907 | name: "lib1", |
| 2908 | } |
| 2909 | cc_library { |
| 2910 | name: "lib2", |
| 2911 | static_libs: ["lib1"], |
| 2912 | } |
| 2913 | ` |
| 2914 | |
| 2915 | func TestStaticLibDepExport(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 2916 | t.Parallel() |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2917 | ctx := testCc(t, staticLibAndroidBp) |
| 2918 | |
| 2919 | // Check the shared version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2920 | variant := "android_arm64_armv8-a_shared" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2921 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 2922 | checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2923 | |
| 2924 | // Check the static version of lib2. |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2925 | variant = "android_arm64_armv8-a_static" |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2926 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) |
| 2927 | // libc++_static is linked additionally. |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 2928 | checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins"}, module) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2931 | var compilerFlagsTestCases = []struct { |
| 2932 | in string |
| 2933 | out bool |
| 2934 | }{ |
| 2935 | { |
| 2936 | in: "a", |
| 2937 | out: false, |
| 2938 | }, |
| 2939 | { |
| 2940 | in: "-a", |
| 2941 | out: true, |
| 2942 | }, |
| 2943 | { |
| 2944 | in: "-Ipath/to/something", |
| 2945 | out: false, |
| 2946 | }, |
| 2947 | { |
| 2948 | in: "-isystempath/to/something", |
| 2949 | out: false, |
| 2950 | }, |
| 2951 | { |
| 2952 | in: "--coverage", |
| 2953 | out: false, |
| 2954 | }, |
| 2955 | { |
| 2956 | in: "-include a/b", |
| 2957 | out: true, |
| 2958 | }, |
| 2959 | { |
| 2960 | in: "-include a/b c/d", |
| 2961 | out: false, |
| 2962 | }, |
| 2963 | { |
| 2964 | in: "-DMACRO", |
| 2965 | out: true, |
| 2966 | }, |
| 2967 | { |
| 2968 | in: "-DMAC RO", |
| 2969 | out: false, |
| 2970 | }, |
| 2971 | { |
| 2972 | in: "-a -b", |
| 2973 | out: false, |
| 2974 | }, |
| 2975 | { |
| 2976 | in: "-DMACRO=definition", |
| 2977 | out: true, |
| 2978 | }, |
| 2979 | { |
| 2980 | in: "-DMACRO=defi nition", |
| 2981 | out: true, // TODO(jiyong): this should be false |
| 2982 | }, |
| 2983 | { |
| 2984 | in: "-DMACRO(x)=x + 1", |
| 2985 | out: true, |
| 2986 | }, |
| 2987 | { |
| 2988 | in: "-DMACRO=\"defi nition\"", |
| 2989 | out: true, |
| 2990 | }, |
| 2991 | } |
| 2992 | |
| 2993 | type mockContext struct { |
| 2994 | BaseModuleContext |
| 2995 | result bool |
| 2996 | } |
| 2997 | |
| 2998 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 2999 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 3000 | ctx.result = false |
| 3001 | } |
| 3002 | |
| 3003 | func TestCompilerFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3004 | t.Parallel() |
Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 3005 | for _, testCase := range compilerFlagsTestCases { |
| 3006 | ctx := &mockContext{result: true} |
| 3007 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) |
| 3008 | if ctx.result != testCase.out { |
| 3009 | t.Errorf("incorrect output:") |
| 3010 | t.Errorf(" input: %#v", testCase.in) |
| 3011 | t.Errorf(" expected: %#v", testCase.out) |
| 3012 | t.Errorf(" got: %#v", ctx.result) |
| 3013 | } |
| 3014 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 3015 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 3016 | |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3017 | func TestRecovery(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3018 | t.Parallel() |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3019 | ctx := testCc(t, ` |
| 3020 | cc_library_shared { |
| 3021 | name: "librecovery", |
| 3022 | recovery: true, |
| 3023 | } |
| 3024 | cc_library_shared { |
| 3025 | name: "librecovery32", |
| 3026 | recovery: true, |
| 3027 | compile_multilib:"32", |
| 3028 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3029 | cc_library_shared { |
| 3030 | name: "libHalInRecovery", |
| 3031 | recovery_available: true, |
| 3032 | vendor: true, |
| 3033 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3034 | `) |
| 3035 | |
| 3036 | variants := ctx.ModuleVariantsForTests("librecovery") |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 3037 | const arm64 = "android_recovery_arm64_armv8-a_shared" |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3038 | if len(variants) != 1 || !android.InList(arm64, variants) { |
| 3039 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) |
| 3040 | } |
| 3041 | |
| 3042 | variants = ctx.ModuleVariantsForTests("librecovery32") |
| 3043 | if android.InList(arm64, variants) { |
| 3044 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) |
| 3045 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3046 | |
| 3047 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) |
| 3048 | if !recoveryModule.Platform() { |
| 3049 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") |
| 3050 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3051 | } |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 3052 | |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3053 | func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3054 | t.Parallel() |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3055 | bp := ` |
| 3056 | cc_prebuilt_test_library_shared { |
| 3057 | name: "test_lib", |
| 3058 | relative_install_path: "foo/bar/baz", |
| 3059 | srcs: ["srcpath/dontusethispath/baz.so"], |
| 3060 | } |
| 3061 | |
| 3062 | cc_test { |
| 3063 | name: "main_test", |
| 3064 | data_libs: ["test_lib"], |
| 3065 | gtest: false, |
| 3066 | } |
| 3067 | ` |
| 3068 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 3069 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3070 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3071 | config.TestProductVariables.Platform_vndk_version = StringPtr("29") |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3072 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) |
| 3073 | |
| 3074 | ctx := testCcWithConfig(t, config) |
| 3075 | module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module() |
| 3076 | testBinary := module.(*Module).linker.(*testBinary) |
| 3077 | outputFiles, err := module.(android.OutputFileProducer).OutputFiles("") |
| 3078 | if err != nil { |
| 3079 | t.Fatalf("Expected cc_test to produce output files, error: %s", err) |
| 3080 | } |
| 3081 | if len(outputFiles) != 1 { |
| 3082 | t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) |
| 3083 | } |
| 3084 | if len(testBinary.dataPaths()) != 1 { |
Colin Cross | 7e2e794 | 2023-11-16 12:56:02 -0800 | [diff] [blame] | 3085 | t.Errorf("expected exactly one test data file. test data files: [%v]", testBinary.dataPaths()) |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | outputPath := outputFiles[0].String() |
| 3089 | |
| 3090 | if !strings.HasSuffix(outputPath, "/main_test") { |
| 3091 | t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) |
| 3092 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3093 | entries := android.AndroidMkEntriesForTest(t, ctx, module)[0] |
Chris Parsons | 1f6d90f | 2020-06-17 16:10:42 -0400 | [diff] [blame] | 3094 | if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { |
| 3095 | t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ |
| 3096 | " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) |
| 3097 | } |
| 3098 | } |
| 3099 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3100 | func TestVersionedStubs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3101 | t.Parallel() |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3102 | ctx := testCc(t, ` |
| 3103 | cc_library_shared { |
| 3104 | name: "libFoo", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3105 | srcs: ["foo.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3106 | stubs: { |
| 3107 | symbol_file: "foo.map.txt", |
| 3108 | versions: ["1", "2", "3"], |
| 3109 | }, |
| 3110 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3111 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3112 | cc_library_shared { |
| 3113 | name: "libBar", |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3114 | srcs: ["bar.c"], |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3115 | shared_libs: ["libFoo#1"], |
| 3116 | }`) |
| 3117 | |
| 3118 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3119 | expectedVariants := []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3120 | "android_arm64_armv8-a_shared", |
| 3121 | "android_arm64_armv8-a_shared_1", |
| 3122 | "android_arm64_armv8-a_shared_2", |
| 3123 | "android_arm64_armv8-a_shared_3", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 3124 | "android_arm64_armv8-a_shared_current", |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3125 | "android_arm_armv7-a-neon_shared", |
| 3126 | "android_arm_armv7-a-neon_shared_1", |
| 3127 | "android_arm_armv7-a-neon_shared_2", |
| 3128 | "android_arm_armv7-a-neon_shared_3", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 3129 | "android_arm_armv7-a-neon_shared_current", |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3130 | } |
| 3131 | variantsMismatch := false |
| 3132 | if len(variants) != len(expectedVariants) { |
| 3133 | variantsMismatch = true |
| 3134 | } else { |
| 3135 | for _, v := range expectedVariants { |
| 3136 | if !inList(v, variants) { |
| 3137 | variantsMismatch = false |
| 3138 | } |
| 3139 | } |
| 3140 | } |
| 3141 | if variantsMismatch { |
| 3142 | t.Errorf("variants of libFoo expected:\n") |
| 3143 | for _, v := range expectedVariants { |
| 3144 | t.Errorf("%q\n", v) |
| 3145 | } |
| 3146 | t.Errorf(", but got:\n") |
| 3147 | for _, v := range variants { |
| 3148 | t.Errorf("%q\n", v) |
| 3149 | } |
| 3150 | } |
| 3151 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3152 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3153 | libFlags := libBarLinkRule.Args["libFlags"] |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3154 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 3155 | if !strings.Contains(libFlags, libFoo1StubPath) { |
| 3156 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) |
| 3157 | } |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3158 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3159 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") |
Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 3160 | cFlags := libBarCompileRule.Args["cFlags"] |
| 3161 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" |
| 3162 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { |
| 3163 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) |
| 3164 | } |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 3165 | } |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3166 | |
Liz Kammer | 48cdbeb | 2023-03-17 10:17:50 -0400 | [diff] [blame] | 3167 | func TestStubsForLibraryInMultipleApexes(t *testing.T) { |
| 3168 | t.Parallel() |
| 3169 | ctx := testCc(t, ` |
| 3170 | cc_library_shared { |
| 3171 | name: "libFoo", |
| 3172 | srcs: ["foo.c"], |
| 3173 | stubs: { |
| 3174 | symbol_file: "foo.map.txt", |
| 3175 | versions: ["current"], |
| 3176 | }, |
| 3177 | apex_available: ["bar", "a1"], |
| 3178 | } |
| 3179 | |
| 3180 | cc_library_shared { |
| 3181 | name: "libBar", |
| 3182 | srcs: ["bar.c"], |
| 3183 | shared_libs: ["libFoo"], |
| 3184 | apex_available: ["a1"], |
| 3185 | } |
| 3186 | |
| 3187 | cc_library_shared { |
| 3188 | name: "libA1", |
| 3189 | srcs: ["a1.c"], |
| 3190 | shared_libs: ["libFoo"], |
| 3191 | apex_available: ["a1"], |
| 3192 | } |
| 3193 | |
| 3194 | cc_library_shared { |
| 3195 | name: "libBarA1", |
| 3196 | srcs: ["bara1.c"], |
| 3197 | shared_libs: ["libFoo"], |
| 3198 | apex_available: ["bar", "a1"], |
| 3199 | } |
| 3200 | |
| 3201 | cc_library_shared { |
| 3202 | name: "libAnyApex", |
| 3203 | srcs: ["anyApex.c"], |
| 3204 | shared_libs: ["libFoo"], |
| 3205 | apex_available: ["//apex_available:anyapex"], |
| 3206 | } |
| 3207 | |
| 3208 | cc_library_shared { |
| 3209 | name: "libBaz", |
| 3210 | srcs: ["baz.c"], |
| 3211 | shared_libs: ["libFoo"], |
| 3212 | apex_available: ["baz"], |
| 3213 | } |
| 3214 | |
| 3215 | cc_library_shared { |
| 3216 | name: "libQux", |
| 3217 | srcs: ["qux.c"], |
| 3218 | shared_libs: ["libFoo"], |
| 3219 | apex_available: ["qux", "bar"], |
| 3220 | }`) |
| 3221 | |
| 3222 | variants := ctx.ModuleVariantsForTests("libFoo") |
| 3223 | expectedVariants := []string{ |
| 3224 | "android_arm64_armv8-a_shared", |
| 3225 | "android_arm64_armv8-a_shared_current", |
| 3226 | "android_arm_armv7-a-neon_shared", |
| 3227 | "android_arm_armv7-a-neon_shared_current", |
| 3228 | } |
| 3229 | variantsMismatch := false |
| 3230 | if len(variants) != len(expectedVariants) { |
| 3231 | variantsMismatch = true |
| 3232 | } else { |
| 3233 | for _, v := range expectedVariants { |
| 3234 | if !inList(v, variants) { |
| 3235 | variantsMismatch = false |
| 3236 | } |
| 3237 | } |
| 3238 | } |
| 3239 | if variantsMismatch { |
| 3240 | t.Errorf("variants of libFoo expected:\n") |
| 3241 | for _, v := range expectedVariants { |
| 3242 | t.Errorf("%q\n", v) |
| 3243 | } |
| 3244 | t.Errorf(", but got:\n") |
| 3245 | for _, v := range variants { |
| 3246 | t.Errorf("%q\n", v) |
| 3247 | } |
| 3248 | } |
| 3249 | |
| 3250 | linkAgainstFoo := []string{"libBarA1"} |
| 3251 | linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"} |
| 3252 | |
| 3253 | libFooPath := "libFoo/android_arm64_armv8-a_shared/libFoo.so" |
| 3254 | for _, lib := range linkAgainstFoo { |
| 3255 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3256 | libFlags := libLinkRule.Args["libFlags"] |
| 3257 | if !strings.Contains(libFlags, libFooPath) { |
| 3258 | t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags) |
| 3259 | } |
| 3260 | } |
| 3261 | |
| 3262 | libFooStubPath := "libFoo/android_arm64_armv8-a_shared_current/libFoo.so" |
| 3263 | for _, lib := range linkAgainstFooStubs { |
| 3264 | libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld") |
| 3265 | libFlags := libLinkRule.Args["libFlags"] |
| 3266 | if !strings.Contains(libFlags, libFooStubPath) { |
| 3267 | t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags) |
| 3268 | } |
| 3269 | } |
| 3270 | } |
| 3271 | |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3272 | func TestVersioningMacro(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3273 | t.Parallel() |
Jooyung Han | b04a499 | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 3274 | for _, tc := range []struct{ moduleName, expected string }{ |
| 3275 | {"libc", "__LIBC_API__"}, |
| 3276 | {"libfoo", "__LIBFOO_API__"}, |
| 3277 | {"libfoo@1", "__LIBFOO_1_API__"}, |
| 3278 | {"libfoo-v1", "__LIBFOO_V1_API__"}, |
| 3279 | {"libfoo.v1", "__LIBFOO_V1_API__"}, |
| 3280 | } { |
| 3281 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) |
| 3282 | } |
| 3283 | } |
| 3284 | |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3285 | func pathsToBase(paths android.Paths) []string { |
| 3286 | var ret []string |
| 3287 | for _, p := range paths { |
| 3288 | ret = append(ret, p.Base()) |
| 3289 | } |
| 3290 | return ret |
| 3291 | } |
| 3292 | |
| 3293 | func TestStaticLibArchiveArgs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3294 | t.Parallel() |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3295 | ctx := testCc(t, ` |
| 3296 | cc_library_static { |
| 3297 | name: "foo", |
| 3298 | srcs: ["foo.c"], |
| 3299 | } |
| 3300 | |
| 3301 | cc_library_static { |
| 3302 | name: "bar", |
| 3303 | srcs: ["bar.c"], |
| 3304 | } |
| 3305 | |
| 3306 | cc_library_shared { |
| 3307 | name: "qux", |
| 3308 | srcs: ["qux.c"], |
| 3309 | } |
| 3310 | |
| 3311 | cc_library_static { |
| 3312 | name: "baz", |
| 3313 | srcs: ["baz.c"], |
| 3314 | static_libs: ["foo"], |
| 3315 | shared_libs: ["qux"], |
| 3316 | whole_static_libs: ["bar"], |
| 3317 | }`) |
| 3318 | |
| 3319 | variant := "android_arm64_armv8-a_static" |
| 3320 | arRule := ctx.ModuleForTests("baz", variant).Rule("ar") |
| 3321 | |
| 3322 | // For static libraries, the object files of a whole static dep are included in the archive |
| 3323 | // directly |
| 3324 | if g, w := pathsToBase(arRule.Inputs), []string{"bar.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3325 | t.Errorf("Expected input objects %q, got %q", w, g) |
| 3326 | } |
| 3327 | |
| 3328 | // non whole static dependencies are not linked into the archive |
| 3329 | if len(arRule.Implicits) > 0 { |
| 3330 | t.Errorf("Expected 0 additional deps, got %q", arRule.Implicits) |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | func TestSharedLibLinkingArgs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3335 | t.Parallel() |
Liz Kammer | 83cf81b | 2022-09-22 08:24:20 -0400 | [diff] [blame] | 3336 | ctx := testCc(t, ` |
| 3337 | cc_library_static { |
| 3338 | name: "foo", |
| 3339 | srcs: ["foo.c"], |
| 3340 | } |
| 3341 | |
| 3342 | cc_library_static { |
| 3343 | name: "bar", |
| 3344 | srcs: ["bar.c"], |
| 3345 | } |
| 3346 | |
| 3347 | cc_library_shared { |
| 3348 | name: "qux", |
| 3349 | srcs: ["qux.c"], |
| 3350 | } |
| 3351 | |
| 3352 | cc_library_shared { |
| 3353 | name: "baz", |
| 3354 | srcs: ["baz.c"], |
| 3355 | static_libs: ["foo"], |
| 3356 | shared_libs: ["qux"], |
| 3357 | whole_static_libs: ["bar"], |
| 3358 | }`) |
| 3359 | |
| 3360 | variant := "android_arm64_armv8-a_shared" |
| 3361 | linkRule := ctx.ModuleForTests("baz", variant).Rule("ld") |
| 3362 | libFlags := linkRule.Args["libFlags"] |
| 3363 | // When dynamically linking, we expect static dependencies to be found on the command line |
| 3364 | if expected := "foo.a"; !strings.Contains(libFlags, expected) { |
| 3365 | t.Errorf("Static lib %q was not found in %q", expected, libFlags) |
| 3366 | } |
| 3367 | // When dynamically linking, we expect whole static dependencies to be found on the command line |
| 3368 | if expected := "bar.a"; !strings.Contains(libFlags, expected) { |
| 3369 | t.Errorf("Static lib %q was not found in %q", expected, libFlags) |
| 3370 | } |
| 3371 | |
| 3372 | // When dynamically linking, we expect shared dependencies to be found on the command line |
| 3373 | if expected := "qux.so"; !strings.Contains(libFlags, expected) { |
| 3374 | t.Errorf("Shared lib %q was not found in %q", expected, libFlags) |
| 3375 | } |
| 3376 | |
| 3377 | // We should only have the objects from the shared library srcs, not the whole static dependencies |
| 3378 | if g, w := pathsToBase(linkRule.Inputs), []string{"baz.o"}; !reflect.DeepEqual(w, g) { |
| 3379 | t.Errorf("Expected input objects %q, got %q", w, g) |
| 3380 | } |
| 3381 | } |
| 3382 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3383 | func TestStaticExecutable(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3384 | t.Parallel() |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3385 | ctx := testCc(t, ` |
| 3386 | cc_binary { |
| 3387 | name: "static_test", |
Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 3388 | srcs: ["foo.c", "baz.o"], |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3389 | static_executable: true, |
| 3390 | }`) |
| 3391 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3392 | variant := "android_arm64_armv8-a" |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3393 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") |
| 3394 | libFlags := binModuleRule.Args["libFlags"] |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 3395 | systemStaticLibs := []string{"libc.a", "libm.a"} |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 3396 | for _, lib := range systemStaticLibs { |
| 3397 | if !strings.Contains(libFlags, lib) { |
| 3398 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) |
| 3399 | } |
| 3400 | } |
| 3401 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} |
| 3402 | for _, lib := range systemSharedLibs { |
| 3403 | if strings.Contains(libFlags, lib) { |
| 3404 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) |
| 3405 | } |
| 3406 | } |
| 3407 | } |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3408 | |
| 3409 | func TestStaticDepsOrderWithStubs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3410 | t.Parallel() |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3411 | ctx := testCc(t, ` |
| 3412 | cc_binary { |
| 3413 | name: "mybin", |
| 3414 | srcs: ["foo.c"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3415 | static_libs: ["libfooC", "libfooB"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3416 | static_executable: true, |
| 3417 | stl: "none", |
| 3418 | } |
| 3419 | |
| 3420 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3421 | name: "libfooB", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3422 | srcs: ["foo.c"], |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3423 | shared_libs: ["libfooC"], |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3424 | stl: "none", |
| 3425 | } |
| 3426 | |
| 3427 | cc_library { |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 3428 | name: "libfooC", |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3429 | srcs: ["foo.c"], |
| 3430 | stl: "none", |
| 3431 | stubs: { |
| 3432 | versions: ["1"], |
| 3433 | }, |
| 3434 | }`) |
| 3435 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 3436 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld") |
| 3437 | actual := mybin.Implicits[:2] |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 3438 | expected := GetOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 3439 | |
| 3440 | if !reflect.DeepEqual(actual, expected) { |
| 3441 | t.Errorf("staticDeps orderings were not propagated correctly"+ |
| 3442 | "\nactual: %v"+ |
| 3443 | "\nexpected: %v", |
| 3444 | actual, |
| 3445 | expected, |
| 3446 | ) |
| 3447 | } |
| 3448 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3449 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3450 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3451 | t.Parallel() |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3452 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` |
| 3453 | cc_library { |
| 3454 | name: "libA", |
| 3455 | srcs: ["foo.c"], |
| 3456 | shared_libs: ["libB"], |
| 3457 | stl: "none", |
| 3458 | } |
| 3459 | |
| 3460 | cc_library { |
| 3461 | name: "libB", |
| 3462 | srcs: ["foo.c"], |
| 3463 | enabled: false, |
| 3464 | stl: "none", |
| 3465 | } |
| 3466 | `) |
| 3467 | } |
| 3468 | |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3469 | func VerifyAFLFuzzTargetVariant(t *testing.T, variant string) { |
| 3470 | bp := ` |
| 3471 | cc_fuzz { |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3472 | name: "test_afl_fuzz_target", |
| 3473 | srcs: ["foo.c"], |
| 3474 | host_supported: true, |
| 3475 | static_libs: [ |
| 3476 | "afl_fuzz_static_lib", |
| 3477 | ], |
| 3478 | shared_libs: [ |
| 3479 | "afl_fuzz_shared_lib", |
| 3480 | ], |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3481 | fuzzing_frameworks: { |
| 3482 | afl: true, |
| 3483 | libfuzzer: false, |
| 3484 | }, |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3485 | } |
| 3486 | cc_library { |
| 3487 | name: "afl_fuzz_static_lib", |
| 3488 | host_supported: true, |
| 3489 | srcs: ["static_file.c"], |
| 3490 | } |
| 3491 | cc_library { |
| 3492 | name: "libfuzzer_only_static_lib", |
| 3493 | host_supported: true, |
| 3494 | srcs: ["static_file.c"], |
| 3495 | } |
| 3496 | cc_library { |
| 3497 | name: "afl_fuzz_shared_lib", |
| 3498 | host_supported: true, |
| 3499 | srcs: ["shared_file.c"], |
| 3500 | static_libs: [ |
| 3501 | "second_static_lib", |
| 3502 | ], |
| 3503 | } |
| 3504 | cc_library_headers { |
| 3505 | name: "libafl_headers", |
| 3506 | vendor_available: true, |
| 3507 | host_supported: true, |
| 3508 | export_include_dirs: [ |
| 3509 | "include", |
| 3510 | "instrumentation", |
| 3511 | ], |
| 3512 | } |
| 3513 | cc_object { |
| 3514 | name: "afl-compiler-rt", |
| 3515 | vendor_available: true, |
| 3516 | host_supported: true, |
| 3517 | cflags: [ |
| 3518 | "-fPIC", |
| 3519 | ], |
| 3520 | srcs: [ |
| 3521 | "instrumentation/afl-compiler-rt.o.c", |
| 3522 | ], |
| 3523 | } |
| 3524 | cc_library { |
| 3525 | name: "second_static_lib", |
| 3526 | host_supported: true, |
| 3527 | srcs: ["second_file.c"], |
| 3528 | } |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3529 | cc_object { |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3530 | name: "aflpp_driver", |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3531 | host_supported: true, |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3532 | srcs: [ |
| 3533 | "aflpp_driver.c", |
| 3534 | ], |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3535 | }` |
| 3536 | |
| 3537 | testEnv := map[string]string{ |
| 3538 | "FUZZ_FRAMEWORK": "AFL", |
| 3539 | } |
| 3540 | |
| 3541 | ctx := android.GroupFixturePreparers(prepareForCcTest, android.FixtureMergeEnv(testEnv)).RunTestWithBp(t, bp) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3542 | |
| 3543 | checkPcGuardFlag := func( |
| 3544 | modName string, variantName string, shouldHave bool) { |
| 3545 | cc := ctx.ModuleForTests(modName, variantName).Rule("cc") |
| 3546 | |
| 3547 | cFlags, ok := cc.Args["cFlags"] |
| 3548 | if !ok { |
| 3549 | t.Errorf("Could not find cFlags for module %s and variant %s", |
| 3550 | modName, variantName) |
| 3551 | } |
| 3552 | |
| 3553 | if strings.Contains( |
| 3554 | cFlags, "-fsanitize-coverage=trace-pc-guard") != shouldHave { |
| 3555 | t.Errorf("Flag was found: %t. Expected to find flag: %t. "+ |
| 3556 | "Test failed for module %s and variant %s", |
| 3557 | !shouldHave, shouldHave, modName, variantName) |
| 3558 | } |
| 3559 | } |
| 3560 | |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3561 | moduleName := "test_afl_fuzz_target" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3562 | checkPcGuardFlag(moduleName, variant+"_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3563 | |
| 3564 | moduleName = "afl_fuzz_static_lib" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3565 | checkPcGuardFlag(moduleName, variant+"_static", false) |
| 3566 | checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3567 | |
| 3568 | moduleName = "second_static_lib" |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3569 | checkPcGuardFlag(moduleName, variant+"_static", false) |
| 3570 | checkPcGuardFlag(moduleName, variant+"_static_fuzzer", true) |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3571 | |
| 3572 | ctx.ModuleForTests("afl_fuzz_shared_lib", |
| 3573 | "android_arm64_armv8-a_shared").Rule("cc") |
| 3574 | ctx.ModuleForTests("afl_fuzz_shared_lib", |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3575 | "android_arm64_armv8-a_shared_fuzzer").Rule("cc") |
| 3576 | } |
| 3577 | |
| 3578 | func TestAFLFuzzTargetForDevice(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3579 | t.Parallel() |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3580 | VerifyAFLFuzzTargetVariant(t, "android_arm64_armv8-a") |
| 3581 | } |
| 3582 | |
| 3583 | func TestAFLFuzzTargetForLinuxHost(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3584 | t.Parallel() |
Cory Barker | 9cfcf6d | 2022-07-22 17:22:02 +0000 | [diff] [blame] | 3585 | if runtime.GOOS != "linux" { |
| 3586 | t.Skip("requires linux") |
| 3587 | } |
| 3588 | |
| 3589 | VerifyAFLFuzzTargetVariant(t, "linux_glibc_x86_64") |
Cory Barker | a1da26f | 2022-06-07 20:12:06 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3592 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles |
| 3593 | // correctly. |
| 3594 | func TestFuzzTarget(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3595 | t.Parallel() |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3596 | ctx := testCc(t, ` |
| 3597 | cc_fuzz { |
| 3598 | name: "fuzz_smoke_test", |
| 3599 | srcs: ["foo.c"], |
| 3600 | }`) |
| 3601 | |
Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 3602 | variant := "android_arm64_armv8-a_fuzzer" |
Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 3603 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") |
| 3604 | } |
| 3605 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 3606 | func assertString(t *testing.T, got, expected string) { |
| 3607 | t.Helper() |
| 3608 | if got != expected { |
| 3609 | t.Errorf("expected %q got %q", expected, got) |
| 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | func assertArrayString(t *testing.T, got, expected []string) { |
| 3614 | t.Helper() |
| 3615 | if len(got) != len(expected) { |
| 3616 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) |
| 3617 | return |
| 3618 | } |
| 3619 | for i := range got { |
| 3620 | if got[i] != expected[i] { |
| 3621 | t.Errorf("expected %d-th %q (%q) got %q (%q)", |
| 3622 | i, expected[i], expected, got[i], got) |
| 3623 | return |
| 3624 | } |
| 3625 | } |
| 3626 | } |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3627 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3628 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { |
| 3629 | t.Helper() |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 3630 | assertArrayString(t, android.SortedKeys(m), expected) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 3631 | } |
| 3632 | |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3633 | func TestDefaults(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3634 | t.Parallel() |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3635 | ctx := testCc(t, ` |
| 3636 | cc_defaults { |
| 3637 | name: "defaults", |
| 3638 | srcs: ["foo.c"], |
| 3639 | static: { |
| 3640 | srcs: ["bar.c"], |
| 3641 | }, |
| 3642 | shared: { |
| 3643 | srcs: ["baz.c"], |
| 3644 | }, |
| 3645 | } |
| 3646 | |
| 3647 | cc_library_static { |
| 3648 | name: "libstatic", |
| 3649 | defaults: ["defaults"], |
| 3650 | } |
| 3651 | |
| 3652 | cc_library_shared { |
| 3653 | name: "libshared", |
| 3654 | defaults: ["defaults"], |
| 3655 | } |
| 3656 | |
| 3657 | cc_library { |
| 3658 | name: "libboth", |
| 3659 | defaults: ["defaults"], |
| 3660 | } |
| 3661 | |
| 3662 | cc_binary { |
| 3663 | name: "binary", |
| 3664 | defaults: ["defaults"], |
| 3665 | }`) |
| 3666 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3667 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3668 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3669 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) |
| 3670 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3671 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3672 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { |
| 3673 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) |
| 3674 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3675 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3676 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { |
| 3677 | t.Errorf("binary ld rule wanted %q, got %q", w, g) |
| 3678 | } |
| 3679 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3680 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3681 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3682 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) |
| 3683 | } |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3684 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3685 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { |
| 3686 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) |
| 3687 | } |
| 3688 | } |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3689 | |
| 3690 | func TestProductVariableDefaults(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3691 | t.Parallel() |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3692 | bp := ` |
| 3693 | cc_defaults { |
| 3694 | name: "libfoo_defaults", |
| 3695 | srcs: ["foo.c"], |
| 3696 | cppflags: ["-DFOO"], |
| 3697 | product_variables: { |
| 3698 | debuggable: { |
| 3699 | cppflags: ["-DBAR"], |
| 3700 | }, |
| 3701 | }, |
| 3702 | } |
| 3703 | |
| 3704 | cc_library { |
| 3705 | name: "libfoo", |
| 3706 | defaults: ["libfoo_defaults"], |
| 3707 | } |
| 3708 | ` |
| 3709 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 3710 | result := android.GroupFixturePreparers( |
| 3711 | prepareForCcTest, |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 3712 | android.PrepareForTestWithVariables, |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3713 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 3714 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3715 | variables.Debuggable = BoolPtr(true) |
| 3716 | }), |
| 3717 | ).RunTestWithBp(t, bp) |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3718 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 3719 | libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module) |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 3720 | android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR") |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3721 | } |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3722 | |
| 3723 | func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { |
| 3724 | t.Parallel() |
| 3725 | bp := ` |
| 3726 | cc_library_static { |
| 3727 | name: "libfoo", |
| 3728 | srcs: ["foo.c"], |
| 3729 | whole_static_libs: ["libbar"], |
| 3730 | } |
| 3731 | |
| 3732 | cc_library_static { |
| 3733 | name: "libbar", |
| 3734 | whole_static_libs: ["libmissing"], |
| 3735 | } |
| 3736 | ` |
| 3737 | |
Paul Duffin | 8567f22 | 2021-03-23 00:02:06 +0000 | [diff] [blame] | 3738 | result := android.GroupFixturePreparers( |
| 3739 | prepareForCcTest, |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 3740 | android.PrepareForTestWithAllowMissingDependencies, |
| 3741 | ).RunTestWithBp(t, bp) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3742 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 3743 | libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a") |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 3744 | android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3745 | |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 3746 | android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing") |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3747 | |
Paul Duffin | 7d8a8ad | 2021-03-07 15:58:39 +0000 | [diff] [blame] | 3748 | libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a") |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 3749 | android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String()) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 3750 | } |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 3751 | |
| 3752 | func TestInstallSharedLibs(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3753 | t.Parallel() |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 3754 | bp := ` |
| 3755 | cc_binary { |
| 3756 | name: "bin", |
| 3757 | host_supported: true, |
| 3758 | shared_libs: ["libshared"], |
| 3759 | runtime_libs: ["libruntime"], |
| 3760 | srcs: [":gen"], |
| 3761 | } |
| 3762 | |
| 3763 | cc_library_shared { |
| 3764 | name: "libshared", |
| 3765 | host_supported: true, |
| 3766 | shared_libs: ["libtransitive"], |
| 3767 | } |
| 3768 | |
| 3769 | cc_library_shared { |
| 3770 | name: "libtransitive", |
| 3771 | host_supported: true, |
| 3772 | } |
| 3773 | |
| 3774 | cc_library_shared { |
| 3775 | name: "libruntime", |
| 3776 | host_supported: true, |
| 3777 | } |
| 3778 | |
| 3779 | cc_binary_host { |
| 3780 | name: "tool", |
| 3781 | srcs: ["foo.cpp"], |
| 3782 | } |
| 3783 | |
| 3784 | genrule { |
| 3785 | name: "gen", |
| 3786 | tools: ["tool"], |
| 3787 | out: ["gen.cpp"], |
| 3788 | cmd: "$(location tool) $(out)", |
| 3789 | } |
| 3790 | ` |
| 3791 | |
Paul Duffin | c3e6ce0 | 2021-03-22 23:21:32 +0000 | [diff] [blame] | 3792 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 3793 | ctx := testCcWithConfig(t, config) |
| 3794 | |
| 3795 | hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install") |
| 3796 | hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install") |
| 3797 | hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install") |
| 3798 | hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install") |
| 3799 | hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install") |
| 3800 | |
| 3801 | if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) { |
| 3802 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3803 | } |
| 3804 | |
| 3805 | if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 3806 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3807 | } |
| 3808 | |
| 3809 | if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) { |
| 3810 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3811 | } |
| 3812 | |
| 3813 | if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) { |
| 3814 | t.Errorf("expected host bin dependency %q, got %q", w, g) |
| 3815 | } |
| 3816 | |
| 3817 | if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 3818 | t.Errorf("expected no host bin dependency %q, got %q", w, g) |
| 3819 | } |
| 3820 | |
| 3821 | deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install") |
| 3822 | deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install") |
| 3823 | deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install") |
| 3824 | deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install") |
| 3825 | |
| 3826 | if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) { |
| 3827 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3828 | } |
| 3829 | |
| 3830 | if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 3831 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3832 | } |
| 3833 | |
| 3834 | if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) { |
| 3835 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3836 | } |
| 3837 | |
| 3838 | if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) { |
| 3839 | t.Errorf("expected device bin dependency %q, got %q", w, g) |
| 3840 | } |
| 3841 | |
| 3842 | if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) { |
| 3843 | t.Errorf("expected no device bin dependency %q, got %q", w, g) |
| 3844 | } |
| 3845 | |
| 3846 | } |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 3847 | |
| 3848 | func TestStubsLibReexportsHeaders(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3849 | t.Parallel() |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 3850 | ctx := testCc(t, ` |
| 3851 | cc_library_shared { |
| 3852 | name: "libclient", |
| 3853 | srcs: ["foo.c"], |
| 3854 | shared_libs: ["libfoo#1"], |
| 3855 | } |
| 3856 | |
| 3857 | cc_library_shared { |
| 3858 | name: "libfoo", |
| 3859 | srcs: ["foo.c"], |
| 3860 | shared_libs: ["libbar"], |
| 3861 | export_shared_lib_headers: ["libbar"], |
| 3862 | stubs: { |
| 3863 | symbol_file: "foo.map.txt", |
| 3864 | versions: ["1", "2", "3"], |
| 3865 | }, |
| 3866 | } |
| 3867 | |
| 3868 | cc_library_shared { |
| 3869 | name: "libbar", |
| 3870 | export_include_dirs: ["include/libbar"], |
| 3871 | srcs: ["foo.c"], |
| 3872 | }`) |
| 3873 | |
| 3874 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 3875 | |
| 3876 | if !strings.Contains(cFlags, "-Iinclude/libbar") { |
| 3877 | t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags) |
| 3878 | } |
| 3879 | } |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 3880 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 3881 | func TestAidlLibraryWithHeaders(t *testing.T) { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3882 | t.Parallel() |
| 3883 | ctx := android.GroupFixturePreparers( |
| 3884 | prepareForCcTest, |
| 3885 | aidl_library.PrepareForTestWithAidlLibrary, |
| 3886 | android.MockFS{ |
| 3887 | "package_bar/Android.bp": []byte(` |
| 3888 | aidl_library { |
| 3889 | name: "bar", |
| 3890 | srcs: ["x/y/Bar.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 3891 | hdrs: ["x/HeaderBar.aidl"], |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3892 | strip_import_prefix: "x", |
| 3893 | } |
| 3894 | `)}.AddToFixture(), |
| 3895 | android.MockFS{ |
| 3896 | "package_foo/Android.bp": []byte(` |
| 3897 | aidl_library { |
| 3898 | name: "foo", |
| 3899 | srcs: ["a/b/Foo.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 3900 | hdrs: ["a/HeaderFoo.aidl"], |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3901 | strip_import_prefix: "a", |
| 3902 | deps: ["bar"], |
| 3903 | } |
| 3904 | cc_library { |
| 3905 | name: "libfoo", |
| 3906 | aidl: { |
| 3907 | libs: ["foo"], |
| 3908 | } |
| 3909 | } |
| 3910 | `), |
| 3911 | }.AddToFixture(), |
| 3912 | ).RunTest(t).TestContext |
| 3913 | |
| 3914 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 3915 | |
| 3916 | android.AssertPathsRelativeToTopEquals( |
| 3917 | t, |
| 3918 | "aidl headers", |
| 3919 | []string{ |
| 3920 | "package_bar/x/HeaderBar.aidl", |
| 3921 | "package_foo/a/HeaderFoo.aidl", |
| 3922 | "package_foo/a/b/Foo.aidl", |
| 3923 | "out/soong/.intermediates/package_foo/libfoo/android_arm64_armv8-a_static/gen/aidl_library.sbox.textproto", |
| 3924 | }, |
| 3925 | libfoo.Rule("aidl_library").Implicits, |
| 3926 | ) |
| 3927 | |
Colin Cross | f61d03d | 2023-11-02 16:56:39 -0700 | [diff] [blame] | 3928 | manifest := android.RuleBuilderSboxProtoForTests(t, ctx, libfoo.Output("aidl_library.sbox.textproto")) |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3929 | aidlCommand := manifest.Commands[0].GetCommand() |
| 3930 | |
| 3931 | expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x" |
| 3932 | if !strings.Contains(aidlCommand, expectedAidlFlags) { |
| 3933 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlags) |
| 3934 | } |
| 3935 | |
| 3936 | outputs := strings.Join(libfoo.AllOutputs(), " ") |
| 3937 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 3938 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BpFoo.h") |
| 3939 | android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BnFoo.h") |
| 3940 | 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] | 3941 | android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp") |
| 3942 | // 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] | 3943 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BpBar.h") |
| 3944 | android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BnBar.h") |
| 3945 | 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] | 3946 | android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp") |
| 3947 | } |
| 3948 | |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 3949 | func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3950 | t.Parallel() |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 3951 | ctx := android.GroupFixturePreparers( |
| 3952 | prepareForCcTest, |
| 3953 | aidl_library.PrepareForTestWithAidlLibrary, |
| 3954 | ).RunTestWithBp(t, ` |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 3955 | cc_library { |
| 3956 | name: "libfoo", |
| 3957 | srcs: ["a/Foo.aidl"], |
| 3958 | aidl: { flags: ["-Werror"], }, |
| 3959 | } |
| 3960 | `) |
| 3961 | |
| 3962 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") |
Colin Cross | f61d03d | 2023-11-02 16:56:39 -0700 | [diff] [blame] | 3963 | manifest := android.RuleBuilderSboxProtoForTests(t, ctx.TestContext, libfoo.Output("aidl.sbox.textproto")) |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 3964 | aidlCommand := manifest.Commands[0].GetCommand() |
| 3965 | expectedAidlFlag := "-Werror" |
| 3966 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 3967 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 3968 | } |
| 3969 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 3970 | |
Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 3971 | func TestAidlFlagsWithMinSdkVersion(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 3972 | t.Parallel() |
Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 3973 | for _, tc := range []struct { |
| 3974 | name string |
| 3975 | sdkVersion string |
| 3976 | variant string |
| 3977 | expected string |
| 3978 | }{ |
| 3979 | { |
| 3980 | name: "default is current", |
| 3981 | sdkVersion: "", |
| 3982 | variant: "android_arm64_armv8-a_static", |
| 3983 | expected: "platform_apis", |
| 3984 | }, |
| 3985 | { |
| 3986 | name: "use sdk_version", |
| 3987 | sdkVersion: `sdk_version: "29"`, |
| 3988 | variant: "android_arm64_armv8-a_static", |
| 3989 | expected: "platform_apis", |
| 3990 | }, |
| 3991 | { |
| 3992 | name: "use sdk_version(sdk variant)", |
| 3993 | sdkVersion: `sdk_version: "29"`, |
| 3994 | variant: "android_arm64_armv8-a_sdk_static", |
| 3995 | expected: "29", |
| 3996 | }, |
| 3997 | { |
| 3998 | name: "use min_sdk_version", |
| 3999 | sdkVersion: `min_sdk_version: "29"`, |
| 4000 | variant: "android_arm64_armv8-a_static", |
| 4001 | expected: "29", |
| 4002 | }, |
| 4003 | } { |
| 4004 | t.Run(tc.name, func(t *testing.T) { |
| 4005 | ctx := testCc(t, ` |
| 4006 | cc_library { |
| 4007 | name: "libfoo", |
| 4008 | stl: "none", |
| 4009 | srcs: ["a/Foo.aidl"], |
| 4010 | `+tc.sdkVersion+` |
| 4011 | } |
| 4012 | `) |
| 4013 | libfoo := ctx.ModuleForTests("libfoo", tc.variant) |
Colin Cross | f61d03d | 2023-11-02 16:56:39 -0700 | [diff] [blame] | 4014 | manifest := android.RuleBuilderSboxProtoForTests(t, ctx, libfoo.Output("aidl.sbox.textproto")) |
Jooyung Han | 07f70c0 | 2021-11-06 07:08:45 +0900 | [diff] [blame] | 4015 | aidlCommand := manifest.Commands[0].GetCommand() |
| 4016 | expectedAidlFlag := "--min_sdk_version=" + tc.expected |
| 4017 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 4018 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 4019 | } |
| 4020 | }) |
| 4021 | } |
| 4022 | } |
| 4023 | |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4024 | func TestInvalidAidlProp(t *testing.T) { |
| 4025 | t.Parallel() |
| 4026 | |
| 4027 | testCases := []struct { |
| 4028 | description string |
| 4029 | bp string |
| 4030 | }{ |
| 4031 | { |
| 4032 | description: "Invalid use of aidl.libs and aidl.include_dirs", |
| 4033 | bp: ` |
| 4034 | cc_library { |
| 4035 | name: "foo", |
| 4036 | aidl: { |
| 4037 | libs: ["foo_aidl"], |
| 4038 | include_dirs: ["bar/include"], |
| 4039 | } |
| 4040 | } |
| 4041 | `, |
| 4042 | }, |
| 4043 | { |
| 4044 | description: "Invalid use of aidl.libs and aidl.local_include_dirs", |
| 4045 | bp: ` |
| 4046 | cc_library { |
| 4047 | name: "foo", |
| 4048 | aidl: { |
| 4049 | libs: ["foo_aidl"], |
| 4050 | local_include_dirs: ["include"], |
| 4051 | } |
| 4052 | } |
| 4053 | `, |
| 4054 | }, |
| 4055 | } |
| 4056 | |
| 4057 | for _, testCase := range testCases { |
| 4058 | t.Run(testCase.description, func(t *testing.T) { |
| 4059 | bp := ` |
| 4060 | aidl_library { |
| 4061 | name: "foo_aidl", |
| 4062 | srcs: ["Foo.aidl"], |
| 4063 | } ` + testCase.bp |
| 4064 | android.GroupFixturePreparers( |
| 4065 | prepareForCcTest, |
| 4066 | aidl_library.PrepareForTestWithAidlLibrary. |
| 4067 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("For aidl headers, please only use aidl.libs prop")), |
| 4068 | ).RunTestWithBp(t, bp) |
| 4069 | }) |
| 4070 | } |
| 4071 | } |
| 4072 | |
Jiyong Park | a008fb0 | 2021-03-16 17:15:53 +0900 | [diff] [blame] | 4073 | func TestMinSdkVersionInClangTriple(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4074 | t.Parallel() |
Jiyong Park | a008fb0 | 2021-03-16 17:15:53 +0900 | [diff] [blame] | 4075 | ctx := testCc(t, ` |
| 4076 | cc_library_shared { |
| 4077 | name: "libfoo", |
| 4078 | srcs: ["foo.c"], |
| 4079 | min_sdk_version: "29", |
| 4080 | }`) |
| 4081 | |
| 4082 | cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4083 | android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29") |
| 4084 | } |
| 4085 | |
Vinh Tran | f192474 | 2022-06-24 16:40:11 -0400 | [diff] [blame] | 4086 | func TestNonDigitMinSdkVersionInClangTriple(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4087 | t.Parallel() |
Vinh Tran | f192474 | 2022-06-24 16:40:11 -0400 | [diff] [blame] | 4088 | bp := ` |
| 4089 | cc_library_shared { |
| 4090 | name: "libfoo", |
| 4091 | srcs: ["foo.c"], |
| 4092 | min_sdk_version: "S", |
| 4093 | } |
| 4094 | ` |
| 4095 | result := android.GroupFixturePreparers( |
| 4096 | prepareForCcTest, |
| 4097 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4098 | variables.Platform_version_active_codenames = []string{"UpsideDownCake", "Tiramisu"} |
| 4099 | }), |
| 4100 | ).RunTestWithBp(t, bp) |
| 4101 | ctx := result.TestContext |
| 4102 | cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4103 | android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android31") |
| 4104 | } |
| 4105 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4106 | func TestIncludeDirsExporting(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4107 | t.Parallel() |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4108 | |
| 4109 | // Trim spaces from the beginning, end and immediately after any newline characters. Leaves |
| 4110 | // embedded newline characters alone. |
| 4111 | trimIndentingSpaces := func(s string) string { |
| 4112 | return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1")) |
| 4113 | } |
| 4114 | |
| 4115 | checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) { |
| 4116 | t.Helper() |
| 4117 | expected = trimIndentingSpaces(expected) |
| 4118 | actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n")) |
| 4119 | if expected != actual { |
| 4120 | t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual) |
| 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo) |
| 4125 | |
| 4126 | checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) { |
| 4127 | t.Helper() |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 4128 | exported, _ := android.SingletonModuleProvider(ctx, module, FlagExporterInfoProvider) |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4129 | name := module.Name() |
| 4130 | |
| 4131 | for _, checker := range checkers { |
| 4132 | checker(t, name, exported) |
| 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | expectedIncludeDirs := func(expectedPaths string) exportedChecker { |
| 4137 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4138 | t.Helper() |
| 4139 | checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs) |
| 4140 | } |
| 4141 | } |
| 4142 | |
| 4143 | expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker { |
| 4144 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4145 | t.Helper() |
| 4146 | checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs) |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | expectedGeneratedHeaders := func(expectedPaths string) exportedChecker { |
| 4151 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4152 | t.Helper() |
| 4153 | checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders) |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker { |
| 4158 | return func(t *testing.T, name string, exported FlagExporterInfo) { |
| 4159 | t.Helper() |
| 4160 | checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps) |
| 4161 | } |
| 4162 | } |
| 4163 | |
| 4164 | genRuleModules := ` |
| 4165 | genrule { |
| 4166 | name: "genrule_foo", |
| 4167 | cmd: "generate-foo", |
| 4168 | out: [ |
| 4169 | "generated_headers/foo/generated_header.h", |
| 4170 | ], |
| 4171 | export_include_dirs: [ |
| 4172 | "generated_headers", |
| 4173 | ], |
| 4174 | } |
| 4175 | |
| 4176 | genrule { |
| 4177 | name: "genrule_bar", |
| 4178 | cmd: "generate-bar", |
| 4179 | out: [ |
| 4180 | "generated_headers/bar/generated_header.h", |
| 4181 | ], |
| 4182 | export_include_dirs: [ |
| 4183 | "generated_headers", |
| 4184 | ], |
| 4185 | } |
| 4186 | ` |
| 4187 | |
| 4188 | t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) { |
| 4189 | ctx := testCc(t, genRuleModules+` |
| 4190 | cc_library { |
| 4191 | name: "libfoo", |
| 4192 | srcs: ["foo.c"], |
| 4193 | export_include_dirs: ["foo/standard"], |
| 4194 | export_system_include_dirs: ["foo/system"], |
| 4195 | generated_headers: ["genrule_foo"], |
| 4196 | export_generated_headers: ["genrule_foo"], |
| 4197 | } |
| 4198 | |
| 4199 | cc_library { |
| 4200 | name: "libbar", |
| 4201 | srcs: ["bar.c"], |
| 4202 | shared_libs: ["libfoo"], |
| 4203 | export_include_dirs: ["bar/standard"], |
| 4204 | export_system_include_dirs: ["bar/system"], |
| 4205 | generated_headers: ["genrule_bar"], |
| 4206 | export_generated_headers: ["genrule_bar"], |
| 4207 | } |
| 4208 | `) |
| 4209 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4210 | checkIncludeDirs(t, ctx, foo, |
| 4211 | expectedIncludeDirs(` |
| 4212 | foo/standard |
| 4213 | .intermediates/genrule_foo/gen/generated_headers |
| 4214 | `), |
| 4215 | expectedSystemIncludeDirs(`foo/system`), |
| 4216 | expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4217 | expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4218 | ) |
| 4219 | |
| 4220 | bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() |
| 4221 | checkIncludeDirs(t, ctx, bar, |
| 4222 | expectedIncludeDirs(` |
| 4223 | bar/standard |
| 4224 | .intermediates/genrule_bar/gen/generated_headers |
| 4225 | `), |
| 4226 | expectedSystemIncludeDirs(`bar/system`), |
| 4227 | expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`), |
| 4228 | expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`), |
| 4229 | ) |
| 4230 | }) |
| 4231 | |
| 4232 | t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) { |
| 4233 | ctx := testCc(t, genRuleModules+` |
| 4234 | cc_library { |
| 4235 | name: "libfoo", |
| 4236 | srcs: ["foo.c"], |
| 4237 | export_include_dirs: ["foo/standard"], |
| 4238 | export_system_include_dirs: ["foo/system"], |
| 4239 | generated_headers: ["genrule_foo"], |
| 4240 | export_generated_headers: ["genrule_foo"], |
| 4241 | } |
| 4242 | |
| 4243 | cc_library { |
| 4244 | name: "libbar", |
| 4245 | srcs: ["bar.c"], |
| 4246 | whole_static_libs: ["libfoo"], |
| 4247 | export_include_dirs: ["bar/standard"], |
| 4248 | export_system_include_dirs: ["bar/system"], |
| 4249 | generated_headers: ["genrule_bar"], |
| 4250 | export_generated_headers: ["genrule_bar"], |
| 4251 | } |
| 4252 | `) |
| 4253 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4254 | checkIncludeDirs(t, ctx, foo, |
| 4255 | expectedIncludeDirs(` |
| 4256 | foo/standard |
| 4257 | .intermediates/genrule_foo/gen/generated_headers |
| 4258 | `), |
| 4259 | expectedSystemIncludeDirs(`foo/system`), |
| 4260 | expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4261 | expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`), |
| 4262 | ) |
| 4263 | |
| 4264 | bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() |
| 4265 | checkIncludeDirs(t, ctx, bar, |
| 4266 | expectedIncludeDirs(` |
| 4267 | bar/standard |
| 4268 | foo/standard |
| 4269 | .intermediates/genrule_foo/gen/generated_headers |
| 4270 | .intermediates/genrule_bar/gen/generated_headers |
| 4271 | `), |
| 4272 | expectedSystemIncludeDirs(` |
| 4273 | bar/system |
| 4274 | foo/system |
| 4275 | `), |
| 4276 | expectedGeneratedHeaders(` |
| 4277 | .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h |
| 4278 | .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h |
| 4279 | `), |
| 4280 | expectedOrderOnlyDeps(` |
| 4281 | .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h |
| 4282 | .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h |
| 4283 | `), |
| 4284 | ) |
| 4285 | }) |
| 4286 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4287 | t.Run("ensure only aidl headers are exported", func(t *testing.T) { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4288 | ctx := android.GroupFixturePreparers( |
| 4289 | prepareForCcTest, |
| 4290 | aidl_library.PrepareForTestWithAidlLibrary, |
| 4291 | ).RunTestWithBp(t, ` |
| 4292 | aidl_library { |
| 4293 | name: "libfoo_aidl", |
| 4294 | srcs: ["x/y/Bar.aidl"], |
| 4295 | strip_import_prefix: "x", |
| 4296 | } |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4297 | cc_library_shared { |
| 4298 | name: "libfoo", |
| 4299 | srcs: [ |
| 4300 | "foo.c", |
| 4301 | "b.aidl", |
| 4302 | "a.proto", |
| 4303 | ], |
| 4304 | aidl: { |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4305 | libs: ["libfoo_aidl"], |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4306 | export_aidl_headers: true, |
| 4307 | } |
| 4308 | } |
Vinh Tran | 367d89d | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 4309 | `).TestContext |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4310 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4311 | checkIncludeDirs(t, ctx, foo, |
| 4312 | expectedIncludeDirs(` |
| 4313 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4314 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4315 | `), |
| 4316 | expectedSystemIncludeDirs(``), |
| 4317 | expectedGeneratedHeaders(` |
| 4318 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h |
| 4319 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h |
| 4320 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4321 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h |
| 4322 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h |
| 4323 | .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] | 4324 | `), |
| 4325 | expectedOrderOnlyDeps(` |
| 4326 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h |
| 4327 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h |
| 4328 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 4329 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h |
| 4330 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h |
| 4331 | .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] | 4332 | `), |
| 4333 | ) |
| 4334 | }) |
| 4335 | |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4336 | t.Run("ensure only proto headers are exported", func(t *testing.T) { |
| 4337 | ctx := testCc(t, genRuleModules+` |
| 4338 | cc_library_shared { |
| 4339 | name: "libfoo", |
| 4340 | srcs: [ |
| 4341 | "foo.c", |
| 4342 | "b.aidl", |
| 4343 | "a.proto", |
| 4344 | ], |
| 4345 | proto: { |
| 4346 | export_proto_headers: true, |
| 4347 | } |
| 4348 | } |
| 4349 | `) |
| 4350 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4351 | checkIncludeDirs(t, ctx, foo, |
| 4352 | expectedIncludeDirs(` |
| 4353 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto |
| 4354 | `), |
| 4355 | expectedSystemIncludeDirs(``), |
| 4356 | expectedGeneratedHeaders(` |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4357 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h |
| 4358 | `), |
| 4359 | expectedOrderOnlyDeps(` |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4360 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h |
| 4361 | `), |
| 4362 | ) |
| 4363 | }) |
| 4364 | |
Paul Duffin | 33056e8 | 2021-02-19 13:49:08 +0000 | [diff] [blame] | 4365 | t.Run("ensure only sysprop headers are exported", func(t *testing.T) { |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4366 | ctx := testCc(t, genRuleModules+` |
| 4367 | cc_library_shared { |
| 4368 | name: "libfoo", |
| 4369 | srcs: [ |
| 4370 | "foo.c", |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4371 | "path/to/a.sysprop", |
Paul Duffin | 3cb603e | 2021-02-19 13:57:10 +0000 | [diff] [blame] | 4372 | "b.aidl", |
| 4373 | "a.proto", |
| 4374 | ], |
| 4375 | } |
| 4376 | `) |
| 4377 | foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() |
| 4378 | checkIncludeDirs(t, ctx, foo, |
| 4379 | expectedIncludeDirs(` |
| 4380 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include |
| 4381 | `), |
| 4382 | expectedSystemIncludeDirs(``), |
| 4383 | expectedGeneratedHeaders(` |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4384 | .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] | 4385 | `), |
| 4386 | expectedOrderOnlyDeps(` |
Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 4387 | .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/path/to/a.sysprop.h |
| 4388 | .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] | 4389 | `), |
| 4390 | ) |
| 4391 | }) |
| 4392 | } |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4393 | |
| 4394 | func TestIncludeDirectoryOrdering(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4395 | t.Parallel() |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4396 | baseExpectedFlags := []string{ |
| 4397 | "${config.ArmThumbCflags}", |
| 4398 | "${config.ArmCflags}", |
| 4399 | "${config.CommonGlobalCflags}", |
| 4400 | "${config.DeviceGlobalCflags}", |
| 4401 | "${config.ExternalCflags}", |
| 4402 | "${config.ArmToolchainCflags}", |
| 4403 | "${config.ArmArmv7ANeonCflags}", |
| 4404 | "${config.ArmGenericCflags}", |
| 4405 | "-target", |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4406 | "armv7a-linux-androideabi21", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | expectedIncludes := []string{ |
| 4410 | "external/foo/android_arm_export_include_dirs", |
| 4411 | "external/foo/lib32_export_include_dirs", |
| 4412 | "external/foo/arm_export_include_dirs", |
| 4413 | "external/foo/android_export_include_dirs", |
| 4414 | "external/foo/linux_export_include_dirs", |
| 4415 | "external/foo/export_include_dirs", |
| 4416 | "external/foo/android_arm_local_include_dirs", |
| 4417 | "external/foo/lib32_local_include_dirs", |
| 4418 | "external/foo/arm_local_include_dirs", |
| 4419 | "external/foo/android_local_include_dirs", |
| 4420 | "external/foo/linux_local_include_dirs", |
| 4421 | "external/foo/local_include_dirs", |
| 4422 | "external/foo", |
| 4423 | "external/foo/libheader1", |
| 4424 | "external/foo/libheader2", |
| 4425 | "external/foo/libwhole1", |
| 4426 | "external/foo/libwhole2", |
| 4427 | "external/foo/libstatic1", |
| 4428 | "external/foo/libstatic2", |
| 4429 | "external/foo/libshared1", |
| 4430 | "external/foo/libshared2", |
| 4431 | "external/foo/liblinux", |
| 4432 | "external/foo/libandroid", |
| 4433 | "external/foo/libarm", |
| 4434 | "external/foo/lib32", |
| 4435 | "external/foo/libandroid_arm", |
| 4436 | "defaults/cc/common/ndk_libc++_shared", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"} |
| 4440 | cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"} |
| 4441 | |
Elliott Hughes | ed4a27b | 2022-05-18 13:15:00 -0700 | [diff] [blame] | 4442 | cflags := []string{"-Werror", "-std=candcpp"} |
Elliott Hughes | fb294e3 | 2023-06-14 10:42:45 -0700 | [diff] [blame] | 4443 | cstd := []string{"-std=gnu17", "-std=conly"} |
Elliott Hughes | c79d9e3 | 2022-01-13 14:56:02 -0800 | [diff] [blame] | 4444 | cppstd := []string{"-std=gnu++20", "-std=cpp", "-fno-rtti"} |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4445 | |
| 4446 | lastIncludes := []string{ |
| 4447 | "out/soong/ndk/sysroot/usr/include", |
| 4448 | "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi", |
| 4449 | } |
| 4450 | |
| 4451 | combineSlices := func(slices ...[]string) []string { |
| 4452 | var ret []string |
| 4453 | for _, s := range slices { |
| 4454 | ret = append(ret, s...) |
| 4455 | } |
| 4456 | return ret |
| 4457 | } |
| 4458 | |
| 4459 | testCases := []struct { |
| 4460 | name string |
| 4461 | src string |
| 4462 | expected []string |
| 4463 | }{ |
| 4464 | { |
| 4465 | name: "c", |
| 4466 | src: "foo.c", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4467 | 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] | 4468 | }, |
| 4469 | { |
| 4470 | name: "cc", |
| 4471 | src: "foo.cc", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4472 | 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] | 4473 | }, |
| 4474 | { |
| 4475 | name: "assemble", |
| 4476 | src: "foo.s", |
Yi Kong | 13beeed | 2023-07-15 03:09:00 +0900 | [diff] [blame] | 4477 | expected: combineSlices(baseExpectedFlags, []string{"${config.CommonGlobalAsflags}"}, expectedIncludes, lastIncludes), |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4478 | }, |
| 4479 | } |
| 4480 | |
| 4481 | for _, tc := range testCases { |
| 4482 | t.Run(tc.name, func(t *testing.T) { |
| 4483 | bp := fmt.Sprintf(` |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4484 | cc_library { |
| 4485 | name: "libfoo", |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4486 | srcs: ["%s"], |
Liz Kammer | 9dc6577 | 2021-12-16 11:38:50 -0500 | [diff] [blame] | 4487 | cflags: ["-std=candcpp"], |
| 4488 | conlyflags: ["-std=conly"], |
| 4489 | cppflags: ["-std=cpp"], |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4490 | local_include_dirs: ["local_include_dirs"], |
| 4491 | export_include_dirs: ["export_include_dirs"], |
| 4492 | export_system_include_dirs: ["export_system_include_dirs"], |
| 4493 | static_libs: ["libstatic1", "libstatic2"], |
| 4494 | whole_static_libs: ["libwhole1", "libwhole2"], |
| 4495 | shared_libs: ["libshared1", "libshared2"], |
| 4496 | header_libs: ["libheader1", "libheader2"], |
| 4497 | target: { |
| 4498 | android: { |
| 4499 | shared_libs: ["libandroid"], |
| 4500 | local_include_dirs: ["android_local_include_dirs"], |
| 4501 | export_include_dirs: ["android_export_include_dirs"], |
| 4502 | }, |
| 4503 | android_arm: { |
| 4504 | shared_libs: ["libandroid_arm"], |
| 4505 | local_include_dirs: ["android_arm_local_include_dirs"], |
| 4506 | export_include_dirs: ["android_arm_export_include_dirs"], |
| 4507 | }, |
| 4508 | linux: { |
| 4509 | shared_libs: ["liblinux"], |
| 4510 | local_include_dirs: ["linux_local_include_dirs"], |
| 4511 | export_include_dirs: ["linux_export_include_dirs"], |
| 4512 | }, |
| 4513 | }, |
| 4514 | multilib: { |
| 4515 | lib32: { |
| 4516 | shared_libs: ["lib32"], |
| 4517 | local_include_dirs: ["lib32_local_include_dirs"], |
| 4518 | export_include_dirs: ["lib32_export_include_dirs"], |
| 4519 | }, |
| 4520 | }, |
| 4521 | arch: { |
| 4522 | arm: { |
| 4523 | shared_libs: ["libarm"], |
| 4524 | local_include_dirs: ["arm_local_include_dirs"], |
| 4525 | export_include_dirs: ["arm_export_include_dirs"], |
| 4526 | }, |
| 4527 | }, |
| 4528 | stl: "libc++", |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4529 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | cc_library_headers { |
| 4533 | name: "libheader1", |
| 4534 | export_include_dirs: ["libheader1"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4535 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4536 | stl: "none", |
| 4537 | } |
| 4538 | |
| 4539 | cc_library_headers { |
| 4540 | name: "libheader2", |
| 4541 | export_include_dirs: ["libheader2"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4542 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4543 | stl: "none", |
| 4544 | } |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4545 | `, tc.src) |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4546 | |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4547 | libs := []string{ |
| 4548 | "libstatic1", |
| 4549 | "libstatic2", |
| 4550 | "libwhole1", |
| 4551 | "libwhole2", |
| 4552 | "libshared1", |
| 4553 | "libshared2", |
| 4554 | "libandroid", |
| 4555 | "libandroid_arm", |
| 4556 | "liblinux", |
| 4557 | "lib32", |
| 4558 | "libarm", |
| 4559 | } |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4560 | |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4561 | for _, lib := range libs { |
| 4562 | bp += fmt.Sprintf(` |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4563 | cc_library { |
| 4564 | name: "%s", |
| 4565 | export_include_dirs: ["%s"], |
Dan Albert | 6bfb6bb | 2022-08-17 20:11:57 +0000 | [diff] [blame] | 4566 | sdk_version: "minimum", |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4567 | stl: "none", |
| 4568 | } |
| 4569 | `, lib, lib) |
Liz Kammer | 08572c6 | 2021-09-30 10:11:04 -0400 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | ctx := android.GroupFixturePreparers( |
| 4573 | PrepareForIntegrationTestWithCc, |
| 4574 | android.FixtureAddTextFile("external/foo/Android.bp", bp), |
| 4575 | ).RunTest(t) |
| 4576 | // Use the arm variant instead of the arm64 variant so that it gets headers from |
| 4577 | // ndk_libandroid_support to test LateStaticLibs. |
| 4578 | cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"] |
| 4579 | |
| 4580 | var includes []string |
| 4581 | flags := strings.Split(cflags, " ") |
| 4582 | for _, flag := range flags { |
| 4583 | if strings.HasPrefix(flag, "-I") { |
| 4584 | includes = append(includes, strings.TrimPrefix(flag, "-I")) |
| 4585 | } else if flag == "-isystem" { |
| 4586 | // skip isystem, include next |
| 4587 | } else if len(flag) > 0 { |
| 4588 | includes = append(includes, flag) |
| 4589 | } |
| 4590 | } |
| 4591 | |
| 4592 | android.AssertArrayString(t, "includes", tc.expected, includes) |
| 4593 | }) |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4594 | } |
| 4595 | |
Colin Cross | ae62818 | 2021-06-14 16:52:28 -0700 | [diff] [blame] | 4596 | } |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 4597 | |
zijunzhao | 933e380 | 2023-01-12 07:26:20 +0000 | [diff] [blame] | 4598 | func TestAddnoOverride64GlobalCflags(t *testing.T) { |
| 4599 | t.Parallel() |
| 4600 | ctx := testCc(t, ` |
| 4601 | cc_library_shared { |
| 4602 | name: "libclient", |
| 4603 | srcs: ["foo.c"], |
| 4604 | shared_libs: ["libfoo#1"], |
| 4605 | } |
| 4606 | |
| 4607 | cc_library_shared { |
| 4608 | name: "libfoo", |
| 4609 | srcs: ["foo.c"], |
| 4610 | shared_libs: ["libbar"], |
| 4611 | export_shared_lib_headers: ["libbar"], |
| 4612 | stubs: { |
| 4613 | symbol_file: "foo.map.txt", |
| 4614 | versions: ["1", "2", "3"], |
| 4615 | }, |
| 4616 | } |
| 4617 | |
| 4618 | cc_library_shared { |
| 4619 | name: "libbar", |
| 4620 | export_include_dirs: ["include/libbar"], |
| 4621 | srcs: ["foo.c"], |
| 4622 | }`) |
| 4623 | |
| 4624 | cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] |
| 4625 | |
| 4626 | if !strings.Contains(cFlags, "${config.NoOverride64GlobalCflags}") { |
| 4627 | t.Errorf("expected %q in cflags, got %q", "${config.NoOverride64GlobalCflags}", cFlags) |
| 4628 | } |
| 4629 | } |
| 4630 | |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 4631 | func TestCcBuildBrokenClangProperty(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4632 | t.Parallel() |
Alix | b5f6d9e | 2022-04-20 23:00:58 +0000 | [diff] [blame] | 4633 | tests := []struct { |
| 4634 | name string |
| 4635 | clang bool |
| 4636 | BuildBrokenClangProperty bool |
| 4637 | err string |
| 4638 | }{ |
| 4639 | { |
| 4640 | name: "error when clang is set to false", |
| 4641 | clang: false, |
| 4642 | err: "is no longer supported", |
| 4643 | }, |
| 4644 | { |
| 4645 | name: "error when clang is set to true", |
| 4646 | clang: true, |
| 4647 | err: "property is deprecated, see Changes.md", |
| 4648 | }, |
| 4649 | { |
| 4650 | name: "no error when BuildBrokenClangProperty is explicitly set to true", |
| 4651 | clang: true, |
| 4652 | BuildBrokenClangProperty: true, |
| 4653 | }, |
| 4654 | } |
| 4655 | |
| 4656 | for _, test := range tests { |
| 4657 | t.Run(test.name, func(t *testing.T) { |
| 4658 | bp := fmt.Sprintf(` |
| 4659 | cc_library { |
| 4660 | name: "foo", |
| 4661 | clang: %t, |
| 4662 | }`, test.clang) |
| 4663 | |
| 4664 | if test.err == "" { |
| 4665 | android.GroupFixturePreparers( |
| 4666 | prepareForCcTest, |
| 4667 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4668 | if test.BuildBrokenClangProperty { |
| 4669 | variables.BuildBrokenClangProperty = test.BuildBrokenClangProperty |
| 4670 | } |
| 4671 | }), |
| 4672 | ).RunTestWithBp(t, bp) |
| 4673 | } else { |
| 4674 | prepareForCcTest. |
| 4675 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 4676 | RunTestWithBp(t, bp) |
| 4677 | } |
| 4678 | }) |
| 4679 | } |
| 4680 | } |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 4681 | |
| 4682 | func TestCcBuildBrokenClangAsFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4683 | t.Parallel() |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 4684 | tests := []struct { |
| 4685 | name string |
| 4686 | clangAsFlags []string |
| 4687 | BuildBrokenClangAsFlags bool |
| 4688 | err string |
| 4689 | }{ |
| 4690 | { |
| 4691 | name: "error when clang_asflags is set", |
| 4692 | clangAsFlags: []string{"-a", "-b"}, |
| 4693 | err: "clang_asflags: property is deprecated", |
| 4694 | }, |
| 4695 | { |
| 4696 | name: "no error when BuildBrokenClangAsFlags is explicitly set to true", |
| 4697 | clangAsFlags: []string{"-a", "-b"}, |
| 4698 | BuildBrokenClangAsFlags: true, |
| 4699 | }, |
| 4700 | } |
| 4701 | |
| 4702 | for _, test := range tests { |
| 4703 | t.Run(test.name, func(t *testing.T) { |
| 4704 | bp := fmt.Sprintf(` |
| 4705 | cc_library { |
| 4706 | name: "foo", |
| 4707 | clang_asflags: %s, |
| 4708 | }`, `["`+strings.Join(test.clangAsFlags, `","`)+`"]`) |
| 4709 | |
| 4710 | if test.err == "" { |
| 4711 | android.GroupFixturePreparers( |
| 4712 | prepareForCcTest, |
| 4713 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4714 | if test.BuildBrokenClangAsFlags { |
| 4715 | variables.BuildBrokenClangAsFlags = test.BuildBrokenClangAsFlags |
| 4716 | } |
| 4717 | }), |
| 4718 | ).RunTestWithBp(t, bp) |
| 4719 | } else { |
| 4720 | prepareForCcTest. |
| 4721 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 4722 | RunTestWithBp(t, bp) |
| 4723 | } |
| 4724 | }) |
| 4725 | } |
| 4726 | } |
| 4727 | |
| 4728 | func TestCcBuildBrokenClangCFlags(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 4729 | t.Parallel() |
Alix Espino | ef47e54 | 2022-09-14 19:10:51 +0000 | [diff] [blame] | 4730 | tests := []struct { |
| 4731 | name string |
| 4732 | clangCFlags []string |
| 4733 | BuildBrokenClangCFlags bool |
| 4734 | err string |
| 4735 | }{ |
| 4736 | { |
| 4737 | name: "error when clang_cflags is set", |
| 4738 | clangCFlags: []string{"-a", "-b"}, |
| 4739 | err: "clang_cflags: property is deprecated", |
| 4740 | }, |
| 4741 | { |
| 4742 | name: "no error when BuildBrokenClangCFlags is explicitly set to true", |
| 4743 | clangCFlags: []string{"-a", "-b"}, |
| 4744 | BuildBrokenClangCFlags: true, |
| 4745 | }, |
| 4746 | } |
| 4747 | |
| 4748 | for _, test := range tests { |
| 4749 | t.Run(test.name, func(t *testing.T) { |
| 4750 | bp := fmt.Sprintf(` |
| 4751 | cc_library { |
| 4752 | name: "foo", |
| 4753 | clang_cflags: %s, |
| 4754 | }`, `["`+strings.Join(test.clangCFlags, `","`)+`"]`) |
| 4755 | |
| 4756 | if test.err == "" { |
| 4757 | android.GroupFixturePreparers( |
| 4758 | prepareForCcTest, |
| 4759 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4760 | if test.BuildBrokenClangCFlags { |
| 4761 | variables.BuildBrokenClangCFlags = test.BuildBrokenClangCFlags |
| 4762 | } |
| 4763 | }), |
| 4764 | ).RunTestWithBp(t, bp) |
| 4765 | } else { |
| 4766 | prepareForCcTest. |
| 4767 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(test.err)). |
| 4768 | RunTestWithBp(t, bp) |
| 4769 | } |
| 4770 | }) |
| 4771 | } |
| 4772 | } |
Wei Li | 5f5d271 | 2023-12-11 15:40:29 -0800 | [diff] [blame] | 4773 | |
| 4774 | func TestStrippedAllOutputFile(t *testing.T) { |
| 4775 | t.Parallel() |
| 4776 | bp := ` |
| 4777 | cc_library { |
| 4778 | name: "test_lib", |
| 4779 | srcs: ["test_lib.cpp"], |
| 4780 | dist: { |
| 4781 | targets: [ "dist_target" ], |
| 4782 | tag: "stripped_all", |
| 4783 | } |
| 4784 | } |
| 4785 | ` |
| 4786 | config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) |
| 4787 | ctx := testCcWithConfig(t, config) |
| 4788 | module := ctx.ModuleForTests("test_lib", "android_arm_armv7-a-neon_shared").Module() |
| 4789 | outputFile, err := module.(android.OutputFileProducer).OutputFiles("stripped_all") |
| 4790 | if err != nil { |
| 4791 | t.Errorf("Expected cc_library to produce output files, error: %s", err) |
| 4792 | return |
| 4793 | } |
| 4794 | if !strings.HasSuffix(outputFile.Strings()[0], "/stripped_all/test_lib.so") { |
| 4795 | t.Errorf("Unexpected output file: %s", outputFile.Strings()[0]) |
| 4796 | return |
| 4797 | } |
| 4798 | } |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 4799 | |
| 4800 | // TODO(b/316829758) Remove this test and do not set VNDK version from other tests |
| 4801 | func TestImageVariantsWithoutVndk(t *testing.T) { |
| 4802 | t.Parallel() |
| 4803 | |
| 4804 | bp := ` |
| 4805 | cc_binary { |
| 4806 | name: "binfoo", |
| 4807 | srcs: ["binfoo.cc"], |
| 4808 | vendor_available: true, |
| 4809 | product_available: true, |
| 4810 | shared_libs: ["libbar"] |
| 4811 | } |
| 4812 | cc_library { |
| 4813 | name: "libbar", |
| 4814 | srcs: ["libbar.cc"], |
| 4815 | vendor_available: true, |
| 4816 | product_available: true, |
| 4817 | } |
| 4818 | ` |
| 4819 | |
| 4820 | ctx := prepareForCcTestWithoutVndk.RunTestWithBp(t, bp) |
| 4821 | |
| 4822 | hasDep := func(m android.Module, wantDep android.Module) bool { |
| 4823 | t.Helper() |
| 4824 | var found bool |
| 4825 | ctx.VisitDirectDeps(m, func(dep blueprint.Module) { |
| 4826 | if dep == wantDep { |
| 4827 | found = true |
| 4828 | } |
| 4829 | }) |
| 4830 | return found |
| 4831 | } |
| 4832 | |
| 4833 | testDepWithVariant := func(imageVariant string) { |
| 4834 | imageVariantStr := "" |
| 4835 | if imageVariant != "core" { |
| 4836 | imageVariantStr = "_" + imageVariant |
| 4837 | } |
| 4838 | binFooModule := ctx.ModuleForTests("binfoo", "android"+imageVariantStr+"_arm64_armv8-a").Module() |
| 4839 | libBarModule := ctx.ModuleForTests("libbar", "android"+imageVariantStr+"_arm64_armv8-a_shared").Module() |
| 4840 | android.AssertBoolEquals(t, "binfoo should have dependency on libbar with image variant "+imageVariant, true, hasDep(binFooModule, libBarModule)) |
| 4841 | } |
| 4842 | |
| 4843 | testDepWithVariant("core") |
| 4844 | testDepWithVariant("vendor") |
| 4845 | testDepWithVariant("product") |
| 4846 | } |
Yi-Yo Chiang | 88960aa | 2024-01-19 15:02:29 +0800 | [diff] [blame] | 4847 | |
| 4848 | func TestVendorSdkVersionWithoutVndk(t *testing.T) { |
| 4849 | t.Parallel() |
| 4850 | |
| 4851 | bp := ` |
| 4852 | cc_library { |
| 4853 | name: "libfoo", |
| 4854 | srcs: ["libfoo.cc"], |
| 4855 | vendor_available: true, |
| 4856 | } |
| 4857 | |
| 4858 | cc_library { |
| 4859 | name: "libbar", |
| 4860 | srcs: ["libbar.cc"], |
| 4861 | vendor_available: true, |
| 4862 | min_sdk_version: "29", |
| 4863 | } |
| 4864 | ` |
| 4865 | |
| 4866 | ctx := prepareForCcTestWithoutVndk.RunTestWithBp(t, bp) |
| 4867 | testSdkVersionFlag := func(module, version string) { |
| 4868 | flags := ctx.ModuleForTests(module, "android_vendor_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 4869 | android.AssertStringDoesContain(t, "min sdk version", flags, "-target aarch64-linux-android"+version) |
| 4870 | } |
| 4871 | |
| 4872 | testSdkVersionFlag("libfoo", "10000") |
| 4873 | testSdkVersionFlag("libbar", "29") |
| 4874 | |
| 4875 | ctx = android.GroupFixturePreparers( |
| 4876 | prepareForCcTestWithoutVndk, |
| 4877 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4878 | if variables.BuildFlags == nil { |
| 4879 | variables.BuildFlags = make(map[string]string) |
| 4880 | } |
| 4881 | variables.BuildFlags["RELEASE_BOARD_API_LEVEL_FROZEN"] = "true" |
| 4882 | }), |
| 4883 | ).RunTestWithBp(t, bp) |
| 4884 | testSdkVersionFlag("libfoo", "30") |
| 4885 | testSdkVersionFlag("libbar", "29") |
| 4886 | } |