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