| 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 | "sort" | 
|  | 24 | "strings" | 
| Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 25 | "testing" | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | "android/soong/android" | 
| Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 28 | ) | 
|  | 29 |  | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 30 | var buildDir string | 
|  | 31 |  | 
|  | 32 | func setUp() { | 
|  | 33 | var err error | 
|  | 34 | buildDir, err = ioutil.TempDir("", "soong_cc_test") | 
|  | 35 | if err != nil { | 
|  | 36 | panic(err) | 
|  | 37 | } | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | func tearDown() { | 
|  | 41 | os.RemoveAll(buildDir) | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | func TestMain(m *testing.M) { | 
|  | 45 | run := func() int { | 
|  | 46 | setUp() | 
|  | 47 | defer tearDown() | 
|  | 48 |  | 
|  | 49 | return m.Run() | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | os.Exit(run()) | 
|  | 53 | } | 
|  | 54 |  | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 55 | func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext { | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 56 | t.Helper() | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 57 | ctx := CreateTestContext() | 
|  | 58 | ctx.Register(config) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 59 |  | 
| Jeff Gaston | d3e141d | 2017-08-08 17:46:01 -0700 | [diff] [blame] | 60 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) | 
| Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 61 | android.FailIfErrored(t, errs) | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 62 | _, errs = ctx.PrepareBuildActions(config) | 
| Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 63 | android.FailIfErrored(t, errs) | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 64 |  | 
|  | 65 | return ctx | 
|  | 66 | } | 
|  | 67 |  | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 68 | func testCc(t *testing.T, bp string) *android.TestContext { | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 69 | t.Helper() | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 70 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
| Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 71 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 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 | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 85 | func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) { | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 86 | t.Helper() | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 87 |  | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 88 | ctx := CreateTestContext() | 
|  | 89 | ctx.Register(config) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 90 |  | 
|  | 91 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) | 
|  | 92 | if len(errs) > 0 { | 
| Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 93 | android.FailIfNoMatchingErrors(t, pattern, errs) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 94 | return | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | _, errs = ctx.PrepareBuildActions(config) | 
|  | 98 | if len(errs) > 0 { | 
| Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 99 | android.FailIfNoMatchingErrors(t, pattern, errs) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 100 | return | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) | 
|  | 104 | } | 
|  | 105 |  | 
| Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 106 | func testCcError(t *testing.T, pattern string, bp string) { | 
|  | 107 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 108 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 109 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 110 | testCcErrorWithConfig(t, pattern, config) | 
|  | 111 | return | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | func testCcErrorProductVndk(t *testing.T, pattern string, bp string) { | 
|  | 115 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 116 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 117 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") | 
|  | 118 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 119 | testCcErrorWithConfig(t, pattern, config) | 
|  | 120 | return | 
|  | 121 | } | 
|  | 122 |  | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 123 | const ( | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 124 | coreVariant     = "android_arm64_armv8-a_shared" | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 125 | vendorVariant   = "android_vendor.VER_arm64_armv8-a_shared" | 
| Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 126 | productVariant  = "android_product.VER_arm64_armv8-a_shared" | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 127 | recoveryVariant = "android_recovery_arm64_armv8-a_shared" | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 128 | ) | 
|  | 129 |  | 
| Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 130 | func TestFuchsiaDeps(t *testing.T) { | 
|  | 131 | t.Helper() | 
|  | 132 |  | 
|  | 133 | bp := ` | 
|  | 134 | cc_library { | 
|  | 135 | name: "libTest", | 
|  | 136 | srcs: ["foo.c"], | 
|  | 137 | target: { | 
|  | 138 | fuchsia: { | 
|  | 139 | srcs: ["bar.c"], | 
|  | 140 | }, | 
|  | 141 | }, | 
|  | 142 | }` | 
|  | 143 |  | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 144 | config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil) | 
|  | 145 | ctx := testCcWithConfig(t, config) | 
| Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 146 |  | 
|  | 147 | rt := false | 
|  | 148 | fb := false | 
|  | 149 |  | 
|  | 150 | ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld") | 
|  | 151 | implicits := ld.Implicits | 
|  | 152 | for _, lib := range implicits { | 
|  | 153 | if strings.Contains(lib.Rel(), "libcompiler_rt") { | 
|  | 154 | rt = true | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | if strings.Contains(lib.Rel(), "libbioniccompat") { | 
|  | 158 | fb = true | 
|  | 159 | } | 
|  | 160 | } | 
|  | 161 |  | 
|  | 162 | if !rt || !fb { | 
|  | 163 | t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat") | 
|  | 164 | } | 
|  | 165 | } | 
|  | 166 |  | 
|  | 167 | func TestFuchsiaTargetDecl(t *testing.T) { | 
|  | 168 | t.Helper() | 
|  | 169 |  | 
|  | 170 | bp := ` | 
|  | 171 | cc_library { | 
|  | 172 | name: "libTest", | 
|  | 173 | srcs: ["foo.c"], | 
|  | 174 | target: { | 
|  | 175 | fuchsia: { | 
|  | 176 | srcs: ["bar.c"], | 
|  | 177 | }, | 
|  | 178 | }, | 
|  | 179 | }` | 
|  | 180 |  | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 181 | config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil) | 
|  | 182 | ctx := testCcWithConfig(t, config) | 
| Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 183 | ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld") | 
|  | 184 | var objs []string | 
|  | 185 | for _, o := range ld.Inputs { | 
|  | 186 | objs = append(objs, o.Base()) | 
|  | 187 | } | 
|  | 188 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { | 
|  | 189 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) | 
|  | 190 | } | 
|  | 191 | } | 
|  | 192 |  | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 193 | func TestVendorSrc(t *testing.T) { | 
|  | 194 | ctx := testCc(t, ` | 
|  | 195 | cc_library { | 
|  | 196 | name: "libTest", | 
|  | 197 | srcs: ["foo.c"], | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 198 | no_libcrt: true, | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 199 | nocrt: true, | 
|  | 200 | system_shared_libs: [], | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 201 | vendor_available: true, | 
|  | 202 | target: { | 
|  | 203 | vendor: { | 
|  | 204 | srcs: ["bar.c"], | 
|  | 205 | }, | 
|  | 206 | }, | 
|  | 207 | } | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 208 | `) | 
|  | 209 |  | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 210 | ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld") | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 211 | var objs []string | 
|  | 212 | for _, o := range ld.Inputs { | 
|  | 213 | objs = append(objs, o.Base()) | 
|  | 214 | } | 
| Colin Cross | 95d33fe | 2018-01-03 13:40:46 -0800 | [diff] [blame] | 215 | if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" { | 
| Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 216 | t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs) | 
|  | 217 | } | 
|  | 218 | } | 
|  | 219 |  | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 220 | func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string, | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 221 | isVndkSp bool, extends string, variant string) { | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 222 |  | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 223 | t.Helper() | 
|  | 224 |  | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 225 | mod := ctx.ModuleForTests(name, variant).Module().(*Module) | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 226 | if !mod.HasVendorVariant() { | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 227 | t.Errorf("%q must have variant %q", name, variant) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 228 | } | 
|  | 229 |  | 
|  | 230 | // Check library properties. | 
|  | 231 | lib, ok := mod.compiler.(*libraryDecorator) | 
|  | 232 | if !ok { | 
|  | 233 | t.Errorf("%q must have libraryDecorator", name) | 
|  | 234 | } else if lib.baseInstaller.subDir != subDir { | 
|  | 235 | t.Errorf("%q must use %q as subdir but it is using %q", name, subDir, | 
|  | 236 | lib.baseInstaller.subDir) | 
|  | 237 | } | 
|  | 238 |  | 
|  | 239 | // Check VNDK properties. | 
|  | 240 | if mod.vndkdep == nil { | 
|  | 241 | t.Fatalf("%q must have `vndkdep`", name) | 
|  | 242 | } | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 243 | if !mod.IsVndk() { | 
|  | 244 | t.Errorf("%q IsVndk() must equal to true", name) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 245 | } | 
|  | 246 | if mod.isVndkSp() != isVndkSp { | 
|  | 247 | t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp) | 
|  | 248 | } | 
|  | 249 |  | 
|  | 250 | // Check VNDK extension properties. | 
|  | 251 | isVndkExt := extends != "" | 
|  | 252 | if mod.isVndkExt() != isVndkExt { | 
|  | 253 | t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt) | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends { | 
|  | 257 | t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends) | 
|  | 258 | } | 
|  | 259 | } | 
|  | 260 |  | 
| Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 261 | func checkSnapshot(t *testing.T, ctx *android.TestContext, singletonName, moduleName, snapshotFilename, subDir, variant string) { | 
|  | 262 | snapshotSingleton := ctx.SingletonForTests(singletonName) | 
| Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 263 |  | 
| Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 264 | mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer) | 
|  | 265 | if !ok { | 
|  | 266 | t.Errorf("%q must have output\n", moduleName) | 
| Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 267 | return | 
|  | 268 | } | 
| Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 269 | outputFiles, err := mod.OutputFiles("") | 
|  | 270 | if err != nil || len(outputFiles) != 1 { | 
|  | 271 | t.Errorf("%q must have single output\n", moduleName) | 
|  | 272 | return | 
|  | 273 | } | 
|  | 274 | snapshotPath := filepath.Join(subDir, snapshotFilename) | 
| Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 275 |  | 
| Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 276 | out := snapshotSingleton.Output(snapshotPath) | 
| Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 277 | if out.Input.String() != outputFiles[0].String() { | 
| Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 278 | t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0]) | 
| Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 279 | } | 
|  | 280 | } | 
|  | 281 |  | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 282 | func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) { | 
|  | 283 | t.Helper() | 
|  | 284 | assertString(t, params.Rule.String(), android.WriteFile.String()) | 
|  | 285 | actual := strings.FieldsFunc(strings.ReplaceAll(params.Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' }) | 
|  | 286 | assertArrayString(t, actual, expected) | 
|  | 287 | } | 
|  | 288 |  | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 289 | func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) { | 
|  | 290 | t.Helper() | 
|  | 291 | vndkSnapshot := ctx.SingletonForTests("vndk-snapshot") | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 292 | checkWriteFileOutput(t, vndkSnapshot.Output(output), expected) | 
|  | 293 | } | 
|  | 294 |  | 
|  | 295 | func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) { | 
|  | 296 | t.Helper() | 
|  | 297 | vndkLibraries := ctx.ModuleForTests(module, "") | 
| Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 298 |  | 
|  | 299 | var output string | 
|  | 300 | if module != "vndkcorevariant.libraries.txt" { | 
|  | 301 | output = insertVndkVersion(module, "VER") | 
|  | 302 | } else { | 
|  | 303 | output = module | 
|  | 304 | } | 
|  | 305 |  | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 306 | checkWriteFileOutput(t, vndkLibraries.Output(output), expected) | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 307 | } | 
|  | 308 |  | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 309 | func TestVndk(t *testing.T) { | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 310 | bp := ` | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 311 | cc_library { | 
|  | 312 | name: "libvndk", | 
|  | 313 | vendor_available: true, | 
|  | 314 | vndk: { | 
|  | 315 | enabled: true, | 
|  | 316 | }, | 
|  | 317 | nocrt: true, | 
|  | 318 | } | 
|  | 319 |  | 
|  | 320 | cc_library { | 
|  | 321 | name: "libvndk_private", | 
|  | 322 | vendor_available: false, | 
|  | 323 | vndk: { | 
|  | 324 | enabled: true, | 
|  | 325 | }, | 
|  | 326 | nocrt: true, | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 327 | stem: "libvndk-private", | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 328 | } | 
|  | 329 |  | 
|  | 330 | cc_library { | 
|  | 331 | name: "libvndk_sp", | 
|  | 332 | vendor_available: true, | 
|  | 333 | vndk: { | 
|  | 334 | enabled: true, | 
|  | 335 | support_system_process: true, | 
|  | 336 | }, | 
|  | 337 | nocrt: true, | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 338 | suffix: "-x", | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 339 | } | 
|  | 340 |  | 
|  | 341 | cc_library { | 
|  | 342 | name: "libvndk_sp_private", | 
|  | 343 | vendor_available: false, | 
|  | 344 | vndk: { | 
|  | 345 | enabled: true, | 
|  | 346 | support_system_process: true, | 
|  | 347 | }, | 
|  | 348 | nocrt: true, | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 349 | target: { | 
|  | 350 | vendor: { | 
|  | 351 | suffix: "-x", | 
|  | 352 | }, | 
|  | 353 | }, | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 354 | } | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 355 | vndk_libraries_txt { | 
|  | 356 | name: "llndk.libraries.txt", | 
|  | 357 | } | 
|  | 358 | vndk_libraries_txt { | 
|  | 359 | name: "vndkcore.libraries.txt", | 
|  | 360 | } | 
|  | 361 | vndk_libraries_txt { | 
|  | 362 | name: "vndksp.libraries.txt", | 
|  | 363 | } | 
|  | 364 | vndk_libraries_txt { | 
|  | 365 | name: "vndkprivate.libraries.txt", | 
|  | 366 | } | 
|  | 367 | vndk_libraries_txt { | 
|  | 368 | name: "vndkcorevariant.libraries.txt", | 
|  | 369 | } | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 370 | ` | 
|  | 371 |  | 
|  | 372 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 373 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 374 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 375 |  | 
|  | 376 | ctx := testCcWithConfig(t, config) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 377 |  | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 378 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "", vendorVariant) | 
|  | 379 | checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "", vendorVariant) | 
|  | 380 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "", vendorVariant) | 
|  | 381 | checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "", vendorVariant) | 
| Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 382 |  | 
|  | 383 | // Check VNDK snapshot output. | 
|  | 384 |  | 
|  | 385 | snapshotDir := "vndk-snapshot" | 
|  | 386 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") | 
|  | 387 |  | 
|  | 388 | vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", | 
|  | 389 | "arm64", "armv8-a")) | 
|  | 390 | vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s", | 
|  | 391 | "arm", "armv7-a-neon")) | 
|  | 392 |  | 
|  | 393 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") | 
|  | 394 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") | 
|  | 395 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") | 
|  | 396 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") | 
|  | 397 |  | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 398 | variant := "android_vendor.VER_arm64_armv8-a_shared" | 
|  | 399 | variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared" | 
| Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 400 |  | 
| Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 401 | checkSnapshot(t, ctx, "vndk-snapshot", "libvndk", "libvndk.so", vndkCoreLibPath, variant) | 
|  | 402 | checkSnapshot(t, ctx, "vndk-snapshot", "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd) | 
|  | 403 | checkSnapshot(t, ctx, "vndk-snapshot", "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant) | 
|  | 404 | checkSnapshot(t, ctx, "vndk-snapshot", "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd) | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 405 |  | 
| Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 406 | snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs") | 
| Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 407 | checkSnapshot(t, ctx, "vndk-snapshot", "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "") | 
|  | 408 | checkSnapshot(t, ctx, "vndk-snapshot", "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "") | 
|  | 409 | checkSnapshot(t, ctx, "vndk-snapshot", "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "") | 
|  | 410 | checkSnapshot(t, ctx, "vndk-snapshot", "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "") | 
| Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 411 |  | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 412 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ | 
|  | 413 | "LLNDK: libc.so", | 
|  | 414 | "LLNDK: libdl.so", | 
|  | 415 | "LLNDK: libft2.so", | 
|  | 416 | "LLNDK: libm.so", | 
|  | 417 | "VNDK-SP: libc++.so", | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 418 | "VNDK-SP: libvndk_sp-x.so", | 
|  | 419 | "VNDK-SP: libvndk_sp_private-x.so", | 
|  | 420 | "VNDK-core: libvndk-private.so", | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 421 | "VNDK-core: libvndk.so", | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 422 | "VNDK-private: libft2.so", | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 423 | "VNDK-private: libvndk-private.so", | 
|  | 424 | "VNDK-private: libvndk_sp_private-x.so", | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 425 | }) | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 426 | checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"}) | 
|  | 427 | checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"}) | 
|  | 428 | checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"}) | 
|  | 429 | checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"}) | 
|  | 430 | checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil) | 
|  | 431 | } | 
|  | 432 |  | 
|  | 433 | func TestVndkLibrariesTxtAndroidMk(t *testing.T) { | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 434 | bp := ` | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 435 | vndk_libraries_txt { | 
|  | 436 | name: "llndk.libraries.txt", | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 437 | }` | 
|  | 438 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 439 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 440 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 441 | ctx := testCcWithConfig(t, config) | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 442 |  | 
|  | 443 | module := ctx.ModuleForTests("llndk.libraries.txt", "") | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 444 | entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0] | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 445 | assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"}) | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 446 | } | 
|  | 447 |  | 
|  | 448 | func TestVndkUsingCoreVariant(t *testing.T) { | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 449 | bp := ` | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 450 | cc_library { | 
|  | 451 | name: "libvndk", | 
|  | 452 | vendor_available: true, | 
|  | 453 | vndk: { | 
|  | 454 | enabled: true, | 
|  | 455 | }, | 
|  | 456 | nocrt: true, | 
|  | 457 | } | 
|  | 458 |  | 
|  | 459 | cc_library { | 
|  | 460 | name: "libvndk_sp", | 
|  | 461 | vendor_available: true, | 
|  | 462 | vndk: { | 
|  | 463 | enabled: true, | 
|  | 464 | support_system_process: true, | 
|  | 465 | }, | 
|  | 466 | nocrt: true, | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | cc_library { | 
|  | 470 | name: "libvndk2", | 
|  | 471 | vendor_available: false, | 
|  | 472 | vndk: { | 
|  | 473 | enabled: true, | 
|  | 474 | }, | 
|  | 475 | nocrt: true, | 
|  | 476 | } | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 477 |  | 
|  | 478 | vndk_libraries_txt { | 
|  | 479 | name: "vndkcorevariant.libraries.txt", | 
|  | 480 | } | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 481 | ` | 
|  | 482 |  | 
|  | 483 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 484 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 485 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 486 | config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true) | 
|  | 487 |  | 
|  | 488 | setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"}) | 
|  | 489 |  | 
|  | 490 | ctx := testCcWithConfig(t, config) | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 491 |  | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 492 | 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] | 493 | } | 
|  | 494 |  | 
|  | 495 | func TestVndkWhenVndkVersionIsNotSet(t *testing.T) { | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 496 | ctx := testCcNoVndk(t, ` | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 497 | cc_library { | 
|  | 498 | name: "libvndk", | 
|  | 499 | vendor_available: true, | 
|  | 500 | vndk: { | 
|  | 501 | enabled: true, | 
|  | 502 | }, | 
|  | 503 | nocrt: true, | 
|  | 504 | } | 
| Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 505 | `) | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 506 |  | 
|  | 507 | checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{ | 
|  | 508 | "LLNDK: libc.so", | 
|  | 509 | "LLNDK: libdl.so", | 
|  | 510 | "LLNDK: libft2.so", | 
|  | 511 | "LLNDK: libm.so", | 
|  | 512 | "VNDK-SP: libc++.so", | 
|  | 513 | "VNDK-core: libvndk.so", | 
|  | 514 | "VNDK-private: libft2.so", | 
|  | 515 | }) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 516 | } | 
|  | 517 |  | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 518 | func TestVndkDepError(t *testing.T) { | 
|  | 519 | // Check whether an error is emitted when a VNDK lib depends on a system lib. | 
|  | 520 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` | 
|  | 521 | cc_library { | 
|  | 522 | name: "libvndk", | 
|  | 523 | vendor_available: true, | 
|  | 524 | vndk: { | 
|  | 525 | enabled: true, | 
|  | 526 | }, | 
|  | 527 | shared_libs: ["libfwk"],  // Cause error | 
|  | 528 | nocrt: true, | 
|  | 529 | } | 
|  | 530 |  | 
|  | 531 | cc_library { | 
|  | 532 | name: "libfwk", | 
|  | 533 | nocrt: true, | 
|  | 534 | } | 
|  | 535 | `) | 
|  | 536 |  | 
|  | 537 | // Check whether an error is emitted when a VNDK lib depends on a vendor lib. | 
|  | 538 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` | 
|  | 539 | cc_library { | 
|  | 540 | name: "libvndk", | 
|  | 541 | vendor_available: true, | 
|  | 542 | vndk: { | 
|  | 543 | enabled: true, | 
|  | 544 | }, | 
|  | 545 | shared_libs: ["libvendor"],  // Cause error | 
|  | 546 | nocrt: true, | 
|  | 547 | } | 
|  | 548 |  | 
|  | 549 | cc_library { | 
|  | 550 | name: "libvendor", | 
|  | 551 | vendor: true, | 
|  | 552 | nocrt: true, | 
|  | 553 | } | 
|  | 554 | `) | 
|  | 555 |  | 
|  | 556 | // Check whether an error is emitted when a VNDK-SP lib depends on a system lib. | 
|  | 557 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` | 
|  | 558 | cc_library { | 
|  | 559 | name: "libvndk_sp", | 
|  | 560 | vendor_available: true, | 
|  | 561 | vndk: { | 
|  | 562 | enabled: true, | 
|  | 563 | support_system_process: true, | 
|  | 564 | }, | 
|  | 565 | shared_libs: ["libfwk"],  // Cause error | 
|  | 566 | nocrt: true, | 
|  | 567 | } | 
|  | 568 |  | 
|  | 569 | cc_library { | 
|  | 570 | name: "libfwk", | 
|  | 571 | nocrt: true, | 
|  | 572 | } | 
|  | 573 | `) | 
|  | 574 |  | 
|  | 575 | // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib. | 
|  | 576 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` | 
|  | 577 | cc_library { | 
|  | 578 | name: "libvndk_sp", | 
|  | 579 | vendor_available: true, | 
|  | 580 | vndk: { | 
|  | 581 | enabled: true, | 
|  | 582 | support_system_process: true, | 
|  | 583 | }, | 
|  | 584 | shared_libs: ["libvendor"],  // Cause error | 
|  | 585 | nocrt: true, | 
|  | 586 | } | 
|  | 587 |  | 
|  | 588 | cc_library { | 
|  | 589 | name: "libvendor", | 
|  | 590 | vendor: true, | 
|  | 591 | nocrt: true, | 
|  | 592 | } | 
|  | 593 | `) | 
|  | 594 |  | 
|  | 595 | // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib. | 
|  | 596 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
|  | 597 | cc_library { | 
|  | 598 | name: "libvndk_sp", | 
|  | 599 | vendor_available: true, | 
|  | 600 | vndk: { | 
|  | 601 | enabled: true, | 
|  | 602 | support_system_process: true, | 
|  | 603 | }, | 
|  | 604 | shared_libs: ["libvndk"],  // Cause error | 
|  | 605 | nocrt: true, | 
|  | 606 | } | 
|  | 607 |  | 
|  | 608 | cc_library { | 
|  | 609 | name: "libvndk", | 
|  | 610 | vendor_available: true, | 
|  | 611 | vndk: { | 
|  | 612 | enabled: true, | 
|  | 613 | }, | 
|  | 614 | nocrt: true, | 
|  | 615 | } | 
|  | 616 | `) | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 617 |  | 
|  | 618 | // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib. | 
|  | 619 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
|  | 620 | cc_library { | 
|  | 621 | name: "libvndk", | 
|  | 622 | vendor_available: true, | 
|  | 623 | vndk: { | 
|  | 624 | enabled: true, | 
|  | 625 | }, | 
|  | 626 | shared_libs: ["libnonvndk"], | 
|  | 627 | nocrt: true, | 
|  | 628 | } | 
|  | 629 |  | 
|  | 630 | cc_library { | 
|  | 631 | name: "libnonvndk", | 
|  | 632 | vendor_available: true, | 
|  | 633 | nocrt: true, | 
|  | 634 | } | 
|  | 635 | `) | 
|  | 636 |  | 
|  | 637 | // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib. | 
|  | 638 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
|  | 639 | cc_library { | 
|  | 640 | name: "libvndkprivate", | 
|  | 641 | vendor_available: false, | 
|  | 642 | vndk: { | 
|  | 643 | enabled: true, | 
|  | 644 | }, | 
|  | 645 | shared_libs: ["libnonvndk"], | 
|  | 646 | nocrt: true, | 
|  | 647 | } | 
|  | 648 |  | 
|  | 649 | cc_library { | 
|  | 650 | name: "libnonvndk", | 
|  | 651 | vendor_available: true, | 
|  | 652 | nocrt: true, | 
|  | 653 | } | 
|  | 654 | `) | 
|  | 655 |  | 
|  | 656 | // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib. | 
|  | 657 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
|  | 658 | cc_library { | 
|  | 659 | name: "libvndksp", | 
|  | 660 | vendor_available: true, | 
|  | 661 | vndk: { | 
|  | 662 | enabled: true, | 
|  | 663 | support_system_process: true, | 
|  | 664 | }, | 
|  | 665 | shared_libs: ["libnonvndk"], | 
|  | 666 | nocrt: true, | 
|  | 667 | } | 
|  | 668 |  | 
|  | 669 | cc_library { | 
|  | 670 | name: "libnonvndk", | 
|  | 671 | vendor_available: true, | 
|  | 672 | nocrt: true, | 
|  | 673 | } | 
|  | 674 | `) | 
|  | 675 |  | 
|  | 676 | // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib. | 
|  | 677 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
|  | 678 | cc_library { | 
|  | 679 | name: "libvndkspprivate", | 
|  | 680 | vendor_available: false, | 
|  | 681 | vndk: { | 
|  | 682 | enabled: true, | 
|  | 683 | support_system_process: true, | 
|  | 684 | }, | 
|  | 685 | shared_libs: ["libnonvndk"], | 
|  | 686 | nocrt: true, | 
|  | 687 | } | 
|  | 688 |  | 
|  | 689 | cc_library { | 
|  | 690 | name: "libnonvndk", | 
|  | 691 | vendor_available: true, | 
|  | 692 | nocrt: true, | 
|  | 693 | } | 
|  | 694 | `) | 
|  | 695 | } | 
|  | 696 |  | 
|  | 697 | func TestDoubleLoadbleDep(t *testing.T) { | 
|  | 698 | // okay to link : LLNDK -> double_loadable VNDK | 
|  | 699 | testCc(t, ` | 
|  | 700 | cc_library { | 
|  | 701 | name: "libllndk", | 
|  | 702 | shared_libs: ["libdoubleloadable"], | 
|  | 703 | } | 
|  | 704 |  | 
|  | 705 | llndk_library { | 
|  | 706 | name: "libllndk", | 
|  | 707 | symbol_file: "", | 
|  | 708 | } | 
|  | 709 |  | 
|  | 710 | cc_library { | 
|  | 711 | name: "libdoubleloadable", | 
|  | 712 | vendor_available: true, | 
|  | 713 | vndk: { | 
|  | 714 | enabled: true, | 
|  | 715 | }, | 
|  | 716 | double_loadable: true, | 
|  | 717 | } | 
|  | 718 | `) | 
|  | 719 | // okay to link : LLNDK -> VNDK-SP | 
|  | 720 | testCc(t, ` | 
|  | 721 | cc_library { | 
|  | 722 | name: "libllndk", | 
|  | 723 | shared_libs: ["libvndksp"], | 
|  | 724 | } | 
|  | 725 |  | 
|  | 726 | llndk_library { | 
|  | 727 | name: "libllndk", | 
|  | 728 | symbol_file: "", | 
|  | 729 | } | 
|  | 730 |  | 
|  | 731 | cc_library { | 
|  | 732 | name: "libvndksp", | 
|  | 733 | vendor_available: true, | 
|  | 734 | vndk: { | 
|  | 735 | enabled: true, | 
|  | 736 | support_system_process: true, | 
|  | 737 | }, | 
|  | 738 | } | 
|  | 739 | `) | 
|  | 740 | // okay to link : double_loadable -> double_loadable | 
|  | 741 | testCc(t, ` | 
|  | 742 | cc_library { | 
|  | 743 | name: "libdoubleloadable1", | 
|  | 744 | shared_libs: ["libdoubleloadable2"], | 
|  | 745 | vendor_available: true, | 
|  | 746 | double_loadable: true, | 
|  | 747 | } | 
|  | 748 |  | 
|  | 749 | cc_library { | 
|  | 750 | name: "libdoubleloadable2", | 
|  | 751 | vendor_available: true, | 
|  | 752 | double_loadable: true, | 
|  | 753 | } | 
|  | 754 | `) | 
|  | 755 | // okay to link : double_loadable VNDK -> double_loadable VNDK private | 
|  | 756 | testCc(t, ` | 
|  | 757 | cc_library { | 
|  | 758 | name: "libdoubleloadable", | 
|  | 759 | vendor_available: true, | 
|  | 760 | vndk: { | 
|  | 761 | enabled: true, | 
|  | 762 | }, | 
|  | 763 | double_loadable: true, | 
|  | 764 | shared_libs: ["libnondoubleloadable"], | 
|  | 765 | } | 
|  | 766 |  | 
|  | 767 | cc_library { | 
|  | 768 | name: "libnondoubleloadable", | 
|  | 769 | vendor_available: false, | 
|  | 770 | vndk: { | 
|  | 771 | enabled: true, | 
|  | 772 | }, | 
|  | 773 | double_loadable: true, | 
|  | 774 | } | 
|  | 775 | `) | 
|  | 776 | // okay to link : LLNDK -> core-only -> vendor_available & double_loadable | 
|  | 777 | testCc(t, ` | 
|  | 778 | cc_library { | 
|  | 779 | name: "libllndk", | 
|  | 780 | shared_libs: ["libcoreonly"], | 
|  | 781 | } | 
|  | 782 |  | 
|  | 783 | llndk_library { | 
|  | 784 | name: "libllndk", | 
|  | 785 | symbol_file: "", | 
|  | 786 | } | 
|  | 787 |  | 
|  | 788 | cc_library { | 
|  | 789 | name: "libcoreonly", | 
|  | 790 | shared_libs: ["libvendoravailable"], | 
|  | 791 | } | 
|  | 792 |  | 
|  | 793 | // indirect dependency of LLNDK | 
|  | 794 | cc_library { | 
|  | 795 | name: "libvendoravailable", | 
|  | 796 | vendor_available: true, | 
|  | 797 | double_loadable: true, | 
|  | 798 | } | 
|  | 799 | `) | 
|  | 800 | } | 
|  | 801 |  | 
| Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 802 | func TestVendorSnapshot(t *testing.T) { | 
|  | 803 | bp := ` | 
|  | 804 | cc_library { | 
|  | 805 | name: "libvndk", | 
|  | 806 | vendor_available: true, | 
|  | 807 | vndk: { | 
|  | 808 | enabled: true, | 
|  | 809 | }, | 
|  | 810 | nocrt: true, | 
|  | 811 | } | 
|  | 812 |  | 
|  | 813 | cc_library { | 
|  | 814 | name: "libvendor", | 
|  | 815 | vendor: true, | 
|  | 816 | nocrt: true, | 
|  | 817 | } | 
|  | 818 |  | 
|  | 819 | cc_library { | 
|  | 820 | name: "libvendor_available", | 
|  | 821 | vendor_available: true, | 
|  | 822 | nocrt: true, | 
|  | 823 | } | 
|  | 824 |  | 
|  | 825 | cc_library_headers { | 
|  | 826 | name: "libvendor_headers", | 
|  | 827 | vendor_available: true, | 
|  | 828 | nocrt: true, | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | cc_binary { | 
|  | 832 | name: "vendor_bin", | 
|  | 833 | vendor: true, | 
|  | 834 | nocrt: true, | 
|  | 835 | } | 
|  | 836 |  | 
|  | 837 | cc_binary { | 
|  | 838 | name: "vendor_available_bin", | 
|  | 839 | vendor_available: true, | 
|  | 840 | nocrt: true, | 
|  | 841 | } | 
|  | 842 | ` | 
|  | 843 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 844 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 845 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 846 | ctx := testCcWithConfig(t, config) | 
|  | 847 |  | 
|  | 848 | // Check Vendor snapshot output. | 
|  | 849 |  | 
|  | 850 | snapshotDir := "vendor-snapshot" | 
|  | 851 | snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64") | 
|  | 852 |  | 
|  | 853 | for _, arch := range [][]string{ | 
|  | 854 | []string{"arm64", "armv8-a"}, | 
|  | 855 | []string{"arm", "armv7-a-neon"}, | 
|  | 856 | } { | 
|  | 857 | archType := arch[0] | 
|  | 858 | archVariant := arch[1] | 
|  | 859 | archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) | 
|  | 860 |  | 
|  | 861 | // For shared libraries, only non-VNDK vendor_available modules are captured | 
|  | 862 | sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant) | 
|  | 863 | sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") | 
|  | 864 | checkSnapshot(t, ctx, "vendor-snapshot", "libvendor", "libvendor.so", sharedDir, sharedVariant) | 
|  | 865 | checkSnapshot(t, ctx, "vendor-snapshot", "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant) | 
|  | 866 |  | 
|  | 867 | // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured. | 
|  | 868 | staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant) | 
|  | 869 | staticDir := filepath.Join(snapshotVariantPath, archDir, "static") | 
|  | 870 | checkSnapshot(t, ctx, "vendor-snapshot", "libvndk", "libvndk.a", staticDir, staticVariant) | 
|  | 871 | checkSnapshot(t, ctx, "vendor-snapshot", "libvendor", "libvendor.a", staticDir, staticVariant) | 
|  | 872 | checkSnapshot(t, ctx, "vendor-snapshot", "libvendor_available", "libvendor_available.a", staticDir, staticVariant) | 
|  | 873 |  | 
|  | 874 | // For binary libraries, all vendor:true and vendor_available modules are captured. | 
|  | 875 | if archType == "arm64" { | 
|  | 876 | binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant) | 
|  | 877 | binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary") | 
|  | 878 | checkSnapshot(t, ctx, "vendor-snapshot", "vendor_bin", "vendor_bin", binaryDir, binaryVariant) | 
|  | 879 | checkSnapshot(t, ctx, "vendor-snapshot", "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant) | 
|  | 880 | } | 
|  | 881 | } | 
|  | 882 | } | 
|  | 883 |  | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 884 | func TestDoubleLoadableDepError(t *testing.T) { | 
|  | 885 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib. | 
|  | 886 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` | 
|  | 887 | cc_library { | 
|  | 888 | name: "libllndk", | 
|  | 889 | shared_libs: ["libnondoubleloadable"], | 
|  | 890 | } | 
|  | 891 |  | 
|  | 892 | llndk_library { | 
|  | 893 | name: "libllndk", | 
|  | 894 | symbol_file: "", | 
|  | 895 | } | 
|  | 896 |  | 
|  | 897 | cc_library { | 
|  | 898 | name: "libnondoubleloadable", | 
|  | 899 | vendor_available: true, | 
|  | 900 | vndk: { | 
|  | 901 | enabled: true, | 
|  | 902 | }, | 
|  | 903 | } | 
|  | 904 | `) | 
|  | 905 |  | 
|  | 906 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib. | 
|  | 907 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` | 
|  | 908 | cc_library { | 
|  | 909 | name: "libllndk", | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 910 | no_libcrt: true, | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 911 | shared_libs: ["libnondoubleloadable"], | 
|  | 912 | } | 
|  | 913 |  | 
|  | 914 | llndk_library { | 
|  | 915 | name: "libllndk", | 
|  | 916 | symbol_file: "", | 
|  | 917 | } | 
|  | 918 |  | 
|  | 919 | cc_library { | 
|  | 920 | name: "libnondoubleloadable", | 
|  | 921 | vendor_available: true, | 
|  | 922 | } | 
|  | 923 | `) | 
|  | 924 |  | 
|  | 925 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib. | 
|  | 926 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` | 
|  | 927 | cc_library { | 
|  | 928 | name: "libdoubleloadable", | 
|  | 929 | vendor_available: true, | 
|  | 930 | double_loadable: true, | 
|  | 931 | shared_libs: ["libnondoubleloadable"], | 
|  | 932 | } | 
|  | 933 |  | 
|  | 934 | cc_library { | 
|  | 935 | name: "libnondoubleloadable", | 
|  | 936 | vendor_available: true, | 
|  | 937 | } | 
|  | 938 | `) | 
|  | 939 |  | 
|  | 940 | // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib. | 
|  | 941 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` | 
|  | 942 | cc_library { | 
|  | 943 | name: "libdoubleloadable", | 
|  | 944 | vendor_available: true, | 
|  | 945 | double_loadable: true, | 
|  | 946 | shared_libs: ["libnondoubleloadable"], | 
|  | 947 | } | 
|  | 948 |  | 
|  | 949 | cc_library { | 
|  | 950 | name: "libnondoubleloadable", | 
|  | 951 | vendor_available: true, | 
|  | 952 | vndk: { | 
|  | 953 | enabled: true, | 
|  | 954 | }, | 
|  | 955 | } | 
|  | 956 | `) | 
|  | 957 |  | 
|  | 958 | // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib. | 
|  | 959 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` | 
|  | 960 | cc_library { | 
|  | 961 | name: "libdoubleloadable", | 
|  | 962 | vendor_available: true, | 
|  | 963 | vndk: { | 
|  | 964 | enabled: true, | 
|  | 965 | }, | 
|  | 966 | double_loadable: true, | 
|  | 967 | shared_libs: ["libnondoubleloadable"], | 
|  | 968 | } | 
|  | 969 |  | 
|  | 970 | cc_library { | 
|  | 971 | name: "libnondoubleloadable", | 
|  | 972 | vendor_available: false, | 
|  | 973 | vndk: { | 
|  | 974 | enabled: true, | 
|  | 975 | }, | 
|  | 976 | } | 
|  | 977 | `) | 
|  | 978 |  | 
|  | 979 | // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly. | 
|  | 980 | testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", ` | 
|  | 981 | cc_library { | 
|  | 982 | name: "libllndk", | 
|  | 983 | shared_libs: ["libcoreonly"], | 
|  | 984 | } | 
|  | 985 |  | 
|  | 986 | llndk_library { | 
|  | 987 | name: "libllndk", | 
|  | 988 | symbol_file: "", | 
|  | 989 | } | 
|  | 990 |  | 
|  | 991 | cc_library { | 
|  | 992 | name: "libcoreonly", | 
|  | 993 | shared_libs: ["libvendoravailable"], | 
|  | 994 | } | 
|  | 995 |  | 
|  | 996 | // indirect dependency of LLNDK | 
|  | 997 | cc_library { | 
|  | 998 | name: "libvendoravailable", | 
|  | 999 | vendor_available: true, | 
|  | 1000 | } | 
|  | 1001 | `) | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1002 | } | 
|  | 1003 |  | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1004 | func TestVndkExt(t *testing.T) { | 
|  | 1005 | // This test checks the VNDK-Ext properties. | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1006 | bp := ` | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1007 | cc_library { | 
|  | 1008 | name: "libvndk", | 
|  | 1009 | vendor_available: true, | 
|  | 1010 | vndk: { | 
|  | 1011 | enabled: true, | 
|  | 1012 | }, | 
|  | 1013 | nocrt: true, | 
|  | 1014 | } | 
| Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1015 | cc_library { | 
|  | 1016 | name: "libvndk2", | 
|  | 1017 | vendor_available: true, | 
|  | 1018 | vndk: { | 
|  | 1019 | enabled: true, | 
|  | 1020 | }, | 
|  | 1021 | target: { | 
|  | 1022 | vendor: { | 
|  | 1023 | suffix: "-suffix", | 
|  | 1024 | }, | 
|  | 1025 | }, | 
|  | 1026 | nocrt: true, | 
|  | 1027 | } | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1028 |  | 
|  | 1029 | cc_library { | 
|  | 1030 | name: "libvndk_ext", | 
|  | 1031 | vendor: true, | 
|  | 1032 | vndk: { | 
|  | 1033 | enabled: true, | 
|  | 1034 | extends: "libvndk", | 
|  | 1035 | }, | 
|  | 1036 | nocrt: true, | 
|  | 1037 | } | 
| Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1038 |  | 
|  | 1039 | cc_library { | 
|  | 1040 | name: "libvndk2_ext", | 
|  | 1041 | vendor: true, | 
|  | 1042 | vndk: { | 
|  | 1043 | enabled: true, | 
|  | 1044 | extends: "libvndk2", | 
|  | 1045 | }, | 
|  | 1046 | nocrt: true, | 
|  | 1047 | } | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1048 |  | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1049 | cc_library { | 
|  | 1050 | name: "libvndk_ext_product", | 
|  | 1051 | product_specific: true, | 
|  | 1052 | vndk: { | 
|  | 1053 | enabled: true, | 
|  | 1054 | extends: "libvndk", | 
|  | 1055 | }, | 
|  | 1056 | nocrt: true, | 
|  | 1057 | } | 
| Jooyung Han | 4c2b942 | 2019-10-22 19:53:47 +0900 | [diff] [blame] | 1058 |  | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1059 | cc_library { | 
|  | 1060 | name: "libvndk2_ext_product", | 
|  | 1061 | product_specific: true, | 
|  | 1062 | vndk: { | 
|  | 1063 | enabled: true, | 
|  | 1064 | extends: "libvndk2", | 
|  | 1065 | }, | 
|  | 1066 | nocrt: true, | 
|  | 1067 | } | 
|  | 1068 | ` | 
|  | 1069 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 1070 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 1071 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") | 
|  | 1072 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 1073 |  | 
|  | 1074 | ctx := testCcWithConfig(t, config) | 
|  | 1075 |  | 
|  | 1076 | checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant) | 
|  | 1077 | checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant) | 
|  | 1078 |  | 
|  | 1079 | mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module) | 
|  | 1080 | assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so") | 
|  | 1081 |  | 
|  | 1082 | mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module) | 
|  | 1083 | assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so") | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1084 | } | 
|  | 1085 |  | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1086 | func TestVndkExtWithoutBoardVndkVersion(t *testing.T) { | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1087 | // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set. | 
|  | 1088 | ctx := testCcNoVndk(t, ` | 
|  | 1089 | cc_library { | 
|  | 1090 | name: "libvndk", | 
|  | 1091 | vendor_available: true, | 
|  | 1092 | vndk: { | 
|  | 1093 | enabled: true, | 
|  | 1094 | }, | 
|  | 1095 | nocrt: true, | 
|  | 1096 | } | 
|  | 1097 |  | 
|  | 1098 | cc_library { | 
|  | 1099 | name: "libvndk_ext", | 
|  | 1100 | vendor: true, | 
|  | 1101 | vndk: { | 
|  | 1102 | enabled: true, | 
|  | 1103 | extends: "libvndk", | 
|  | 1104 | }, | 
|  | 1105 | nocrt: true, | 
|  | 1106 | } | 
|  | 1107 | `) | 
|  | 1108 |  | 
|  | 1109 | // Ensures that the core variant of "libvndk_ext" can be found. | 
|  | 1110 | mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module) | 
|  | 1111 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { | 
|  | 1112 | t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends) | 
|  | 1113 | } | 
|  | 1114 | } | 
|  | 1115 |  | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1116 | func TestVndkExtWithoutProductVndkVersion(t *testing.T) { | 
|  | 1117 | // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set. | 
|  | 1118 | ctx := testCc(t, ` | 
|  | 1119 | cc_library { | 
|  | 1120 | name: "libvndk", | 
|  | 1121 | vendor_available: true, | 
|  | 1122 | vndk: { | 
|  | 1123 | enabled: true, | 
|  | 1124 | }, | 
|  | 1125 | nocrt: true, | 
|  | 1126 | } | 
|  | 1127 |  | 
|  | 1128 | cc_library { | 
|  | 1129 | name: "libvndk_ext_product", | 
|  | 1130 | product_specific: true, | 
|  | 1131 | vndk: { | 
|  | 1132 | enabled: true, | 
|  | 1133 | extends: "libvndk", | 
|  | 1134 | }, | 
|  | 1135 | nocrt: true, | 
|  | 1136 | } | 
|  | 1137 | `) | 
|  | 1138 |  | 
|  | 1139 | // Ensures that the core variant of "libvndk_ext_product" can be found. | 
|  | 1140 | mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module) | 
|  | 1141 | if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" { | 
|  | 1142 | t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends) | 
|  | 1143 | } | 
|  | 1144 | } | 
|  | 1145 |  | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1146 | func TestVndkExtError(t *testing.T) { | 
|  | 1147 | // This test ensures an error is emitted in ill-formed vndk-ext definition. | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1148 | 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] | 1149 | cc_library { | 
|  | 1150 | name: "libvndk", | 
|  | 1151 | vendor_available: true, | 
|  | 1152 | vndk: { | 
|  | 1153 | enabled: true, | 
|  | 1154 | }, | 
|  | 1155 | nocrt: true, | 
|  | 1156 | } | 
|  | 1157 |  | 
|  | 1158 | cc_library { | 
|  | 1159 | name: "libvndk_ext", | 
|  | 1160 | vndk: { | 
|  | 1161 | enabled: true, | 
|  | 1162 | extends: "libvndk", | 
|  | 1163 | }, | 
|  | 1164 | nocrt: true, | 
|  | 1165 | } | 
|  | 1166 | `) | 
|  | 1167 |  | 
|  | 1168 | testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` | 
|  | 1169 | cc_library { | 
|  | 1170 | name: "libvndk", | 
|  | 1171 | vendor_available: true, | 
|  | 1172 | vndk: { | 
|  | 1173 | enabled: true, | 
|  | 1174 | }, | 
|  | 1175 | nocrt: true, | 
|  | 1176 | } | 
|  | 1177 |  | 
|  | 1178 | cc_library { | 
|  | 1179 | name: "libvndk_ext", | 
|  | 1180 | vendor: true, | 
|  | 1181 | vndk: { | 
|  | 1182 | enabled: true, | 
|  | 1183 | }, | 
|  | 1184 | nocrt: true, | 
|  | 1185 | } | 
|  | 1186 | `) | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1187 |  | 
|  | 1188 | testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", ` | 
|  | 1189 | cc_library { | 
|  | 1190 | name: "libvndk", | 
|  | 1191 | vendor_available: true, | 
|  | 1192 | vndk: { | 
|  | 1193 | enabled: true, | 
|  | 1194 | }, | 
|  | 1195 | nocrt: true, | 
|  | 1196 | } | 
|  | 1197 |  | 
|  | 1198 | cc_library { | 
|  | 1199 | name: "libvndk_ext_product", | 
|  | 1200 | product_specific: true, | 
|  | 1201 | vndk: { | 
|  | 1202 | enabled: true, | 
|  | 1203 | }, | 
|  | 1204 | nocrt: true, | 
|  | 1205 | } | 
|  | 1206 | `) | 
|  | 1207 |  | 
|  | 1208 | testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", ` | 
|  | 1209 | cc_library { | 
|  | 1210 | name: "libvndk", | 
|  | 1211 | vendor_available: true, | 
|  | 1212 | vndk: { | 
|  | 1213 | enabled: true, | 
|  | 1214 | }, | 
|  | 1215 | nocrt: true, | 
|  | 1216 | } | 
|  | 1217 |  | 
|  | 1218 | cc_library { | 
|  | 1219 | name: "libvndk_ext_product", | 
|  | 1220 | product_specific: true, | 
|  | 1221 | vendor_available: true, | 
|  | 1222 | vndk: { | 
|  | 1223 | enabled: true, | 
|  | 1224 | extends: "libvndk", | 
|  | 1225 | }, | 
|  | 1226 | nocrt: true, | 
|  | 1227 | } | 
|  | 1228 | `) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1229 | } | 
|  | 1230 |  | 
|  | 1231 | func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) { | 
|  | 1232 | // This test ensures an error is emitted for inconsistent support_system_process. | 
|  | 1233 | testCcError(t, "module \".*\" with mismatched support_system_process", ` | 
|  | 1234 | cc_library { | 
|  | 1235 | name: "libvndk", | 
|  | 1236 | vendor_available: true, | 
|  | 1237 | vndk: { | 
|  | 1238 | enabled: true, | 
|  | 1239 | }, | 
|  | 1240 | nocrt: true, | 
|  | 1241 | } | 
|  | 1242 |  | 
|  | 1243 | cc_library { | 
|  | 1244 | name: "libvndk_sp_ext", | 
|  | 1245 | vendor: true, | 
|  | 1246 | vndk: { | 
|  | 1247 | enabled: true, | 
|  | 1248 | extends: "libvndk", | 
|  | 1249 | support_system_process: true, | 
|  | 1250 | }, | 
|  | 1251 | nocrt: true, | 
|  | 1252 | } | 
|  | 1253 | `) | 
|  | 1254 |  | 
|  | 1255 | testCcError(t, "module \".*\" with mismatched support_system_process", ` | 
|  | 1256 | cc_library { | 
|  | 1257 | name: "libvndk_sp", | 
|  | 1258 | vendor_available: true, | 
|  | 1259 | vndk: { | 
|  | 1260 | enabled: true, | 
|  | 1261 | support_system_process: true, | 
|  | 1262 | }, | 
|  | 1263 | nocrt: true, | 
|  | 1264 | } | 
|  | 1265 |  | 
|  | 1266 | cc_library { | 
|  | 1267 | name: "libvndk_ext", | 
|  | 1268 | vendor: true, | 
|  | 1269 | vndk: { | 
|  | 1270 | enabled: true, | 
|  | 1271 | extends: "libvndk_sp", | 
|  | 1272 | }, | 
|  | 1273 | nocrt: true, | 
|  | 1274 | } | 
|  | 1275 | `) | 
|  | 1276 | } | 
|  | 1277 |  | 
|  | 1278 | func TestVndkExtVendorAvailableFalseError(t *testing.T) { | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1279 | // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1280 | // with `vendor_available: false`. | 
|  | 1281 | testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` | 
|  | 1282 | cc_library { | 
|  | 1283 | name: "libvndk", | 
|  | 1284 | vendor_available: false, | 
|  | 1285 | vndk: { | 
|  | 1286 | enabled: true, | 
|  | 1287 | }, | 
|  | 1288 | nocrt: true, | 
|  | 1289 | } | 
|  | 1290 |  | 
|  | 1291 | cc_library { | 
|  | 1292 | name: "libvndk_ext", | 
|  | 1293 | vendor: true, | 
|  | 1294 | vndk: { | 
|  | 1295 | enabled: true, | 
|  | 1296 | extends: "libvndk", | 
|  | 1297 | }, | 
|  | 1298 | nocrt: true, | 
|  | 1299 | } | 
|  | 1300 | `) | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1301 |  | 
|  | 1302 | testCcErrorProductVndk(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", ` | 
|  | 1303 | cc_library { | 
|  | 1304 | name: "libvndk", | 
|  | 1305 | vendor_available: false, | 
|  | 1306 | vndk: { | 
|  | 1307 | enabled: true, | 
|  | 1308 | }, | 
|  | 1309 | nocrt: true, | 
|  | 1310 | } | 
|  | 1311 |  | 
|  | 1312 | cc_library { | 
|  | 1313 | name: "libvndk_ext_product", | 
|  | 1314 | product_specific: true, | 
|  | 1315 | vndk: { | 
|  | 1316 | enabled: true, | 
|  | 1317 | extends: "libvndk", | 
|  | 1318 | }, | 
|  | 1319 | nocrt: true, | 
|  | 1320 | } | 
|  | 1321 | `) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1322 | } | 
|  | 1323 |  | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1324 | func TestVendorModuleUseVndkExt(t *testing.T) { | 
|  | 1325 | // 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] | 1326 | testCc(t, ` | 
|  | 1327 | cc_library { | 
|  | 1328 | name: "libvndk", | 
|  | 1329 | vendor_available: true, | 
|  | 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 | cc_library { | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1347 | name: "libvndk_sp", | 
|  | 1348 | vendor_available: true, | 
|  | 1349 | vndk: { | 
|  | 1350 | enabled: true, | 
|  | 1351 | support_system_process: true, | 
|  | 1352 | }, | 
|  | 1353 | nocrt: true, | 
|  | 1354 | } | 
|  | 1355 |  | 
|  | 1356 | cc_library { | 
|  | 1357 | name: "libvndk_sp_ext", | 
|  | 1358 | vendor: true, | 
|  | 1359 | vndk: { | 
|  | 1360 | enabled: true, | 
|  | 1361 | extends: "libvndk_sp", | 
|  | 1362 | support_system_process: true, | 
|  | 1363 | }, | 
|  | 1364 | nocrt: true, | 
|  | 1365 | } | 
|  | 1366 |  | 
|  | 1367 | cc_library { | 
|  | 1368 | name: "libvendor", | 
|  | 1369 | vendor: true, | 
|  | 1370 | shared_libs: ["libvndk_ext", "libvndk_sp_ext"], | 
|  | 1371 | nocrt: true, | 
|  | 1372 | } | 
|  | 1373 | `) | 
|  | 1374 | } | 
|  | 1375 |  | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1376 | func TestVndkExtUseVendorLib(t *testing.T) { | 
|  | 1377 | // 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] | 1378 | testCc(t, ` | 
|  | 1379 | cc_library { | 
|  | 1380 | name: "libvndk", | 
|  | 1381 | vendor_available: true, | 
|  | 1382 | vndk: { | 
|  | 1383 | enabled: true, | 
|  | 1384 | }, | 
|  | 1385 | nocrt: true, | 
|  | 1386 | } | 
|  | 1387 |  | 
|  | 1388 | cc_library { | 
|  | 1389 | name: "libvndk_ext", | 
|  | 1390 | vendor: true, | 
|  | 1391 | vndk: { | 
|  | 1392 | enabled: true, | 
|  | 1393 | extends: "libvndk", | 
|  | 1394 | }, | 
|  | 1395 | shared_libs: ["libvendor"], | 
|  | 1396 | nocrt: true, | 
|  | 1397 | } | 
|  | 1398 |  | 
|  | 1399 | cc_library { | 
|  | 1400 | name: "libvendor", | 
|  | 1401 | vendor: true, | 
|  | 1402 | nocrt: true, | 
|  | 1403 | } | 
|  | 1404 | `) | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1405 |  | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1406 | // This test ensures a VNDK-SP-Ext library can depend on a vendor library. | 
|  | 1407 | testCc(t, ` | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1408 | cc_library { | 
|  | 1409 | name: "libvndk_sp", | 
|  | 1410 | vendor_available: true, | 
|  | 1411 | vndk: { | 
|  | 1412 | enabled: true, | 
|  | 1413 | support_system_process: true, | 
|  | 1414 | }, | 
|  | 1415 | nocrt: true, | 
|  | 1416 | } | 
|  | 1417 |  | 
|  | 1418 | cc_library { | 
|  | 1419 | name: "libvndk_sp_ext", | 
|  | 1420 | vendor: true, | 
|  | 1421 | vndk: { | 
|  | 1422 | enabled: true, | 
|  | 1423 | extends: "libvndk_sp", | 
|  | 1424 | support_system_process: true, | 
|  | 1425 | }, | 
|  | 1426 | shared_libs: ["libvendor"],  // Cause an error | 
|  | 1427 | nocrt: true, | 
|  | 1428 | } | 
|  | 1429 |  | 
|  | 1430 | cc_library { | 
|  | 1431 | name: "libvendor", | 
|  | 1432 | vendor: true, | 
|  | 1433 | nocrt: true, | 
|  | 1434 | } | 
|  | 1435 | `) | 
|  | 1436 | } | 
|  | 1437 |  | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1438 | func TestProductVndkExtDependency(t *testing.T) { | 
|  | 1439 | bp := ` | 
|  | 1440 | cc_library { | 
|  | 1441 | name: "libvndk", | 
|  | 1442 | vendor_available: true, | 
|  | 1443 | vndk: { | 
|  | 1444 | enabled: true, | 
|  | 1445 | }, | 
|  | 1446 | nocrt: true, | 
|  | 1447 | } | 
|  | 1448 |  | 
|  | 1449 | cc_library { | 
|  | 1450 | name: "libvndk_ext_product", | 
|  | 1451 | product_specific: true, | 
|  | 1452 | vndk: { | 
|  | 1453 | enabled: true, | 
|  | 1454 | extends: "libvndk", | 
|  | 1455 | }, | 
|  | 1456 | shared_libs: ["libproduct_for_vndklibs"], | 
|  | 1457 | nocrt: true, | 
|  | 1458 | } | 
|  | 1459 |  | 
|  | 1460 | cc_library { | 
|  | 1461 | name: "libvndk_sp", | 
|  | 1462 | vendor_available: true, | 
|  | 1463 | vndk: { | 
|  | 1464 | enabled: true, | 
|  | 1465 | support_system_process: true, | 
|  | 1466 | }, | 
|  | 1467 | nocrt: true, | 
|  | 1468 | } | 
|  | 1469 |  | 
|  | 1470 | cc_library { | 
|  | 1471 | name: "libvndk_sp_ext_product", | 
|  | 1472 | product_specific: true, | 
|  | 1473 | vndk: { | 
|  | 1474 | enabled: true, | 
|  | 1475 | extends: "libvndk_sp", | 
|  | 1476 | support_system_process: true, | 
|  | 1477 | }, | 
|  | 1478 | shared_libs: ["libproduct_for_vndklibs"], | 
|  | 1479 | nocrt: true, | 
|  | 1480 | } | 
|  | 1481 |  | 
|  | 1482 | cc_library { | 
|  | 1483 | name: "libproduct", | 
|  | 1484 | product_specific: true, | 
|  | 1485 | shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"], | 
|  | 1486 | nocrt: true, | 
|  | 1487 | } | 
|  | 1488 |  | 
|  | 1489 | cc_library { | 
|  | 1490 | name: "libproduct_for_vndklibs", | 
|  | 1491 | product_specific: true, | 
|  | 1492 | nocrt: true, | 
|  | 1493 | } | 
|  | 1494 | ` | 
|  | 1495 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 1496 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 1497 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") | 
|  | 1498 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 1499 |  | 
|  | 1500 | testCcWithConfig(t, config) | 
|  | 1501 | } | 
|  | 1502 |  | 
| Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 1503 | func TestVndkSpExtUseVndkError(t *testing.T) { | 
|  | 1504 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK | 
|  | 1505 | // library. | 
|  | 1506 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
|  | 1507 | cc_library { | 
|  | 1508 | name: "libvndk", | 
|  | 1509 | vendor_available: true, | 
|  | 1510 | vndk: { | 
|  | 1511 | enabled: true, | 
|  | 1512 | }, | 
|  | 1513 | nocrt: true, | 
|  | 1514 | } | 
|  | 1515 |  | 
|  | 1516 | cc_library { | 
|  | 1517 | name: "libvndk_sp", | 
|  | 1518 | vendor_available: true, | 
|  | 1519 | vndk: { | 
|  | 1520 | enabled: true, | 
|  | 1521 | support_system_process: true, | 
|  | 1522 | }, | 
|  | 1523 | nocrt: true, | 
|  | 1524 | } | 
|  | 1525 |  | 
|  | 1526 | cc_library { | 
|  | 1527 | name: "libvndk_sp_ext", | 
|  | 1528 | vendor: true, | 
|  | 1529 | vndk: { | 
|  | 1530 | enabled: true, | 
|  | 1531 | extends: "libvndk_sp", | 
|  | 1532 | support_system_process: true, | 
|  | 1533 | }, | 
|  | 1534 | shared_libs: ["libvndk"],  // Cause an error | 
|  | 1535 | nocrt: true, | 
|  | 1536 | } | 
|  | 1537 | `) | 
|  | 1538 |  | 
|  | 1539 | // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext | 
|  | 1540 | // library. | 
|  | 1541 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
|  | 1542 | cc_library { | 
|  | 1543 | name: "libvndk", | 
|  | 1544 | vendor_available: true, | 
|  | 1545 | vndk: { | 
|  | 1546 | enabled: true, | 
|  | 1547 | }, | 
|  | 1548 | nocrt: true, | 
|  | 1549 | } | 
|  | 1550 |  | 
|  | 1551 | cc_library { | 
|  | 1552 | name: "libvndk_ext", | 
|  | 1553 | vendor: true, | 
|  | 1554 | vndk: { | 
|  | 1555 | enabled: true, | 
|  | 1556 | extends: "libvndk", | 
|  | 1557 | }, | 
|  | 1558 | nocrt: true, | 
|  | 1559 | } | 
|  | 1560 |  | 
|  | 1561 | cc_library { | 
|  | 1562 | name: "libvndk_sp", | 
|  | 1563 | vendor_available: true, | 
|  | 1564 | vndk: { | 
|  | 1565 | enabled: true, | 
|  | 1566 | support_system_process: true, | 
|  | 1567 | }, | 
|  | 1568 | nocrt: true, | 
|  | 1569 | } | 
|  | 1570 |  | 
|  | 1571 | cc_library { | 
|  | 1572 | name: "libvndk_sp_ext", | 
|  | 1573 | vendor: true, | 
|  | 1574 | vndk: { | 
|  | 1575 | enabled: true, | 
|  | 1576 | extends: "libvndk_sp", | 
|  | 1577 | support_system_process: true, | 
|  | 1578 | }, | 
|  | 1579 | shared_libs: ["libvndk_ext"],  // Cause an error | 
|  | 1580 | nocrt: true, | 
|  | 1581 | } | 
|  | 1582 | `) | 
|  | 1583 | } | 
|  | 1584 |  | 
|  | 1585 | func TestVndkUseVndkExtError(t *testing.T) { | 
|  | 1586 | // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a | 
|  | 1587 | // VNDK-Ext/VNDK-SP-Ext library. | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1588 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` | 
|  | 1589 | cc_library { | 
|  | 1590 | name: "libvndk", | 
|  | 1591 | vendor_available: true, | 
|  | 1592 | vndk: { | 
|  | 1593 | enabled: true, | 
|  | 1594 | }, | 
|  | 1595 | nocrt: true, | 
|  | 1596 | } | 
|  | 1597 |  | 
|  | 1598 | cc_library { | 
|  | 1599 | name: "libvndk_ext", | 
|  | 1600 | vendor: true, | 
|  | 1601 | vndk: { | 
|  | 1602 | enabled: true, | 
|  | 1603 | extends: "libvndk", | 
|  | 1604 | }, | 
|  | 1605 | nocrt: true, | 
|  | 1606 | } | 
|  | 1607 |  | 
|  | 1608 | cc_library { | 
|  | 1609 | name: "libvndk2", | 
|  | 1610 | vendor_available: true, | 
|  | 1611 | vndk: { | 
|  | 1612 | enabled: true, | 
|  | 1613 | }, | 
|  | 1614 | shared_libs: ["libvndk_ext"], | 
|  | 1615 | nocrt: true, | 
|  | 1616 | } | 
|  | 1617 | `) | 
|  | 1618 |  | 
| Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1619 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1620 | cc_library { | 
|  | 1621 | name: "libvndk", | 
|  | 1622 | vendor_available: true, | 
|  | 1623 | vndk: { | 
|  | 1624 | enabled: true, | 
|  | 1625 | }, | 
|  | 1626 | nocrt: true, | 
|  | 1627 | } | 
|  | 1628 |  | 
|  | 1629 | cc_library { | 
|  | 1630 | name: "libvndk_ext", | 
|  | 1631 | vendor: true, | 
|  | 1632 | vndk: { | 
|  | 1633 | enabled: true, | 
|  | 1634 | extends: "libvndk", | 
|  | 1635 | }, | 
|  | 1636 | nocrt: true, | 
|  | 1637 | } | 
|  | 1638 |  | 
|  | 1639 | cc_library { | 
|  | 1640 | name: "libvndk2", | 
|  | 1641 | vendor_available: true, | 
|  | 1642 | vndk: { | 
|  | 1643 | enabled: true, | 
|  | 1644 | }, | 
|  | 1645 | target: { | 
|  | 1646 | vendor: { | 
|  | 1647 | shared_libs: ["libvndk_ext"], | 
|  | 1648 | }, | 
|  | 1649 | }, | 
|  | 1650 | nocrt: true, | 
|  | 1651 | } | 
|  | 1652 | `) | 
|  | 1653 |  | 
|  | 1654 | testCcError(t, "dependency \".*\" of \".*\" missing variant", ` | 
|  | 1655 | cc_library { | 
|  | 1656 | name: "libvndk_sp", | 
|  | 1657 | vendor_available: true, | 
|  | 1658 | vndk: { | 
|  | 1659 | enabled: true, | 
|  | 1660 | support_system_process: true, | 
|  | 1661 | }, | 
|  | 1662 | nocrt: true, | 
|  | 1663 | } | 
|  | 1664 |  | 
|  | 1665 | cc_library { | 
|  | 1666 | name: "libvndk_sp_ext", | 
|  | 1667 | vendor: true, | 
|  | 1668 | vndk: { | 
|  | 1669 | enabled: true, | 
|  | 1670 | extends: "libvndk_sp", | 
|  | 1671 | support_system_process: true, | 
|  | 1672 | }, | 
|  | 1673 | nocrt: true, | 
|  | 1674 | } | 
|  | 1675 |  | 
|  | 1676 | cc_library { | 
|  | 1677 | name: "libvndk_sp_2", | 
|  | 1678 | vendor_available: true, | 
|  | 1679 | vndk: { | 
|  | 1680 | enabled: true, | 
|  | 1681 | support_system_process: true, | 
|  | 1682 | }, | 
|  | 1683 | shared_libs: ["libvndk_sp_ext"], | 
|  | 1684 | nocrt: true, | 
|  | 1685 | } | 
|  | 1686 | `) | 
|  | 1687 |  | 
| Martin Stjernholm | ef449fe | 2018-11-06 16:12:13 +0000 | [diff] [blame] | 1688 | testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", ` | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1689 | cc_library { | 
|  | 1690 | name: "libvndk_sp", | 
|  | 1691 | vendor_available: true, | 
|  | 1692 | vndk: { | 
|  | 1693 | enabled: true, | 
|  | 1694 | }, | 
|  | 1695 | nocrt: true, | 
|  | 1696 | } | 
|  | 1697 |  | 
|  | 1698 | cc_library { | 
|  | 1699 | name: "libvndk_sp_ext", | 
|  | 1700 | vendor: true, | 
|  | 1701 | vndk: { | 
|  | 1702 | enabled: true, | 
|  | 1703 | extends: "libvndk_sp", | 
|  | 1704 | }, | 
|  | 1705 | nocrt: true, | 
|  | 1706 | } | 
|  | 1707 |  | 
|  | 1708 | cc_library { | 
|  | 1709 | name: "libvndk_sp2", | 
|  | 1710 | vendor_available: true, | 
|  | 1711 | vndk: { | 
|  | 1712 | enabled: true, | 
|  | 1713 | }, | 
|  | 1714 | target: { | 
|  | 1715 | vendor: { | 
|  | 1716 | shared_libs: ["libvndk_sp_ext"], | 
|  | 1717 | }, | 
|  | 1718 | }, | 
|  | 1719 | nocrt: true, | 
|  | 1720 | } | 
|  | 1721 | `) | 
|  | 1722 | } | 
|  | 1723 |  | 
| Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1724 | func TestEnforceProductVndkVersion(t *testing.T) { | 
|  | 1725 | bp := ` | 
|  | 1726 | cc_library { | 
|  | 1727 | name: "libllndk", | 
|  | 1728 | } | 
|  | 1729 | llndk_library { | 
|  | 1730 | name: "libllndk", | 
|  | 1731 | symbol_file: "", | 
|  | 1732 | } | 
|  | 1733 | cc_library { | 
|  | 1734 | name: "libvndk", | 
|  | 1735 | vendor_available: true, | 
|  | 1736 | vndk: { | 
|  | 1737 | enabled: true, | 
|  | 1738 | }, | 
|  | 1739 | nocrt: true, | 
|  | 1740 | } | 
|  | 1741 | cc_library { | 
|  | 1742 | name: "libvndk_sp", | 
|  | 1743 | vendor_available: true, | 
|  | 1744 | vndk: { | 
|  | 1745 | enabled: true, | 
|  | 1746 | support_system_process: true, | 
|  | 1747 | }, | 
|  | 1748 | nocrt: true, | 
|  | 1749 | } | 
|  | 1750 | cc_library { | 
|  | 1751 | name: "libva", | 
|  | 1752 | vendor_available: true, | 
|  | 1753 | nocrt: true, | 
|  | 1754 | } | 
|  | 1755 | cc_library { | 
|  | 1756 | name: "libproduct_va", | 
|  | 1757 | product_specific: true, | 
|  | 1758 | vendor_available: true, | 
|  | 1759 | nocrt: true, | 
|  | 1760 | } | 
|  | 1761 | cc_library { | 
|  | 1762 | name: "libprod", | 
|  | 1763 | product_specific: true, | 
|  | 1764 | shared_libs: [ | 
|  | 1765 | "libllndk", | 
|  | 1766 | "libvndk", | 
|  | 1767 | "libvndk_sp", | 
|  | 1768 | "libva", | 
|  | 1769 | "libproduct_va", | 
|  | 1770 | ], | 
|  | 1771 | nocrt: true, | 
|  | 1772 | } | 
|  | 1773 | cc_library { | 
|  | 1774 | name: "libvendor", | 
|  | 1775 | vendor: true, | 
|  | 1776 | shared_libs: [ | 
|  | 1777 | "libllndk", | 
|  | 1778 | "libvndk", | 
|  | 1779 | "libvndk_sp", | 
|  | 1780 | "libva", | 
|  | 1781 | "libproduct_va", | 
|  | 1782 | ], | 
|  | 1783 | nocrt: true, | 
|  | 1784 | } | 
|  | 1785 | ` | 
|  | 1786 |  | 
|  | 1787 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 1788 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 1789 | config.TestProductVariables.ProductVndkVersion = StringPtr("current") | 
|  | 1790 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 1791 |  | 
|  | 1792 | ctx := testCcWithConfig(t, config) | 
|  | 1793 |  | 
| Justin Yun | 98df0d1 | 2020-02-28 15:07:59 +0900 | [diff] [blame] | 1794 | checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "", productVariant) | 
|  | 1795 | checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "", productVariant) | 
| Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1796 | } | 
|  | 1797 |  | 
|  | 1798 | func TestEnforceProductVndkVersionErrors(t *testing.T) { | 
|  | 1799 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` | 
|  | 1800 | cc_library { | 
|  | 1801 | name: "libprod", | 
|  | 1802 | product_specific: true, | 
|  | 1803 | shared_libs: [ | 
|  | 1804 | "libvendor", | 
|  | 1805 | ], | 
|  | 1806 | nocrt: true, | 
|  | 1807 | } | 
|  | 1808 | cc_library { | 
|  | 1809 | name: "libvendor", | 
|  | 1810 | vendor: true, | 
|  | 1811 | nocrt: true, | 
|  | 1812 | } | 
|  | 1813 | `) | 
|  | 1814 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` | 
|  | 1815 | cc_library { | 
|  | 1816 | name: "libprod", | 
|  | 1817 | product_specific: true, | 
|  | 1818 | shared_libs: [ | 
|  | 1819 | "libsystem", | 
|  | 1820 | ], | 
|  | 1821 | nocrt: true, | 
|  | 1822 | } | 
|  | 1823 | cc_library { | 
|  | 1824 | name: "libsystem", | 
|  | 1825 | nocrt: true, | 
|  | 1826 | } | 
|  | 1827 | `) | 
|  | 1828 | testCcErrorProductVndk(t, "Vendor module that is not VNDK should not link to \".*\" which is marked as `vendor_available: false`", ` | 
|  | 1829 | cc_library { | 
|  | 1830 | name: "libprod", | 
|  | 1831 | product_specific: true, | 
|  | 1832 | shared_libs: [ | 
|  | 1833 | "libvndk_private", | 
|  | 1834 | ], | 
|  | 1835 | nocrt: true, | 
|  | 1836 | } | 
|  | 1837 | cc_library { | 
|  | 1838 | name: "libvndk_private", | 
|  | 1839 | vendor_available: false, | 
|  | 1840 | vndk: { | 
|  | 1841 | enabled: true, | 
|  | 1842 | }, | 
|  | 1843 | nocrt: true, | 
|  | 1844 | } | 
|  | 1845 | `) | 
|  | 1846 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", ` | 
|  | 1847 | cc_library { | 
|  | 1848 | name: "libprod", | 
|  | 1849 | product_specific: true, | 
|  | 1850 | shared_libs: [ | 
|  | 1851 | "libsystem_ext", | 
|  | 1852 | ], | 
|  | 1853 | nocrt: true, | 
|  | 1854 | } | 
|  | 1855 | cc_library { | 
|  | 1856 | name: "libsystem_ext", | 
|  | 1857 | system_ext_specific: true, | 
|  | 1858 | nocrt: true, | 
|  | 1859 | } | 
|  | 1860 | `) | 
|  | 1861 | testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", ` | 
|  | 1862 | cc_library { | 
|  | 1863 | name: "libsystem", | 
|  | 1864 | shared_libs: [ | 
|  | 1865 | "libproduct_va", | 
|  | 1866 | ], | 
|  | 1867 | nocrt: true, | 
|  | 1868 | } | 
|  | 1869 | cc_library { | 
|  | 1870 | name: "libproduct_va", | 
|  | 1871 | product_specific: true, | 
|  | 1872 | vendor_available: true, | 
|  | 1873 | nocrt: true, | 
|  | 1874 | } | 
|  | 1875 | `) | 
|  | 1876 | } | 
|  | 1877 |  | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1878 | func TestMakeLinkType(t *testing.T) { | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1879 | bp := ` | 
|  | 1880 | cc_library { | 
|  | 1881 | name: "libvndk", | 
|  | 1882 | vendor_available: true, | 
|  | 1883 | vndk: { | 
|  | 1884 | enabled: true, | 
|  | 1885 | }, | 
|  | 1886 | } | 
|  | 1887 | cc_library { | 
|  | 1888 | name: "libvndksp", | 
|  | 1889 | vendor_available: true, | 
|  | 1890 | vndk: { | 
|  | 1891 | enabled: true, | 
|  | 1892 | support_system_process: true, | 
|  | 1893 | }, | 
|  | 1894 | } | 
|  | 1895 | cc_library { | 
|  | 1896 | name: "libvndkprivate", | 
|  | 1897 | vendor_available: false, | 
|  | 1898 | vndk: { | 
|  | 1899 | enabled: true, | 
|  | 1900 | }, | 
|  | 1901 | } | 
|  | 1902 | cc_library { | 
|  | 1903 | name: "libvendor", | 
|  | 1904 | vendor: true, | 
|  | 1905 | } | 
|  | 1906 | cc_library { | 
|  | 1907 | name: "libvndkext", | 
|  | 1908 | vendor: true, | 
|  | 1909 | vndk: { | 
|  | 1910 | enabled: true, | 
|  | 1911 | extends: "libvndk", | 
|  | 1912 | }, | 
|  | 1913 | } | 
|  | 1914 | vndk_prebuilt_shared { | 
|  | 1915 | name: "prevndk", | 
|  | 1916 | version: "27", | 
|  | 1917 | target_arch: "arm", | 
|  | 1918 | binder32bit: true, | 
|  | 1919 | vendor_available: true, | 
|  | 1920 | vndk: { | 
|  | 1921 | enabled: true, | 
|  | 1922 | }, | 
|  | 1923 | arch: { | 
|  | 1924 | arm: { | 
|  | 1925 | srcs: ["liba.so"], | 
|  | 1926 | }, | 
|  | 1927 | }, | 
|  | 1928 | } | 
|  | 1929 | cc_library { | 
|  | 1930 | name: "libllndk", | 
|  | 1931 | } | 
|  | 1932 | llndk_library { | 
|  | 1933 | name: "libllndk", | 
|  | 1934 | symbol_file: "", | 
|  | 1935 | } | 
|  | 1936 | cc_library { | 
|  | 1937 | name: "libllndkprivate", | 
|  | 1938 | } | 
|  | 1939 | llndk_library { | 
|  | 1940 | name: "libllndkprivate", | 
|  | 1941 | vendor_available: false, | 
|  | 1942 | symbol_file: "", | 
|  | 1943 | }` | 
|  | 1944 |  | 
|  | 1945 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1946 | config.TestProductVariables.DeviceVndkVersion = StringPtr("current") | 
|  | 1947 | config.TestProductVariables.Platform_vndk_version = StringPtr("VER") | 
|  | 1948 | // native:vndk | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1949 | ctx := testCcWithConfig(t, config) | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1950 |  | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1951 | assertMapKeys(t, vndkCoreLibraries(config), | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1952 | []string{"libvndk", "libvndkprivate"}) | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1953 | assertMapKeys(t, vndkSpLibraries(config), | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1954 | []string{"libc++", "libvndksp"}) | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1955 | assertMapKeys(t, llndkLibraries(config), | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 1956 | []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"}) | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1957 | assertMapKeys(t, vndkPrivateLibraries(config), | 
| Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 1958 | []string{"libft2", "libllndkprivate", "libvndkprivate"}) | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1959 |  | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 1960 | vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared" | 
| Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1961 |  | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1962 | tests := []struct { | 
|  | 1963 | variant  string | 
|  | 1964 | name     string | 
|  | 1965 | expected string | 
|  | 1966 | }{ | 
|  | 1967 | {vendorVariant, "libvndk", "native:vndk"}, | 
|  | 1968 | {vendorVariant, "libvndksp", "native:vndk"}, | 
|  | 1969 | {vendorVariant, "libvndkprivate", "native:vndk_private"}, | 
|  | 1970 | {vendorVariant, "libvendor", "native:vendor"}, | 
|  | 1971 | {vendorVariant, "libvndkext", "native:vendor"}, | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1972 | {vendorVariant, "libllndk.llndk", "native:vndk"}, | 
| Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1973 | {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1974 | {coreVariant, "libvndk", "native:platform"}, | 
|  | 1975 | {coreVariant, "libvndkprivate", "native:platform"}, | 
|  | 1976 | {coreVariant, "libllndk", "native:platform"}, | 
|  | 1977 | } | 
|  | 1978 | for _, test := range tests { | 
|  | 1979 | t.Run(test.name, func(t *testing.T) { | 
|  | 1980 | module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module) | 
|  | 1981 | assertString(t, module.makeLinkType, test.expected) | 
|  | 1982 | }) | 
|  | 1983 | } | 
|  | 1984 | } | 
|  | 1985 |  | 
| Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1986 | var ( | 
|  | 1987 | str11 = "01234567891" | 
|  | 1988 | str10 = str11[:10] | 
|  | 1989 | str9  = str11[:9] | 
|  | 1990 | str5  = str11[:5] | 
|  | 1991 | str4  = str11[:4] | 
|  | 1992 | ) | 
|  | 1993 |  | 
|  | 1994 | var splitListForSizeTestCases = []struct { | 
|  | 1995 | in   []string | 
|  | 1996 | out  [][]string | 
|  | 1997 | size int | 
|  | 1998 | }{ | 
|  | 1999 | { | 
|  | 2000 | in:   []string{str10}, | 
|  | 2001 | out:  [][]string{{str10}}, | 
|  | 2002 | size: 10, | 
|  | 2003 | }, | 
|  | 2004 | { | 
|  | 2005 | in:   []string{str9}, | 
|  | 2006 | out:  [][]string{{str9}}, | 
|  | 2007 | size: 10, | 
|  | 2008 | }, | 
|  | 2009 | { | 
|  | 2010 | in:   []string{str5}, | 
|  | 2011 | out:  [][]string{{str5}}, | 
|  | 2012 | size: 10, | 
|  | 2013 | }, | 
|  | 2014 | { | 
|  | 2015 | in:   []string{str11}, | 
|  | 2016 | out:  nil, | 
|  | 2017 | size: 10, | 
|  | 2018 | }, | 
|  | 2019 | { | 
|  | 2020 | in:   []string{str10, str10}, | 
|  | 2021 | out:  [][]string{{str10}, {str10}}, | 
|  | 2022 | size: 10, | 
|  | 2023 | }, | 
|  | 2024 | { | 
|  | 2025 | in:   []string{str9, str10}, | 
|  | 2026 | out:  [][]string{{str9}, {str10}}, | 
|  | 2027 | size: 10, | 
|  | 2028 | }, | 
|  | 2029 | { | 
|  | 2030 | in:   []string{str10, str9}, | 
|  | 2031 | out:  [][]string{{str10}, {str9}}, | 
|  | 2032 | size: 10, | 
|  | 2033 | }, | 
|  | 2034 | { | 
|  | 2035 | in:   []string{str5, str4}, | 
|  | 2036 | out:  [][]string{{str5, str4}}, | 
|  | 2037 | size: 10, | 
|  | 2038 | }, | 
|  | 2039 | { | 
|  | 2040 | in:   []string{str5, str4, str5}, | 
|  | 2041 | out:  [][]string{{str5, str4}, {str5}}, | 
|  | 2042 | size: 10, | 
|  | 2043 | }, | 
|  | 2044 | { | 
|  | 2045 | in:   []string{str5, str4, str5, str4}, | 
|  | 2046 | out:  [][]string{{str5, str4}, {str5, str4}}, | 
|  | 2047 | size: 10, | 
|  | 2048 | }, | 
|  | 2049 | { | 
|  | 2050 | in:   []string{str5, str4, str5, str5}, | 
|  | 2051 | out:  [][]string{{str5, str4}, {str5}, {str5}}, | 
|  | 2052 | size: 10, | 
|  | 2053 | }, | 
|  | 2054 | { | 
|  | 2055 | in:   []string{str5, str5, str5, str4}, | 
|  | 2056 | out:  [][]string{{str5}, {str5}, {str5, str4}}, | 
|  | 2057 | size: 10, | 
|  | 2058 | }, | 
|  | 2059 | { | 
|  | 2060 | in:   []string{str9, str11}, | 
|  | 2061 | out:  nil, | 
|  | 2062 | size: 10, | 
|  | 2063 | }, | 
|  | 2064 | { | 
|  | 2065 | in:   []string{str11, str9}, | 
|  | 2066 | out:  nil, | 
|  | 2067 | size: 10, | 
|  | 2068 | }, | 
|  | 2069 | } | 
|  | 2070 |  | 
|  | 2071 | func TestSplitListForSize(t *testing.T) { | 
|  | 2072 | for _, testCase := range splitListForSizeTestCases { | 
| Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 2073 | out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size) | 
| Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 2074 |  | 
|  | 2075 | var outStrings [][]string | 
|  | 2076 |  | 
|  | 2077 | if len(out) > 0 { | 
|  | 2078 | outStrings = make([][]string, len(out)) | 
|  | 2079 | for i, o := range out { | 
|  | 2080 | outStrings[i] = o.Strings() | 
|  | 2081 | } | 
|  | 2082 | } | 
|  | 2083 |  | 
|  | 2084 | if !reflect.DeepEqual(outStrings, testCase.out) { | 
| Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2085 | t.Errorf("incorrect output:") | 
|  | 2086 | t.Errorf("     input: %#v", testCase.in) | 
|  | 2087 | t.Errorf("      size: %d", testCase.size) | 
|  | 2088 | t.Errorf("  expected: %#v", testCase.out) | 
| Colin Cross | 5b52959 | 2017-05-09 13:34:34 -0700 | [diff] [blame] | 2089 | t.Errorf("       got: %#v", outStrings) | 
| Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2090 | } | 
|  | 2091 | } | 
|  | 2092 | } | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2093 |  | 
|  | 2094 | var staticLinkDepOrderTestCases = []struct { | 
|  | 2095 | // This is a string representation of a map[moduleName][]moduleDependency . | 
|  | 2096 | // It models the dependencies declared in an Android.bp file. | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2097 | inStatic string | 
|  | 2098 |  | 
|  | 2099 | // This is a string representation of a map[moduleName][]moduleDependency . | 
|  | 2100 | // It models the dependencies declared in an Android.bp file. | 
|  | 2101 | inShared string | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2102 |  | 
|  | 2103 | // allOrdered is a string representation of a map[moduleName][]moduleDependency . | 
|  | 2104 | // The keys of allOrdered specify which modules we would like to check. | 
|  | 2105 | // The values of allOrdered specify the expected result (of the transitive closure of all | 
|  | 2106 | // dependencies) for each module to test | 
|  | 2107 | allOrdered string | 
|  | 2108 |  | 
|  | 2109 | // outOrdered is a string representation of a map[moduleName][]moduleDependency . | 
|  | 2110 | // The keys of outOrdered specify which modules we would like to check. | 
|  | 2111 | // The values of outOrdered specify the expected result (of the ordered linker command line) | 
|  | 2112 | // for each module to test. | 
|  | 2113 | outOrdered string | 
|  | 2114 | }{ | 
|  | 2115 | // Simple tests | 
|  | 2116 | { | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2117 | inStatic:   "", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2118 | outOrdered: "", | 
|  | 2119 | }, | 
|  | 2120 | { | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2121 | inStatic:   "a:", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2122 | outOrdered: "a:", | 
|  | 2123 | }, | 
|  | 2124 | { | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2125 | inStatic:   "a:b; b:", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2126 | outOrdered: "a:b; b:", | 
|  | 2127 | }, | 
|  | 2128 | // Tests of reordering | 
|  | 2129 | { | 
|  | 2130 | // diamond example | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2131 | inStatic:   "a:d,b,c; b:d; c:d; d:", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2132 | outOrdered: "a:b,c,d; b:d; c:d; d:", | 
|  | 2133 | }, | 
|  | 2134 | { | 
|  | 2135 | // somewhat real example | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2136 | 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] | 2137 | outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b", | 
|  | 2138 | }, | 
|  | 2139 | { | 
|  | 2140 | // multiple reorderings | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2141 | inStatic:   "a:b,c,d,e; d:b; e:c", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2142 | outOrdered: "a:d,b,e,c; d:b; e:c", | 
|  | 2143 | }, | 
|  | 2144 | { | 
|  | 2145 | // should reorder without adding new transitive dependencies | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2146 | inStatic:   "bin:lib2,lib1;             lib1:lib2,liboptional", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2147 | allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional", | 
|  | 2148 | outOrdered: "bin:lib1,lib2;             lib1:lib2,liboptional", | 
|  | 2149 | }, | 
|  | 2150 | { | 
|  | 2151 | // multiple levels of dependencies | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2152 | 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] | 2153 | allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", | 
|  | 2154 | outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d", | 
|  | 2155 | }, | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2156 | // shared dependencies | 
|  | 2157 | { | 
|  | 2158 | // Note that this test doesn't recurse, to minimize the amount of logic it tests. | 
|  | 2159 | // So, we don't actually have to check that a shared dependency of c will change the order | 
|  | 2160 | // of a library that depends statically on b and on c.  We only need to check that if c has | 
|  | 2161 | // a shared dependency on b, that that shows up in allOrdered. | 
|  | 2162 | inShared:   "c:b", | 
|  | 2163 | allOrdered: "c:b", | 
|  | 2164 | outOrdered: "c:", | 
|  | 2165 | }, | 
|  | 2166 | { | 
|  | 2167 | // This test doesn't actually include any shared dependencies but it's a reminder of what | 
|  | 2168 | // the second phase of the above test would look like | 
|  | 2169 | inStatic:   "a:b,c; c:b", | 
|  | 2170 | allOrdered: "a:c,b; c:b", | 
|  | 2171 | outOrdered: "a:c,b; c:b", | 
|  | 2172 | }, | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2173 | // tiebreakers for when two modules specifying different orderings and there is no dependency | 
|  | 2174 | // to dictate an order | 
|  | 2175 | { | 
|  | 2176 | // 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] | 2177 | 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] | 2178 | outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d", | 
|  | 2179 | }, | 
|  | 2180 | { | 
|  | 2181 | // 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] | 2182 | 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] | 2183 | outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d;   a2:b2,c2,d,e; b2:d,e; c2:d,e", | 
|  | 2184 | }, | 
|  | 2185 | // Tests involving duplicate dependencies | 
|  | 2186 | { | 
|  | 2187 | // simple duplicate | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2188 | inStatic:   "a:b,c,c,b", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2189 | outOrdered: "a:c,b", | 
|  | 2190 | }, | 
|  | 2191 | { | 
|  | 2192 | // duplicates with reordering | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2193 | inStatic:   "a:b,c,d,c; c:b", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2194 | outOrdered: "a:d,c,b", | 
|  | 2195 | }, | 
|  | 2196 | // Tests to confirm the nonexistence of infinite loops. | 
|  | 2197 | // These cases should never happen, so as long as the test terminates and the | 
|  | 2198 | // result is deterministic then that should be fine. | 
|  | 2199 | { | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2200 | inStatic:   "a:a", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2201 | outOrdered: "a:a", | 
|  | 2202 | }, | 
|  | 2203 | { | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2204 | inStatic:   "a:b;   b:c;   c:a", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2205 | allOrdered: "a:b,c; b:c,a; c:a,b", | 
|  | 2206 | outOrdered: "a:b;   b:c;   c:a", | 
|  | 2207 | }, | 
|  | 2208 | { | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2209 | inStatic:   "a:b,c;   b:c,a;   c:a,b", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2210 | allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a", | 
|  | 2211 | outOrdered: "a:c,b;   b:a,c;   c:b,a", | 
|  | 2212 | }, | 
|  | 2213 | } | 
|  | 2214 |  | 
|  | 2215 | // converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}]) | 
|  | 2216 | func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) { | 
|  | 2217 | // convert from "a:b,c; d:e" to "a:b,c;d:e" | 
|  | 2218 | strippedText := strings.Replace(text, " ", "", -1) | 
|  | 2219 | if len(strippedText) < 1 { | 
|  | 2220 | return []android.Path{}, make(map[android.Path][]android.Path, 0) | 
|  | 2221 | } | 
|  | 2222 | allDeps = make(map[android.Path][]android.Path, 0) | 
|  | 2223 |  | 
|  | 2224 | // convert from "a:b,c;d:e" to ["a:b,c", "d:e"] | 
|  | 2225 | moduleTexts := strings.Split(strippedText, ";") | 
|  | 2226 |  | 
|  | 2227 | outputForModuleName := func(moduleName string) android.Path { | 
|  | 2228 | return android.PathForTesting(moduleName) | 
|  | 2229 | } | 
|  | 2230 |  | 
|  | 2231 | for _, moduleText := range moduleTexts { | 
|  | 2232 | // convert from "a:b,c" to ["a", "b,c"] | 
|  | 2233 | components := strings.Split(moduleText, ":") | 
|  | 2234 | if len(components) != 2 { | 
|  | 2235 | panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1)) | 
|  | 2236 | } | 
|  | 2237 | moduleName := components[0] | 
|  | 2238 | moduleOutput := outputForModuleName(moduleName) | 
|  | 2239 | modulesInOrder = append(modulesInOrder, moduleOutput) | 
|  | 2240 |  | 
|  | 2241 | depString := components[1] | 
|  | 2242 | // convert from "b,c" to ["b", "c"] | 
|  | 2243 | depNames := strings.Split(depString, ",") | 
|  | 2244 | if len(depString) < 1 { | 
|  | 2245 | depNames = []string{} | 
|  | 2246 | } | 
|  | 2247 | var deps []android.Path | 
|  | 2248 | for _, depName := range depNames { | 
|  | 2249 | deps = append(deps, outputForModuleName(depName)) | 
|  | 2250 | } | 
|  | 2251 | allDeps[moduleOutput] = deps | 
|  | 2252 | } | 
|  | 2253 | return modulesInOrder, allDeps | 
|  | 2254 | } | 
|  | 2255 |  | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2256 | func TestLinkReordering(t *testing.T) { | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2257 | for _, testCase := range staticLinkDepOrderTestCases { | 
|  | 2258 | errs := []string{} | 
|  | 2259 |  | 
|  | 2260 | // parse testcase | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2261 | _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic) | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2262 | expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered) | 
|  | 2263 | if testCase.allOrdered == "" { | 
|  | 2264 | // allow the test case to skip specifying allOrdered | 
|  | 2265 | testCase.allOrdered = testCase.outOrdered | 
|  | 2266 | } | 
|  | 2267 | _, expectedAllDeps := parseModuleDeps(testCase.allOrdered) | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2268 | _, givenAllSharedDeps := parseModuleDeps(testCase.inShared) | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2269 |  | 
|  | 2270 | // For each module whose post-reordered dependencies were specified, validate that | 
|  | 2271 | // reordering the inputs produces the expected outputs. | 
|  | 2272 | for _, moduleName := range expectedModuleNames { | 
|  | 2273 | moduleDeps := givenTransitiveDeps[moduleName] | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2274 | givenSharedDeps := givenAllSharedDeps[moduleName] | 
|  | 2275 | orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps) | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2276 |  | 
|  | 2277 | correctAllOrdered := expectedAllDeps[moduleName] | 
|  | 2278 | if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) { | 
|  | 2279 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+ | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2280 | "\nin static:%q"+ | 
|  | 2281 | "\nin shared:%q"+ | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2282 | "\nmodule:   %v"+ | 
|  | 2283 | "\nexpected: %s"+ | 
|  | 2284 | "\nactual:   %s", | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2285 | testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps)) | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2286 | } | 
|  | 2287 |  | 
|  | 2288 | correctOutputDeps := expectedTransitiveDeps[moduleName] | 
|  | 2289 | if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) { | 
|  | 2290 | errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+ | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2291 | "\nin static:%q"+ | 
|  | 2292 | "\nin shared:%q"+ | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2293 | "\nmodule:   %v"+ | 
|  | 2294 | "\nexpected: %s"+ | 
|  | 2295 | "\nactual:   %s", | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2296 | testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps)) | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2297 | } | 
|  | 2298 | } | 
|  | 2299 |  | 
|  | 2300 | if len(errs) > 0 { | 
|  | 2301 | sort.Strings(errs) | 
|  | 2302 | for _, err := range errs { | 
|  | 2303 | t.Error(err) | 
|  | 2304 | } | 
|  | 2305 | } | 
|  | 2306 | } | 
|  | 2307 | } | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2308 |  | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2309 | func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { | 
|  | 2310 | for _, moduleName := range moduleNames { | 
|  | 2311 | module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) | 
|  | 2312 | output := module.outputFile.Path() | 
|  | 2313 | paths = append(paths, output) | 
|  | 2314 | } | 
|  | 2315 | return paths | 
|  | 2316 | } | 
|  | 2317 |  | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2318 | func TestStaticLibDepReordering(t *testing.T) { | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2319 | ctx := testCc(t, ` | 
|  | 2320 | cc_library { | 
|  | 2321 | name: "a", | 
|  | 2322 | static_libs: ["b", "c", "d"], | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2323 | stl: "none", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2324 | } | 
|  | 2325 | cc_library { | 
|  | 2326 | name: "b", | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2327 | stl: "none", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2328 | } | 
|  | 2329 | cc_library { | 
|  | 2330 | name: "c", | 
|  | 2331 | static_libs: ["b"], | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2332 | stl: "none", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2333 | } | 
|  | 2334 | cc_library { | 
|  | 2335 | name: "d", | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2336 | stl: "none", | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2337 | } | 
|  | 2338 |  | 
|  | 2339 | `) | 
|  | 2340 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2341 | variant := "android_arm64_armv8-a_static" | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2342 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2343 | actual := moduleA.depsInLinkOrder | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2344 | expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"}) | 
|  | 2345 |  | 
|  | 2346 | if !reflect.DeepEqual(actual, expected) { | 
|  | 2347 | t.Errorf("staticDeps orderings were not propagated correctly"+ | 
|  | 2348 | "\nactual:   %v"+ | 
|  | 2349 | "\nexpected: %v", | 
|  | 2350 | actual, | 
|  | 2351 | expected, | 
|  | 2352 | ) | 
|  | 2353 | } | 
| Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2354 | } | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2355 |  | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2356 | func TestStaticLibDepReorderingWithShared(t *testing.T) { | 
|  | 2357 | ctx := testCc(t, ` | 
|  | 2358 | cc_library { | 
|  | 2359 | name: "a", | 
|  | 2360 | static_libs: ["b", "c"], | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2361 | stl: "none", | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2362 | } | 
|  | 2363 | cc_library { | 
|  | 2364 | name: "b", | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2365 | stl: "none", | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2366 | } | 
|  | 2367 | cc_library { | 
|  | 2368 | name: "c", | 
|  | 2369 | shared_libs: ["b"], | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2370 | stl: "none", | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2371 | } | 
|  | 2372 |  | 
|  | 2373 | `) | 
|  | 2374 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2375 | variant := "android_arm64_armv8-a_static" | 
| Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2376 | moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) | 
|  | 2377 | actual := moduleA.depsInLinkOrder | 
|  | 2378 | expected := getOutputPaths(ctx, variant, []string{"c", "b"}) | 
|  | 2379 |  | 
|  | 2380 | if !reflect.DeepEqual(actual, expected) { | 
|  | 2381 | t.Errorf("staticDeps orderings did not account for shared libs"+ | 
|  | 2382 | "\nactual:   %v"+ | 
|  | 2383 | "\nexpected: %v", | 
|  | 2384 | actual, | 
|  | 2385 | expected, | 
|  | 2386 | ) | 
|  | 2387 | } | 
|  | 2388 | } | 
|  | 2389 |  | 
| Jooyung Han | 89124ba | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2390 | func checkEquals(t *testing.T, message string, expected, actual interface{}) { | 
|  | 2391 | if !reflect.DeepEqual(actual, expected) { | 
|  | 2392 | t.Errorf(message+ | 
|  | 2393 | "\nactual:   %v"+ | 
|  | 2394 | "\nexpected: %v", | 
|  | 2395 | actual, | 
|  | 2396 | expected, | 
|  | 2397 | ) | 
|  | 2398 | } | 
|  | 2399 | } | 
|  | 2400 |  | 
| Jooyung Han | 67a96cd | 2020-03-13 15:23:36 +0900 | [diff] [blame] | 2401 | func TestLlndkLibrary(t *testing.T) { | 
|  | 2402 | ctx := testCc(t, ` | 
|  | 2403 | cc_library { | 
|  | 2404 | name: "libllndk", | 
|  | 2405 | stubs: { versions: ["1", "2"] }, | 
|  | 2406 | } | 
|  | 2407 | llndk_library { | 
|  | 2408 | name: "libllndk", | 
|  | 2409 | } | 
|  | 2410 | `) | 
|  | 2411 | actual := ctx.ModuleVariantsForTests("libllndk.llndk") | 
|  | 2412 | expected := []string{ | 
|  | 2413 | "android_vendor.VER_arm64_armv8-a_shared", | 
|  | 2414 | "android_vendor.VER_arm64_armv8-a_shared_1", | 
|  | 2415 | "android_vendor.VER_arm64_armv8-a_shared_2", | 
|  | 2416 | "android_vendor.VER_arm_armv7-a-neon_shared", | 
|  | 2417 | "android_vendor.VER_arm_armv7-a-neon_shared_1", | 
|  | 2418 | "android_vendor.VER_arm_armv7-a-neon_shared_2", | 
|  | 2419 | } | 
|  | 2420 | checkEquals(t, "variants for llndk stubs", expected, actual) | 
|  | 2421 |  | 
|  | 2422 | params := ctx.ModuleForTests("libllndk.llndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub") | 
|  | 2423 | checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"]) | 
|  | 2424 |  | 
|  | 2425 | params = ctx.ModuleForTests("libllndk.llndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub") | 
|  | 2426 | checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"]) | 
|  | 2427 | } | 
|  | 2428 |  | 
| Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2429 | func TestLlndkHeaders(t *testing.T) { | 
|  | 2430 | ctx := testCc(t, ` | 
|  | 2431 | llndk_headers { | 
|  | 2432 | name: "libllndk_headers", | 
|  | 2433 | export_include_dirs: ["my_include"], | 
|  | 2434 | } | 
|  | 2435 | llndk_library { | 
|  | 2436 | name: "libllndk", | 
|  | 2437 | export_llndk_headers: ["libllndk_headers"], | 
|  | 2438 | } | 
|  | 2439 | cc_library { | 
|  | 2440 | name: "libvendor", | 
|  | 2441 | shared_libs: ["libllndk"], | 
|  | 2442 | vendor: true, | 
|  | 2443 | srcs: ["foo.c"], | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2444 | no_libcrt: true, | 
| Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2445 | nocrt: true, | 
| Jiyong Park | a46a4d5 | 2017-12-14 19:54:34 +0900 | [diff] [blame] | 2446 | } | 
|  | 2447 | `) | 
|  | 2448 |  | 
|  | 2449 | // _static variant is used since _shared reuses *.o from the static variant | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2450 | 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] | 2451 | cflags := cc.Args["cFlags"] | 
|  | 2452 | if !strings.Contains(cflags, "-Imy_include") { | 
|  | 2453 | t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) | 
|  | 2454 | } | 
|  | 2455 | } | 
|  | 2456 |  | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2457 | func checkRuntimeLibs(t *testing.T, expected []string, module *Module) { | 
|  | 2458 | actual := module.Properties.AndroidMkRuntimeLibs | 
|  | 2459 | if !reflect.DeepEqual(actual, expected) { | 
|  | 2460 | t.Errorf("incorrect runtime_libs for shared libs"+ | 
|  | 2461 | "\nactual:   %v"+ | 
|  | 2462 | "\nexpected: %v", | 
|  | 2463 | actual, | 
|  | 2464 | expected, | 
|  | 2465 | ) | 
|  | 2466 | } | 
|  | 2467 | } | 
|  | 2468 |  | 
|  | 2469 | const runtimeLibAndroidBp = ` | 
|  | 2470 | cc_library { | 
|  | 2471 | name: "libvendor_available1", | 
|  | 2472 | vendor_available: true, | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2473 | no_libcrt : true, | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2474 | nocrt : true, | 
|  | 2475 | system_shared_libs : [], | 
|  | 2476 | } | 
|  | 2477 | cc_library { | 
|  | 2478 | name: "libvendor_available2", | 
|  | 2479 | vendor_available: true, | 
|  | 2480 | runtime_libs: ["libvendor_available1"], | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2481 | no_libcrt : true, | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2482 | nocrt : true, | 
|  | 2483 | system_shared_libs : [], | 
|  | 2484 | } | 
|  | 2485 | cc_library { | 
|  | 2486 | name: "libvendor_available3", | 
|  | 2487 | vendor_available: true, | 
|  | 2488 | runtime_libs: ["libvendor_available1"], | 
|  | 2489 | target: { | 
|  | 2490 | vendor: { | 
|  | 2491 | exclude_runtime_libs: ["libvendor_available1"], | 
|  | 2492 | } | 
|  | 2493 | }, | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2494 | no_libcrt : true, | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2495 | nocrt : true, | 
|  | 2496 | system_shared_libs : [], | 
|  | 2497 | } | 
|  | 2498 | cc_library { | 
|  | 2499 | name: "libcore", | 
|  | 2500 | runtime_libs: ["libvendor_available1"], | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2501 | no_libcrt : true, | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2502 | nocrt : true, | 
|  | 2503 | system_shared_libs : [], | 
|  | 2504 | } | 
|  | 2505 | cc_library { | 
|  | 2506 | name: "libvendor1", | 
|  | 2507 | vendor: true, | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2508 | no_libcrt : true, | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2509 | nocrt : true, | 
|  | 2510 | system_shared_libs : [], | 
|  | 2511 | } | 
|  | 2512 | cc_library { | 
|  | 2513 | name: "libvendor2", | 
|  | 2514 | vendor: true, | 
|  | 2515 | runtime_libs: ["libvendor_available1", "libvendor1"], | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2516 | no_libcrt : true, | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2517 | nocrt : true, | 
|  | 2518 | system_shared_libs : [], | 
|  | 2519 | } | 
|  | 2520 | ` | 
|  | 2521 |  | 
|  | 2522 | func TestRuntimeLibs(t *testing.T) { | 
|  | 2523 | ctx := testCc(t, runtimeLibAndroidBp) | 
|  | 2524 |  | 
|  | 2525 | // runtime_libs for core variants use the module names without suffixes. | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2526 | variant := "android_arm64_armv8-a_shared" | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2527 |  | 
|  | 2528 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) | 
|  | 2529 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) | 
|  | 2530 |  | 
|  | 2531 | module = ctx.ModuleForTests("libcore", variant).Module().(*Module) | 
|  | 2532 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) | 
|  | 2533 |  | 
|  | 2534 | // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core | 
|  | 2535 | // and vendor variants. | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2536 | variant = "android_vendor.VER_arm64_armv8-a_shared" | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2537 |  | 
|  | 2538 | module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) | 
|  | 2539 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module) | 
|  | 2540 |  | 
|  | 2541 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) | 
|  | 2542 | checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module) | 
|  | 2543 | } | 
|  | 2544 |  | 
|  | 2545 | func TestExcludeRuntimeLibs(t *testing.T) { | 
|  | 2546 | ctx := testCc(t, runtimeLibAndroidBp) | 
|  | 2547 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2548 | variant := "android_arm64_armv8-a_shared" | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2549 | module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) | 
|  | 2550 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) | 
|  | 2551 |  | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2552 | variant = "android_vendor.VER_arm64_armv8-a_shared" | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2553 | module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) | 
|  | 2554 | checkRuntimeLibs(t, nil, module) | 
|  | 2555 | } | 
|  | 2556 |  | 
|  | 2557 | func TestRuntimeLibsNoVndk(t *testing.T) { | 
|  | 2558 | ctx := testCcNoVndk(t, runtimeLibAndroidBp) | 
|  | 2559 |  | 
|  | 2560 | // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is. | 
|  | 2561 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2562 | variant := "android_arm64_armv8-a_shared" | 
| Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2563 |  | 
|  | 2564 | module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) | 
|  | 2565 | checkRuntimeLibs(t, []string{"libvendor_available1"}, module) | 
|  | 2566 |  | 
|  | 2567 | module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module) | 
|  | 2568 | checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module) | 
|  | 2569 | } | 
|  | 2570 |  | 
| Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2571 | func checkStaticLibs(t *testing.T, expected []string, module *Module) { | 
| Jooyung Han | 0c4e016 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2572 | t.Helper() | 
| Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2573 | actual := module.Properties.AndroidMkStaticLibs | 
|  | 2574 | if !reflect.DeepEqual(actual, expected) { | 
|  | 2575 | t.Errorf("incorrect static_libs"+ | 
|  | 2576 | "\nactual:   %v"+ | 
|  | 2577 | "\nexpected: %v", | 
|  | 2578 | actual, | 
|  | 2579 | expected, | 
|  | 2580 | ) | 
|  | 2581 | } | 
|  | 2582 | } | 
|  | 2583 |  | 
|  | 2584 | const staticLibAndroidBp = ` | 
|  | 2585 | cc_library { | 
|  | 2586 | name: "lib1", | 
|  | 2587 | } | 
|  | 2588 | cc_library { | 
|  | 2589 | name: "lib2", | 
|  | 2590 | static_libs: ["lib1"], | 
|  | 2591 | } | 
|  | 2592 | ` | 
|  | 2593 |  | 
|  | 2594 | func TestStaticLibDepExport(t *testing.T) { | 
|  | 2595 | ctx := testCc(t, staticLibAndroidBp) | 
|  | 2596 |  | 
|  | 2597 | // Check the shared version of lib2. | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2598 | variant := "android_arm64_armv8-a_shared" | 
| Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2599 | module := ctx.ModuleForTests("lib2", variant).Module().(*Module) | 
| Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2600 | 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] | 2601 |  | 
|  | 2602 | // Check the static version of lib2. | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2603 | variant = "android_arm64_armv8-a_static" | 
| Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 2604 | module = ctx.ModuleForTests("lib2", variant).Module().(*Module) | 
|  | 2605 | // libc++_static is linked additionally. | 
| Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 2606 | 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] | 2607 | } | 
|  | 2608 |  | 
| Jiyong Park | d08b697 | 2017-09-26 10:50:54 +0900 | [diff] [blame] | 2609 | var compilerFlagsTestCases = []struct { | 
|  | 2610 | in  string | 
|  | 2611 | out bool | 
|  | 2612 | }{ | 
|  | 2613 | { | 
|  | 2614 | in:  "a", | 
|  | 2615 | out: false, | 
|  | 2616 | }, | 
|  | 2617 | { | 
|  | 2618 | in:  "-a", | 
|  | 2619 | out: true, | 
|  | 2620 | }, | 
|  | 2621 | { | 
|  | 2622 | in:  "-Ipath/to/something", | 
|  | 2623 | out: false, | 
|  | 2624 | }, | 
|  | 2625 | { | 
|  | 2626 | in:  "-isystempath/to/something", | 
|  | 2627 | out: false, | 
|  | 2628 | }, | 
|  | 2629 | { | 
|  | 2630 | in:  "--coverage", | 
|  | 2631 | out: false, | 
|  | 2632 | }, | 
|  | 2633 | { | 
|  | 2634 | in:  "-include a/b", | 
|  | 2635 | out: true, | 
|  | 2636 | }, | 
|  | 2637 | { | 
|  | 2638 | in:  "-include a/b c/d", | 
|  | 2639 | out: false, | 
|  | 2640 | }, | 
|  | 2641 | { | 
|  | 2642 | in:  "-DMACRO", | 
|  | 2643 | out: true, | 
|  | 2644 | }, | 
|  | 2645 | { | 
|  | 2646 | in:  "-DMAC RO", | 
|  | 2647 | out: false, | 
|  | 2648 | }, | 
|  | 2649 | { | 
|  | 2650 | in:  "-a -b", | 
|  | 2651 | out: false, | 
|  | 2652 | }, | 
|  | 2653 | { | 
|  | 2654 | in:  "-DMACRO=definition", | 
|  | 2655 | out: true, | 
|  | 2656 | }, | 
|  | 2657 | { | 
|  | 2658 | in:  "-DMACRO=defi nition", | 
|  | 2659 | out: true, // TODO(jiyong): this should be false | 
|  | 2660 | }, | 
|  | 2661 | { | 
|  | 2662 | in:  "-DMACRO(x)=x + 1", | 
|  | 2663 | out: true, | 
|  | 2664 | }, | 
|  | 2665 | { | 
|  | 2666 | in:  "-DMACRO=\"defi nition\"", | 
|  | 2667 | out: true, | 
|  | 2668 | }, | 
|  | 2669 | } | 
|  | 2670 |  | 
|  | 2671 | type mockContext struct { | 
|  | 2672 | BaseModuleContext | 
|  | 2673 | result bool | 
|  | 2674 | } | 
|  | 2675 |  | 
|  | 2676 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { | 
|  | 2677 | // CheckBadCompilerFlags calls this function when the flag should be rejected | 
|  | 2678 | ctx.result = false | 
|  | 2679 | } | 
|  | 2680 |  | 
|  | 2681 | func TestCompilerFlags(t *testing.T) { | 
|  | 2682 | for _, testCase := range compilerFlagsTestCases { | 
|  | 2683 | ctx := &mockContext{result: true} | 
|  | 2684 | CheckBadCompilerFlags(ctx, "", []string{testCase.in}) | 
|  | 2685 | if ctx.result != testCase.out { | 
|  | 2686 | t.Errorf("incorrect output:") | 
|  | 2687 | t.Errorf("     input: %#v", testCase.in) | 
|  | 2688 | t.Errorf("  expected: %#v", testCase.out) | 
|  | 2689 | t.Errorf("       got: %#v", ctx.result) | 
|  | 2690 | } | 
|  | 2691 | } | 
| Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2692 | } | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2693 |  | 
|  | 2694 | func TestVendorPublicLibraries(t *testing.T) { | 
|  | 2695 | ctx := testCc(t, ` | 
|  | 2696 | cc_library_headers { | 
|  | 2697 | name: "libvendorpublic_headers", | 
|  | 2698 | export_include_dirs: ["my_include"], | 
|  | 2699 | } | 
|  | 2700 | vendor_public_library { | 
|  | 2701 | name: "libvendorpublic", | 
|  | 2702 | symbol_file: "", | 
|  | 2703 | export_public_headers: ["libvendorpublic_headers"], | 
|  | 2704 | } | 
|  | 2705 | cc_library { | 
|  | 2706 | name: "libvendorpublic", | 
|  | 2707 | srcs: ["foo.c"], | 
|  | 2708 | vendor: true, | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2709 | no_libcrt: true, | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2710 | nocrt: true, | 
|  | 2711 | } | 
|  | 2712 |  | 
|  | 2713 | cc_library { | 
|  | 2714 | name: "libsystem", | 
|  | 2715 | shared_libs: ["libvendorpublic"], | 
|  | 2716 | vendor: false, | 
|  | 2717 | srcs: ["foo.c"], | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2718 | no_libcrt: true, | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2719 | nocrt: true, | 
|  | 2720 | } | 
|  | 2721 | cc_library { | 
|  | 2722 | name: "libvendor", | 
|  | 2723 | shared_libs: ["libvendorpublic"], | 
|  | 2724 | vendor: true, | 
|  | 2725 | srcs: ["foo.c"], | 
| Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 2726 | no_libcrt: true, | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2727 | nocrt: true, | 
|  | 2728 | } | 
|  | 2729 | `) | 
|  | 2730 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2731 | coreVariant := "android_arm64_armv8-a_shared" | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2732 | vendorVariant := "android_vendor.VER_arm64_armv8-a_shared" | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2733 |  | 
|  | 2734 | // test if header search paths are correctly added | 
|  | 2735 | // _static variant is used since _shared reuses *.o from the static variant | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2736 | cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc") | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2737 | cflags := cc.Args["cFlags"] | 
|  | 2738 | if !strings.Contains(cflags, "-Imy_include") { | 
|  | 2739 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) | 
|  | 2740 | } | 
|  | 2741 |  | 
|  | 2742 | // test if libsystem is linked to the stub | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2743 | ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2744 | libflags := ld.Args["libFlags"] | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2745 | stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix}) | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2746 | if !strings.Contains(libflags, stubPaths[0].String()) { | 
|  | 2747 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) | 
|  | 2748 | } | 
|  | 2749 |  | 
|  | 2750 | // test if libvendor is linked to the real shared lib | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2751 | ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2752 | libflags = ld.Args["libFlags"] | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2753 | stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) | 
| Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 2754 | if !strings.Contains(libflags, stubPaths[0].String()) { | 
|  | 2755 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) | 
|  | 2756 | } | 
|  | 2757 |  | 
|  | 2758 | } | 
| Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2759 |  | 
|  | 2760 | func TestRecovery(t *testing.T) { | 
|  | 2761 | ctx := testCc(t, ` | 
|  | 2762 | cc_library_shared { | 
|  | 2763 | name: "librecovery", | 
|  | 2764 | recovery: true, | 
|  | 2765 | } | 
|  | 2766 | cc_library_shared { | 
|  | 2767 | name: "librecovery32", | 
|  | 2768 | recovery: true, | 
|  | 2769 | compile_multilib:"32", | 
|  | 2770 | } | 
| Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2771 | cc_library_shared { | 
|  | 2772 | name: "libHalInRecovery", | 
|  | 2773 | recovery_available: true, | 
|  | 2774 | vendor: true, | 
|  | 2775 | } | 
| Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2776 | `) | 
|  | 2777 |  | 
|  | 2778 | variants := ctx.ModuleVariantsForTests("librecovery") | 
| Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 2779 | const arm64 = "android_recovery_arm64_armv8-a_shared" | 
| Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2780 | if len(variants) != 1 || !android.InList(arm64, variants) { | 
|  | 2781 | t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants) | 
|  | 2782 | } | 
|  | 2783 |  | 
|  | 2784 | variants = ctx.ModuleVariantsForTests("librecovery32") | 
|  | 2785 | if android.InList(arm64, variants) { | 
|  | 2786 | t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64) | 
|  | 2787 | } | 
| Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2788 |  | 
|  | 2789 | recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module) | 
|  | 2790 | if !recoveryModule.Platform() { | 
|  | 2791 | t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product") | 
|  | 2792 | } | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2793 | } | 
| Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2794 |  | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2795 | func TestVersionedStubs(t *testing.T) { | 
|  | 2796 | ctx := testCc(t, ` | 
|  | 2797 | cc_library_shared { | 
|  | 2798 | name: "libFoo", | 
| Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2799 | srcs: ["foo.c"], | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2800 | stubs: { | 
|  | 2801 | symbol_file: "foo.map.txt", | 
|  | 2802 | versions: ["1", "2", "3"], | 
|  | 2803 | }, | 
|  | 2804 | } | 
| Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2805 |  | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2806 | cc_library_shared { | 
|  | 2807 | name: "libBar", | 
| Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2808 | srcs: ["bar.c"], | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2809 | shared_libs: ["libFoo#1"], | 
|  | 2810 | }`) | 
|  | 2811 |  | 
|  | 2812 | variants := ctx.ModuleVariantsForTests("libFoo") | 
|  | 2813 | expectedVariants := []string{ | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2814 | "android_arm64_armv8-a_shared", | 
|  | 2815 | "android_arm64_armv8-a_shared_1", | 
|  | 2816 | "android_arm64_armv8-a_shared_2", | 
|  | 2817 | "android_arm64_armv8-a_shared_3", | 
|  | 2818 | "android_arm_armv7-a-neon_shared", | 
|  | 2819 | "android_arm_armv7-a-neon_shared_1", | 
|  | 2820 | "android_arm_armv7-a-neon_shared_2", | 
|  | 2821 | "android_arm_armv7-a-neon_shared_3", | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2822 | } | 
|  | 2823 | variantsMismatch := false | 
|  | 2824 | if len(variants) != len(expectedVariants) { | 
|  | 2825 | variantsMismatch = true | 
|  | 2826 | } else { | 
|  | 2827 | for _, v := range expectedVariants { | 
|  | 2828 | if !inList(v, variants) { | 
|  | 2829 | variantsMismatch = false | 
|  | 2830 | } | 
|  | 2831 | } | 
|  | 2832 | } | 
|  | 2833 | if variantsMismatch { | 
|  | 2834 | t.Errorf("variants of libFoo expected:\n") | 
|  | 2835 | for _, v := range expectedVariants { | 
|  | 2836 | t.Errorf("%q\n", v) | 
|  | 2837 | } | 
|  | 2838 | t.Errorf(", but got:\n") | 
|  | 2839 | for _, v := range variants { | 
|  | 2840 | t.Errorf("%q\n", v) | 
|  | 2841 | } | 
|  | 2842 | } | 
|  | 2843 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2844 | libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld") | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2845 | libFlags := libBarLinkRule.Args["libFlags"] | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2846 | libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so" | 
| Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2847 | if !strings.Contains(libFlags, libFoo1StubPath) { | 
|  | 2848 | t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags) | 
|  | 2849 | } | 
| Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2850 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2851 | libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc") | 
| Jiyong Park | da732bd | 2018-11-02 18:23:15 +0900 | [diff] [blame] | 2852 | cFlags := libBarCompileRule.Args["cFlags"] | 
|  | 2853 | libFoo1VersioningMacro := "-D__LIBFOO_API__=1" | 
|  | 2854 | if !strings.Contains(cFlags, libFoo1VersioningMacro) { | 
|  | 2855 | t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags) | 
|  | 2856 | } | 
| Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 2857 | } | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2858 |  | 
| Jooyung Han | 89124ba | 2020-03-13 18:57:35 +0900 | [diff] [blame] | 2859 | func TestVersioningMacro(t *testing.T) { | 
|  | 2860 | for _, tc := range []struct{ moduleName, expected string }{ | 
|  | 2861 | {"libc", "__LIBC_API__"}, | 
|  | 2862 | {"libfoo", "__LIBFOO_API__"}, | 
|  | 2863 | {"libfoo@1", "__LIBFOO_1_API__"}, | 
|  | 2864 | {"libfoo-v1", "__LIBFOO_V1_API__"}, | 
|  | 2865 | {"libfoo.v1", "__LIBFOO_V1_API__"}, | 
|  | 2866 | } { | 
|  | 2867 | checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName)) | 
|  | 2868 | } | 
|  | 2869 | } | 
|  | 2870 |  | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2871 | func TestStaticExecutable(t *testing.T) { | 
|  | 2872 | ctx := testCc(t, ` | 
|  | 2873 | cc_binary { | 
|  | 2874 | name: "static_test", | 
| Pete Bentley | fcf55bf | 2019-08-16 20:14:32 +0100 | [diff] [blame] | 2875 | srcs: ["foo.c", "baz.o"], | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2876 | static_executable: true, | 
|  | 2877 | }`) | 
|  | 2878 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2879 | variant := "android_arm64_armv8-a" | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2880 | binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld") | 
|  | 2881 | libFlags := binModuleRule.Args["libFlags"] | 
| Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 2882 | systemStaticLibs := []string{"libc.a", "libm.a"} | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 2883 | for _, lib := range systemStaticLibs { | 
|  | 2884 | if !strings.Contains(libFlags, lib) { | 
|  | 2885 | t.Errorf("Static lib %q was not found in %q", lib, libFlags) | 
|  | 2886 | } | 
|  | 2887 | } | 
|  | 2888 | systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"} | 
|  | 2889 | for _, lib := range systemSharedLibs { | 
|  | 2890 | if strings.Contains(libFlags, lib) { | 
|  | 2891 | t.Errorf("Shared lib %q was found in %q", lib, libFlags) | 
|  | 2892 | } | 
|  | 2893 | } | 
|  | 2894 | } | 
| Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2895 |  | 
|  | 2896 | func TestStaticDepsOrderWithStubs(t *testing.T) { | 
|  | 2897 | ctx := testCc(t, ` | 
|  | 2898 | cc_binary { | 
|  | 2899 | name: "mybin", | 
|  | 2900 | srcs: ["foo.c"], | 
| Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2901 | static_libs: ["libfooB"], | 
| Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2902 | static_executable: true, | 
|  | 2903 | stl: "none", | 
|  | 2904 | } | 
|  | 2905 |  | 
|  | 2906 | cc_library { | 
| Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2907 | name: "libfooB", | 
| Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2908 | srcs: ["foo.c"], | 
| Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2909 | shared_libs: ["libfooC"], | 
| Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2910 | stl: "none", | 
|  | 2911 | } | 
|  | 2912 |  | 
|  | 2913 | cc_library { | 
| Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2914 | name: "libfooC", | 
| Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2915 | srcs: ["foo.c"], | 
|  | 2916 | stl: "none", | 
|  | 2917 | stubs: { | 
|  | 2918 | versions: ["1"], | 
|  | 2919 | }, | 
|  | 2920 | }`) | 
|  | 2921 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2922 | mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Module().(*Module) | 
| Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2923 | actual := mybin.depsInLinkOrder | 
| Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 2924 | expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"}) | 
| Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2925 |  | 
|  | 2926 | if !reflect.DeepEqual(actual, expected) { | 
|  | 2927 | t.Errorf("staticDeps orderings were not propagated correctly"+ | 
|  | 2928 | "\nactual:   %v"+ | 
|  | 2929 | "\nexpected: %v", | 
|  | 2930 | actual, | 
|  | 2931 | expected, | 
|  | 2932 | ) | 
|  | 2933 | } | 
|  | 2934 | } | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2935 |  | 
| Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 2936 | func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { | 
|  | 2937 | testCcError(t, `module "libA" .* depends on disabled module "libB"`, ` | 
|  | 2938 | cc_library { | 
|  | 2939 | name: "libA", | 
|  | 2940 | srcs: ["foo.c"], | 
|  | 2941 | shared_libs: ["libB"], | 
|  | 2942 | stl: "none", | 
|  | 2943 | } | 
|  | 2944 |  | 
|  | 2945 | cc_library { | 
|  | 2946 | name: "libB", | 
|  | 2947 | srcs: ["foo.c"], | 
|  | 2948 | enabled: false, | 
|  | 2949 | stl: "none", | 
|  | 2950 | } | 
|  | 2951 | `) | 
|  | 2952 | } | 
|  | 2953 |  | 
| Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 2954 | // Simple smoke test for the cc_fuzz target that ensures the rule compiles | 
|  | 2955 | // correctly. | 
|  | 2956 | func TestFuzzTarget(t *testing.T) { | 
|  | 2957 | ctx := testCc(t, ` | 
|  | 2958 | cc_fuzz { | 
|  | 2959 | name: "fuzz_smoke_test", | 
|  | 2960 | srcs: ["foo.c"], | 
|  | 2961 | }`) | 
|  | 2962 |  | 
| Paul Duffin | 075c417 | 2019-12-19 19:06:13 +0000 | [diff] [blame] | 2963 | variant := "android_arm64_armv8-a_fuzzer" | 
| Mitch Phillips | da9a463 | 2019-07-15 09:34:09 -0700 | [diff] [blame] | 2964 | ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc") | 
|  | 2965 | } | 
|  | 2966 |  | 
| Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 2967 | func TestAidl(t *testing.T) { | 
|  | 2968 | } | 
|  | 2969 |  | 
| Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2970 | func assertString(t *testing.T, got, expected string) { | 
|  | 2971 | t.Helper() | 
|  | 2972 | if got != expected { | 
|  | 2973 | t.Errorf("expected %q got %q", expected, got) | 
|  | 2974 | } | 
|  | 2975 | } | 
|  | 2976 |  | 
|  | 2977 | func assertArrayString(t *testing.T, got, expected []string) { | 
|  | 2978 | t.Helper() | 
|  | 2979 | if len(got) != len(expected) { | 
|  | 2980 | t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got) | 
|  | 2981 | return | 
|  | 2982 | } | 
|  | 2983 | for i := range got { | 
|  | 2984 | if got[i] != expected[i] { | 
|  | 2985 | t.Errorf("expected %d-th %q (%q) got %q (%q)", | 
|  | 2986 | i, expected[i], expected, got[i], got) | 
|  | 2987 | return | 
|  | 2988 | } | 
|  | 2989 | } | 
|  | 2990 | } | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2991 |  | 
| Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2992 | func assertMapKeys(t *testing.T, m map[string]string, expected []string) { | 
|  | 2993 | t.Helper() | 
|  | 2994 | assertArrayString(t, android.SortedStringKeys(m), expected) | 
|  | 2995 | } | 
|  | 2996 |  | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 2997 | func TestDefaults(t *testing.T) { | 
|  | 2998 | ctx := testCc(t, ` | 
|  | 2999 | cc_defaults { | 
|  | 3000 | name: "defaults", | 
|  | 3001 | srcs: ["foo.c"], | 
|  | 3002 | static: { | 
|  | 3003 | srcs: ["bar.c"], | 
|  | 3004 | }, | 
|  | 3005 | shared: { | 
|  | 3006 | srcs: ["baz.c"], | 
|  | 3007 | }, | 
|  | 3008 | } | 
|  | 3009 |  | 
|  | 3010 | cc_library_static { | 
|  | 3011 | name: "libstatic", | 
|  | 3012 | defaults: ["defaults"], | 
|  | 3013 | } | 
|  | 3014 |  | 
|  | 3015 | cc_library_shared { | 
|  | 3016 | name: "libshared", | 
|  | 3017 | defaults: ["defaults"], | 
|  | 3018 | } | 
|  | 3019 |  | 
|  | 3020 | cc_library { | 
|  | 3021 | name: "libboth", | 
|  | 3022 | defaults: ["defaults"], | 
|  | 3023 | } | 
|  | 3024 |  | 
|  | 3025 | cc_binary { | 
|  | 3026 | name: "binary", | 
|  | 3027 | defaults: ["defaults"], | 
|  | 3028 | }`) | 
|  | 3029 |  | 
|  | 3030 | pathsToBase := func(paths android.Paths) []string { | 
|  | 3031 | var ret []string | 
|  | 3032 | for _, p := range paths { | 
|  | 3033 | ret = append(ret, p.Base()) | 
|  | 3034 | } | 
|  | 3035 | return ret | 
|  | 3036 | } | 
|  | 3037 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3038 | shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld") | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3039 | if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { | 
|  | 3040 | t.Errorf("libshared ld rule wanted %q, got %q", w, g) | 
|  | 3041 | } | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3042 | bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld") | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3043 | if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { | 
|  | 3044 | t.Errorf("libboth ld rule wanted %q, got %q", w, g) | 
|  | 3045 | } | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3046 | binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld") | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3047 | if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { | 
|  | 3048 | t.Errorf("binary ld rule wanted %q, got %q", w, g) | 
|  | 3049 | } | 
|  | 3050 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3051 | static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar") | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3052 | if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { | 
|  | 3053 | t.Errorf("libstatic ar rule wanted %q, got %q", w, g) | 
|  | 3054 | } | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3055 | bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar") | 
| Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3056 | if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { | 
|  | 3057 | t.Errorf("libboth ar rule wanted %q, got %q", w, g) | 
|  | 3058 | } | 
|  | 3059 | } | 
| Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 3060 |  | 
|  | 3061 | func TestProductVariableDefaults(t *testing.T) { | 
|  | 3062 | bp := ` | 
|  | 3063 | cc_defaults { | 
|  | 3064 | name: "libfoo_defaults", | 
|  | 3065 | srcs: ["foo.c"], | 
|  | 3066 | cppflags: ["-DFOO"], | 
|  | 3067 | product_variables: { | 
|  | 3068 | debuggable: { | 
|  | 3069 | cppflags: ["-DBAR"], | 
|  | 3070 | }, | 
|  | 3071 | }, | 
|  | 3072 | } | 
|  | 3073 |  | 
|  | 3074 | cc_library { | 
|  | 3075 | name: "libfoo", | 
|  | 3076 | defaults: ["libfoo_defaults"], | 
|  | 3077 | } | 
|  | 3078 | ` | 
|  | 3079 |  | 
|  | 3080 | config := TestConfig(buildDir, android.Android, nil, bp, nil) | 
|  | 3081 | config.TestProductVariables.Debuggable = BoolPtr(true) | 
|  | 3082 |  | 
|  | 3083 | ctx := CreateTestContext() | 
|  | 3084 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { | 
|  | 3085 | ctx.BottomUp("variable", android.VariableMutator).Parallel() | 
|  | 3086 | }) | 
|  | 3087 | ctx.Register(config) | 
|  | 3088 |  | 
|  | 3089 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) | 
|  | 3090 | android.FailIfErrored(t, errs) | 
|  | 3091 | _, errs = ctx.PrepareBuildActions(config) | 
|  | 3092 | android.FailIfErrored(t, errs) | 
|  | 3093 |  | 
|  | 3094 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) | 
|  | 3095 | if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) { | 
|  | 3096 | t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags) | 
|  | 3097 | } | 
|  | 3098 | } |