blob: 5c4e222ddf1f26c9e2e4dbf80d5c10469f5285e2 [file] [log] [blame]
Tao Bao0ba5c942018-08-14 22:20:22 -07001// 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
Jaewoong Jung4b79e982020-06-01 10:45:49 -070015package etc
Tao Bao0ba5c942018-08-14 22:20:22 -070016
17import (
Kiyoung Kimae11c232021-07-19 11:38:04 +090018 "fmt"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070019 "os"
Patrice Arruda300cef92019-02-22 15:47:57 -080020 "path/filepath"
Tao Bao0ba5c942018-08-14 22:20:22 -070021 "testing"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070022
Kiyoung Kimae11c232021-07-19 11:38:04 +090023 "github.com/google/blueprint/proptools"
24
Jaewoong Jung4b79e982020-06-01 10:45:49 -070025 "android/soong/android"
Spandan Das756d3402023-06-05 22:49:50 +000026 "android/soong/bazel/cquery"
Kiyoung Kimae11c232021-07-19 11:38:04 +090027 "android/soong/snapshot"
Tao Bao0ba5c942018-08-14 22:20:22 -070028)
29
Jaewoong Jung4b79e982020-06-01 10:45:49 -070030func TestMain(m *testing.M) {
Paul Duffin5f9f7712021-03-15 15:35:49 +000031 os.Exit(m.Run())
Jaewoong Jung4b79e982020-06-01 10:45:49 -070032}
33
Paul Duffin89648f92021-03-20 00:36:55 +000034var prepareForPrebuiltEtcTest = android.GroupFixturePreparers(
Paul Duffin1172fed2021-03-08 11:28:18 +000035 android.PrepareForTestWithArchMutator,
36 PrepareForTestWithPrebuiltEtc,
37 android.FixtureMergeMockFs(android.MockFS{
Colin Cross98be1bb2019-12-13 20:41:13 -080038 "foo.conf": nil,
39 "bar.conf": nil,
40 "baz.conf": nil,
Paul Duffin1172fed2021-03-08 11:28:18 +000041 }),
42)
Colin Cross98be1bb2019-12-13 20:41:13 -080043
Kiyoung Kimae11c232021-07-19 11:38:04 +090044var prepareForPrebuiltEtcSnapshotTest = android.GroupFixturePreparers(
45 prepareForPrebuiltEtcTest,
46 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
47 snapshot.VendorSnapshotImageSingleton.Init(ctx)
48 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
49 }),
50 android.FixtureModifyConfig(func(config android.Config) {
51 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
52 config.TestProductVariables.RecoverySnapshotVersion = proptools.StringPtr("current")
53 }),
54)
55
Tao Bao0ba5c942018-08-14 22:20:22 -070056func TestPrebuiltEtcVariants(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +000057 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Tao Bao0ba5c942018-08-14 22:20:22 -070058 prebuilt_etc {
59 name: "foo.conf",
60 src: "foo.conf",
61 }
62 prebuilt_etc {
63 name: "bar.conf",
64 src: "bar.conf",
65 recovery_available: true,
66 }
67 prebuilt_etc {
68 name: "baz.conf",
69 src: "baz.conf",
70 recovery: true,
71 }
72 `)
73
Paul Duffin921fac72021-03-10 09:00:58 +000074 foo_variants := result.ModuleVariantsForTests("foo.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070075 if len(foo_variants) != 1 {
76 t.Errorf("expected 1, got %#v", foo_variants)
77 }
78
Paul Duffin921fac72021-03-10 09:00:58 +000079 bar_variants := result.ModuleVariantsForTests("bar.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070080 if len(bar_variants) != 2 {
81 t.Errorf("expected 2, got %#v", bar_variants)
82 }
83
Paul Duffin921fac72021-03-10 09:00:58 +000084 baz_variants := result.ModuleVariantsForTests("baz.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070085 if len(baz_variants) != 1 {
Cole Faustdff9c142023-09-01 16:11:47 -070086 t.Errorf("expected 1, got %#v", baz_variants)
Tao Bao0ba5c942018-08-14 22:20:22 -070087 }
88}
Jiyong Park139a2e62018-10-26 21:49:39 +090089
90func TestPrebuiltEtcOutputPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +000091 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jiyong Park139a2e62018-10-26 21:49:39 +090092 prebuilt_etc {
93 name: "foo.conf",
94 src: "foo.conf",
95 filename: "foo.installed.conf",
96 }
97 `)
98
Paul Duffin921fac72021-03-10 09:00:58 +000099 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffine84b1332021-03-12 11:59:43 +0000100 android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePath.Base())
Jiyong Park139a2e62018-10-26 21:49:39 +0900101}
Jiyong Park1a7cf082018-11-13 11:59:12 +0900102
103func TestPrebuiltEtcGlob(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000104 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jiyong Park1a7cf082018-11-13 11:59:12 +0900105 prebuilt_etc {
106 name: "my_foo",
107 src: "foo.*",
108 }
109 prebuilt_etc {
110 name: "my_bar",
111 src: "bar.*",
112 filename_from_src: true,
113 }
114 `)
115
Paul Duffin921fac72021-03-10 09:00:58 +0000116 p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffine84b1332021-03-12 11:59:43 +0000117 android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePath.Base())
Jiyong Park1a7cf082018-11-13 11:59:12 +0900118
Paul Duffin921fac72021-03-10 09:00:58 +0000119 p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffine84b1332021-03-12 11:59:43 +0000120 android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePath.Base())
Jiyong Park1a7cf082018-11-13 11:59:12 +0900121}
Anton Hanssonce0e2582019-02-04 14:19:27 +0000122
123func TestPrebuiltEtcAndroidMk(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000124 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Anton Hanssonce0e2582019-02-04 14:19:27 +0000125 prebuilt_etc {
126 name: "foo",
127 src: "foo.conf",
128 owner: "abc",
129 filename_from_src: true,
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700130 required: ["modA", "moduleB"],
131 host_required: ["hostModA", "hostModB"],
132 target_required: ["targetModA"],
Anton Hanssonce0e2582019-02-04 14:19:27 +0000133 }
134 `)
135
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700136 expected := map[string][]string{
137 "LOCAL_MODULE": {"foo"},
138 "LOCAL_MODULE_CLASS": {"ETC"},
139 "LOCAL_MODULE_OWNER": {"abc"},
140 "LOCAL_INSTALLED_MODULE_STEM": {"foo.conf"},
141 "LOCAL_REQUIRED_MODULES": {"modA", "moduleB"},
142 "LOCAL_HOST_REQUIRED_MODULES": {"hostModA", "hostModB"},
143 "LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"},
Wei Li598f92d2023-01-04 17:12:24 -0800144 "LOCAL_SOONG_MODULE_TYPE": {"prebuilt_etc"},
Anton Hanssonce0e2582019-02-04 14:19:27 +0000145 }
146
Paul Duffin921fac72021-03-10 09:00:58 +0000147 mod := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc)
148 entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0]
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700149 for k, expectedValue := range expected {
150 if value, ok := entries.EntryMap[k]; ok {
Paul Duffine84b1332021-03-12 11:59:43 +0000151 android.AssertDeepEquals(t, k, expectedValue, value)
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700152 } else {
153 t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
Anton Hanssonce0e2582019-02-04 14:19:27 +0000154 }
155 }
156}
Jaewoong Jung24788182019-02-04 14:34:10 -0800157
Liz Kammer0449a632020-06-26 10:12:36 -0700158func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000159 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Liz Kammer0449a632020-06-26 10:12:36 -0700160 prebuilt_etc {
161 name: "foo.conf",
162 src: "foo.conf",
163 relative_install_path: "bar",
164 }
165 `)
166
Paul Duffin921fac72021-03-10 09:00:58 +0000167 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000168 expected := "out/soong/target/product/test_device/system/etc/bar"
169 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Liz Kammer0449a632020-06-26 10:12:36 -0700170}
171
172func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000173 prepareForPrebuiltEtcTest.
Paul Duffin1172fed2021-03-08 11:28:18 +0000174 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")).
175 RunTestWithBp(t, `
176 prebuilt_etc {
177 name: "foo.conf",
178 src: "foo.conf",
179 sub_dir: "bar",
180 relative_install_path: "bar",
181 }
182 `)
Liz Kammer0449a632020-06-26 10:12:36 -0700183}
184
Jaewoong Jung24788182019-02-04 14:34:10 -0800185func TestPrebuiltEtcHost(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000186 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jaewoong Jung24788182019-02-04 14:34:10 -0800187 prebuilt_etc_host {
188 name: "foo.conf",
189 src: "foo.conf",
190 }
191 `)
192
Colin Cross0c66bc62021-07-20 09:47:41 -0700193 buildOS := result.Config.BuildOS.String()
Paul Duffin921fac72021-03-10 09:00:58 +0000194 p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
Jaewoong Jung24788182019-02-04 14:34:10 -0800195 if !p.Host() {
196 t.Errorf("host bit is not set for a prebuilt_etc_host module.")
197 }
198}
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800199
Colin Cross725eac62022-10-03 15:31:29 -0700200func TestPrebuiltEtcAllowMissingDependencies(t *testing.T) {
201 result := android.GroupFixturePreparers(
202 prepareForPrebuiltEtcTest,
203 android.PrepareForTestDisallowNonExistentPaths,
204 android.FixtureModifyConfig(
205 func(config android.Config) {
206 config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
207 }),
208 ).RunTestWithBp(t, `
209 prebuilt_etc {
210 name: "foo.conf",
211 filename_from_src: true,
212 arch: {
213 x86: {
214 src: "x86.conf",
215 },
216 },
217 }
218 `)
219
220 android.AssertStringEquals(t, "expected error rule", "android/soong/android.Error",
221 result.ModuleForTests("foo.conf", "android_arm64_armv8-a").Output("foo.conf").Rule.String())
222}
223
Inseob Kim27408bf2021-04-06 21:00:17 +0900224func TestPrebuiltRootInstallDirPath(t *testing.T) {
225 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
226 prebuilt_root {
227 name: "foo.conf",
228 src: "foo.conf",
229 filename: "foo.conf",
230 }
231 `)
232
233 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
234 expected := "out/soong/target/product/test_device/system"
235 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
236}
237
238func TestPrebuiltRootInstallDirPathValidate(t *testing.T) {
239 prepareForPrebuiltEtcTest.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("filename cannot contain separator")).RunTestWithBp(t, `
240 prebuilt_root {
241 name: "foo.conf",
242 src: "foo.conf",
243 filename: "foo/bar.conf",
244 }
245 `)
246}
247
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800248func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000249 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800250 prebuilt_usr_share {
251 name: "foo.conf",
252 src: "foo.conf",
253 sub_dir: "bar",
254 }
255 `)
256
Paul Duffin921fac72021-03-10 09:00:58 +0000257 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000258 expected := "out/soong/target/product/test_device/system/usr/share/bar"
259 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800260}
Patrice Arruda300cef92019-02-22 15:47:57 -0800261
262func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000263 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Patrice Arruda300cef92019-02-22 15:47:57 -0800264 prebuilt_usr_share_host {
265 name: "foo.conf",
266 src: "foo.conf",
267 sub_dir: "bar",
268 }
269 `)
270
Colin Cross0c66bc62021-07-20 09:47:41 -0700271 buildOS := result.Config.BuildOS.String()
Paul Duffin921fac72021-03-10 09:00:58 +0000272 p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000273 expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar")
274 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Patrice Arruda300cef92019-02-22 15:47:57 -0800275}
Patrice Arruda61583eb2019-05-14 08:20:45 -0700276
277func TestPrebuiltFontInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000278 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Patrice Arruda61583eb2019-05-14 08:20:45 -0700279 prebuilt_font {
280 name: "foo.conf",
281 src: "foo.conf",
282 }
283 `)
284
Paul Duffin921fac72021-03-10 09:00:58 +0000285 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000286 expected := "out/soong/target/product/test_device/system/fonts"
287 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700288}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700289
290func TestPrebuiltFirmwareDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000291 targetPath := "out/soong/target/product/test_device"
Patrice Arruda057a8b12019-06-03 15:29:27 -0700292 tests := []struct {
293 description string
294 config string
295 expectedPath string
296 }{{
297 description: "prebuilt: system firmware",
298 config: `
299 prebuilt_firmware {
300 name: "foo.conf",
301 src: "foo.conf",
302 }`,
303 expectedPath: filepath.Join(targetPath, "system/etc/firmware"),
304 }, {
305 description: "prebuilt: vendor firmware",
306 config: `
307 prebuilt_firmware {
308 name: "foo.conf",
309 src: "foo.conf",
310 soc_specific: true,
311 sub_dir: "sub_dir",
312 }`,
313 expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"),
314 }}
315 for _, tt := range tests {
316 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000317 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000318 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000319 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700320 })
321 }
322}
Patrice Arruda0f688002020-06-08 21:40:25 +0000323
324func TestPrebuiltDSPDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000325 targetPath := "out/soong/target/product/test_device"
Patrice Arruda0f688002020-06-08 21:40:25 +0000326 tests := []struct {
327 description string
328 config string
329 expectedPath string
330 }{{
331 description: "prebuilt: system dsp",
332 config: `
333 prebuilt_dsp {
334 name: "foo.conf",
335 src: "foo.conf",
336 }`,
337 expectedPath: filepath.Join(targetPath, "system/etc/dsp"),
338 }, {
339 description: "prebuilt: vendor dsp",
340 config: `
341 prebuilt_dsp {
342 name: "foo.conf",
343 src: "foo.conf",
344 soc_specific: true,
345 sub_dir: "sub_dir",
346 }`,
347 expectedPath: filepath.Join(targetPath, "vendor/dsp/sub_dir"),
348 }}
349 for _, tt := range tests {
350 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000351 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000352 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000353 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda0f688002020-06-08 21:40:25 +0000354 })
355 }
356}
Colin Cross83ebf232021-04-09 09:41:23 -0700357
358func TestPrebuiltRFSADirPath(t *testing.T) {
359 targetPath := "out/soong/target/product/test_device"
360 tests := []struct {
361 description string
362 config string
363 expectedPath string
364 }{{
365 description: "prebuilt: system rfsa",
366 config: `
367 prebuilt_rfsa {
368 name: "foo.conf",
369 src: "foo.conf",
370 }`,
371 expectedPath: filepath.Join(targetPath, "system/lib/rfsa"),
372 }, {
373 description: "prebuilt: vendor rfsa",
374 config: `
375 prebuilt_rfsa {
376 name: "foo.conf",
377 src: "foo.conf",
378 soc_specific: true,
379 sub_dir: "sub_dir",
380 }`,
381 expectedPath: filepath.Join(targetPath, "vendor/lib/rfsa/sub_dir"),
382 }}
383 for _, tt := range tests {
384 t.Run(tt.description, func(t *testing.T) {
385 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
386 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
387 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
388 })
389 }
390}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900391
392func checkIfSnapshotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) {
393 checkIfSnapshotExistAsExpected(t, result, image, moduleName, true)
394}
395
396func checkIfSnapshotNotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) {
397 checkIfSnapshotExistAsExpected(t, result, image, moduleName, false)
398}
399
400func checkIfSnapshotExistAsExpected(t *testing.T, result *android.TestResult, image string, moduleName string, expectToExist bool) {
401 snapshotSingleton := result.SingletonForTests(image + "-snapshot")
402 archType := "arm64"
403 archVariant := "armv8-a"
404 archDir := fmt.Sprintf("arch-%s", archType)
405
406 snapshotDir := fmt.Sprintf("%s-snapshot", image)
407 snapshotVariantPath := filepath.Join(snapshotDir, archType)
408 outputDir := filepath.Join(snapshotVariantPath, archDir, "etc")
409 imageVariant := ""
410 if image == "recovery" {
411 imageVariant = "recovery_"
412 }
413 mod := result.ModuleForTests(moduleName, fmt.Sprintf("android_%s%s_%s", imageVariant, archType, archVariant))
414 outputFiles := mod.OutputFiles(t, "")
415 if len(outputFiles) != 1 {
416 t.Errorf("%q must have single output\n", moduleName)
417 return
418 }
419 snapshotPath := filepath.Join(outputDir, moduleName)
420
421 if expectToExist {
422 out := snapshotSingleton.Output(snapshotPath)
423
424 if out.Input.String() != outputFiles[0].String() {
425 t.Errorf("The input of snapshot %q must be %q, but %q", "prebuilt_vendor", out.Input.String(), outputFiles[0])
426 }
427
428 snapshotJsonPath := snapshotPath + ".json"
429
430 if snapshotSingleton.MaybeOutput(snapshotJsonPath).Rule == nil {
431 t.Errorf("%q expected but not found", snapshotJsonPath)
432 }
433 } else {
434 out := snapshotSingleton.MaybeOutput(snapshotPath)
435 if out.Rule != nil {
436 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
437 }
438 }
439}
440
441func TestPrebuiltTakeSnapshot(t *testing.T) {
442 var testBp = `
443 prebuilt_etc {
444 name: "prebuilt_vendor",
445 src: "foo.conf",
446 vendor: true,
447 }
448
449 prebuilt_etc {
450 name: "prebuilt_vendor_indirect",
451 src: "foo.conf",
452 vendor: true,
453 }
454
455 prebuilt_etc {
456 name: "prebuilt_recovery",
457 src: "bar.conf",
458 recovery: true,
459 }
460
461 prebuilt_etc {
462 name: "prebuilt_recovery_indirect",
463 src: "bar.conf",
464 recovery: true,
465 }
466 `
467
468 t.Run("prebuilt: vendor and recovery snapshot", func(t *testing.T) {
469 result := prepareForPrebuiltEtcSnapshotTest.RunTestWithBp(t, testBp)
470
471 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor")
472 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor_indirect")
473 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery")
474 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery_indirect")
475 })
476
477 t.Run("prebuilt: directed snapshot", func(t *testing.T) {
478 prepareForPrebuiltEtcDirectedSnapshotTest := android.GroupFixturePreparers(
479 prepareForPrebuiltEtcSnapshotTest,
480 android.FixtureModifyConfig(func(config android.Config) {
481 config.TestProductVariables.DirectedVendorSnapshot = true
482 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
483 config.TestProductVariables.VendorSnapshotModules["prebuilt_vendor"] = true
484 config.TestProductVariables.DirectedRecoverySnapshot = true
485 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
486 config.TestProductVariables.RecoverySnapshotModules["prebuilt_recovery"] = true
487 }),
488 )
489
490 result := prepareForPrebuiltEtcDirectedSnapshotTest.RunTestWithBp(t, testBp)
491
492 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor")
493 checkIfSnapshotNotTaken(t, result, "vendor", "prebuilt_vendor_indirect")
494 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery")
495 checkIfSnapshotNotTaken(t, result, "recovery", "prebuilt_recovery_indirect")
496 })
497}
Spandan Das756d3402023-06-05 22:49:50 +0000498
499func TestPrebuiltEtcAndroidMkEntriesWithBazel(t *testing.T) {
500 t.Parallel()
501 bp := `
502prebuilt_etc {
503 name: "myetc",
504 src: "prebuilt_etc.rc", // filename in src tree
505 filename: "init.rc", // target filename on device
506 sub_dir: "subdir", // relative subdir for installation
507 bazel_module: { label: "//foo/bar:myetc" },
508}
509`
510 res := android.GroupFixturePreparers(
511 prepareForPrebuiltEtcTest,
512 android.FixtureModifyConfig(func(cfg android.Config) {
513 cfg.BazelContext = android.MockBazelContext{
514 LabelToPrebuiltFileInfo: map[string]cquery.PrebuiltFileInfo{
515 "//foo/bar:myetc": cquery.PrebuiltFileInfo{
516 Src: "foo/bar/prebuilt_etc.rc",
517 Dir: "etc/subdir",
518 Filename: "init.rc",
519 Installable: true,
520 },
521 },
522 }
523 }),
524 ).RunTestWithBp(t, bp)
525 ctx := res.ModuleForTests("myetc", "android_arm64_armv8-a")
526 mod := ctx.Module()
527 entries := android.AndroidMkEntriesForTest(t, res.TestContext, mod)[0]
528 // verify androidmk entries
529 android.AssertStringDoesContain(t, "LOCAL_MODULE_PATH should contain", entries.EntryMap["LOCAL_MODULE_PATH"][0], "etc/subdir")
530 android.AssertStringEquals(t, "LOCAL_INSTALLED_MODULE_STEM is incorrect", "init.rc", entries.EntryMap["LOCAL_INSTALLED_MODULE_STEM"][0])
531 // verify installation rules
532 install := ctx.Description("install")
533 android.AssertStringEquals(t, "Source location of prebuilt_etc installation", "out/soong/.intermediates/myetc/android_arm64_armv8-a/init.rc", install.Input.String())
534 android.AssertStringEquals(t, "Target location of prebuilt_etc installation", "out/soong/target/product/test_device/system/etc/subdir/init.rc", install.Output.String())
535}