blob: fdb5648738fbef68c672002c5bdaadc62ddcc596 [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 (
Jaewoong Jung4b79e982020-06-01 10:45:49 -070018 "os"
Patrice Arruda300cef92019-02-22 15:47:57 -080019 "path/filepath"
Tao Bao0ba5c942018-08-14 22:20:22 -070020 "testing"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070021
22 "android/soong/android"
Tao Bao0ba5c942018-08-14 22:20:22 -070023)
24
Jaewoong Jung4b79e982020-06-01 10:45:49 -070025func TestMain(m *testing.M) {
Paul Duffin5f9f7712021-03-15 15:35:49 +000026 os.Exit(m.Run())
Jaewoong Jung4b79e982020-06-01 10:45:49 -070027}
28
Paul Duffin89648f92021-03-20 00:36:55 +000029var prepareForPrebuiltEtcTest = android.GroupFixturePreparers(
Paul Duffin1172fed2021-03-08 11:28:18 +000030 android.PrepareForTestWithArchMutator,
31 PrepareForTestWithPrebuiltEtc,
32 android.FixtureMergeMockFs(android.MockFS{
Colin Cross98be1bb2019-12-13 20:41:13 -080033 "foo.conf": nil,
34 "bar.conf": nil,
35 "baz.conf": nil,
Paul Duffin1172fed2021-03-08 11:28:18 +000036 }),
37)
Colin Cross98be1bb2019-12-13 20:41:13 -080038
Tao Bao0ba5c942018-08-14 22:20:22 -070039func TestPrebuiltEtcVariants(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +000040 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Tao Bao0ba5c942018-08-14 22:20:22 -070041 prebuilt_etc {
42 name: "foo.conf",
43 src: "foo.conf",
44 }
45 prebuilt_etc {
46 name: "bar.conf",
47 src: "bar.conf",
48 recovery_available: true,
49 }
50 prebuilt_etc {
51 name: "baz.conf",
52 src: "baz.conf",
53 recovery: true,
54 }
55 `)
56
Paul Duffin921fac72021-03-10 09:00:58 +000057 foo_variants := result.ModuleVariantsForTests("foo.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070058 if len(foo_variants) != 1 {
59 t.Errorf("expected 1, got %#v", foo_variants)
60 }
61
Paul Duffin921fac72021-03-10 09:00:58 +000062 bar_variants := result.ModuleVariantsForTests("bar.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070063 if len(bar_variants) != 2 {
64 t.Errorf("expected 2, got %#v", bar_variants)
65 }
66
Paul Duffin921fac72021-03-10 09:00:58 +000067 baz_variants := result.ModuleVariantsForTests("baz.conf")
Tao Bao0ba5c942018-08-14 22:20:22 -070068 if len(baz_variants) != 1 {
69 t.Errorf("expected 1, got %#v", bar_variants)
70 }
71}
Jiyong Park139a2e62018-10-26 21:49:39 +090072
73func TestPrebuiltEtcOutputPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +000074 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jiyong Park139a2e62018-10-26 21:49:39 +090075 prebuilt_etc {
76 name: "foo.conf",
77 src: "foo.conf",
78 filename: "foo.installed.conf",
79 }
80 `)
81
Paul Duffin921fac72021-03-10 09:00:58 +000082 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffine84b1332021-03-12 11:59:43 +000083 android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePath.Base())
Jiyong Park139a2e62018-10-26 21:49:39 +090084}
Jiyong Park1a7cf082018-11-13 11:59:12 +090085
86func TestPrebuiltEtcGlob(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +000087 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jiyong Park1a7cf082018-11-13 11:59:12 +090088 prebuilt_etc {
89 name: "my_foo",
90 src: "foo.*",
91 }
92 prebuilt_etc {
93 name: "my_bar",
94 src: "bar.*",
95 filename_from_src: true,
96 }
97 `)
98
Paul Duffin921fac72021-03-10 09:00:58 +000099 p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffine84b1332021-03-12 11:59:43 +0000100 android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePath.Base())
Jiyong Park1a7cf082018-11-13 11:59:12 +0900101
Paul Duffin921fac72021-03-10 09:00:58 +0000102 p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffine84b1332021-03-12 11:59:43 +0000103 android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePath.Base())
Jiyong Park1a7cf082018-11-13 11:59:12 +0900104}
Anton Hanssonce0e2582019-02-04 14:19:27 +0000105
106func TestPrebuiltEtcAndroidMk(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000107 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Anton Hanssonce0e2582019-02-04 14:19:27 +0000108 prebuilt_etc {
109 name: "foo",
110 src: "foo.conf",
111 owner: "abc",
112 filename_from_src: true,
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700113 required: ["modA", "moduleB"],
114 host_required: ["hostModA", "hostModB"],
115 target_required: ["targetModA"],
Anton Hanssonce0e2582019-02-04 14:19:27 +0000116 }
117 `)
118
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700119 expected := map[string][]string{
120 "LOCAL_MODULE": {"foo"},
121 "LOCAL_MODULE_CLASS": {"ETC"},
122 "LOCAL_MODULE_OWNER": {"abc"},
123 "LOCAL_INSTALLED_MODULE_STEM": {"foo.conf"},
124 "LOCAL_REQUIRED_MODULES": {"modA", "moduleB"},
125 "LOCAL_HOST_REQUIRED_MODULES": {"hostModA", "hostModB"},
126 "LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"},
Anton Hanssonce0e2582019-02-04 14:19:27 +0000127 }
128
Paul Duffin921fac72021-03-10 09:00:58 +0000129 mod := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc)
130 entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0]
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700131 for k, expectedValue := range expected {
132 if value, ok := entries.EntryMap[k]; ok {
Paul Duffine84b1332021-03-12 11:59:43 +0000133 android.AssertDeepEquals(t, k, expectedValue, value)
Jaewoong Jung9aa3ab12019-04-03 15:47:29 -0700134 } else {
135 t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
Anton Hanssonce0e2582019-02-04 14:19:27 +0000136 }
137 }
138}
Jaewoong Jung24788182019-02-04 14:34:10 -0800139
Liz Kammer0449a632020-06-26 10:12:36 -0700140func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000141 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Liz Kammer0449a632020-06-26 10:12:36 -0700142 prebuilt_etc {
143 name: "foo.conf",
144 src: "foo.conf",
145 relative_install_path: "bar",
146 }
147 `)
148
Paul Duffin921fac72021-03-10 09:00:58 +0000149 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000150 expected := "out/soong/target/product/test_device/system/etc/bar"
151 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Liz Kammer0449a632020-06-26 10:12:36 -0700152}
153
154func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000155 prepareForPrebuiltEtcTest.
Paul Duffin1172fed2021-03-08 11:28:18 +0000156 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")).
157 RunTestWithBp(t, `
158 prebuilt_etc {
159 name: "foo.conf",
160 src: "foo.conf",
161 sub_dir: "bar",
162 relative_install_path: "bar",
163 }
164 `)
Liz Kammer0449a632020-06-26 10:12:36 -0700165}
166
Jaewoong Jung24788182019-02-04 14:34:10 -0800167func TestPrebuiltEtcHost(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000168 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jaewoong Jung24788182019-02-04 14:34:10 -0800169 prebuilt_etc_host {
170 name: "foo.conf",
171 src: "foo.conf",
172 }
173 `)
174
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700175 buildOS := android.BuildOs.String()
Paul Duffin921fac72021-03-10 09:00:58 +0000176 p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
Jaewoong Jung24788182019-02-04 14:34:10 -0800177 if !p.Host() {
178 t.Errorf("host bit is not set for a prebuilt_etc_host module.")
179 }
180}
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800181
Inseob Kim27408bf2021-04-06 21:00:17 +0900182func TestPrebuiltRootInstallDirPath(t *testing.T) {
183 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
184 prebuilt_root {
185 name: "foo.conf",
186 src: "foo.conf",
187 filename: "foo.conf",
188 }
189 `)
190
191 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
192 expected := "out/soong/target/product/test_device/system"
193 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
194}
195
196func TestPrebuiltRootInstallDirPathValidate(t *testing.T) {
197 prepareForPrebuiltEtcTest.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("filename cannot contain separator")).RunTestWithBp(t, `
198 prebuilt_root {
199 name: "foo.conf",
200 src: "foo.conf",
201 filename: "foo/bar.conf",
202 }
203 `)
204}
205
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800206func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000207 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800208 prebuilt_usr_share {
209 name: "foo.conf",
210 src: "foo.conf",
211 sub_dir: "bar",
212 }
213 `)
214
Paul Duffin921fac72021-03-10 09:00:58 +0000215 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000216 expected := "out/soong/target/product/test_device/system/usr/share/bar"
217 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Jaewoong Jungc3fcdb42019-02-13 05:50:33 -0800218}
Patrice Arruda300cef92019-02-22 15:47:57 -0800219
220func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000221 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Patrice Arruda300cef92019-02-22 15:47:57 -0800222 prebuilt_usr_share_host {
223 name: "foo.conf",
224 src: "foo.conf",
225 sub_dir: "bar",
226 }
227 `)
228
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700229 buildOS := android.BuildOs.String()
Paul Duffin921fac72021-03-10 09:00:58 +0000230 p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000231 expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar")
232 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Patrice Arruda300cef92019-02-22 15:47:57 -0800233}
Patrice Arruda61583eb2019-05-14 08:20:45 -0700234
235func TestPrebuiltFontInstallDirPath(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000236 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, `
Patrice Arruda61583eb2019-05-14 08:20:45 -0700237 prebuilt_font {
238 name: "foo.conf",
239 src: "foo.conf",
240 }
241 `)
242
Paul Duffin921fac72021-03-10 09:00:58 +0000243 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000244 expected := "out/soong/target/product/test_device/system/fonts"
245 android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
Patrice Arruda61583eb2019-05-14 08:20:45 -0700246}
Patrice Arruda057a8b12019-06-03 15:29:27 -0700247
248func TestPrebuiltFirmwareDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000249 targetPath := "out/soong/target/product/test_device"
Patrice Arruda057a8b12019-06-03 15:29:27 -0700250 tests := []struct {
251 description string
252 config string
253 expectedPath string
254 }{{
255 description: "prebuilt: system firmware",
256 config: `
257 prebuilt_firmware {
258 name: "foo.conf",
259 src: "foo.conf",
260 }`,
261 expectedPath: filepath.Join(targetPath, "system/etc/firmware"),
262 }, {
263 description: "prebuilt: vendor firmware",
264 config: `
265 prebuilt_firmware {
266 name: "foo.conf",
267 src: "foo.conf",
268 soc_specific: true,
269 sub_dir: "sub_dir",
270 }`,
271 expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"),
272 }}
273 for _, tt := range tests {
274 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000275 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000276 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000277 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda057a8b12019-06-03 15:29:27 -0700278 })
279 }
280}
Patrice Arruda0f688002020-06-08 21:40:25 +0000281
282func TestPrebuiltDSPDirPath(t *testing.T) {
Paul Duffin5f9f7712021-03-15 15:35:49 +0000283 targetPath := "out/soong/target/product/test_device"
Patrice Arruda0f688002020-06-08 21:40:25 +0000284 tests := []struct {
285 description string
286 config string
287 expectedPath string
288 }{{
289 description: "prebuilt: system dsp",
290 config: `
291 prebuilt_dsp {
292 name: "foo.conf",
293 src: "foo.conf",
294 }`,
295 expectedPath: filepath.Join(targetPath, "system/etc/dsp"),
296 }, {
297 description: "prebuilt: vendor dsp",
298 config: `
299 prebuilt_dsp {
300 name: "foo.conf",
301 src: "foo.conf",
302 soc_specific: true,
303 sub_dir: "sub_dir",
304 }`,
305 expectedPath: filepath.Join(targetPath, "vendor/dsp/sub_dir"),
306 }}
307 for _, tt := range tests {
308 t.Run(tt.description, func(t *testing.T) {
Paul Duffin89648f92021-03-20 00:36:55 +0000309 result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config)
Paul Duffin921fac72021-03-10 09:00:58 +0000310 p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
Paul Duffin5f9f7712021-03-15 15:35:49 +0000311 android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
Patrice Arruda0f688002020-06-08 21:40:25 +0000312 })
313 }
314}