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