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 kernel
16
17import (
18	"os"
19	"testing"
20
21	"android/soong/android"
22	"android/soong/cc"
23)
24
25func TestKernelModulesFilelist(t *testing.T) {
26	ctx := android.GroupFixturePreparers(
27		cc.PrepareForTestWithCcDefaultModules,
28		android.FixtureRegisterWithContext(registerKernelBuildComponents),
29		android.MockFS{
30			"depmod.cpp": nil,
31			"mod1.ko":    nil,
32			"mod2.ko":    nil,
33		}.AddToFixture(),
34	).RunTestWithBp(t, `
35		prebuilt_kernel_modules {
36			name: "foo",
37			srcs: ["*.ko"],
38			kernel_version: "5.10",
39		}
40	`)
41
42	expected := []string{
43		"lib/modules/5.10/mod1.ko",
44		"lib/modules/5.10/mod2.ko",
45		"lib/modules/5.10/modules.load",
46		"lib/modules/5.10/modules.dep",
47		"lib/modules/5.10/modules.softdep",
48		"lib/modules/5.10/modules.alias",
49	}
50
51	var actual []string
52	for _, ps := range ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().PackagingSpecs() {
53		actual = append(actual, ps.RelPathInPackage())
54	}
55	actual = android.SortedUniqueStrings(actual)
56	expected = android.SortedUniqueStrings(expected)
57	android.AssertDeepEquals(t, "foo packaging specs", expected, actual)
58}
59
60func TestMain(m *testing.M) {
61	os.Exit(m.Run())
62}
63