aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'prog/mutation_test.go')
-rw-r--r--prog/mutation_test.go181
1 files changed, 94 insertions, 87 deletions
diff --git a/prog/mutation_test.go b/prog/mutation_test.go
index 771c6c143..3b254bf48 100644
--- a/prog/mutation_test.go
+++ b/prog/mutation_test.go
@@ -66,104 +66,111 @@ func TestMutateCorpus(t *testing.T) {
}
func TestMutateTable(t *testing.T) {
+ target := initTargetTest(t, "test", "64")
tests := [][2]string{
- // Insert calls.
- {
- "mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x3, 0x32, 0xffffffffffffffff, 0x0)\n" +
- "pipe2(&(0x7f0000000000)={0x0, 0x0}, 0x0)\n",
-
- "mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x3, 0x32, 0xffffffffffffffff, 0x0)\n" +
- "sched_yield()\n" +
- "pipe2(&(0x7f0000000000)={0x0, 0x0}, 0x0)\n",
- },
+ // Insert a call.
+ {`
+mutate0()
+mutate2()
+`, `
+mutate0()
+mutate1()
+mutate2()
+`},
// Remove calls and update args.
- {
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "sched_yield()\n" +
- "read(r0, &(0x7f0000000000)=\"\", 0x1)\n" +
- "sched_yield()\n",
-
- "sched_yield()\n" +
- "read(0xffffffffffffffff, &(0x7f0000000000)=\"\", 0x1)\n" +
- "sched_yield()\n",
- },
+ {`
+r0 = mutate5(&(0x7f0000000000)="2e2f66696c653000", 0x0)
+mutate0()
+mutate6(r0, &(0x7f0000000000)="00", 0x1)
+mutate1()
+`, `
+mutate0()
+mutate6(0xffffffffffffffff, &(0x7f0000000000)="00", 0x1)
+mutate1()
+`},
// Mutate flags.
- {
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "sched_yield()\n" +
- "read(r0, &(0x7f0000000000)=\"\", 0x1)\n" +
- "sched_yield()\n",
-
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x2)\n" +
- "sched_yield()\n" +
- "read(r0, &(0x7f0000000000)=\"\", 0x1)\n" +
- "sched_yield()\n",
- },
+ {`
+r0 = mutate5(&(0x7f0000000000)="2e2f66696c653000", 0x0)
+mutate0()
+mutate6(r0, &(0x7f0000000000)="00", 0x1)
+mutate1()
+`, `
+r0 = mutate5(&(0x7f0000000000)="2e2f66696c653000", 0xcdcdcdcdcdcdcdcd)
+mutate0()
+mutate6(r0, &(0x7f0000000000)="00", 0x1)
+mutate1()
+`},
// Mutate data (delete byte and update size).
- {
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"11223344\", 0x4)\n",
-
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"112244\", 0x3)\n",
- },
+ {`
+mutate4(&(0x7f0000000000)="11223344", 0x4)
+`, `
+mutate4(&(0x7f0000000000)="112244", 0x3)
+`},
// Mutate data (insert byte and update size).
- {
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"1122\", 0x2)\n",
-
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"112255\", 0x3)\n",
- },
+ // TODO: this is not working, because Mutate constantly tends
+ // update addresses and insert mmap's.
+ /*
+ {`
+ mutate4(&(0x7f0000000000)="1122", 0x2)
+ `, `
+ mutate4(&(0x7f0000000000)="112200", 0x3)
+ `},
+ */
// Mutate data (change byte).
- {
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"1122\", 0x2)\n",
-
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"1155\", 0x2)\n",
- },
+ {`
+mutate4(&(0x7f0000000000)="1122", 0x2)
+`, `
+mutate4(&(0x7f0000000000)="1100", 0x2)
+`},
// Change filename.
- {
- "open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"\", 0x0)\n",
-
- "open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653100\", 0x22c0, 0x1)\n" +
- "write(r0, &(0x7f0000000000)=\"\", 0x0)\n",
- },
+ {`
+mutate5(&(0x7f0000001000)="2e2f66696c653000", 0x22c0)
+mutate5(&(0x7f0000001000)="2e2f66696c653000", 0x22c0)
+`, `
+mutate5(&(0x7f0000001000)="2e2f66696c653000", 0x22c0)
+mutate5(&(0x7f0000001000)="2e2f66696c653100", 0x22c0)
+`},
// Extend an array.
- {
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "readv(r0, &(0x7f0000000000)=[{&(0x7f0000001000)=\"00\", 0x1}, {&(0x7f0000002000)=\"00\", 0x2}], 0x2)\n",
-
- "mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x3, 0x32, 0xffffffffffffffff, 0x0)\n" +
- "r0 = open(&(0x7f0000001000)=\"2e2f66696c653000\", 0x22c0, 0x1)\n" +
- "readv(r0, &(0x7f0000000000)=[{&(0x7f0000001000)=\"00\", 0x1}, {&(0x7f0000002000)=\"00\", 0x2}, {&(0x7f0000000000)=\"00\", 0x3}], 0x3)\n",
- },
+ {`
+mutate3(&(0x7f0000000000)=[0x1, 0x1], 0x2)
+`, `
+mmap(&(0x7f0000000000/0x1000)=nil, 0x1000)
+mutate3(&(0x7f0000000000)=[0x1, 0x1, 0x1], 0x3)
+`},
}
- target, rs, _ := initTest(t)
-nextTest:
for ti, test := range tests {
- p, err := target.Deserialize([]byte(test[0]))
- if err != nil {
- t.Fatalf("failed to deserialize original program %v: %v", ti, err)
- }
- if testing.Short() {
- continue
- }
- for i := 0; i < 1e6; i++ {
- p1 := p.Clone()
- p1.Mutate(rs, 30, nil, nil)
- data1 := p1.Serialize()
- if string(data1) == test[1] {
- t.Logf("test #%v: success on iter %v", ti, i)
- continue nextTest
+ test := test
+ t.Run(fmt.Sprint(ti), func(t *testing.T) {
+ t.Parallel()
+ p, err := target.Deserialize([]byte(test[0]))
+ if err != nil {
+ t.Fatalf("failed to deserialize original program: %v", err)
}
- _ = fmt.Printf
- }
- t.Fatalf("failed to achieve mutation goal\noriginal:\n%s\n\ngoal:\n%s\n", test[0], test[1])
+ goal, err := target.Deserialize([]byte(test[1]))
+ if err != nil {
+ t.Fatalf("failed to deserialize goal program: %v", err)
+ }
+ want := goal.Serialize()
+ enabled := make(map[*Syscall]bool)
+ for _, c := range p.Calls {
+ enabled[c.Meta] = true
+ }
+ for _, c := range goal.Calls {
+ enabled[c.Meta] = true
+ }
+ ct := target.BuildChoiceTable(nil, enabled)
+ rs := rand.NewSource(0)
+ for i := 0; i < 1e5; i++ {
+ p1 := p.Clone()
+ p1.Mutate(rs, len(goal.Calls), ct, nil)
+ data1 := p1.Serialize()
+ if bytes.Equal(want, data1) {
+ t.Logf("success on iter %v", i)
+ return
+ }
+ }
+ t.Fatalf("failed to achieve goal, original:%s\ngoal:%s", test[0], test[1])
+ })
}
}