From 94b087b1f1dce14942bc35bb35a8f58e57b1fc63 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 13 May 2024 14:39:47 +0200 Subject: pkg/fuzzer: deflake comparisons Do two exec hints to only leave stable comparison argument pairs. In local experiments, it allows to reduce their count by 30-40% (on average). --- prog/hints.go | 14 ++++++++++++++ prog/hints_test.go | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) (limited to 'prog') diff --git a/prog/hints.go b/prog/hints.go index cbfe9c859..1dca452db 100644 --- a/prog/hints.go +++ b/prog/hints.go @@ -63,6 +63,20 @@ func (m CompMap) String() string { return buf.String() } +// InplaceIntersect() only leaves the value pairs that are also present in other. +func (m CompMap) InplaceIntersect(other CompMap) { + for val1, nested := range m { + for val2 := range nested { + if !other[val1][val2] { + delete(nested, val2) + } + } + if len(nested) == 0 { + delete(m, val1) + } + } +} + // Mutates the program using the comparison operands stored in compMaps. // For each of the mutants executes the exec callback. // The callback must return whether we should continue substitution (true) diff --git a/prog/hints_test.go b/prog/hints_test.go index a4b8da7bf..8b15ae473 100644 --- a/prog/hints_test.go +++ b/prog/hints_test.go @@ -13,6 +13,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/syzkaller/pkg/image" + "github.com/stretchr/testify/assert" ) type ConstArgTest struct { @@ -666,6 +667,24 @@ func TestHintsData(t *testing.T) { } } +func TestInplaceIntersect(t *testing.T) { + m1 := CompMap{ + 0xdead: compSet(0x1, 0x2), + 0xbeef: compSet(0x3, 0x4), + 0xffff: compSet(0x5), + } + m2 := CompMap{ + 0xdead: compSet(0x2), + 0xbeef: compSet(0x3, 0x6), + 0xeeee: compSet(0x6), + } + m1.InplaceIntersect(m2) + assert.Equal(t, CompMap{ + 0xdead: compSet(0x2), + 0xbeef: compSet(0x3), + }, m1) +} + func BenchmarkHints(b *testing.B) { target, cleanup := initBench(b) defer cleanup() -- cgit mrf-deployment