blob: 1d9aa8e58e70dbfb4be6e146a105c00142866dff [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"
Kiyoung Kimae11c232021-07-19 11:38:04 +090026 "android/soong/snapshot"
Tao Bao0ba5c942018-08-14 22:20:22 -070027)
28
Jaewoong Jung4b79e982020-06-01 10:45:49 -070029func TestMain(m *testing.M) {
Paul Duffin5f9f7712021-03-15 15:35:49 +000030 os.Exit(m.Run())
Jaewoong Jung4b79e982020-06-01 10:45:49 -070031}
32
Paul Duffin89648f92021-03-20 00:36:55 +000033var prepareForPrebuiltEtcTest = android.GroupFixturePreparers(
Paul Duffin1172fed2021-03-08 11:28:18 +000034 android.PrepareForTestWithArchMutator,
35 PrepareForTestWithPrebuiltEtc,
36 android.FixtureMergeMockFs(android.MockFS{
Colin Cross98be1bb2019-12-13 20:41:13 -080037 "foo.conf": nil,
38 "bar.conf": nil,
39 "baz.conf": nil,
Paul Duffin1172fed2021-03-08 11:28:18 +000040 }),
41)
Colin Cross98be1bb2019-12-13 20:41:13 -080042
Kiyoung Kimae11c232021-07-19 11:38:04 +090043var prepareForPrebuiltEtcSnapshotTest = android.GroupFixturePreparers(
44 prepareForPrebuiltEtcTest,
45 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
46 snapshot.VendorSnapshotImageSingleton.Init(ctx)
47 snapshot.RecoverySnapshotImageSingleton.Init(ctx)
48 }),
49 android.FixtureModifyConfig(func(config android.Config) {
50 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
51 config.TestProductVariables.RecoverySnapshotVersion = proptools.StringPtr("current")
52 }),
53)
54
Tao Bao0ba5c942018-08-14 22:20:22 -070055func TestPrebuiltEtcVariants(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +000056 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Tao Bao0ba5c942018-08-14 22:20:22 -070057 prebuilt_etc {
58 name: "foo.conf",
59 src: "foo.conf",
60 }
61 prebuilt_etc {
62 name: "bar.conf",
63 src: "bar.conf",
64 recovery_available: true,
65 }
66 prebuilt_etc {
67 name: "baz.conf",
68 src: "baz.conf",
69 recovery: true,
70 }
71 `)
72
Paul Duffin921fac72021-03-10 09:00:58 +000073 foo_variants := result.ModuleVariantsForTests("foo.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070074 if len(foo_variants) != 1 {
75 t.Errorf("expected 1, got %#v", foo_variants)
76 }
77
Paul Duffin921fac72021-03-10 09:00:58 +000078 bar_variants := result.ModuleVariantsForTests("bar.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070079 if len(bar_variants) != 2 {
80 t.Errorf("expected 2, got %#v", bar_variants)
81 }
82
Paul Duffin921fac72021-03-10 09:00:58 +000083 baz_variants := result.ModuleVariantsForTests("baz.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070084 if len(baz_variants) != 1 {
Cole Faustdff9c142023-09-01 16:11:47 -070085 t.Errorf("expected 1, got %#v", baz_variants)
Tao Bao0ba5c942018-08-14 22:20:22 -070086 }
87}
Jiyong Park139a2e62018-10-26 21:49:39 +090088
89func TestPrebuiltEtcOutputPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +000090 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jiyong Park139a2e62018-10-26 21:49:39 +090091 prebuilt_etc {
92 name: "foo.conf",
93 src: "foo.conf",
94 filename: "foo.installed.conf",
95 }
96 `)
97
Paul Duffin921fac72021-03-10 09:00:58 +000098 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +110099 android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePaths[0].Base())
Jiyong Park139a2e62018-10-26 21:49:39 +0900100}
Jiyong Park1a7cf082018-11-13 11:59:12 +0900101
102func TestPrebuiltEtcGlob(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000103 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jiyong Park1a7cf082018-11-13 11:59:12 +0900104 prebuilt_etc {
105 name: "my_foo",
106 src: "foo.*",
107 }
108 prebuilt_etc {
109 name: "my_bar",
110 src: "bar.*",
111 filename_from_src: true,
112 }
113 `)
114
Paul Duffin921fac72021-03-10 09:00:58 +0000115 p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100116 android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePaths[0].Base())
Jiyong Park1a7cf082018-11-13 11:59:12 +0900117
Paul Duffin921fac72021-03-10 09:00:58 +0000118 p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
Thiébaud Weksteen00e8b312024-03-18 14:06:00 +1100119 android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePaths[0].Base())
120}
121
122func TestPrebuiltEtcMultipleSrcs(t *testing.T) {
123 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
124 prebuilt_etc {
125 name: "foo",
126 srcs: ["*.conf"],
127 }
128 `)
129
130 p := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc)
131 android.AssertStringEquals(t, "output file path", "bar.conf", p.outputFilePaths[0].Base())
132 android.AssertStringEquals(t, "output file path", "baz.conf", p.outputFilePaths[1].Base())
133 android.AssertStringEquals(t, "output file path", "foo.conf", p.outputFilePaths[2].Base())
Jiyong Park1a7cf082018-11-13 11:59:12 +0900134}
Anton Hanssonce0e2582019-02-04 14:19:27 +0000135
136func TestPrebuiltEtcAndroidMk(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000137 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Anton Hanssonce0e2582019-02-04 14:19:27 +0000138 prebuilt_etc {
139 name: "foo",
140 src: "foo.conf",
141 owner: "abc",
142 filename_from_src: true,
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700143 required: ["modA", "moduleB"],
144 host_required: ["hostModA", "hostModB"],
145 target_required: ["targetModA"],
Anton Hanssonce0e2582019-02-04 14:19:27 +0000146 }
147 `)
148
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700149 expected := map[string][]string{
150 "LOCAL_MODULE": {"foo"},
151 "LOCAL_MODULE_CLASS": {"ETC"},
152 "LOCAL_MODULE_OWNER": {"abc"},
153 "LOCAL_INSTALLED_MODULE_STEM": {"foo.conf"},
154 "LOCAL_REQUIRED_MODULES": {"modA", "moduleB"},
155 "LOCAL_HOST_REQUIRED_MODULES": {"hostModA", "hostModB"},
156 "LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"},
Wei Li598f92d2023-01-04 17:12:24 -0800157 "LOCAL_SOONG_MODULE_TYPE": {"prebuilt_etc"},
Anton Hanssonce0e2582019-02-04 14:19:27 +0000158 }
159
Paul Duffin921fac72021-03-10 09:00:58 +0000160 mod := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc)
161 entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0]
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700162 for k, expectedValue := range expected {
163 if value, ok := entries.EntryMap[k]; ok {
Paul Duffine84b1332021-03-12 11:59:43 +0000164 android.AssertDeepEquals(t, k, expectedValue, value)
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700165 } else {
166 t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
Anton Hanssonce0e2582019-02-04 14:19:27 +0000167 }
168 }
169}
Jaewoong Jung24788182019-02-04 14:34:10 -0800170
Liz Kammer0449a632020-06-26 10:12:36 -0700171func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000172 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Liz Kammer0449a632020-06-26 10:12:36 -0700173 prebuilt_etc {
174 name: "foo.conf",
175 src: "foo.conf",
176 relative_install_path: "bar",
177 }
178 `)
179
Paul Duffin921fac72021-03-10 09:00:58 +0000180 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000181 expected := "out/soong/target/product/test_device/system/etc/bar"
182 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Liz Kammer0449a632020-06-26 10:12:36 -0700183}
184
185func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000186 prepareForPrebuiltEtcTest.
Paul Duffin1172fed2021-03-08 11:28:18 +0000187 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")).
188 RunTestWithBp(t, `
189 prebuilt_etc {
190 name: "foo.conf",
191 src: "foo.conf",
192 sub_dir: "bar",
193 relative_install_path: "bar",
194 }
195 `)
Liz Kammer0449a632020-06-26 10:12:36 -0700196}
197
Jaewoong Jung24788182019-02-04 14:34:10 -0800198func TestPrebuiltEtcHost(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000199 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jaewoong Jung24788182019-02-04 14:34:10 -0800200 prebuilt_etc_host {
201 name: "foo.conf",
202 src: "foo.conf",
203 }
204 `)
205
Colin Cross0c66bc62021-07-20 09:47:41 -0700206 buildOS := result.Config.BuildOS.String()
Paul Duffin921fac72021-03-10 09:00:58 +0000207 p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
Jaewoong Jung24788182019-02-04 14:34:10 -0800208 if !p.Host() {
209 t.Errorf("host bit is not set for a prebuilt_etc_host module.")
210 }
211}
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800212
Colin Cross725eac62022-10-03 15:31:29 -0700213func TestPrebuiltEtcAllowMissingDependencies(t *testing.T) {
214 result := android.GroupFixturePreparers(
215 prepareForPrebuiltEtcTest,
216 android.PrepareForTestDisallowNonExistentPaths,
217 android.FixtureModifyConfig(
218 func(config android.Config) {
219 config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
220 }),
221 ).RunTestWithBp(t, `
222 prebuilt_etc {
223 name: "foo.conf",
224 filename_from_src: true,
225 arch: {
226 x86: {
227 src: "x86.conf",
228 },
229 },
230 }
231 `)
232
233 android.AssertStringEquals(t, "expected error rule", "android/soong/android.Error",
234 result.ModuleForTests("foo.conf", "android_arm64_armv8-a").Output("foo.conf").Rule.String())
235}
236
Inseob Kim27408bf2021-04-06 21:00:17 +0900237func TestPrebuiltRootInstallDirPath(t *testing.T) {
238 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
239 prebuilt_root {
240 name: "foo.conf",
241 src: "foo.conf",
242 filename: "foo.conf",
243 }
244 `)
245
246 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
247 expected := "out/soong/target/product/test_device/system"
248 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
249}
250
251func TestPrebuiltRootInstallDirPathValidate(t *testing.T) {
252 prepareForPrebuiltEtcTest.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("filename cannot contain separator")).RunTestWithBp(t, `
253 prebuilt_root {
254 name: "foo.conf",
255 src: "foo.conf",
256 filename: "foo/bar.conf",
257 }
258 `)
259}
260
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800261func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000262 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800263 prebuilt_usr_share {
264 name: "foo.conf",
265 src: "foo.conf",
266 sub_dir: "bar",
267 }
268 `)
269
Paul Duffin921fac72021-03-10 09:00:58 +0000270 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000271 expected := "out/soong/target/product/test_device/system/usr/share/bar"
272 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800273}
Patrice Arruda300cef92019-02-22 15:47:57 -0800274
275func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000276 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Patrice Arruda300cef92019-02-22 15:47:57 -0800277 prebuilt_usr_share_host {
278 name: "foo.conf",
279 src: "foo.conf",
280 sub_dir: "bar",
281 }
282 `)
283
Colin Cross0c66bc62021-07-20 09:47:41 -0700284 buildOS := result.Config.BuildOS.String()
Paul Duffin921fac72021-03-10 09:00:58 +0000285 p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000286 expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar")
287 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Patrice Arruda300cef92019-02-22 15:47:57 -0800288}
Patrice Arruda61583eb2019-05-14 08:20:45 -0700289
290func TestPrebuiltFontInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000291 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Patrice Arruda61583eb2019-05-14 08:20:45 -0700292 prebuilt_font {
293 name: "foo.conf",
294 src: "foo.conf",
295 }
296 `)
297
Paul Duffin921fac72021-03-10 09:00:58 +0000298 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000299 expected := "out/soong/target/product/test_device/system/fonts"
300 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700301}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700302
303func TestPrebuiltFirmwareDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000304 targetPath := "out/soong/target/product/test_device"
Patrice Arruda057a8b12019-06-03 15:29:27 -0700305 tests := []struct {
306 description string
307 config string
308 expectedPath string
309 }{{
310 description: "prebuilt: system firmware",
311 config: `
312 prebuilt_firmware {
313 name: "foo.conf",
314 src: "foo.conf",
315 }`,
316 expectedPath: filepath.Join(targetPath, "system/etc/firmware"),
317 }, {
318 description: "prebuilt: vendor firmware",
319 config: `
320 prebuilt_firmware {
321 name: "foo.conf",
322 src: "foo.conf",
323 soc_specific: true,
324 sub_dir: "sub_dir",
325 }`,
326 expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"),
327 }}
328 for _, tt := range tests {
329 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000330 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000331 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000332 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700333 })
334 }
335}
Patrice Arruda0f688002020-06-08 21:40:25 +0000336
337func TestPrebuiltDSPDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000338 targetPath := "out/soong/target/product/test_device"
Patrice Arruda0f688002020-06-08 21:40:25 +0000339 tests := []struct {
340 description string
341 config string
342 expectedPath string
343 }{{
344 description: "prebuilt: system dsp",
345 config: `
346 prebuilt_dsp {
347 name: "foo.conf",
348 src: "foo.conf",
349 }`,
350 expectedPath: filepath.Join(targetPath, "system/etc/dsp"),
351 }, {
352 description: "prebuilt: vendor dsp",
353 config: `
354 prebuilt_dsp {
355 name: "foo.conf",
356 src: "foo.conf",
357 soc_specific: true,
358 sub_dir: "sub_dir",
359 }`,
360 expectedPath: filepath.Join(targetPath, "vendor/dsp/sub_dir"),
361 }}
362 for _, tt := range tests {
363 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000364 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000365 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000366 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda0f688002020-06-08 21:40:25 +0000367 })
368 }
369}
Colin Cross83ebf232021-04-09 09:41:23 -0700370
371func TestPrebuiltRFSADirPath(t *testing.T) {
372 targetPath := "out/soong/target/product/test_device"
373 tests := []struct {
374 description string
375 config string
376 expectedPath string
377 }{{
378 description: "prebuilt: system rfsa",
379 config: `
380 prebuilt_rfsa {
381 name: "foo.conf",
382 src: "foo.conf",
383 }`,
384 expectedPath: filepath.Join(targetPath, "system/lib/rfsa"),
385 }, {
386 description: "prebuilt: vendor rfsa",
387 config: `
388 prebuilt_rfsa {
389 name: "foo.conf",
390 src: "foo.conf",
391 soc_specific: true,
392 sub_dir: "sub_dir",
393 }`,
394 expectedPath: filepath.Join(targetPath, "vendor/lib/rfsa/sub_dir"),
395 }}
396 for _, tt := range tests {
397 t.Run(tt.description, func(t *testing.T) {
398 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
399 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
400 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
401 })
402 }
403}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900404
405func checkIfSnapshotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) {
406 checkIfSnapshotExistAsExpected(t, result, image, moduleName, true)
407}
408
409func checkIfSnapshotNotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) {
410 checkIfSnapshotExistAsExpected(t, result, image, moduleName, false)
411}
412
413func checkIfSnapshotExistAsExpected(t *testing.T, result *android.TestResult, image string, moduleName string, expectToExist bool) {
414 snapshotSingleton := result.SingletonForTests(image + "-snapshot")
415 archType := "arm64"
416 archVariant := "armv8-a"
417 archDir := fmt.Sprintf("arch-%s", archType)
418
419 snapshotDir := fmt.Sprintf("%s-snapshot", image)
420 snapshotVariantPath := filepath.Join(snapshotDir, archType)
421 outputDir := filepath.Join(snapshotVariantPath, archDir, "etc")
422 imageVariant := ""
423 if image == "recovery" {
424 imageVariant = "recovery_"
425 }
426 mod := result.ModuleForTests(moduleName, fmt.Sprintf("android_%s%s_%s", imageVariant, archType, archVariant))
427 outputFiles := mod.OutputFiles(t, "")
428 if len(outputFiles) != 1 {
429 t.Errorf("%q must have single output\n", moduleName)
430 return
431 }
432 snapshotPath := filepath.Join(outputDir, moduleName)
433
434 if expectToExist {
435 out := snapshotSingleton.Output(snapshotPath)
436
437 if out.Input.String() != outputFiles[0].String() {
438 t.Errorf("The input of snapshot %q must be %q, but %q", "prebuilt_vendor", out.Input.String(), outputFiles[0])
439 }
440
441 snapshotJsonPath := snapshotPath + ".json"
442
443 if snapshotSingleton.MaybeOutput(snapshotJsonPath).Rule == nil {
444 t.Errorf("%q expected but not found", snapshotJsonPath)
445 }
446 } else {
447 out := snapshotSingleton.MaybeOutput(snapshotPath)
448 if out.Rule != nil {
449 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
450 }
451 }
452}
453
454func TestPrebuiltTakeSnapshot(t *testing.T) {
455 var testBp = `
456 prebuilt_etc {
457 name: "prebuilt_vendor",
458 src: "foo.conf",
459 vendor: true,
460 }
461
462 prebuilt_etc {
463 name: "prebuilt_vendor_indirect",
464 src: "foo.conf",
465 vendor: true,
466 }
467
468 prebuilt_etc {
469 name: "prebuilt_recovery",
470 src: "bar.conf",
471 recovery: true,
472 }
473
474 prebuilt_etc {
475 name: "prebuilt_recovery_indirect",
476 src: "bar.conf",
477 recovery: true,
478 }
479 `
480
481 t.Run("prebuilt: vendor and recovery snapshot", func(t *testing.T) {
482 result := prepareForPrebuiltEtcSnapshotTest.RunTestWithBp(t, testBp)
483
484 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor")
485 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor_indirect")
486 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery")
487 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery_indirect")
488 })
489
490 t.Run("prebuilt: directed snapshot", func(t *testing.T) {
491 prepareForPrebuiltEtcDirectedSnapshotTest := android.GroupFixturePreparers(
492 prepareForPrebuiltEtcSnapshotTest,
493 android.FixtureModifyConfig(func(config android.Config) {
494 config.TestProductVariables.DirectedVendorSnapshot = true
495 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
496 config.TestProductVariables.VendorSnapshotModules["prebuilt_vendor"] = true
497 config.TestProductVariables.DirectedRecoverySnapshot = true
498 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
499 config.TestProductVariables.RecoverySnapshotModules["prebuilt_recovery"] = true
500 }),
501 )
502
503 result := prepareForPrebuiltEtcDirectedSnapshotTest.RunTestWithBp(t, testBp)
504
505 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor")
506 checkIfSnapshotNotTaken(t, result, "vendor", "prebuilt_vendor_indirect")
507 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery")
508 checkIfSnapshotNotTaken(t, result, "recovery", "prebuilt_recovery_indirect")
509 })
510}