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