From 68f80dec7aa2d7c4ae909b4b3eb0953bc3990701 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 13 Feb 2023 20:36:16 +0100 Subject: 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) --- prog/collide_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'prog/collide_test.go') 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) + } + } +} -- cgit mrf-deployment