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