github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/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 {IncludeRegexp: `^drivers/spi/spi-pl022\.c$`}, 20 { 21 // nolint:lll 22 IncludeRegexp: `^drivers/irqchip/irq-vic\.c$|^Documentation/devicetree/bindings/interrupt-controller/arm,vic\.yaml$`, 23 }, 24 }, 25 } 26 docs := &Subsystem{ 27 PathRules: []PathRule{ 28 {IncludeRegexp: `^Documentation/.*$`}, 29 }, 30 } 31 m := MakePathMatcher([]*Subsystem{arm, docs}) 32 assert.ElementsMatch(t, []*Subsystem{arm, docs}, 33 m.Match(`Documentation/devicetree/bindings/interrupt-controller/arm,vic.yaml`)) 34 assert.ElementsMatch(t, []*Subsystem{arm}, m.Match(`arch/arm/a.c`)) 35 assert.ElementsMatch(t, []*Subsystem{docs}, m.Match(`Documentation/a/b/c.md`)) 36 assert.Empty(t, m.Match(`arch/boot/dts/a.c`)) 37 } 38 39 func TestPathMatchOrder(t *testing.T) { 40 s := &Subsystem{ 41 PathRules: []PathRule{ 42 { 43 IncludeRegexp: `^a/b/.*$`, 44 ExcludeRegexp: `^a/.*$`, 45 }, 46 }, 47 } 48 m := MakePathMatcher([]*Subsystem{s}) 49 // If we first exclude a/, then a/b/c never matches. 50 assert.Empty(t, m.Match("a/b/c")) 51 }