From 3a4c5e2da302d43152f2e8b1362d8568c0d57e6e Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 18 Jan 2023 18:45:55 +0100 Subject: pkg/subsystem/linux: determine parent-child relations For that, extract a coincidence count matrix from a path coverage, then apply the following rule. Subsystem A is a child of B if both hold true: 1) More than 2/3 of paths that relate to A also relate to B. 2) B covers more directory tree entities than A. --- pkg/subsystem/linux/subsystems_test.go | 54 +++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'pkg/subsystem/linux/subsystems_test.go') diff --git a/pkg/subsystem/linux/subsystems_test.go b/pkg/subsystem/linux/subsystems_test.go index 09d835e3f..52cf8540c 100644 --- a/pkg/subsystem/linux/subsystems_test.go +++ b/pkg/subsystem/linux/subsystems_test.go @@ -20,9 +20,11 @@ func TestGroupLinuxSubsystems(t *testing.T) { if err != nil { t.Fatal(err) } - // The regexps used for matching rules may change later, so let's not compare them here. for _, s := range subsystems { + // The regexps used for matching rules may change later, so let's not compare them here. s.PathRules = nil + // It complicates the test, so let's skip it here. + s.Parents = nil } expected := []*entity.Subsystem{ { @@ -36,8 +38,14 @@ func TestGroupLinuxSubsystems(t *testing.T) { Maintainers: []string{"email_ext4@email.com", "email_ext4_2@email.com"}, }, { - Name: "mm", - Lists: []string{"linux-mm@kvack.org"}, + Name: "mm", + Lists: []string{"linux-mm@kvack.org"}, + Maintainers: []string{"email_mm@email.com"}, + }, + { + Name: "tmpfs", + Lists: []string{"tmpfs@kvack.org"}, + Maintainers: []string{"email_shmem@email.com"}, }, { Name: "kernel", @@ -57,7 +65,8 @@ func TestCustomCallRules(t *testing.T) { t.Fatal(err) } expectCalls := map[string][]string{ - "ext4": []string{"syz_mount_image$ext4"}, + "ext4": {"syz_mount_image$ext4"}, + "tmpfs": {"syz_mount_image$tmpfs"}, } gotCalls := map[string][]string{} for _, s := range subsystems { @@ -106,9 +115,8 @@ func TestLinuxSubsystemPaths(t *testing.T) { list: []string{"kernel", "mm"}, }, { - // Shmem has no mailing list. path: `mm/shmem.c`, - list: []string{"kernel", "mm"}, + list: []string{"kernel", "mm", "tmpfs"}, }, { path: `include/net/ah.h`, @@ -133,6 +141,32 @@ func TestLinuxSubsystemPaths(t *testing.T) { } } +func TestLinuxSubsystemParents(t *testing.T) { + // For the list of subsystems, see TestLinuxSubsystemsList. + // Here we rely on the same ones. + repo := prepareTestLinuxRepo(t, []byte(testMaintainers)) + subsystems, err := listFromRepoInner(repo, nil) + if err != nil { + t.Fatal(err) + } + + expectParents := map[string][]string{ + "ext4": {"fs"}, + "mm": {"kernel"}, + "fs": {"kernel"}, + "tmpfs": {"mm"}, + "freevxfs": {"fs"}, + } + for _, s := range subsystems { + names := []string{} + for _, p := range s.Parents { + names = append(names, p.Name) + } + assert.ElementsMatch(t, names, expectParents[s.Name], + "wrong parents for %#v", s.Name) + } +} + func prepareTestLinuxRepo(t *testing.T, maintainers []byte) fs.FS { return fstest.MapFS{ `fs/ext4/fsync.c`: {}, @@ -152,9 +186,9 @@ func prepareTestLinuxRepo(t *testing.T, maintainers []byte) fs.FS { var ( testRules = &customRules{ subsystemCalls: map[string][]string{ - "ext4": []string{"syz_mount_image$ext4"}, - "vxfs": []string{"syz_mount_image$vxfs"}, - "tmpfs": []string{"syz_mount_image$tmpfs"}, + "ext4": {"syz_mount_image$ext4"}, + "vxfs": {"syz_mount_image$vxfs"}, + "tmpfs": {"syz_mount_image$tmpfs"}, }, } testMaintainers = ` @@ -212,7 +246,7 @@ F: tools/testing/selftests/vm/ TMPFS (SHMEM FILESYSTEM) M: Developer -L: linux-mm@kvack.org +L: tmpfs@kvack.org S: Maintained F: include/linux/shmem_fs.h F: mm/shmem.c -- cgit mrf-deployment