From 95871dcc45f6531b4c692ff892aad56bdd95e16f Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 10 Feb 2023 12:14:36 +0100 Subject: pkg/subsystem: restructure the package Remove the entity and match subpackages. Regenerate the linux.go file. --- pkg/subsystem/linux/path_coincidence_test.go | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 pkg/subsystem/linux/path_coincidence_test.go (limited to 'pkg/subsystem/linux/path_coincidence_test.go') diff --git a/pkg/subsystem/linux/path_coincidence_test.go b/pkg/subsystem/linux/path_coincidence_test.go new file mode 100644 index 000000000..ac32dcd31 --- /dev/null +++ b/pkg/subsystem/linux/path_coincidence_test.go @@ -0,0 +1,49 @@ +// Copyright 2023 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package linux + +import ( + "testing" + "testing/fstest" + + "github.com/google/syzkaller/pkg/subsystem" + "github.com/stretchr/testify/assert" +) + +func TestBuildCoincidenceMatrix(t *testing.T) { + vfs := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ + {IncludeRegexp: `^fs/`}, + }} + ext4 := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ + {IncludeRegexp: `^fs/ext4/`}, + }} + ntfs := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ + {IncludeRegexp: `^fs/ntfs/`}, + }} + kernel := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ + {IncludeRegexp: `.*`}, + }} + + fs := fstest.MapFS{ + ".git/obj/12345": {}, + "fs/inode.c": {}, + "fs/ext4/file.c": {}, + "fs/ntfs/file.c": {}, + "fs/fat/file.c": {}, + "net/socket.c": {}, + } + matrix, err := BuildCoincidenceMatrix(fs, []*subsystem.Subsystem{vfs, ntfs, ext4, kernel}, nil) + assert.NoError(t, err) + + // Test total counts. + assert.Equal(t, 5, matrix.Count(kernel)) + assert.Equal(t, 4, matrix.Count(vfs)) + assert.Equal(t, 1, matrix.Count(ext4)) + + // Test pairwise counts. + assert.Equal(t, 1, matrix.Get(vfs, ext4)) + assert.Equal(t, 1, matrix.Get(vfs, ntfs)) + assert.Equal(t, 0, matrix.Get(ext4, ntfs)) + assert.Equal(t, 4, matrix.Get(kernel, vfs)) +} -- cgit mrf-deployment