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