filesystem_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 filesystem
  15. import (
  16. "os"
  17. "testing"
  18. "android/soong/android"
  19. "android/soong/cc"
  20. )
  21. func TestMain(m *testing.M) {
  22. os.Exit(m.Run())
  23. }
  24. var fixture = android.GroupFixturePreparers(
  25. android.PrepareForIntegrationTestWithAndroid,
  26. cc.PrepareForIntegrationTestWithCc,
  27. PrepareForTestWithFilesystemBuildComponents,
  28. )
  29. func TestFileSystemDeps(t *testing.T) {
  30. result := fixture.RunTestWithBp(t, `
  31. android_filesystem {
  32. name: "myfilesystem",
  33. }
  34. `)
  35. // produces "myfilesystem.img"
  36. result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
  37. }
  38. func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
  39. result := fixture.RunTestWithBp(t, `
  40. android_system_image {
  41. name: "myfilesystem",
  42. deps: [
  43. "libfoo",
  44. "libbar",
  45. ],
  46. linker_config_src: "linker.config.json",
  47. }
  48. cc_library {
  49. name: "libfoo",
  50. stubs: {
  51. symbol_file: "libfoo.map.txt",
  52. },
  53. }
  54. cc_library {
  55. name: "libbar",
  56. }
  57. `)
  58. module := result.ModuleForTests("myfilesystem", "android_common")
  59. output := module.Output("system/etc/linker.config.pb")
  60. android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
  61. output.RuleParams.Command, "libfoo.so")
  62. android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
  63. output.RuleParams.Command, "libbar.so")
  64. }
  65. func registerComponent(ctx android.RegistrationContext) {
  66. ctx.RegisterModuleType("component", componentFactory)
  67. }
  68. func componentFactory() android.Module {
  69. m := &component{}
  70. m.AddProperties(&m.properties)
  71. android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
  72. return m
  73. }
  74. type component struct {
  75. android.ModuleBase
  76. properties struct {
  77. Install_copy_in_data []string
  78. }
  79. }
  80. func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  81. output := android.PathForModuleOut(ctx, c.Name())
  82. dir := android.PathForModuleInstall(ctx, "components")
  83. ctx.InstallFile(dir, c.Name(), output)
  84. dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
  85. for _, d := range c.properties.Install_copy_in_data {
  86. ctx.InstallFile(dataDir, d, output)
  87. }
  88. }
  89. func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
  90. f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
  91. result := f.RunTestWithBp(t, `
  92. android_system_image {
  93. name: "myfilesystem",
  94. multilib: {
  95. common: {
  96. deps: ["foo"],
  97. },
  98. },
  99. linker_config_src: "linker.config.json",
  100. }
  101. component {
  102. name: "foo",
  103. install_copy_in_data: ["bar"],
  104. }
  105. `)
  106. module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
  107. android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
  108. }