dexpreopt_bootjars_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2019 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. package java
  15. import (
  16. "path/filepath"
  17. "reflect"
  18. "sort"
  19. "testing"
  20. "android/soong/android"
  21. "android/soong/dexpreopt"
  22. )
  23. func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) {
  24. bp := `
  25. java_sdk_library {
  26. name: "foo",
  27. srcs: ["a.java"],
  28. api_packages: ["foo"],
  29. }
  30. java_library {
  31. name: "bar",
  32. srcs: ["b.java"],
  33. installable: true,
  34. }
  35. dex_import {
  36. name: "baz",
  37. jars: ["a.jar"],
  38. }
  39. `
  40. config := testConfig(nil, bp, nil)
  41. pathCtx := android.PathContextForTesting(config)
  42. dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
  43. dexpreoptConfig.BootJars = android.CreateConfiguredJarList(pathCtx, []string{"platform:foo", "platform:bar", "platform:baz"})
  44. dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
  45. ctx := testContext()
  46. RegisterDexpreoptBootJarsComponents(ctx)
  47. run(t, ctx, config)
  48. dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars")
  49. rule := dexpreoptBootJars.Output(ruleFile)
  50. for i := range expectedInputs {
  51. expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i])
  52. }
  53. for i := range expectedOutputs {
  54. expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i])
  55. }
  56. inputs := rule.Implicits.Strings()
  57. sort.Strings(inputs)
  58. sort.Strings(expectedInputs)
  59. outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings()
  60. sort.Strings(outputs)
  61. sort.Strings(expectedOutputs)
  62. if !reflect.DeepEqual(inputs, expectedInputs) {
  63. t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs)
  64. }
  65. if !reflect.DeepEqual(outputs, expectedOutputs) {
  66. t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs)
  67. }
  68. }
  69. func TestDexpreoptBootJars(t *testing.T) {
  70. ruleFile := "boot-foo.art"
  71. expectedInputs := []string{
  72. "dex_artjars/android/apex/com.android.art/javalib/arm64/boot.art",
  73. "dex_bootjars_input/foo.jar",
  74. "dex_bootjars_input/bar.jar",
  75. "dex_bootjars_input/baz.jar",
  76. }
  77. expectedOutputs := []string{
  78. "dex_bootjars/android/system/framework/arm64/boot.invocation",
  79. "dex_bootjars/android/system/framework/arm64/boot-foo.art",
  80. "dex_bootjars/android/system/framework/arm64/boot-bar.art",
  81. "dex_bootjars/android/system/framework/arm64/boot-baz.art",
  82. "dex_bootjars/android/system/framework/arm64/boot-foo.oat",
  83. "dex_bootjars/android/system/framework/arm64/boot-bar.oat",
  84. "dex_bootjars/android/system/framework/arm64/boot-baz.oat",
  85. "dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
  86. "dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
  87. "dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
  88. "dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
  89. "dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
  90. "dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
  91. }
  92. testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
  93. }
  94. // Changes to the boot.zip structure may break the ART APK scanner.
  95. func TestDexpreoptBootZip(t *testing.T) {
  96. ruleFile := "boot.zip"
  97. ctx := android.PathContextForTesting(testConfig(nil, "", nil))
  98. expectedInputs := []string{}
  99. for _, target := range ctx.Config().Targets[android.Android] {
  100. for _, ext := range []string{".art", ".oat", ".vdex"} {
  101. for _, jar := range []string{"foo", "bar", "baz"} {
  102. expectedInputs = append(expectedInputs,
  103. filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext))
  104. }
  105. }
  106. }
  107. expectedOutputs := []string{
  108. "dex_bootjars/boot.zip",
  109. }
  110. testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
  111. }