compat_config_sdk_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2021 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 sdk
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. "android/soong/java"
  19. )
  20. func testSnapshotWithCompatConfig(t *testing.T, sdk string) {
  21. result := android.GroupFixturePreparers(
  22. prepareForSdkTestWithJava,
  23. java.PrepareForTestWithPlatformCompatConfig,
  24. prepareForSdkTestWithApex,
  25. ).RunTestWithBp(t, sdk+`
  26. platform_compat_config {
  27. name: "myconfig",
  28. }
  29. `)
  30. CheckSnapshot(t, result, "mysdk", "",
  31. checkAndroidBpContents(`
  32. // This is auto-generated. DO NOT EDIT.
  33. prebuilt_platform_compat_config {
  34. name: "myconfig",
  35. prefer: false,
  36. visibility: ["//visibility:public"],
  37. metadata: "compat_configs/myconfig/myconfig_meta.xml",
  38. }
  39. `),
  40. checkAllCopyRules(`
  41. .intermediates/myconfig/android_common/myconfig_meta.xml -> compat_configs/myconfig/myconfig_meta.xml
  42. `),
  43. snapshotTestChecker(checkSnapshotWithoutSource,
  44. func(t *testing.T, result *android.TestResult) {
  45. // Make sure that the snapshot metadata is collated by the platform compat config singleton.
  46. java.CheckMergedCompatConfigInputs(t, result, "snapshot module", "snapshot/compat_configs/myconfig/myconfig_meta.xml")
  47. }),
  48. snapshotTestChecker(checkSnapshotWithSourcePreferred,
  49. func(t *testing.T, result *android.TestResult) {
  50. // Make sure that the snapshot metadata is collated by the platform compat config singleton.
  51. java.CheckMergedCompatConfigInputs(t, result, "snapshot module",
  52. "out/soong/.intermediates/myconfig/android_common/myconfig_meta.xml",
  53. )
  54. }),
  55. snapshotTestChecker(checkSnapshotPreferredWithSource,
  56. func(t *testing.T, result *android.TestResult) {
  57. // Make sure that the snapshot metadata is collated by the platform compat config singleton.
  58. java.CheckMergedCompatConfigInputs(t, result, "snapshot module",
  59. "snapshot/compat_configs/myconfig/myconfig_meta.xml",
  60. )
  61. }),
  62. )
  63. }
  64. func TestSnapshotWithCompatConfig(t *testing.T) {
  65. testSnapshotWithCompatConfig(t, `
  66. sdk {
  67. name: "mysdk",
  68. compat_configs: ["myconfig"],
  69. }
  70. `)
  71. }
  72. func TestSnapshotWithCompatConfig_Apex(t *testing.T) {
  73. testSnapshotWithCompatConfig(t, `
  74. apex {
  75. name: "myapex",
  76. key: "myapex.key",
  77. min_sdk_version: "2",
  78. compat_configs: ["myconfig"],
  79. }
  80. sdk {
  81. name: "mysdk",
  82. apexes: ["myapex"],
  83. }
  84. `)
  85. }