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