aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/linux/subsystems_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-01-18 13:24:01 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-10 14:34:44 +0100
commitb1bb0c3d3f03d5f6ab34f8dfac388f63c2011e0d (patch)
tree80aeb571faa33c66066644c868cd77d136ab6e8e /pkg/subsystem/linux/subsystems_test.go
parent9fabcd5358c5e2df6f3936739fd726ed12d86b3a (diff)
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.
Diffstat (limited to 'pkg/subsystem/linux/subsystems_test.go')
-rw-r--r--pkg/subsystem/linux/subsystems_test.go62
1 files changed, 62 insertions, 0 deletions
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`: {},