library_stub_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 cc
  15. import (
  16. _ "fmt"
  17. _ "sort"
  18. "testing"
  19. "android/soong/android"
  20. "android/soong/multitree"
  21. )
  22. func TestCcApiStubLibraryOutputFiles(t *testing.T) {
  23. bp := `
  24. cc_api_stub_library {
  25. name: "foo",
  26. symbol_file: "foo.map.txt",
  27. first_version: "29",
  28. }
  29. `
  30. result := prepareForCcTest.RunTestWithBp(t, bp)
  31. outputs := result.ModuleForTests("foo", "android_arm64_armv8-a_shared").AllOutputs()
  32. expected_file_suffixes := []string{".c", "stub.map", ".o", ".so"}
  33. for _, expected_file_suffix := range expected_file_suffixes {
  34. android.AssertBoolEquals(t, expected_file_suffix+" file not found in output", true, android.SuffixInList(outputs, expected_file_suffix))
  35. }
  36. }
  37. func TestCcApiStubLibraryVariants(t *testing.T) {
  38. bp := `
  39. cc_api_stub_library {
  40. name: "foo",
  41. symbol_file: "foo.map.txt",
  42. first_version: "29",
  43. }
  44. `
  45. result := prepareForCcTest.RunTestWithBp(t, bp)
  46. variants := result.ModuleVariantsForTests("foo")
  47. expected_variants := []string{"29", "30", "S", "Tiramisu"} //TODO: make this test deterministic by using fixtures
  48. for _, expected_variant := range expected_variants {
  49. android.AssertBoolEquals(t, expected_variant+" variant not found in foo", true, android.SubstringInList(variants, expected_variant))
  50. }
  51. }
  52. func TestCcLibraryUsesCcApiStubLibrary(t *testing.T) {
  53. bp := `
  54. cc_api_stub_library {
  55. name: "foo",
  56. symbol_file: "foo.map.txt",
  57. first_version: "29",
  58. }
  59. cc_library {
  60. name: "foo_user",
  61. shared_libs: [
  62. "foo#29",
  63. ],
  64. }
  65. `
  66. prepareForCcTest.RunTestWithBp(t, bp)
  67. }
  68. func TestApiSurfaceOutputs(t *testing.T) {
  69. bp := `
  70. api_surface {
  71. name: "mysdk",
  72. contributions: [
  73. "foo",
  74. ],
  75. }
  76. cc_api_contribution {
  77. name: "foo",
  78. symbol_file: "foo.map.txt",
  79. first_version: "29",
  80. }
  81. `
  82. result := android.GroupFixturePreparers(
  83. prepareForCcTest,
  84. multitree.PrepareForTestWithApiSurface,
  85. ).RunTestWithBp(t, bp)
  86. mysdk := result.ModuleForTests("mysdk", "")
  87. actual_surface_inputs := mysdk.Rule("phony").BuildParams.Inputs.Strings()
  88. expected_file_suffixes := []string{"mysdk/foo/foo.map.txt"}
  89. for _, expected_file_suffix := range expected_file_suffixes {
  90. android.AssertBoolEquals(t, expected_file_suffix+" file not found in input", true, android.SuffixInList(actual_surface_inputs, expected_file_suffix))
  91. }
  92. // check args/inputs to rule
  93. /*api_surface_gen_rule_args := result.ModuleForTests("mysdk", "").Rule("genApiSurfaceBuildFiles").Args
  94. android.AssertStringEquals(t, "name", "foo.mysdk", api_surface_gen_rule_args["name"])
  95. android.AssertStringEquals(t, "symbol_file", "foo.map.txt", api_surface_gen_rule_args["symbol_file"])*/
  96. }