From b1bb0c3d3f03d5f6ab34f8dfac388f63c2011e0d Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 18 Jan 2023 13:24:01 +0100 Subject: pkg/subsystem/linux: test path rules of subsystems Now that we have subsystem names, it's easy to test whether syzkaller extract and groups the path matching rules correctly. --- pkg/subsystem/linux/subsystems_test.go | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'pkg/subsystem/linux') diff --git a/pkg/subsystem/linux/subsystems_test.go b/pkg/subsystem/linux/subsystems_test.go index 4a1ff9f0d..b4f0818ff 100644 --- a/pkg/subsystem/linux/subsystems_test.go +++ b/pkg/subsystem/linux/subsystems_test.go @@ -9,6 +9,7 @@ import ( "testing/fstest" "github.com/google/syzkaller/pkg/subsystem/entity" + "github.com/google/syzkaller/pkg/subsystem/match" "github.com/stretchr/testify/assert" ) @@ -70,6 +71,67 @@ func TestCustomCallRules(t *testing.T) { } } +func TestLinuxSubsystemPaths(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, testRules) + if err != nil { + t.Fatal(err) + } + matcher := match.MakePathMatcher(subsystems) + tests := []struct { + path string + list []string + }{ + { + path: `fs/internal.h`, + list: []string{"kernel", "fs"}, + }, + { + path: `fs/ext4/mmp.c`, + list: []string{"kernel", "fs", "ext4"}, + }, + { + // The subsystem is not present in our test MAINTAINERS. + path: `fs/fat/inode.c`, + list: []string{"kernel", "fs"}, + }, + { + path: `fs/freevxfs/vxfs_olt.c`, + list: []string{"kernel", "fs"}, + }, + { + path: `mm/memory.c`, + list: []string{"kernel", "mm"}, + }, + { + path: `mm/shmem.c`, + list: []string{"kernel", "mm"}, + }, + { + path: `include/net/ah.h`, + list: []string{"kernel"}, + }, + { + path: `include/linux/mm.h`, + list: []string{"kernel", "mm"}, + }, + { + path: `include/linux/fs.h`, + list: []string{"kernel", "fs"}, + }, + } + for _, test := range tests { + retList := []string{} + for _, s := range matcher.Match(test.path) { + retList = append(retList, s.Name) + } + assert.ElementsMatchf(t, retList, test.list, + "invalid subsystems for %#v", test.path) + } +} + func prepareTestLinuxRepo(t *testing.T, maintainers []byte) fs.FS { return fstest.MapFS{ `fs/ext4/fsync.c`: {}, -- cgit mrf-deployment