blob: 444ffd0aa55f0ed32f3367d7f990f75d13b70506 [file] [log] [blame]
Jooyung Han9706cbc2021-04-15 22:43:48 +09001// Copyright 2021 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
15package filesystem
16
17import (
18 "os"
19 "testing"
20
21 "android/soong/android"
Jiyong Parkfa616132021-04-20 11:36:40 +090022 "android/soong/cc"
Jooyung Han9706cbc2021-04-15 22:43:48 +090023)
24
25func TestMain(m *testing.M) {
26 os.Exit(m.Run())
27}
28
29var fixture = android.GroupFixturePreparers(
30 android.PrepareForIntegrationTestWithAndroid,
Jiyong Parkfa616132021-04-20 11:36:40 +090031 cc.PrepareForIntegrationTestWithCc,
Jooyung Han9706cbc2021-04-15 22:43:48 +090032 PrepareForTestWithFilesystemBuildComponents,
33)
34
35func TestFileSystemDeps(t *testing.T) {
36 result := fixture.RunTestWithBp(t, `
37 android_filesystem {
38 name: "myfilesystem",
39 }
40 `)
41
42 // produces "myfilesystem.img"
43 result.ModuleForTests("myfilesystem", "android_common").Output("myfilesystem.img")
44}
Jiyong Parkfa616132021-04-20 11:36:40 +090045
46func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
47 result := fixture.RunTestWithBp(t, `
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090048 android_system_image {
Jiyong Parkfa616132021-04-20 11:36:40 +090049 name: "myfilesystem",
50 deps: [
51 "libfoo",
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090052 "libbar",
Jiyong Parkfa616132021-04-20 11:36:40 +090053 ],
54 linker_config_src: "linker.config.json",
55 }
56
57 cc_library {
58 name: "libfoo",
59 stubs: {
60 symbol_file: "libfoo.map.txt",
61 },
62 }
63
64 cc_library {
65 name: "libbar",
66 }
67 `)
68
69 module := result.ModuleForTests("myfilesystem", "android_common")
70 output := module.Output("system/etc/linker.config.pb")
71
72 android.AssertStringDoesContain(t, "linker.config.pb should have libfoo",
73 output.RuleParams.Command, "libfoo.so")
74 android.AssertStringDoesNotContain(t, "linker.config.pb should not have libbar",
75 output.RuleParams.Command, "libbar.so")
76}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090077
78func registerComponent(ctx android.RegistrationContext) {
79 ctx.RegisterModuleType("component", componentFactory)
80}
81
82func componentFactory() android.Module {
83 m := &component{}
84 m.AddProperties(&m.properties)
85 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
86 return m
87}
88
89type component struct {
90 android.ModuleBase
91 properties struct {
92 Install_copy_in_data []string
93 }
94}
95
96func (c *component) GenerateAndroidBuildActions(ctx android.ModuleContext) {
97 output := android.PathForModuleOut(ctx, c.Name())
98 dir := android.PathForModuleInstall(ctx, "components")
99 ctx.InstallFile(dir, c.Name(), output)
100
101 dataDir := android.PathForModuleInPartitionInstall(ctx, "data", "components")
102 for _, d := range c.properties.Install_copy_in_data {
103 ctx.InstallFile(dataDir, d, output)
104 }
105}
106
107func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
108 f := android.GroupFixturePreparers(fixture, android.FixtureRegisterWithContext(registerComponent))
109 result := f.RunTestWithBp(t, `
110 android_system_image {
111 name: "myfilesystem",
112 multilib: {
113 common: {
114 deps: ["foo"],
115 },
116 },
117 linker_config_src: "linker.config.json",
118 }
119 component {
120 name: "foo",
121 install_copy_in_data: ["bar"],
122 }
123 `)
124
125 module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
126 android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
127}
Jiyong Parkbc485482022-11-15 22:31:49 +0900128
Alice Wang000e3a32023-01-03 16:11:20 +0000129func TestAvbGenVbmetaImage(t *testing.T) {
130 result := fixture.RunTestWithBp(t, `
131 avb_gen_vbmeta_image {
132 name: "input_hashdesc",
133 src: "input.img",
134 partition_name: "input_partition_name",
135 salt: "2222",
136 }`)
137 cmd := result.ModuleForTests("input_hashdesc", "android_arm64_armv8-a").Rule("avbGenVbmetaImage").RuleParams.Command
138 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
139 cmd, "--partition_name input_partition_name")
140 android.AssertStringDoesContain(t, "Can't find --do_not_append_vbmeta_image",
141 cmd, "--do_not_append_vbmeta_image")
142 android.AssertStringDoesContain(t, "Can't find --output_vbmeta_image",
143 cmd, "--output_vbmeta_image ")
144 android.AssertStringDoesContain(t, "Can't find --salt argument",
145 cmd, "--salt 2222")
146}
147
Jiyong Parkbc485482022-11-15 22:31:49 +0900148func TestAvbAddHashFooter(t *testing.T) {
149 result := fixture.RunTestWithBp(t, `
Alice Wang000e3a32023-01-03 16:11:20 +0000150 avb_gen_vbmeta_image {
151 name: "input_hashdesc",
152 src: "input.img",
153 partition_name: "input",
154 salt: "2222",
155 }
156
Jiyong Parkbc485482022-11-15 22:31:49 +0900157 avb_add_hash_footer {
158 name: "myfooter",
159 src: "input.img",
160 filename: "output.img",
161 partition_name: "mypartition",
162 private_key: "mykey",
163 salt: "1111",
164 props: [
165 {
166 name: "prop1",
167 value: "value1",
168 },
169 {
170 name: "prop2",
171 file: "value_file",
172 },
173 ],
Alice Wang000e3a32023-01-03 16:11:20 +0000174 include_descriptors_from_images: ["input_hashdesc"],
Jiyong Parkbc485482022-11-15 22:31:49 +0900175 }
176 `)
177 cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
178 android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
179 cmd, "--partition_name mypartition")
180 android.AssertStringDoesContain(t, "Can't find correct --key argument",
181 cmd, "--key mykey")
182 android.AssertStringDoesContain(t, "Can't find --salt argument",
183 cmd, "--salt 1111")
184 android.AssertStringDoesContain(t, "Can't find --prop argument",
185 cmd, "--prop 'prop1:value1'")
186 android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
187 cmd, "--prop_from_file 'prop2:value_file'")
Alice Wang000e3a32023-01-03 16:11:20 +0000188 android.AssertStringDoesContain(t, "Can't find --include_descriptors_from_image",
189 cmd, "--include_descriptors_from_image ")
Jiyong Parkbc485482022-11-15 22:31:49 +0900190}