filesystem_test.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. "android/soong/etc"
  21. "github.com/google/blueprint/proptools"
  22. )
  23. func TestMain(m *testing.M) {
  24. os.Exit(m.Run())
  25. }
  26. var fixture = android.GroupFixturePreparers(
  27. android.PrepareForIntegrationTestWithAndroid,
  28. etc.PrepareForTestWithPrebuiltEtc,
  29. cc.PrepareForIntegrationTestWithCc,
  30. PrepareForTestWithFilesystemBuildComponents,
  31. )
  32. func TestFileSystemDeps(t *testing.T) {
  33. result := fixture.RunTestWithBp(t, `
  34. android_filesystem {
  35. name: "myfilesystem",
  36. }
  37. `)
  38. // produces "myfilesystem.img"
  39. result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
  40. }
  41. func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
  42. result := fixture.RunTestWithBp(t, `
  43. android_system_image {
  44. name: "myfilesystem",
  45. deps: [
  46. "libfoo",
  47. "libbar",
  48. ],
  49. linker_config_src: "linker.config.json",
  50. }
  51. cc_library {
  52. name: "libfoo",
  53. stubs: {
  54. symbol_file: "libfoo.map.txt",
  55. },
  56. }
  57. cc_library {
  58. name: "libbar",
  59. }
  60. `)
  61. module := result.ModuleForTests("myfilesystem", "android_common")
  62. output := module.Output("system/etc/linker.config.pb")
  63. android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
  64. output.RuleParams.Command, "libfoo.so")
  65. android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
  66. output.RuleParams.Command, "libbar.so")
  67. }
  68. func registerComponent(ctx android.RegistrationContext) {
  69. ctx.RegisterModuleType("component", componentFactory)
  70. }
  71. func componentFactory() android.Module {
  72. m := &component{}
  73. m.AddProperties(&m.properties)
  74. android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
  75. return m
  76. }
  77. type component struct {
  78. android.ModuleBase
  79. properties struct {
  80. Install_copy_in_data []string
  81. }
  82. }
  83. func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  84. output := android.PathForModuleOut(ctx, c.Name())
  85. dir := android.PathForModuleInstall(ctx, "components")
  86. ctx.InstallFile(dir, c.Name(), output)
  87. dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
  88. for _, d := range c.properties.Install_copy_in_data {
  89. ctx.InstallFile(dataDir, d, output)
  90. }
  91. }
  92. func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
  93. f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
  94. result := f.RunTestWithBp(t, `
  95. android_system_image {
  96. name: "myfilesystem",
  97. multilib: {
  98. common: {
  99. deps: ["foo"],
  100. },
  101. },
  102. linker_config_src: "linker.config.json",
  103. }
  104. component {
  105. name: "foo",
  106. install_copy_in_data: ["bar"],
  107. }
  108. `)
  109. module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
  110. android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
  111. }
  112. func TestAvbGenVbmetaImage(t *testing.T) {
  113. result := fixture.RunTestWithBp(t, `
  114. avb_gen_vbmeta_image {
  115. name: "input_hashdesc",
  116. src: "input.img",
  117. partition_name: "input_partition_name",
  118. salt: "2222",
  119. }`)
  120. cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
  121. android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
  122. cmd, "--partition_name input_partition_name")
  123. android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
  124. cmd, "--do_not_append_vbmeta_image")
  125. android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
  126. cmd, "--output_vbmeta_image ")
  127. android.AssertStringDoesContain(t, "Can't find --salt argument",
  128. cmd, "--salt 2222")
  129. }
  130. func TestAvbAddHashFooter(t *testing.T) {
  131. result := fixture.RunTestWithBp(t, `
  132. avb_gen_vbmeta_image {
  133. name: "input_hashdesc",
  134. src: "input.img",
  135. partition_name: "input",
  136. salt: "2222",
  137. }
  138. avb_add_hash_footer {
  139. name: "myfooter",
  140. src: "input.img",
  141. filename: "output.img",
  142. partition_name: "mypartition",
  143. private_key: "mykey",
  144. salt: "1111",
  145. props: [
  146. {
  147. name: "prop1",
  148. value: "value1",
  149. },
  150. {
  151. name: "prop2",
  152. file: "value_file",
  153. },
  154. ],
  155. include_descriptors_from_images: ["input_hashdesc"],
  156. }
  157. `)
  158. cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
  159. android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
  160. cmd, "--partition_name mypartition")
  161. android.AssertStringDoesContain(t, "Can't find correct --key argument",
  162. cmd, "--key mykey")
  163. android.AssertStringDoesContain(t, "Can't find --salt argument",
  164. cmd, "--salt 1111")
  165. android.AssertStringDoesContain(t, "Can't find --prop argument",
  166. cmd, "--prop 'prop1:value1'")
  167. android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
  168. cmd, "--prop_from_file 'prop2:value_file'")
  169. android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
  170. cmd, "--include_descriptors_from_image ")
  171. }
  172. func TestFileSystemShouldInstallCoreVariantIfTargetBuildAppsIsSet(t *testing.T) {
  173. context := android.GroupFixturePreparers(
  174. fixture,
  175. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  176. variables.Unbundled_build_apps = []string{"bar"}
  177. }),
  178. )
  179. result := context.RunTestWithBp(t, `
  180. android_system_image {
  181. name: "myfilesystem",
  182. deps: [
  183. "libfoo",
  184. ],
  185. linker_config_src: "linker.config.json",
  186. }
  187. cc_library {
  188. name: "libfoo",
  189. shared_libs: [
  190. "libbar",
  191. ],
  192. stl: "none",
  193. }
  194. cc_library {
  195. name: "libbar",
  196. sdk_version: "9",
  197. stl: "none",
  198. }
  199. `)
  200. inputs := result.ModuleForTests("myfilesystem", "android_common").Output("deps.zip").Implicits
  201. android.AssertStringListContains(t, "filesystem should have libbar even for unbundled build",
  202. inputs.Strings(),
  203. "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")
  204. }
  205. func TestFileSystemWithCoverageVariants(t *testing.T) {
  206. context := android.GroupFixturePreparers(
  207. fixture,
  208. android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
  209. variables.GcovCoverage = proptools.BoolPtr(true)
  210. variables.Native_coverage = proptools.BoolPtr(true)
  211. }),
  212. )
  213. result := context.RunTestWithBp(t, `
  214. prebuilt_etc {
  215. name: "prebuilt",
  216. src: ":myfilesystem",
  217. }
  218. android_system_image {
  219. name: "myfilesystem",
  220. deps: [
  221. "libfoo",
  222. ],
  223. linker_config_src: "linker.config.json",
  224. }
  225. cc_library {
  226. name: "libfoo",
  227. shared_libs: [
  228. "libbar",
  229. ],
  230. stl: "none",
  231. }
  232. cc_library {
  233. name: "libbar",
  234. stl: "none",
  235. }
  236. `)
  237. filesystem := result.ModuleForTests("myfilesystem", "android_common_cov")
  238. inputs := filesystem.Output("deps.zip").Implicits
  239. android.AssertStringListContains(t, "filesystem should have libfoo(cov)",
  240. inputs.Strings(),
  241. "out/soong/.intermediates/libfoo/android_arm64_armv8-a_shared_cov/libfoo.so")
  242. android.AssertStringListContains(t, "filesystem should have libbar(cov)",
  243. inputs.Strings(),
  244. "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared_cov/libbar.so")
  245. filesystemOutput := filesystem.Output("myfilesystem.img").Output
  246. prebuiltInput := result.ModuleForTests("prebuilt", "android_arm64_armv8-a").Rule("Cp").Input
  247. if filesystemOutput != prebuiltInput {
  248. t.Error("prebuilt should use cov variant of filesystem")
  249. }
  250. }