From 9fabcd5358c5e2df6f3936739fd726ed12d86b3a Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 3 Feb 2023 18:14:33 +0100 Subject: pkg/subsystem/linux: add custom call lists This information will let us extract subsystems from reproducers. --- pkg/subsystem/linux/subsystems_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (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 caf675244..4a1ff9f0d 100644 --- a/pkg/subsystem/linux/subsystems_test.go +++ b/pkg/subsystem/linux/subsystems_test.go @@ -47,6 +47,29 @@ func TestGroupLinuxSubsystems(t *testing.T) { assert.ElementsMatch(t, subsystems, expected) } +func TestCustomCallRules(t *testing.T) { + subsystems, err := listFromRepoInner( + prepareTestLinuxRepo(t, []byte(testMaintainers)), + testRules, + ) + if err != nil { + t.Fatal(err) + } + expectCalls := map[string][]string{ + "ext4": []string{"syz_mount_image$ext4"}, + } + gotCalls := map[string][]string{} + for _, s := range subsystems { + if len(s.Syscalls) > 0 { + gotCalls[s.Name] = s.Syscalls + } + } + assert.Equal(t, len(expectCalls), len(gotCalls)) + for name, expect := range expectCalls { + assert.ElementsMatchf(t, expect, gotCalls[name], "syscalls of %s", name) + } +} + func prepareTestLinuxRepo(t *testing.T, maintainers []byte) fs.FS { return fstest.MapFS{ `fs/ext4/fsync.c`: {}, @@ -64,6 +87,13 @@ 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"}, + }, + } testMaintainers = ` Maintainers List ---------------- -- cgit mrf-deployment