aboutsummaryrefslogtreecommitdiffstats
path: root/prog/collide_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-02-13 20:36:16 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-14 14:56:49 +0100
commit68f80dec7aa2d7c4ae909b4b3eb0953bc3990701 (patch)
treee67c30b44eccdf99ffdac459dc3d287a6a8ed37f /prog/collide_test.go
parent9db88265dbce82f690f9b166b24bba1570d15854 (diff)
prog: add a new DupCallCollide collide type
It duplicates random calls in a program and makes the duplicated copies async. E.g. it could transform r0 = test() test2(r0) to r0 = test() test2(r0) (async) test2(r0) or test() (async) r0 = test() test2(r0)
Diffstat (limited to 'prog/collide_test.go')
-rw-r--r--prog/collide_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/prog/collide_test.go b/prog/collide_test.go
index 269b541ff..0e29777a7 100644
--- a/prog/collide_test.go
+++ b/prog/collide_test.go
@@ -6,6 +6,8 @@ package prog
import (
"math/rand"
"testing"
+
+ "github.com/stretchr/testify/assert"
)
func TestAssignRandomAsync(t *testing.T) {
@@ -148,3 +150,61 @@ dup(r3)
}
}
}
+
+func TestDupCallCollide(t *testing.T) {
+ tests := []struct {
+ os string
+ arch string
+ orig string
+ rets []string
+ }{
+ {
+ "linux", "amd64",
+ `r0 = openat(0xffffffffffffff9c, &AUTO='./file1\x00', 0x42, 0x1ff)
+r1 = dup(r0)
+r2 = dup(r1)
+dup(r2)
+`,
+ []string{
+ `r0 = openat(0xffffffffffffff9c, &(0x7f0000000040)='./file1\x00', 0x42, 0x1ff)
+dup(r0) (async)
+r1 = dup(r0)
+r2 = dup(r1)
+dup(r2)
+`,
+ `r0 = openat(0xffffffffffffff9c, &(0x7f0000000040)='./file1\x00', 0x42, 0x1ff)
+r1 = dup(r0)
+r2 = dup(r1)
+dup(r2) (async)
+dup(r2)
+`,
+ },
+ },
+ }
+ _, rs, iters := initTest(t)
+ if iters > 100 {
+ // Let's save resources -- we don't need that many for these small tests.
+ iters = 100
+ }
+ r := rand.New(rs)
+ for _, test := range tests {
+ target, err := GetTarget(test.os, test.arch)
+ if err != nil {
+ t.Fatal(err)
+ }
+ p, err := target.Deserialize([]byte(test.orig), Strict)
+ if err != nil {
+ t.Fatal(err)
+ }
+ detected := map[string]struct{}{}
+ for i := 0; i < iters; i++ {
+ collided, err := DupCallCollide(p, r)
+ assert.NoError(t, err)
+ detected[string(collided.Serialize())] = struct{}{}
+ }
+ for _, variant := range test.rets {
+ _, exists := detected[variant]
+ assert.True(t, exists)
+ }
+ }
+}