sdk_repo_host_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 android_sdk
  15. import (
  16. "fmt"
  17. "runtime"
  18. "sort"
  19. "testing"
  20. "android/soong/android"
  21. "android/soong/cc"
  22. "github.com/google/blueprint/pathtools"
  23. )
  24. var fixture = android.GroupFixturePreparers(
  25. android.PrepareForIntegrationTestWithAndroid,
  26. cc.PrepareForIntegrationTestWithCc,
  27. android.FixtureRegisterWithContext(registerBuildComponents),
  28. )
  29. func TestSdkRepoHostDeps(t *testing.T) {
  30. if runtime.GOOS != "linux" {
  31. t.Skipf("Skipping sdk_repo_host testing that is only supported on linux not %s", runtime.GOOS)
  32. }
  33. result := fixture.RunTestWithBp(t, `
  34. android_sdk_repo_host {
  35. name: "platform-tools",
  36. }
  37. `)
  38. // produces "sdk-repo-{OS}-platform-tools.zip"
  39. result.ModuleForTests("platform-tools", "linux_glibc_common").Output("sdk-repo-linux-platform-tools.zip")
  40. }
  41. func TestRemapPackageSpecs(t *testing.T) {
  42. testcases := []struct {
  43. name string
  44. input []string
  45. remaps []remapProperties
  46. output []string
  47. err string
  48. }{
  49. {
  50. name: "basic remap",
  51. input: []string{"a", "c"},
  52. remaps: []remapProperties{
  53. {From: "a", To: "b"},
  54. },
  55. output: []string{"b", "c"},
  56. },
  57. {
  58. name: "non-matching remap",
  59. input: []string{"a"},
  60. remaps: []remapProperties{
  61. {From: "b", To: "c"},
  62. },
  63. output: []string{"a"},
  64. },
  65. {
  66. name: "glob",
  67. input: []string{"bin/d", "liba.so", "libb.so", "lib/c.so"},
  68. remaps: []remapProperties{
  69. {From: "lib*.so", To: "lib/"},
  70. },
  71. output: []string{"bin/d", "lib/c.so", "lib/liba.so", "lib/libb.so"},
  72. },
  73. {
  74. name: "bad glob",
  75. input: []string{"a"},
  76. remaps: []remapProperties{
  77. {From: "**", To: "./"},
  78. },
  79. err: fmt.Sprintf("Error parsing \"**\": %v", pathtools.GlobLastRecursiveErr.Error()),
  80. },
  81. {
  82. name: "globbed dirs",
  83. input: []string{"a/b/c"},
  84. remaps: []remapProperties{
  85. {From: "a/*/c", To: "./"},
  86. },
  87. output: []string{"b/c"},
  88. },
  89. }
  90. for _, test := range testcases {
  91. t.Run(test.name, func(t *testing.T) {
  92. specs := map[string]android.PackagingSpec{}
  93. for _, input := range test.input {
  94. spec := android.PackagingSpec{}
  95. spec.SetRelPathInPackage(input)
  96. specs[input] = spec
  97. }
  98. err := remapPackageSpecs(specs, test.remaps)
  99. if test.err != "" {
  100. android.AssertErrorMessageEquals(t, "", test.err, err)
  101. } else {
  102. outputs := []string{}
  103. for path, spec := range specs {
  104. android.AssertStringEquals(t, "path does not match rel path", path, spec.RelPathInPackage())
  105. outputs = append(outputs, path)
  106. }
  107. sort.Strings(outputs)
  108. android.AssertArrayString(t, "outputs mismatch", test.output, outputs)
  109. }
  110. })
  111. }
  112. }