blob: e346bd79fdef1d619a55b83d475ed119bd0b2582 [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
yangbill63c5e192024-03-27 09:02:12 +0000290func TestPrebuiltPrebuiltUserHyphenDataInstallDirPath(t *testing.T) {
291 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
292 prebuilt_usr_hyphendata {
293 name: "foo.conf",
294 src: "foo.conf",
295 sub_dir: "bar",
296 }
297 `)
298
299 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
300 expected := "out/soong/target/product/test_device/system/usr/hyphen-data/bar"
301 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
302}
303
Patrice Arruda61583eb2019-05-14 08:20:45 -0700304func TestPrebuiltFontInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000305 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Patrice Arruda61583eb2019-05-14 08:20:45 -0700306 prebuilt_font {
307 name: "foo.conf",
308 src: "foo.conf",
309 }
310 `)
311
Paul Duffin921fac72021-03-10 09:00:58 +0000312 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000313 expected := "out/soong/target/product/test_device/system/fonts"
314 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700315}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700316
317func TestPrebuiltFirmwareDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000318 targetPath := "out/soong/target/product/test_device"
Patrice Arruda057a8b12019-06-03 15:29:27 -0700319 tests := []struct {
320 description string
321 config string
322 expectedPath string
323 }{{
324 description: "prebuilt: system firmware",
325 config: `
326 prebuilt_firmware {
327 name: "foo.conf",
328 src: "foo.conf",
329 }`,
330 expectedPath: filepath.Join(targetPath, "system/etc/firmware"),
331 }, {
332 description: "prebuilt: vendor firmware",
333 config: `
334 prebuilt_firmware {
335 name: "foo.conf",
336 src: "foo.conf",
337 soc_specific: true,
338 sub_dir: "sub_dir",
339 }`,
340 expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"),
341 }}
342 for _, tt := range tests {
343 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000344 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000345 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000346 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700347 })
348 }
349}
Patrice Arruda0f688002020-06-08 21:40:25 +0000350
351func TestPrebuiltDSPDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000352 targetPath := "out/soong/target/product/test_device"
Patrice Arruda0f688002020-06-08 21:40:25 +0000353 tests := []struct {
354 description string
355 config string
356 expectedPath string
357 }{{
358 description: "prebuilt: system dsp",
359 config: `
360 prebuilt_dsp {
361 name: "foo.conf",
362 src: "foo.conf",
363 }`,
364 expectedPath: filepath.Join(targetPath, "system/etc/dsp"),
365 }, {
366 description: "prebuilt: vendor dsp",
367 config: `
368 prebuilt_dsp {
369 name: "foo.conf",
370 src: "foo.conf",
371 soc_specific: true,
372 sub_dir: "sub_dir",
373 }`,
374 expectedPath: filepath.Join(targetPath, "vendor/dsp/sub_dir"),
375 }}
376 for _, tt := range tests {
377 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000378 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000379 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000380 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda0f688002020-06-08 21:40:25 +0000381 })
382 }
383}
Colin Cross83ebf232021-04-09 09:41:23 -0700384
385func TestPrebuiltRFSADirPath(t *testing.T) {
386 targetPath := "out/soong/target/product/test_device"
387 tests := []struct {
388 description string
389 config string
390 expectedPath string
391 }{{
392 description: "prebuilt: system rfsa",
393 config: `
394 prebuilt_rfsa {
395 name: "foo.conf",
396 src: "foo.conf",
397 }`,
398 expectedPath: filepath.Join(targetPath, "system/lib/rfsa"),
399 }, {
400 description: "prebuilt: vendor rfsa",
401 config: `
402 prebuilt_rfsa {
403 name: "foo.conf",
404 src: "foo.conf",
405 soc_specific: true,
406 sub_dir: "sub_dir",
407 }`,
408 expectedPath: filepath.Join(targetPath, "vendor/lib/rfsa/sub_dir"),
409 }}
410 for _, tt := range tests {
411 t.Run(tt.description, func(t *testing.T) {
412 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
413 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
414 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
415 })
416 }
417}
Kiyoung Kimae11c232021-07-19 11:38:04 +0900418
419func checkIfSnapshotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) {
420 checkIfSnapshotExistAsExpected(t, result, image, moduleName, true)
421}
422
423func checkIfSnapshotNotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) {
424 checkIfSnapshotExistAsExpected(t, result, image, moduleName, false)
425}
426
427func checkIfSnapshotExistAsExpected(t *testing.T, result *android.TestResult, image string, moduleName string, expectToExist bool) {
428 snapshotSingleton := result.SingletonForTests(image + "-snapshot")
429 archType := "arm64"
430 archVariant := "armv8-a"
431 archDir := fmt.Sprintf("arch-%s", archType)
432
433 snapshotDir := fmt.Sprintf("%s-snapshot", image)
434 snapshotVariantPath := filepath.Join(snapshotDir, archType)
435 outputDir := filepath.Join(snapshotVariantPath, archDir, "etc")
436 imageVariant := ""
437 if image == "recovery" {
438 imageVariant = "recovery_"
439 }
440 mod := result.ModuleForTests(moduleName, fmt.Sprintf("android_%s%s_%s", imageVariant, archType, archVariant))
441 outputFiles := mod.OutputFiles(t, "")
442 if len(outputFiles) != 1 {
443 t.Errorf("%q must have single output\n", moduleName)
444 return
445 }
446 snapshotPath := filepath.Join(outputDir, moduleName)
447
448 if expectToExist {
449 out := snapshotSingleton.Output(snapshotPath)
450
451 if out.Input.String() != outputFiles[0].String() {
452 t.Errorf("The input of snapshot %q must be %q, but %q", "prebuilt_vendor", out.Input.String(), outputFiles[0])
453 }
454
455 snapshotJsonPath := snapshotPath + ".json"
456
457 if snapshotSingleton.MaybeOutput(snapshotJsonPath).Rule == nil {
458 t.Errorf("%q expected but not found", snapshotJsonPath)
459 }
460 } else {
461 out := snapshotSingleton.MaybeOutput(snapshotPath)
462 if out.Rule != nil {
463 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
464 }
465 }
466}
467
468func TestPrebuiltTakeSnapshot(t *testing.T) {
469 var testBp = `
470 prebuilt_etc {
471 name: "prebuilt_vendor",
472 src: "foo.conf",
473 vendor: true,
474 }
475
476 prebuilt_etc {
477 name: "prebuilt_vendor_indirect",
478 src: "foo.conf",
479 vendor: true,
480 }
481
482 prebuilt_etc {
483 name: "prebuilt_recovery",
484 src: "bar.conf",
485 recovery: true,
486 }
487
488 prebuilt_etc {
489 name: "prebuilt_recovery_indirect",
490 src: "bar.conf",
491 recovery: true,
492 }
493 `
494
495 t.Run("prebuilt: vendor and recovery snapshot", func(t *testing.T) {
496 result := prepareForPrebuiltEtcSnapshotTest.RunTestWithBp(t, testBp)
497
498 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor")
499 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor_indirect")
500 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery")
501 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery_indirect")
502 })
503
504 t.Run("prebuilt: directed snapshot", func(t *testing.T) {
505 prepareForPrebuiltEtcDirectedSnapshotTest := android.GroupFixturePreparers(
506 prepareForPrebuiltEtcSnapshotTest,
507 android.FixtureModifyConfig(func(config android.Config) {
508 config.TestProductVariables.DirectedVendorSnapshot = true
509 config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
510 config.TestProductVariables.VendorSnapshotModules["prebuilt_vendor"] = true
511 config.TestProductVariables.DirectedRecoverySnapshot = true
512 config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
513 config.TestProductVariables.RecoverySnapshotModules["prebuilt_recovery"] = true
514 }),
515 )
516
517 result := prepareForPrebuiltEtcDirectedSnapshotTest.RunTestWithBp(t, testBp)
518
519 checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor")
520 checkIfSnapshotNotTaken(t, result, "vendor", "prebuilt_vendor_indirect")
521 checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery")
522 checkIfSnapshotNotTaken(t, result, "recovery", "prebuilt_recovery_indirect")
523 })
524}