| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1 | // Copyright 2018 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 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 18 | "io/ioutil" |
| 19 | "os" |
| 20 | "strings" |
| 21 | "testing" |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/cc" |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 27 | "android/soong/java" |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 28 | ) |
| 29 | |
| Jaewoong Jung | d6585fe | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 30 | var buildDir string |
| 31 | |
| Jaewoong Jung | 9c49b28 | 2020-05-14 14:15:24 -0700 | [diff] [blame^] | 32 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 33 | |
| 34 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) *android.TestContext { |
| Jaewoong Jung | d6585fe | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 35 | var config android.Config |
| 36 | config, buildDir = setup(t) |
| Jaewoong Jung | 9c49b28 | 2020-05-14 14:15:24 -0700 | [diff] [blame^] | 37 | for _, handler := range handlers { |
| 38 | tempFS := map[string][]byte{} |
| 39 | handler(tempFS, config) |
| 40 | } |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 41 | defer teardown(buildDir) |
| 42 | |
| 43 | ctx := android.NewTestArchContext() |
| Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 44 | ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory)) |
| 45 | ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory)) |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 46 | ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory)) |
| Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 47 | ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) |
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 48 | ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory)) |
| Jaewoong Jung | 9c49b28 | 2020-05-14 14:15:24 -0700 | [diff] [blame^] | 49 | ctx.RegisterModuleType("apex_set", android.ModuleFactoryAdaptor(apexSetFactory)) |
| Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 50 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 51 | |
| 52 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 53 | ctx.TopDown("apex_deps", apexDepsMutator) |
| 54 | ctx.BottomUp("apex", apexMutator) |
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 55 | ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel() |
| 56 | ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel() |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 57 | }) |
| 58 | |
| 59 | ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) |
| 60 | ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory)) |
| Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 61 | ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory)) |
| Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 62 | ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory)) |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 63 | ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 64 | ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 65 | ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) |
| Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 66 | ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) |
| Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 67 | ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory)) |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 68 | ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory)) |
| Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 69 | ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) |
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 70 | ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 71 | ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel() |
| 72 | }) |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 73 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 74 | ctx.BottomUp("image", cc.ImageMutator).Parallel() |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 75 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 76 | ctx.BottomUp("vndk", cc.VndkMutator).Parallel() |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 77 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 78 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
| 79 | }) |
| 80 | |
| 81 | ctx.Register() |
| 82 | |
| 83 | bp = bp + ` |
| 84 | toolchain_library { |
| 85 | name: "libcompiler_rt-extras", |
| 86 | src: "", |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 87 | vendor_available: true, |
| 88 | recovery_available: true, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | toolchain_library { |
| 92 | name: "libatomic", |
| 93 | src: "", |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 94 | vendor_available: true, |
| 95 | recovery_available: true, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | toolchain_library { |
| 99 | name: "libgcc", |
| 100 | src: "", |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 101 | vendor_available: true, |
| 102 | recovery_available: true, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | toolchain_library { |
| Yi Kong | b0e95c1 | 2019-05-07 04:46:14 +0000 | [diff] [blame] | 106 | name: "libgcc_stripped", |
| 107 | src: "", |
| 108 | vendor_available: true, |
| 109 | recovery_available: true, |
| 110 | } |
| 111 | |
| 112 | toolchain_library { |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 113 | name: "libclang_rt.builtins-aarch64-android", |
| 114 | src: "", |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 115 | vendor_available: true, |
| 116 | recovery_available: true, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | toolchain_library { |
| 120 | name: "libclang_rt.builtins-arm-android", |
| 121 | src: "", |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 122 | vendor_available: true, |
| 123 | recovery_available: true, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | cc_object { |
| 127 | name: "crtbegin_so", |
| 128 | stl: "none", |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 129 | vendor_available: true, |
| 130 | recovery_available: true, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | cc_object { |
| 134 | name: "crtend_so", |
| 135 | stl: "none", |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 136 | vendor_available: true, |
| 137 | recovery_available: true, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 138 | } |
| 139 | |
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 140 | cc_object { |
| 141 | name: "crtbegin_static", |
| 142 | stl: "none", |
| 143 | } |
| 144 | |
| 145 | cc_object { |
| 146 | name: "crtend_android", |
| 147 | stl: "none", |
| 148 | } |
| 149 | |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 150 | llndk_library { |
| 151 | name: "libc", |
| 152 | symbol_file: "", |
| 153 | } |
| 154 | |
| 155 | llndk_library { |
| 156 | name: "libm", |
| 157 | symbol_file: "", |
| 158 | } |
| 159 | |
| 160 | llndk_library { |
| 161 | name: "libdl", |
| 162 | symbol_file: "", |
| 163 | } |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 164 | ` |
| 165 | |
| 166 | ctx.MockFileSystem(map[string][]byte{ |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 167 | "Android.bp": []byte(bp), |
| 168 | "build/target/product/security": nil, |
| 169 | "apex_manifest.json": nil, |
| Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 170 | "AndroidManifest.xml": nil, |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 171 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 172 | "system/sepolicy/apex/myapex_keytest-file_contexts": nil, |
| 173 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 174 | "mylib.cpp": nil, |
| 175 | "myprebuilt": nil, |
| 176 | "my_include": nil, |
| 177 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 178 | "vendor/foo/devkeys/test.pk8": nil, |
| 179 | "testkey.x509.pem": nil, |
| 180 | "testkey.pk8": nil, |
| 181 | "testkey.override.x509.pem": nil, |
| 182 | "testkey.override.pk8": nil, |
| 183 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 184 | "vendor/foo/devkeys/testkey.pem": nil, |
| Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 185 | "NOTICE": nil, |
| 186 | "custom_notice": nil, |
| Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 187 | "testkey2.avbpubkey": nil, |
| 188 | "testkey2.pem": nil, |
| Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 189 | "myapex-arm64.apex": nil, |
| 190 | "myapex-arm.apex": nil, |
| Jaewoong Jung | 9c49b28 | 2020-05-14 14:15:24 -0700 | [diff] [blame^] | 191 | "myapex.apks": nil, |
| Jiyong Park | d37a882 | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 192 | "frameworks/base/api/current.txt": nil, |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 193 | }) |
| 194 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 195 | android.FailIfErrored(t, errs) |
| 196 | _, errs = ctx.PrepareBuildActions(config) |
| 197 | android.FailIfErrored(t, errs) |
| 198 | |
| 199 | return ctx |
| 200 | } |
| 201 | |
| 202 | func setup(t *testing.T) (config android.Config, buildDir string) { |
| 203 | buildDir, err := ioutil.TempDir("", "soong_apex_test") |
| 204 | if err != nil { |
| 205 | t.Fatal(err) |
| 206 | } |
| 207 | |
| 208 | config = android.TestArchConfig(buildDir, nil) |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 209 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 210 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 211 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| Jiyong Park | d37a882 | 2019-04-18 17:25:49 +0900 | [diff] [blame] | 212 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 213 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 214 | return |
| 215 | } |
| 216 | |
| 217 | func teardown(buildDir string) { |
| 218 | os.RemoveAll(buildDir) |
| 219 | } |
| 220 | |
| 221 | // ensure that 'result' contains 'expected' |
| 222 | func ensureContains(t *testing.T, result string, expected string) { |
| 223 | if !strings.Contains(result, expected) { |
| 224 | t.Errorf("%q is not found in %q", expected, result) |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // ensures that 'result' does not contain 'notExpected' |
| 229 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
| 230 | if strings.Contains(result, notExpected) { |
| 231 | t.Errorf("%q is found in %q", notExpected, result) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | func ensureListContains(t *testing.T, result []string, expected string) { |
| 236 | if !android.InList(expected, result) { |
| 237 | t.Errorf("%q is not found in %v", expected, result) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
| 242 | if android.InList(notExpected, result) { |
| 243 | t.Errorf("%q is found in %v", notExpected, result) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // Minimal test |
| 248 | func TestBasicApex(t *testing.T) { |
| 249 | ctx := testApex(t, ` |
| Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 250 | apex_defaults { |
| 251 | name: "myapex-defaults", |
| Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 252 | manifest: ":myapex.manifest", |
| 253 | androidManifest: ":myapex.androidmanifest", |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 254 | key: "myapex.key", |
| 255 | native_shared_libs: ["mylib"], |
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 256 | multilib: { |
| 257 | both: { |
| 258 | binaries: ["foo",], |
| 259 | } |
| 260 | } |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 261 | } |
| 262 | |
| Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 263 | apex { |
| 264 | name: "myapex", |
| 265 | defaults: ["myapex-defaults"], |
| 266 | } |
| 267 | |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 268 | apex_key { |
| 269 | name: "myapex.key", |
| 270 | public_key: "testkey.avbpubkey", |
| 271 | private_key: "testkey.pem", |
| 272 | } |
| 273 | |
| Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 274 | filegroup { |
| 275 | name: "myapex.manifest", |
| 276 | srcs: ["apex_manifest.json"], |
| 277 | } |
| 278 | |
| 279 | filegroup { |
| 280 | name: "myapex.androidmanifest", |
| 281 | srcs: ["AndroidManifest.xml"], |
| 282 | } |
| 283 | |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 284 | cc_library { |
| 285 | name: "mylib", |
| 286 | srcs: ["mylib.cpp"], |
| 287 | shared_libs: ["mylib2"], |
| 288 | system_shared_libs: [], |
| 289 | stl: "none", |
| 290 | } |
| 291 | |
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 292 | cc_binary { |
| 293 | name: "foo", |
| 294 | srcs: ["mylib.cpp"], |
| 295 | compile_multilib: "both", |
| 296 | multilib: { |
| 297 | lib32: { |
| 298 | suffix: "32", |
| 299 | }, |
| 300 | lib64: { |
| 301 | suffix: "64", |
| 302 | }, |
| 303 | }, |
| 304 | symlinks: ["foo_link_"], |
| 305 | symlink_preferred_arch: true, |
| 306 | system_shared_libs: [], |
| 307 | static_executable: true, |
| 308 | stl: "none", |
| 309 | } |
| 310 | |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 311 | cc_library { |
| 312 | name: "mylib2", |
| 313 | srcs: ["mylib.cpp"], |
| 314 | system_shared_libs: [], |
| 315 | stl: "none", |
| Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 316 | notice: "custom_notice", |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 317 | } |
| 318 | `) |
| 319 | |
| 320 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 321 | |
| 322 | optFlags := apexRule.Args["opt_flags"] |
| 323 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
| Jaewoong Jung | d6585fe | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 324 | // Ensure that the NOTICE output is being packaged as an asset. |
| 325 | ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE") |
| Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 326 | |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 327 | copyCmds := apexRule.Args["copy_commands"] |
| 328 | |
| 329 | // Ensure that main rule creates an output |
| 330 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 331 | |
| 332 | // Ensure that apex variant is created for the direct dep |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 333 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 334 | |
| 335 | // Ensure that apex variant is created for the indirect dep |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 336 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 337 | |
| 338 | // Ensure that both direct and indirect deps are copied into apex |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 339 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 340 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 341 | |
| 342 | // Ensure that the platform variant ends with _core_shared |
| 343 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 344 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 345 | |
| 346 | // Ensure that all symlinks are present. |
| 347 | found_foo_link_64 := false |
| 348 | found_foo := false |
| 349 | for _, cmd := range strings.Split(copyCmds, " && ") { |
| 350 | if strings.HasPrefix(cmd, "ln -s foo64") { |
| 351 | if strings.HasSuffix(cmd, "bin/foo") { |
| 352 | found_foo = true |
| 353 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 354 | found_foo_link_64 = true |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | good := found_foo && found_foo_link_64 |
| 359 | if !good { |
| 360 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 361 | } |
| Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 362 | |
| Jaewoong Jung | 5c6572e | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 363 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule") |
| 364 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
| Jaewoong Jung | d6585fe | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 365 | if len(noticeInputs) != 2 { |
| 366 | t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs)) |
| Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 367 | } |
| 368 | ensureListContains(t, noticeInputs, "NOTICE") |
| 369 | ensureListContains(t, noticeInputs, "custom_notice") |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | func TestBasicZipApex(t *testing.T) { |
| 373 | ctx := testApex(t, ` |
| 374 | apex { |
| 375 | name: "myapex", |
| 376 | key: "myapex.key", |
| 377 | payload_type: "zip", |
| 378 | native_shared_libs: ["mylib"], |
| 379 | } |
| 380 | |
| 381 | apex_key { |
| 382 | name: "myapex.key", |
| 383 | public_key: "testkey.avbpubkey", |
| 384 | private_key: "testkey.pem", |
| 385 | } |
| 386 | |
| 387 | cc_library { |
| 388 | name: "mylib", |
| 389 | srcs: ["mylib.cpp"], |
| 390 | shared_libs: ["mylib2"], |
| 391 | system_shared_libs: [], |
| 392 | stl: "none", |
| 393 | } |
| 394 | |
| 395 | cc_library { |
| 396 | name: "mylib2", |
| 397 | srcs: ["mylib.cpp"], |
| 398 | system_shared_libs: [], |
| 399 | stl: "none", |
| 400 | } |
| 401 | `) |
| 402 | |
| 403 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule") |
| 404 | copyCmds := zipApexRule.Args["copy_commands"] |
| 405 | |
| 406 | // Ensure that main rule creates an output |
| 407 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 408 | |
| 409 | // Ensure that APEX variant is created for the direct dep |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 410 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 411 | |
| 412 | // Ensure that APEX variant is created for the indirect dep |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 413 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 414 | |
| 415 | // Ensure that both direct and indirect deps are copied into apex |
| 416 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 417 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | func TestApexWithStubs(t *testing.T) { |
| 421 | ctx := testApex(t, ` |
| 422 | apex { |
| 423 | name: "myapex", |
| 424 | key: "myapex.key", |
| 425 | native_shared_libs: ["mylib", "mylib3"], |
| 426 | } |
| 427 | |
| 428 | apex_key { |
| 429 | name: "myapex.key", |
| 430 | public_key: "testkey.avbpubkey", |
| 431 | private_key: "testkey.pem", |
| 432 | } |
| 433 | |
| 434 | cc_library { |
| 435 | name: "mylib", |
| 436 | srcs: ["mylib.cpp"], |
| 437 | shared_libs: ["mylib2", "mylib3"], |
| 438 | system_shared_libs: [], |
| 439 | stl: "none", |
| 440 | } |
| 441 | |
| 442 | cc_library { |
| 443 | name: "mylib2", |
| 444 | srcs: ["mylib.cpp"], |
| Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 445 | cflags: ["-include mylib.h"], |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 446 | system_shared_libs: [], |
| 447 | stl: "none", |
| 448 | stubs: { |
| 449 | versions: ["1", "2", "3"], |
| 450 | }, |
| 451 | } |
| 452 | |
| 453 | cc_library { |
| 454 | name: "mylib3", |
| Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 455 | srcs: ["mylib.cpp"], |
| 456 | shared_libs: ["mylib4"], |
| 457 | system_shared_libs: [], |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 458 | stl: "none", |
| 459 | stubs: { |
| 460 | versions: ["10", "11", "12"], |
| 461 | }, |
| 462 | } |
| Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 463 | |
| 464 | cc_library { |
| 465 | name: "mylib4", |
| 466 | srcs: ["mylib.cpp"], |
| 467 | system_shared_libs: [], |
| 468 | stl: "none", |
| 469 | } |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 470 | `) |
| 471 | |
| 472 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 473 | copyCmds := apexRule.Args["copy_commands"] |
| 474 | |
| 475 | // Ensure that direct non-stubs dep is always included |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 476 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 477 | |
| 478 | // Ensure that indirect stubs dep is not included |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 479 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 480 | |
| 481 | // Ensure that direct stubs dep is included |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 482 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 483 | |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 484 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 485 | |
| 486 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 487 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 488 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 489 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 490 | |
| 491 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 492 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 493 | // .. and not linking to the stubs variant of mylib3 |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 494 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so") |
| Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 495 | |
| 496 | // Ensure that stubs libs are built without -include flags |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 497 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 498 | ensureNotContains(t, mylib2Cflags, "-include ") |
| Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 499 | |
| 500 | // Ensure that genstub is invoked with --apex |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 501 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"]) |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 502 | } |
| 503 | |
| Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 504 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
| 505 | ctx := testApex(t, ` |
| 506 | apex { |
| 507 | name: "myapex", |
| 508 | key: "myapex.key", |
| 509 | native_shared_libs: ["mylib"], |
| 510 | } |
| 511 | |
| 512 | apex_key { |
| 513 | name: "myapex.key", |
| 514 | public_key: "testkey.avbpubkey", |
| 515 | private_key: "testkey.pem", |
| 516 | } |
| 517 | |
| 518 | cc_library { |
| 519 | name: "mylib", |
| 520 | srcs: ["mylib.cpp"], |
| 521 | shared_libs: ["libfoo#10"], |
| 522 | system_shared_libs: [], |
| 523 | stl: "none", |
| 524 | } |
| 525 | |
| 526 | cc_library { |
| 527 | name: "libfoo", |
| 528 | srcs: ["mylib.cpp"], |
| 529 | shared_libs: ["libbar"], |
| 530 | system_shared_libs: [], |
| 531 | stl: "none", |
| 532 | stubs: { |
| 533 | versions: ["10", "20", "30"], |
| 534 | }, |
| 535 | } |
| 536 | |
| 537 | cc_library { |
| 538 | name: "libbar", |
| 539 | srcs: ["mylib.cpp"], |
| 540 | system_shared_libs: [], |
| 541 | stl: "none", |
| 542 | } |
| 543 | |
| 544 | `) |
| 545 | |
| 546 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 547 | copyCmds := apexRule.Args["copy_commands"] |
| 548 | |
| 549 | // Ensure that direct non-stubs dep is always included |
| 550 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 551 | |
| 552 | // Ensure that indirect stubs dep is not included |
| 553 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 554 | |
| 555 | // Ensure that dependency of stubs is not included |
| 556 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 557 | |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 558 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
| Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 559 | |
| 560 | // Ensure that mylib is linking with version 10 of libfoo |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 561 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so") |
| Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 562 | // ... and not linking to the non-stub (impl) variant of libfoo |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 563 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so") |
| Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 564 | |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 565 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"] |
| Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 566 | |
| 567 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 568 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
| 569 | } |
| 570 | |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 571 | func TestApexWithSystemLibsStubs(t *testing.T) { |
| 572 | ctx := testApex(t, ` |
| 573 | apex { |
| 574 | name: "myapex", |
| 575 | key: "myapex.key", |
| 576 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 577 | } |
| 578 | |
| 579 | apex_key { |
| 580 | name: "myapex.key", |
| 581 | public_key: "testkey.avbpubkey", |
| 582 | private_key: "testkey.pem", |
| 583 | } |
| 584 | |
| 585 | cc_library { |
| 586 | name: "mylib", |
| 587 | srcs: ["mylib.cpp"], |
| 588 | shared_libs: ["libdl#27"], |
| 589 | stl: "none", |
| 590 | } |
| 591 | |
| 592 | cc_library_shared { |
| 593 | name: "mylib_shared", |
| 594 | srcs: ["mylib.cpp"], |
| 595 | shared_libs: ["libdl#27"], |
| 596 | stl: "none", |
| 597 | } |
| 598 | |
| 599 | cc_library { |
| 600 | name: "libc", |
| 601 | no_libgcc: true, |
| 602 | nocrt: true, |
| 603 | system_shared_libs: [], |
| 604 | stl: "none", |
| 605 | stubs: { |
| 606 | versions: ["27", "28", "29"], |
| 607 | }, |
| 608 | } |
| 609 | |
| 610 | cc_library { |
| 611 | name: "libm", |
| 612 | no_libgcc: true, |
| 613 | nocrt: true, |
| 614 | system_shared_libs: [], |
| 615 | stl: "none", |
| 616 | stubs: { |
| 617 | versions: ["27", "28", "29"], |
| 618 | }, |
| 619 | } |
| 620 | |
| 621 | cc_library { |
| 622 | name: "libdl", |
| 623 | no_libgcc: true, |
| 624 | nocrt: true, |
| 625 | system_shared_libs: [], |
| 626 | stl: "none", |
| 627 | stubs: { |
| 628 | versions: ["27", "28", "29"], |
| 629 | }, |
| 630 | } |
| Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 631 | |
| 632 | cc_library { |
| 633 | name: "libBootstrap", |
| 634 | srcs: ["mylib.cpp"], |
| 635 | stl: "none", |
| 636 | bootstrap: true, |
| 637 | } |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 638 | `) |
| 639 | |
| 640 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 641 | copyCmds := apexRule.Args["copy_commands"] |
| 642 | |
| 643 | // Ensure that mylib, libm, libdl are included. |
| Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 644 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 645 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 646 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 647 | |
| 648 | // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs) |
| Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 649 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 650 | |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 651 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
| 652 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 653 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"] |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 654 | |
| 655 | // For dependency to libc |
| 656 | // Ensure that mylib is linking with the latest version of stubs |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 657 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 658 | // ... and not linking to the non-stub (impl) variant |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 659 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 660 | // ... Cflags from stub is correctly exported to mylib |
| 661 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 662 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 663 | |
| 664 | // For dependency to libm |
| 665 | // Ensure that mylib is linking with the non-stub (impl) variant |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 666 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 667 | // ... and not linking to the stub variant |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 668 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 669 | // ... and is not compiling with the stub |
| 670 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 671 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 672 | |
| 673 | // For dependency to libdl |
| 674 | // Ensure that mylib is linking with the specified version of stubs |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 675 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 676 | // ... and not linking to the other versions of stubs |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 677 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so") |
| 678 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 679 | // ... and not linking to the non-stub (impl) variant |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 680 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 681 | // ... Cflags from stub is correctly exported to mylib |
| 682 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 683 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
| Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 684 | |
| 685 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
| 686 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"] |
| 687 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so") |
| 688 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so") |
| 689 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so") |
| Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 690 | } |
| Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 691 | |
| 692 | func TestFilesInSubDir(t *testing.T) { |
| 693 | ctx := testApex(t, ` |
| 694 | apex { |
| 695 | name: "myapex", |
| 696 | key: "myapex.key", |
| Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 697 | native_shared_libs: ["mylib"], |
| 698 | binaries: ["mybin"], |
| Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 699 | prebuilts: ["myetc"], |
| Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 700 | compile_multilib: "both", |
| Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | apex_key { |
| 704 | name: "myapex.key", |
| 705 | public_key: "testkey.avbpubkey", |
| 706 | private_key: "testkey.pem", |
| 707 | } |
| 708 | |
| 709 | prebuilt_etc { |
| 710 | name: "myetc", |
| 711 | src: "myprebuilt", |
| 712 | sub_dir: "foo/bar", |
| 713 | } |
| Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 714 | |
| 715 | cc_library { |
| 716 | name: "mylib", |
| 717 | srcs: ["mylib.cpp"], |
| 718 | relative_install_path: "foo/bar", |
| 719 | system_shared_libs: [], |
| 720 | stl: "none", |
| 721 | } |
| 722 | |
| 723 | cc_binary { |
| 724 | name: "mybin", |
| 725 | srcs: ["mylib.cpp"], |
| 726 | relative_install_path: "foo/bar", |
| 727 | system_shared_libs: [], |
| 728 | static_executable: true, |
| 729 | stl: "none", |
| 730 | } |
| Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 731 | `) |
| 732 | |
| 733 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig") |
| 734 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 735 | |
| Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 736 | // Ensure that the subdirectories are all listed |
| Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 737 | ensureListContains(t, dirs, "etc") |
| 738 | ensureListContains(t, dirs, "etc/foo") |
| 739 | ensureListContains(t, dirs, "etc/foo/bar") |
| Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 740 | ensureListContains(t, dirs, "lib64") |
| 741 | ensureListContains(t, dirs, "lib64/foo") |
| 742 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 743 | ensureListContains(t, dirs, "lib") |
| 744 | ensureListContains(t, dirs, "lib/foo") |
| 745 | ensureListContains(t, dirs, "lib/foo/bar") |
| 746 | |
| Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 747 | ensureListContains(t, dirs, "bin") |
| 748 | ensureListContains(t, dirs, "bin/foo") |
| 749 | ensureListContains(t, dirs, "bin/foo/bar") |
| Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 750 | } |
| Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 751 | |
| 752 | func TestUseVendor(t *testing.T) { |
| 753 | ctx := testApex(t, ` |
| 754 | apex { |
| 755 | name: "myapex", |
| 756 | key: "myapex.key", |
| 757 | native_shared_libs: ["mylib"], |
| 758 | use_vendor: true, |
| 759 | } |
| 760 | |
| 761 | apex_key { |
| 762 | name: "myapex.key", |
| 763 | public_key: "testkey.avbpubkey", |
| 764 | private_key: "testkey.pem", |
| 765 | } |
| 766 | |
| 767 | cc_library { |
| 768 | name: "mylib", |
| 769 | srcs: ["mylib.cpp"], |
| 770 | shared_libs: ["mylib2"], |
| 771 | system_shared_libs: [], |
| 772 | vendor_available: true, |
| 773 | stl: "none", |
| 774 | } |
| 775 | |
| 776 | cc_library { |
| 777 | name: "mylib2", |
| 778 | srcs: ["mylib.cpp"], |
| 779 | system_shared_libs: [], |
| 780 | vendor_available: true, |
| 781 | stl: "none", |
| 782 | } |
| 783 | `) |
| 784 | |
| 785 | inputsList := []string{} |
| 786 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() { |
| 787 | for _, implicit := range i.Implicits { |
| 788 | inputsList = append(inputsList, implicit.String()) |
| 789 | } |
| 790 | } |
| 791 | inputsString := strings.Join(inputsList, " ") |
| 792 | |
| 793 | // ensure that the apex includes vendor variants of the direct and indirect deps |
| 794 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so") |
| 795 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so") |
| 796 | |
| 797 | // ensure that the apex does not include core variants |
| 798 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so") |
| 799 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
| 800 | } |
| Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 801 | |
| 802 | func TestStaticLinking(t *testing.T) { |
| 803 | ctx := testApex(t, ` |
| 804 | apex { |
| 805 | name: "myapex", |
| 806 | key: "myapex.key", |
| 807 | native_shared_libs: ["mylib"], |
| 808 | } |
| 809 | |
| 810 | apex_key { |
| 811 | name: "myapex.key", |
| 812 | public_key: "testkey.avbpubkey", |
| 813 | private_key: "testkey.pem", |
| 814 | } |
| 815 | |
| 816 | cc_library { |
| 817 | name: "mylib", |
| 818 | srcs: ["mylib.cpp"], |
| 819 | system_shared_libs: [], |
| 820 | stl: "none", |
| 821 | stubs: { |
| 822 | versions: ["1", "2", "3"], |
| 823 | }, |
| 824 | } |
| 825 | |
| 826 | cc_binary { |
| 827 | name: "not_in_apex", |
| 828 | srcs: ["mylib.cpp"], |
| 829 | static_libs: ["mylib"], |
| 830 | static_executable: true, |
| 831 | system_shared_libs: [], |
| 832 | stl: "none", |
| 833 | } |
| Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 834 | `) |
| 835 | |
| 836 | ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"] |
| 837 | |
| 838 | // Ensure that not_in_apex is linking with the static variant of mylib |
| Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 839 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a") |
| Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 840 | } |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 841 | |
| 842 | func TestKeys(t *testing.T) { |
| 843 | ctx := testApex(t, ` |
| 844 | apex { |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 845 | name: "myapex_keytest", |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 846 | key: "myapex.key", |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 847 | certificate: ":myapex.certificate", |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 848 | native_shared_libs: ["mylib"], |
| 849 | } |
| 850 | |
| 851 | cc_library { |
| 852 | name: "mylib", |
| 853 | srcs: ["mylib.cpp"], |
| 854 | system_shared_libs: [], |
| 855 | stl: "none", |
| 856 | } |
| 857 | |
| 858 | apex_key { |
| 859 | name: "myapex.key", |
| 860 | public_key: "testkey.avbpubkey", |
| 861 | private_key: "testkey.pem", |
| 862 | } |
| 863 | |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 864 | android_app_certificate { |
| 865 | name: "myapex.certificate", |
| 866 | certificate: "testkey", |
| 867 | } |
| 868 | |
| 869 | android_app_certificate { |
| 870 | name: "myapex.certificate.override", |
| 871 | certificate: "testkey.override", |
| 872 | } |
| 873 | |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 874 | `) |
| 875 | |
| 876 | // check the APEX keys |
| Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 877 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 878 | |
| 879 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 880 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 881 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 882 | } |
| 883 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 884 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 885 | "vendor/foo/devkeys/testkey.pem") |
| 886 | } |
| 887 | |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 888 | // check the APK certs. It should be overridden to myapex.certificate.override |
| 889 | certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"] |
| 890 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 891 | t.Errorf("cert and private key %q are not %q", certs, |
| Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 892 | "testkey.override.509.pem testkey.override.pk8") |
| Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 893 | } |
| 894 | } |
| Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 895 | |
| 896 | func TestMacro(t *testing.T) { |
| 897 | ctx := testApex(t, ` |
| 898 | apex { |
| 899 | name: "myapex", |
| 900 | key: "myapex.key", |
| 901 | native_shared_libs: ["mylib"], |
| 902 | } |
| 903 | |
| 904 | apex { |
| 905 | name: "otherapex", |
| 906 | key: "myapex.key", |
| 907 | native_shared_libs: ["mylib"], |
| 908 | } |
| 909 | |
| 910 | apex_key { |
| 911 | name: "myapex.key", |
| 912 | public_key: "testkey.avbpubkey", |
| 913 | private_key: "testkey.pem", |
| 914 | } |
| 915 | |
| 916 | cc_library { |
| 917 | name: "mylib", |
| 918 | srcs: ["mylib.cpp"], |
| 919 | system_shared_libs: [], |
| 920 | stl: "none", |
| 921 | } |
| 922 | `) |
| 923 | |
| 924 | // non-APEX variant does not have __ANDROID__APEX__ defined |
| 925 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 926 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 927 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 928 | |
| 929 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 930 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 931 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 932 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 933 | |
| 934 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 935 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"] |
| 936 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 937 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 938 | } |
| Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 939 | |
| 940 | func TestHeaderLibsDependency(t *testing.T) { |
| 941 | ctx := testApex(t, ` |
| 942 | apex { |
| 943 | name: "myapex", |
| 944 | key: "myapex.key", |
| 945 | native_shared_libs: ["mylib"], |
| 946 | } |
| 947 | |
| 948 | apex_key { |
| 949 | name: "myapex.key", |
| 950 | public_key: "testkey.avbpubkey", |
| 951 | private_key: "testkey.pem", |
| 952 | } |
| 953 | |
| 954 | cc_library_headers { |
| 955 | name: "mylib_headers", |
| 956 | export_include_dirs: ["my_include"], |
| 957 | system_shared_libs: [], |
| 958 | stl: "none", |
| 959 | } |
| 960 | |
| 961 | cc_library { |
| 962 | name: "mylib", |
| 963 | srcs: ["mylib.cpp"], |
| 964 | system_shared_libs: [], |
| 965 | stl: "none", |
| 966 | header_libs: ["mylib_headers"], |
| 967 | export_header_lib_headers: ["mylib_headers"], |
| 968 | stubs: { |
| 969 | versions: ["1", "2", "3"], |
| 970 | }, |
| 971 | } |
| 972 | |
| 973 | cc_library { |
| 974 | name: "otherlib", |
| 975 | srcs: ["mylib.cpp"], |
| 976 | system_shared_libs: [], |
| 977 | stl: "none", |
| 978 | shared_libs: ["mylib"], |
| 979 | } |
| 980 | `) |
| 981 | |
| 982 | cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 983 | |
| 984 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 985 | ensureContains(t, cFlags, "-Imy_include") |
| 986 | } |
| Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 987 | |
| Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 988 | func TestNonTestApex(t *testing.T) { |
| 989 | ctx := testApex(t, ` |
| 990 | apex { |
| 991 | name: "myapex", |
| 992 | key: "myapex.key", |
| 993 | native_shared_libs: ["mylib_common"], |
| 994 | } |
| 995 | |
| 996 | apex_key { |
| 997 | name: "myapex.key", |
| 998 | public_key: "testkey.avbpubkey", |
| 999 | private_key: "testkey.pem", |
| 1000 | } |
| 1001 | |
| 1002 | cc_library { |
| 1003 | name: "mylib_common", |
| 1004 | srcs: ["mylib.cpp"], |
| 1005 | system_shared_libs: [], |
| 1006 | stl: "none", |
| 1007 | } |
| 1008 | `) |
| 1009 | |
| 1010 | module := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 1011 | apexRule := module.Rule("apexRule") |
| 1012 | copyCmds := apexRule.Args["copy_commands"] |
| 1013 | |
| 1014 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 1015 | t.Log("Apex was a test apex!") |
| 1016 | t.Fail() |
| 1017 | } |
| 1018 | // Ensure that main rule creates an output |
| 1019 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 1020 | |
| 1021 | // Ensure that apex variant is created for the direct dep |
| 1022 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex") |
| 1023 | |
| 1024 | // Ensure that both direct and indirect deps are copied into apex |
| 1025 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 1026 | |
| 1027 | // Ensure that the platform variant ends with _core_shared |
| 1028 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared") |
| 1029 | |
| 1030 | if !android.InAnyApex("mylib_common") { |
| 1031 | t.Log("Found mylib_common not in any apex!") |
| 1032 | t.Fail() |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | func TestTestApex(t *testing.T) { |
| 1037 | if android.InAnyApex("mylib_common_test") { |
| 1038 | t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!") |
| 1039 | } |
| 1040 | ctx := testApex(t, ` |
| 1041 | apex_test { |
| 1042 | name: "myapex", |
| 1043 | key: "myapex.key", |
| 1044 | native_shared_libs: ["mylib_common_test"], |
| 1045 | } |
| 1046 | |
| 1047 | apex_key { |
| 1048 | name: "myapex.key", |
| 1049 | public_key: "testkey.avbpubkey", |
| 1050 | private_key: "testkey.pem", |
| 1051 | } |
| 1052 | |
| 1053 | cc_library { |
| 1054 | name: "mylib_common_test", |
| 1055 | srcs: ["mylib.cpp"], |
| 1056 | system_shared_libs: [], |
| 1057 | stl: "none", |
| 1058 | } |
| 1059 | `) |
| 1060 | |
| 1061 | module := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 1062 | apexRule := module.Rule("apexRule") |
| 1063 | copyCmds := apexRule.Args["copy_commands"] |
| 1064 | |
| 1065 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 1066 | t.Log("Apex was not a test apex!") |
| 1067 | t.Fail() |
| 1068 | } |
| 1069 | // Ensure that main rule creates an output |
| 1070 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 1071 | |
| 1072 | // Ensure that apex variant is created for the direct dep |
| 1073 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex") |
| 1074 | |
| 1075 | // Ensure that both direct and indirect deps are copied into apex |
| 1076 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 1077 | |
| 1078 | // Ensure that the platform variant ends with _core_shared |
| 1079 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared") |
| 1080 | |
| 1081 | if android.InAnyApex("mylib_common_test") { |
| 1082 | t.Log("Found mylib_common_test in some apex!") |
| 1083 | t.Fail() |
| 1084 | } |
| 1085 | } |
| 1086 | |
| Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1087 | func TestApexWithTarget(t *testing.T) { |
| 1088 | ctx := testApex(t, ` |
| 1089 | apex { |
| 1090 | name: "myapex", |
| 1091 | key: "myapex.key", |
| 1092 | multilib: { |
| 1093 | first: { |
| 1094 | native_shared_libs: ["mylib_common"], |
| 1095 | } |
| 1096 | }, |
| 1097 | target: { |
| 1098 | android: { |
| 1099 | multilib: { |
| 1100 | first: { |
| 1101 | native_shared_libs: ["mylib"], |
| 1102 | } |
| 1103 | } |
| 1104 | }, |
| 1105 | host: { |
| 1106 | multilib: { |
| 1107 | first: { |
| 1108 | native_shared_libs: ["mylib2"], |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | apex_key { |
| 1116 | name: "myapex.key", |
| 1117 | public_key: "testkey.avbpubkey", |
| 1118 | private_key: "testkey.pem", |
| 1119 | } |
| 1120 | |
| 1121 | cc_library { |
| 1122 | name: "mylib", |
| 1123 | srcs: ["mylib.cpp"], |
| 1124 | system_shared_libs: [], |
| 1125 | stl: "none", |
| 1126 | } |
| 1127 | |
| 1128 | cc_library { |
| 1129 | name: "mylib_common", |
| 1130 | srcs: ["mylib.cpp"], |
| 1131 | system_shared_libs: [], |
| 1132 | stl: "none", |
| 1133 | compile_multilib: "first", |
| 1134 | } |
| 1135 | |
| 1136 | cc_library { |
| 1137 | name: "mylib2", |
| 1138 | srcs: ["mylib.cpp"], |
| 1139 | system_shared_libs: [], |
| 1140 | stl: "none", |
| 1141 | compile_multilib: "first", |
| 1142 | } |
| 1143 | `) |
| 1144 | |
| 1145 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 1146 | copyCmds := apexRule.Args["copy_commands"] |
| 1147 | |
| 1148 | // Ensure that main rule creates an output |
| 1149 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 1150 | |
| 1151 | // Ensure that apex variant is created for the direct dep |
| 1152 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
| 1153 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex") |
| 1154 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
| 1155 | |
| 1156 | // Ensure that both direct and indirect deps are copied into apex |
| 1157 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1158 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 1159 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1160 | |
| 1161 | // Ensure that the platform variant ends with _core_shared |
| 1162 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 1163 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared") |
| 1164 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
| 1165 | } |
| Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1166 | |
| 1167 | func TestApexWithShBinary(t *testing.T) { |
| 1168 | ctx := testApex(t, ` |
| 1169 | apex { |
| 1170 | name: "myapex", |
| 1171 | key: "myapex.key", |
| 1172 | binaries: ["myscript"], |
| 1173 | } |
| 1174 | |
| 1175 | apex_key { |
| 1176 | name: "myapex.key", |
| 1177 | public_key: "testkey.avbpubkey", |
| 1178 | private_key: "testkey.pem", |
| 1179 | } |
| 1180 | |
| 1181 | sh_binary { |
| 1182 | name: "myscript", |
| 1183 | src: "mylib.cpp", |
| 1184 | filename: "myscript.sh", |
| 1185 | sub_dir: "script", |
| 1186 | } |
| 1187 | `) |
| 1188 | |
| 1189 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 1190 | copyCmds := apexRule.Args["copy_commands"] |
| 1191 | |
| 1192 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 1193 | } |
| Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1194 | |
| 1195 | func TestApexInProductPartition(t *testing.T) { |
| 1196 | ctx := testApex(t, ` |
| 1197 | apex { |
| 1198 | name: "myapex", |
| 1199 | key: "myapex.key", |
| 1200 | native_shared_libs: ["mylib"], |
| 1201 | product_specific: true, |
| 1202 | } |
| 1203 | |
| 1204 | apex_key { |
| 1205 | name: "myapex.key", |
| 1206 | public_key: "testkey.avbpubkey", |
| 1207 | private_key: "testkey.pem", |
| 1208 | product_specific: true, |
| 1209 | } |
| 1210 | |
| 1211 | cc_library { |
| 1212 | name: "mylib", |
| 1213 | srcs: ["mylib.cpp"], |
| 1214 | system_shared_libs: [], |
| 1215 | stl: "none", |
| 1216 | } |
| 1217 | `) |
| 1218 | |
| 1219 | apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle) |
| 1220 | expected := "target/product/test_device/product/apex" |
| 1221 | actual := apex.installDir.RelPathString() |
| 1222 | if actual != expected { |
| 1223 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 1224 | } |
| Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1225 | } |
| Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 1226 | |
| 1227 | func TestApexKeyFromOtherModule(t *testing.T) { |
| 1228 | ctx := testApex(t, ` |
| 1229 | apex_key { |
| 1230 | name: "myapex.key", |
| 1231 | public_key: ":my.avbpubkey", |
| 1232 | private_key: ":my.pem", |
| 1233 | product_specific: true, |
| 1234 | } |
| 1235 | |
| 1236 | filegroup { |
| 1237 | name: "my.avbpubkey", |
| 1238 | srcs: ["testkey2.avbpubkey"], |
| 1239 | } |
| 1240 | |
| 1241 | filegroup { |
| 1242 | name: "my.pem", |
| 1243 | srcs: ["testkey2.pem"], |
| 1244 | } |
| 1245 | `) |
| 1246 | |
| 1247 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 1248 | expected_pubkey := "testkey2.avbpubkey" |
| 1249 | actual_pubkey := apex_key.public_key_file.String() |
| 1250 | if actual_pubkey != expected_pubkey { |
| 1251 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 1252 | } |
| 1253 | expected_privkey := "testkey2.pem" |
| 1254 | actual_privkey := apex_key.private_key_file.String() |
| 1255 | if actual_privkey != expected_privkey { |
| 1256 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 1257 | } |
| 1258 | } |
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | func TestPrebuilt(t *testing.T) { |
| 1261 | ctx := testApex(t, ` |
| 1262 | prebuilt_apex { |
| 1263 | name: "myapex", |
| Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1264 | arch: { |
| 1265 | arm64: { |
| 1266 | src: "myapex-arm64.apex", |
| 1267 | }, |
| 1268 | arm: { |
| 1269 | src: "myapex-arm.apex", |
| 1270 | }, |
| 1271 | }, |
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1272 | } |
| 1273 | `) |
| 1274 | |
| 1275 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 1276 | |
| Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1277 | expectedInput := "myapex-arm64.apex" |
| 1278 | if prebuilt.inputApex.String() != expectedInput { |
| 1279 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 1280 | } |
| Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1281 | } |
| Nikita Ioffe | ed75f61 | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1282 | |
| 1283 | func TestPrebuiltFilenameOverride(t *testing.T) { |
| 1284 | ctx := testApex(t, ` |
| 1285 | prebuilt_apex { |
| 1286 | name: "myapex", |
| 1287 | src: "myapex-arm.apex", |
| 1288 | filename: "notmyapex.apex", |
| 1289 | } |
| 1290 | `) |
| 1291 | |
| 1292 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 1293 | |
| 1294 | expected := "notmyapex.apex" |
| 1295 | if p.installFilename != expected { |
| 1296 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 1297 | } |
| 1298 | } |
| Jaewoong Jung | 9c49b28 | 2020-05-14 14:15:24 -0700 | [diff] [blame^] | 1299 | |
| 1300 | // TODO(jungjw): Move this to proptools |
| 1301 | func intPtr(i int) *int { |
| 1302 | return &i |
| 1303 | } |
| 1304 | |
| 1305 | func TestApexSet(t *testing.T) { |
| 1306 | ctx := testApex(t, ` |
| 1307 | apex_set { |
| 1308 | name: "myapex", |
| 1309 | set: "myapex.apks", |
| 1310 | filename: "foo_v2.apex", |
| 1311 | overrides: ["foo"], |
| 1312 | } |
| 1313 | `, func(fs map[string][]byte, config android.Config) { |
| 1314 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
| 1315 | config.TestProductVariables.DeviceArch = proptools.StringPtr("arm") |
| 1316 | config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm64") |
| 1317 | }) |
| 1318 | |
| 1319 | m := ctx.ModuleForTests("myapex", "android_common") |
| 1320 | |
| 1321 | // Check extract_apks tool parameters. |
| 1322 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 1323 | actual := extractedApex.Args["abis"] |
| 1324 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 1325 | if actual != expected { |
| 1326 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 1327 | } |
| 1328 | actual = extractedApex.Args["sdk-version"] |
| 1329 | expected = "30" |
| 1330 | if actual != expected { |
| 1331 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 1332 | } |
| 1333 | } |