From 95871dcc45f6531b4c692ff892aad56bdd95e16f Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 10 Feb 2023 12:14:36 +0100 Subject: pkg/subsystem: restructure the package Remove the entity and match subpackages. Regenerate the linux.go file. --- pkg/subsystem/linux/coincidence_test.go | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 pkg/subsystem/linux/coincidence_test.go (limited to 'pkg/subsystem/linux/coincidence_test.go') 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) +} -- cgit mrf-deployment