aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/match_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/match_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/match_test.go')
-rw-r--r--pkg/subsystem/match_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/pkg/subsystem/match_test.go b/pkg/subsystem/match_test.go
new file mode 100644
index 000000000..7c96b0bcd
--- /dev/null
+++ b/pkg/subsystem/match_test.go
@@ -0,0 +1,51 @@
+// 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 subsystem
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestPathMatcher(t *testing.T) {
+ arm := &Subsystem{
+ PathRules: []PathRule{
+ {
+ IncludeRegexp: `^arch/arm/.*$`,
+ ExcludeRegexp: `^arch/arm/boot/dts/.*$`,
+ },
+ {IncludeRegexp: `^drivers/spi/spi-pl022\.c$`},
+ {
+ // nolint:lll
+ IncludeRegexp: `^drivers/irqchip/irq-vic\.c$|^Documentation/devicetree/bindings/interrupt-controller/arm,vic\.yaml$`,
+ },
+ },
+ }
+ docs := &Subsystem{
+ PathRules: []PathRule{
+ {IncludeRegexp: `^Documentation/.*$`},
+ },
+ }
+ m := MakePathMatcher([]*Subsystem{arm, docs})
+ assert.ElementsMatch(t, []*Subsystem{arm, docs},
+ m.Match(`Documentation/devicetree/bindings/interrupt-controller/arm,vic.yaml`))
+ assert.ElementsMatch(t, []*Subsystem{arm}, m.Match(`arch/arm/a.c`))
+ assert.ElementsMatch(t, []*Subsystem{docs}, m.Match(`Documentation/a/b/c.md`))
+ assert.Empty(t, m.Match(`arch/boot/dts/a.c`))
+}
+
+func TestPathMatchOrder(t *testing.T) {
+ s := &Subsystem{
+ PathRules: []PathRule{
+ {
+ IncludeRegexp: `^a/b/.*$`,
+ ExcludeRegexp: `^a/.*$`,
+ },
+ },
+ }
+ m := MakePathMatcher([]*Subsystem{s})
+ // If we first exclude a/, then a/b/c never matches.
+ assert.Empty(t, m.Match("a/b/c"))
+}