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