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