diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-02-10 12:14:36 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-02-10 14:34:44 +0100 |
| commit | 95871dcc45f6531b4c692ff892aad56bdd95e16f (patch) | |
| tree | 95c8ffe8b8a36b1dc9473cc3a07e7286595e0b2f /pkg/subsystem/linux/coincidence_test.go | |
| parent | 0ee9f5fa4e372b5a2da4ac27418e6c5bccbcaf7a (diff) | |
pkg/subsystem: restructure the package
Remove the entity and match subpackages.
Regenerate the linux.go file.
Diffstat (limited to 'pkg/subsystem/linux/coincidence_test.go')
| -rw-r--r-- | pkg/subsystem/linux/coincidence_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/subsystem/linux/coincidence_test.go b/pkg/subsystem/linux/coincidence_test.go new file mode 100644 index 000000000..8aaf5ed0a --- /dev/null +++ b/pkg/subsystem/linux/coincidence_test.go @@ -0,0 +1,40 @@ +// 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" + + "github.com/google/syzkaller/pkg/subsystem" + "github.com/stretchr/testify/assert" +) + +func TestCoincidenceMatrix(t *testing.T) { + cm := MakeCoincidenceMatrix() + a, b, c := &subsystem.Subsystem{}, &subsystem.Subsystem{}, &subsystem.Subsystem{} + cm.Record(a, b) + cm.Record(b, c) + + // Test counts. + assert.Equal(t, cm.Count(a), 1) + assert.Equal(t, cm.Count(b), 2) + assert.Equal(t, cm.Count(c), 1) + + // Test pairwise counts. + assert.Equal(t, cm.Get(a, b), 1) + assert.Equal(t, cm.Get(b, c), 1) + assert.Equal(t, cm.Get(a, c), 0) + + // Test the iterator. + type pair struct { + a *subsystem.Subsystem + b *subsystem.Subsystem + } + expected := []pair{{a, b}, {b, a}, {b, c}, {c, b}} + got := []pair{} + cm.NonEmptyPairs(func(a, b *subsystem.Subsystem, _ int) { + got = append(got, pair{a, b}) + }) + assert.ElementsMatch(t, expected, got) +} |
