• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15package filesystem
16
17import (
18	"os"
19	"testing"
20
21	"android/soong/android"
22	"android/soong/cc"
23)
24
25func TestMain(m *testing.M) {
26	os.Exit(m.Run())
27}
28
29var fixture = android.GroupFixturePreparers(
30	android.PrepareForIntegrationTestWithAndroid,
31	cc.PrepareForIntegrationTestWithCc,
32	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}
45
46func TestFileSystemFillsLinkerConfigWithStubLibs(t *testing.T) {
47	result := fixture.RunTestWithBp(t, `
48		android_system_image {
49			name: "myfilesystem",
50			deps: [
51				"libfoo",
52				"libbar",
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}
77
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}
128