app_set_test.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2020 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. "fmt"
  17. "reflect"
  18. "strings"
  19. "testing"
  20. "android/soong/android"
  21. )
  22. func TestAndroidAppSet(t *testing.T) {
  23. result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
  24. android_app_set {
  25. name: "foo",
  26. set: "prebuilts/apks/app.apks",
  27. prerelease: true,
  28. }`)
  29. module := result.ModuleForTests("foo", "android_common")
  30. const packedSplitApks = "foo.zip"
  31. params := module.Output(packedSplitApks)
  32. if params.Rule == nil {
  33. t.Errorf("expected output %s is missing", packedSplitApks)
  34. }
  35. if s := params.Args["allow-prereleased"]; s != "true" {
  36. t.Errorf("wrong allow-prereleased value: '%s', expected 'true'", s)
  37. }
  38. if s := params.Args["partition"]; s != "system" {
  39. t.Errorf("wrong partition value: '%s', expected 'system'", s)
  40. }
  41. android.AssertPathRelativeToTopEquals(t, "incorrect output path",
  42. "out/soong/.intermediates/foo/android_common/foo.apk", params.Output)
  43. android.AssertPathsRelativeToTopEquals(t, "incorrect implicit output paths",
  44. []string{
  45. "out/soong/.intermediates/foo/android_common/foo.zip",
  46. "out/soong/.intermediates/foo/android_common/apkcerts.txt",
  47. },
  48. params.ImplicitOutputs.Paths())
  49. mkEntries := android.AndroidMkEntriesForTest(t, result.TestContext, module.Module())[0]
  50. actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"]
  51. expectedInstallFile := []string{
  52. strings.Replace(params.ImplicitOutputs[0].String(), android.OutSoongDir, result.Config.SoongOutDir(), 1),
  53. }
  54. if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) {
  55. t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',",
  56. actualInstallFile, expectedInstallFile)
  57. }
  58. }
  59. func TestAndroidAppSet_Variants(t *testing.T) {
  60. bp := `
  61. android_app_set {
  62. name: "foo",
  63. set: "prebuilts/apks/app.apks",
  64. }`
  65. testCases := []struct {
  66. name string
  67. targets []android.Target
  68. aaptPrebuiltDPI []string
  69. sdkVersion int
  70. expected map[string]string
  71. }{
  72. {
  73. name: "One",
  74. targets: []android.Target{
  75. {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
  76. },
  77. aaptPrebuiltDPI: []string{"ldpi", "xxhdpi"},
  78. sdkVersion: 29,
  79. expected: map[string]string{
  80. "abis": "X86",
  81. "allow-prereleased": "false",
  82. "screen-densities": "LDPI,XXHDPI",
  83. "sdk-version": "29",
  84. "skip-sdk-check": "false",
  85. "stem": "foo",
  86. },
  87. },
  88. {
  89. name: "Two",
  90. targets: []android.Target{
  91. {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64}},
  92. {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
  93. },
  94. aaptPrebuiltDPI: nil,
  95. sdkVersion: 30,
  96. expected: map[string]string{
  97. "abis": "X86_64,X86",
  98. "allow-prereleased": "false",
  99. "screen-densities": "all",
  100. "sdk-version": "30",
  101. "skip-sdk-check": "false",
  102. "stem": "foo",
  103. },
  104. },
  105. }
  106. for _, test := range testCases {
  107. ctx := android.GroupFixturePreparers(
  108. PrepareForTestWithJavaDefaultModules,
  109. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  110. variables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
  111. variables.Platform_sdk_version = &test.sdkVersion
  112. }),
  113. android.FixtureModifyConfig(func(config android.Config) {
  114. config.Targets[android.Android] = test.targets
  115. }),
  116. ).RunTestWithBp(t, bp)
  117. module := ctx.ModuleForTests("foo", "android_common")
  118. const packedSplitApks = "foo.zip"
  119. params := module.Output(packedSplitApks)
  120. for k, v := range test.expected {
  121. t.Run(test.name, func(t *testing.T) {
  122. android.AssertStringEquals(t, fmt.Sprintf("arg value for `%s`", k), v, params.Args[k])
  123. })
  124. }
  125. }
  126. }