aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/linux/path_coincidence_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-02-10 12:14:36 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-10 14:34:44 +0100
commit95871dcc45f6531b4c692ff892aad56bdd95e16f (patch)
tree95c8ffe8b8a36b1dc9473cc3a07e7286595e0b2f /pkg/subsystem/linux/path_coincidence_test.go
parent0ee9f5fa4e372b5a2da4ac27418e6c5bccbcaf7a (diff)
pkg/subsystem: restructure the package
Remove the entity and match subpackages. Regenerate the linux.go file.
Diffstat (limited to 'pkg/subsystem/linux/path_coincidence_test.go')
-rw-r--r--pkg/subsystem/linux/path_coincidence_test.go49
1 files changed, 49 insertions, 0 deletions
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))
+}