aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-05-13 14:39:47 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-05-15 09:05:55 +0000
commit94b087b1f1dce14942bc35bb35a8f58e57b1fc63 (patch)
tree946e436b5b3bdc909148f18152acb9af5b0d5089 /prog
parent7e8e0c0fed2e3e8db2778e6427d68c561eb77078 (diff)
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).
Diffstat (limited to 'prog')
-rw-r--r--prog/hints.go14
-rw-r--r--prog/hints_test.go19
2 files changed, 33 insertions, 0 deletions
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()