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