prebuilt_apis_test.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 java
  15. import (
  16. "sort"
  17. "strings"
  18. "testing"
  19. "android/soong/android"
  20. "github.com/google/blueprint"
  21. )
  22. func intPtr(v int) *int {
  23. return &v
  24. }
  25. func TestPrebuiltApis_SystemModulesCreation(t *testing.T) {
  26. result := android.GroupFixturePreparers(
  27. prepareForJavaTest,
  28. FixtureWithPrebuiltApis(map[string][]string{
  29. "31": {},
  30. "32": {},
  31. "current": {},
  32. }),
  33. ).RunTest(t)
  34. sdkSystemModules := []string{}
  35. result.VisitAllModules(func(module blueprint.Module) {
  36. name := android.RemoveOptionalPrebuiltPrefix(module.Name())
  37. if strings.HasPrefix(name, "sdk_") && strings.HasSuffix(name, "_system_modules") {
  38. sdkSystemModules = append(sdkSystemModules, name)
  39. }
  40. })
  41. sort.Strings(sdkSystemModules)
  42. expected := []string{
  43. // 31 only has public system modules.
  44. "sdk_public_31_system_modules",
  45. // 32 and current both have public and module-lib system modules.
  46. "sdk_public_32_system_modules",
  47. "sdk_module-lib_32_system_modules",
  48. "sdk_public_current_system_modules",
  49. "sdk_module-lib_current_system_modules",
  50. }
  51. sort.Strings(expected)
  52. android.AssertArrayString(t, "sdk system modules", expected, sdkSystemModules)
  53. }
  54. func TestPrebuiltApis_WithExtensions(t *testing.T) {
  55. runTestWithBaseExtensionLevel := func(v int) (foo_input, bar_input, baz_input string) {
  56. result := android.GroupFixturePreparers(
  57. prepareForJavaTest,
  58. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  59. variables.Platform_base_sdk_extension_version = intPtr(v)
  60. }),
  61. FixtureWithPrebuiltApisAndExtensions(map[string][]string{
  62. "31": {"foo"},
  63. "32": {"foo", "bar", "baz"},
  64. "current": {"foo", "bar"},
  65. }, map[string][]string{
  66. "1": {"foo"},
  67. "2": {"foo", "bar"},
  68. }),
  69. ).RunTest(t)
  70. foo_input = result.ModuleForTests("foo.api.public.latest", "").Rule("generator").Implicits[0].String()
  71. bar_input = result.ModuleForTests("bar.api.public.latest", "").Rule("generator").Implicits[0].String()
  72. baz_input = result.ModuleForTests("baz.api.public.latest", "").Rule("generator").Implicits[0].String()
  73. return
  74. }
  75. // Extension 2 is the latest for both foo and bar, finalized after the base extension version.
  76. foo_input, bar_input, baz_input := runTestWithBaseExtensionLevel(1)
  77. android.AssertStringEquals(t, "Expected latest foo = extension level 2", "prebuilts/sdk/extensions/2/public/api/foo.txt", foo_input)
  78. android.AssertStringEquals(t, "Expected latest bar = extension level 2", "prebuilts/sdk/extensions/2/public/api/bar.txt", bar_input)
  79. android.AssertStringEquals(t, "Expected latest baz = api level 32", "prebuilts/sdk/32/public/api/baz.txt", baz_input)
  80. // Extension 2 is the latest for both foo and bar, finalized together with 32
  81. foo_input, bar_input, baz_input = runTestWithBaseExtensionLevel(2)
  82. android.AssertStringEquals(t, "Expected latest foo = extension level 2", "prebuilts/sdk/extensions/2/public/api/foo.txt", foo_input)
  83. android.AssertStringEquals(t, "Expected latest bar = extension level 2", "prebuilts/sdk/extensions/2/public/api/bar.txt", bar_input)
  84. android.AssertStringEquals(t, "Expected latest baz = api level 32", "prebuilts/sdk/32/public/api/baz.txt", baz_input)
  85. // Extension 3 is the current extension, but it has not yet been finalized.
  86. foo_input, bar_input, baz_input = runTestWithBaseExtensionLevel(3)
  87. android.AssertStringEquals(t, "Expected latest foo = extension level 2", "prebuilts/sdk/extensions/2/public/api/foo.txt", foo_input)
  88. android.AssertStringEquals(t, "Expected latest bar = extension level 2", "prebuilts/sdk/extensions/2/public/api/bar.txt", bar_input)
  89. android.AssertStringEquals(t, "Expected latest baz = api level 32", "prebuilts/sdk/32/public/api/baz.txt", baz_input)
  90. }