github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/subsystem/linux/path_coincidence_test.go (about) 1 // Copyright 2023 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package linux 5 6 import ( 7 "testing" 8 "testing/fstest" 9 10 "github.com/google/syzkaller/pkg/subsystem" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestBuildCoincidenceMatrix(t *testing.T) { 15 vfs := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ 16 {IncludeRegexp: `^fs/`}, 17 }} 18 ext4 := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ 19 {IncludeRegexp: `^fs/ext4/`}, 20 }} 21 ntfs := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ 22 {IncludeRegexp: `^fs/ntfs/`}, 23 }} 24 kernel := &subsystem.Subsystem{PathRules: []subsystem.PathRule{ 25 {IncludeRegexp: `.*`}, 26 }} 27 28 fs := fstest.MapFS{ 29 ".git/obj/12345": {}, 30 "fs/inode.c": {}, 31 "fs/ext4/file.c": {}, 32 "fs/ntfs/file.c": {}, 33 "fs/fat/file.c": {}, 34 "net/socket.c": {}, 35 } 36 matrix, err := BuildCoincidenceMatrix(fs, []*subsystem.Subsystem{vfs, ntfs, ext4, kernel}, nil) 37 assert.NoError(t, err) 38 39 // Test total counts. 40 assert.Equal(t, 5, matrix.Count(kernel)) 41 assert.Equal(t, 4, matrix.Count(vfs)) 42 assert.Equal(t, 1, matrix.Count(ext4)) 43 44 // Test pairwise counts. 45 assert.Equal(t, 1, matrix.Get(vfs, ext4)) 46 assert.Equal(t, 1, matrix.Get(vfs, ntfs)) 47 assert.Equal(t, 0, matrix.Get(ext4, ntfs)) 48 assert.Equal(t, 4, matrix.Get(kernel, vfs)) 49 }