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