github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/subsystem/match_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 subsystem 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestPathMatcher(t *testing.T) { 13 arm := &Subsystem{ 14 PathRules: []PathRule{ 15 { 16 IncludeRegexp: `^arch/arm/.*$`, 17 ExcludeRegexp: `^arch/arm/boot/dts/.*$`, 18 }, 19 // Add a somewhat overlapping rule so that we test that no duplicates are returned. 20 { 21 IncludeRegexp: `^arch/arm/a/.*$`, 22 }, 23 {IncludeRegexp: `^drivers/spi/spi-pl022\.c$`}, 24 { 25 // nolint:lll 26 IncludeRegexp: `^drivers/irqchip/irq-vic\.c$|^Documentation/devicetree/bindings/interrupt-controller/arm,vic\.yaml$`, 27 }, 28 }, 29 } 30 docs := &Subsystem{ 31 PathRules: []PathRule{ 32 {IncludeRegexp: `^Documentation/.*$`}, 33 }, 34 } 35 m := MakePathMatcher([]*Subsystem{arm, docs}) 36 assert.ElementsMatch(t, []*Subsystem{arm, docs}, 37 m.Match(`Documentation/devicetree/bindings/interrupt-controller/arm,vic.yaml`)) 38 assert.ElementsMatch(t, []*Subsystem{arm}, m.Match(`arch/arm/a/a.c`)) 39 assert.ElementsMatch(t, []*Subsystem{docs}, m.Match(`Documentation/a/b/c.md`)) 40 assert.Empty(t, m.Match(`arch/boot/dts/a.c`)) 41 } 42 43 func TestPathMatchOrder(t *testing.T) { 44 s := &Subsystem{ 45 PathRules: []PathRule{ 46 { 47 IncludeRegexp: `^a/b/.*$`, 48 ExcludeRegexp: `^a/.*$`, 49 }, 50 }, 51 } 52 m := MakePathMatcher([]*Subsystem{s}) 53 // If we first exclude a/, then a/b/c never matches. 54 assert.Empty(t, m.Match("a/b/c")) 55 }