Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package filesystem |
| 16 | |
| 17 | import ( |
| 18 | "os" |
| 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 22 | "android/soong/cc" |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func TestMain(m *testing.M) { |
| 26 | os.Exit(m.Run()) |
| 27 | } |
| 28 | |
| 29 | var fixture = android.GroupFixturePreparers( |
| 30 | android.PrepareForIntegrationTestWithAndroid, |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 31 | cc.PrepareForIntegrationTestWithCc, |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 32 | PrepareForTestWithFilesystemBuildComponents, |
| 33 | ) |
| 34 | |
| 35 | func 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 Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 45 | |
| 46 | func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) { |
| 47 | result := fixture.RunTestWithBp(t, ` |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 48 | android_system_image { |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 49 | name: "myfilesystem", |
| 50 | deps: [ |
| 51 | "libfoo", |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 52 | "libbar", |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 53 | ], |
| 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 Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 77 | |
| 78 | func registerComponent(ctx android.RegistrationContext) { |
| 79 | ctx.RegisterModuleType("component", componentFactory) |
| 80 | } |
| 81 | |
| 82 | func componentFactory() android.Module { |
| 83 | m := &component{} |
| 84 | m.AddProperties(&m.properties) |
| 85 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 86 | return m |
| 87 | } |
| 88 | |
| 89 | type component struct { |
| 90 | android.ModuleBase |
| 91 | properties struct { |
| 92 | Install_copy_in_data []string |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func (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 | |
| 107 | func 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 | } |