prebuilt_etc_test.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. // Copyright 2018 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 etc
  15. import (
  16. "os"
  17. "path/filepath"
  18. "testing"
  19. "android/soong/android"
  20. )
  21. func TestMain(m *testing.M) {
  22. os.Exit(m.Run())
  23. }
  24. var prepareForPrebuiltEtcTest = android.GroupFixturePreparers(
  25. android.PrepareForTestWithArchMutator,
  26. PrepareForTestWithPrebuiltEtc,
  27. android.FixtureMergeMockFs(android.MockFS{
  28. "foo.conf": nil,
  29. "bar.conf": nil,
  30. "baz.conf": nil,
  31. }),
  32. )
  33. func TestPrebuiltEtcVariants(t *testing.T) {
  34. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  35. prebuilt_etc {
  36. name: "foo.conf",
  37. src: "foo.conf",
  38. }
  39. prebuilt_etc {
  40. name: "bar.conf",
  41. src: "bar.conf",
  42. recovery_available: true,
  43. }
  44. prebuilt_etc {
  45. name: "baz.conf",
  46. src: "baz.conf",
  47. recovery: true,
  48. }
  49. `)
  50. foo_variants := result.ModuleVariantsForTests("foo.conf")
  51. if len(foo_variants) != 1 {
  52. t.Errorf("expected 1, got %#v", foo_variants)
  53. }
  54. bar_variants := result.ModuleVariantsForTests("bar.conf")
  55. if len(bar_variants) != 2 {
  56. t.Errorf("expected 2, got %#v", bar_variants)
  57. }
  58. baz_variants := result.ModuleVariantsForTests("baz.conf")
  59. if len(baz_variants) != 1 {
  60. t.Errorf("expected 1, got %#v", bar_variants)
  61. }
  62. }
  63. func TestPrebuiltEtcOutputPath(t *testing.T) {
  64. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  65. prebuilt_etc {
  66. name: "foo.conf",
  67. src: "foo.conf",
  68. filename: "foo.installed.conf",
  69. }
  70. `)
  71. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  72. android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePath.Base())
  73. }
  74. func TestPrebuiltEtcGlob(t *testing.T) {
  75. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  76. prebuilt_etc {
  77. name: "my_foo",
  78. src: "foo.*",
  79. }
  80. prebuilt_etc {
  81. name: "my_bar",
  82. src: "bar.*",
  83. filename_from_src: true,
  84. }
  85. `)
  86. p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
  87. android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePath.Base())
  88. p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
  89. android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePath.Base())
  90. }
  91. func TestPrebuiltEtcAndroidMk(t *testing.T) {
  92. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  93. prebuilt_etc {
  94. name: "foo",
  95. src: "foo.conf",
  96. owner: "abc",
  97. filename_from_src: true,
  98. required: ["modA", "moduleB"],
  99. host_required: ["hostModA", "hostModB"],
  100. target_required: ["targetModA"],
  101. }
  102. `)
  103. expected := map[string][]string{
  104. "LOCAL_MODULE": {"foo"},
  105. "LOCAL_MODULE_CLASS": {"ETC"},
  106. "LOCAL_MODULE_OWNER": {"abc"},
  107. "LOCAL_INSTALLED_MODULE_STEM": {"foo.conf"},
  108. "LOCAL_REQUIRED_MODULES": {"modA", "moduleB"},
  109. "LOCAL_HOST_REQUIRED_MODULES": {"hostModA", "hostModB"},
  110. "LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"},
  111. }
  112. mod := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc)
  113. entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0]
  114. for k, expectedValue := range expected {
  115. if value, ok := entries.EntryMap[k]; ok {
  116. android.AssertDeepEquals(t, k, expectedValue, value)
  117. } else {
  118. t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
  119. }
  120. }
  121. }
  122. func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
  123. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  124. prebuilt_etc {
  125. name: "foo.conf",
  126. src: "foo.conf",
  127. relative_install_path: "bar",
  128. }
  129. `)
  130. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  131. expected := "out/soong/target/product/test_device/system/etc/bar"
  132. android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
  133. }
  134. func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
  135. prepareForPrebuiltEtcTest.
  136. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")).
  137. RunTestWithBp(t, `
  138. prebuilt_etc {
  139. name: "foo.conf",
  140. src: "foo.conf",
  141. sub_dir: "bar",
  142. relative_install_path: "bar",
  143. }
  144. `)
  145. }
  146. func TestPrebuiltEtcHost(t *testing.T) {
  147. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  148. prebuilt_etc_host {
  149. name: "foo.conf",
  150. src: "foo.conf",
  151. }
  152. `)
  153. buildOS := result.Config.BuildOS.String()
  154. p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
  155. if !p.Host() {
  156. t.Errorf("host bit is not set for a prebuilt_etc_host module.")
  157. }
  158. }
  159. func TestPrebuiltRootInstallDirPath(t *testing.T) {
  160. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  161. prebuilt_root {
  162. name: "foo.conf",
  163. src: "foo.conf",
  164. filename: "foo.conf",
  165. }
  166. `)
  167. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  168. expected := "out/soong/target/product/test_device/system"
  169. android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
  170. }
  171. func TestPrebuiltRootInstallDirPathValidate(t *testing.T) {
  172. prepareForPrebuiltEtcTest.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("filename cannot contain separator")).RunTestWithBp(t, `
  173. prebuilt_root {
  174. name: "foo.conf",
  175. src: "foo.conf",
  176. filename: "foo/bar.conf",
  177. }
  178. `)
  179. }
  180. func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
  181. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  182. prebuilt_usr_share {
  183. name: "foo.conf",
  184. src: "foo.conf",
  185. sub_dir: "bar",
  186. }
  187. `)
  188. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  189. expected := "out/soong/target/product/test_device/system/usr/share/bar"
  190. android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
  191. }
  192. func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
  193. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  194. prebuilt_usr_share_host {
  195. name: "foo.conf",
  196. src: "foo.conf",
  197. sub_dir: "bar",
  198. }
  199. `)
  200. buildOS := result.Config.BuildOS.String()
  201. p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
  202. expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar")
  203. android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
  204. }
  205. func TestPrebuiltFontInstallDirPath(t *testing.T) {
  206. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
  207. prebuilt_font {
  208. name: "foo.conf",
  209. src: "foo.conf",
  210. }
  211. `)
  212. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  213. expected := "out/soong/target/product/test_device/system/fonts"
  214. android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
  215. }
  216. func TestPrebuiltFirmwareDirPath(t *testing.T) {
  217. targetPath := "out/soong/target/product/test_device"
  218. tests := []struct {
  219. description string
  220. config string
  221. expectedPath string
  222. }{{
  223. description: "prebuilt: system firmware",
  224. config: `
  225. prebuilt_firmware {
  226. name: "foo.conf",
  227. src: "foo.conf",
  228. }`,
  229. expectedPath: filepath.Join(targetPath, "system/etc/firmware"),
  230. }, {
  231. description: "prebuilt: vendor firmware",
  232. config: `
  233. prebuilt_firmware {
  234. name: "foo.conf",
  235. src: "foo.conf",
  236. soc_specific: true,
  237. sub_dir: "sub_dir",
  238. }`,
  239. expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"),
  240. }}
  241. for _, tt := range tests {
  242. t.Run(tt.description, func(t *testing.T) {
  243. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
  244. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  245. android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
  246. })
  247. }
  248. }
  249. func TestPrebuiltDSPDirPath(t *testing.T) {
  250. targetPath := "out/soong/target/product/test_device"
  251. tests := []struct {
  252. description string
  253. config string
  254. expectedPath string
  255. }{{
  256. description: "prebuilt: system dsp",
  257. config: `
  258. prebuilt_dsp {
  259. name: "foo.conf",
  260. src: "foo.conf",
  261. }`,
  262. expectedPath: filepath.Join(targetPath, "system/etc/dsp"),
  263. }, {
  264. description: "prebuilt: vendor dsp",
  265. config: `
  266. prebuilt_dsp {
  267. name: "foo.conf",
  268. src: "foo.conf",
  269. soc_specific: true,
  270. sub_dir: "sub_dir",
  271. }`,
  272. expectedPath: filepath.Join(targetPath, "vendor/dsp/sub_dir"),
  273. }}
  274. for _, tt := range tests {
  275. t.Run(tt.description, func(t *testing.T) {
  276. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
  277. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  278. android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
  279. })
  280. }
  281. }
  282. func TestPrebuiltRFSADirPath(t *testing.T) {
  283. targetPath := "out/soong/target/product/test_device"
  284. tests := []struct {
  285. description string
  286. config string
  287. expectedPath string
  288. }{{
  289. description: "prebuilt: system rfsa",
  290. config: `
  291. prebuilt_rfsa {
  292. name: "foo.conf",
  293. src: "foo.conf",
  294. }`,
  295. expectedPath: filepath.Join(targetPath, "system/lib/rfsa"),
  296. }, {
  297. description: "prebuilt: vendor rfsa",
  298. config: `
  299. prebuilt_rfsa {
  300. name: "foo.conf",
  301. src: "foo.conf",
  302. soc_specific: true,
  303. sub_dir: "sub_dir",
  304. }`,
  305. expectedPath: filepath.Join(targetPath, "vendor/lib/rfsa/sub_dir"),
  306. }}
  307. for _, tt := range tests {
  308. t.Run(tt.description, func(t *testing.T) {
  309. result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
  310. p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
  311. android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
  312. })
  313. }
  314. }