aboutsummaryrefslogtreecommitdiffstats
path: root/sys/linux/init_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-03-17 10:44:38 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-03-17 21:19:13 +0100
commita2f9a446496d23c4bf6db95e0d4337583595c78c (patch)
treeb745c1e04b7b2f4997ca823a7d7a294bf62671f6 /sys/linux/init_test.go
parent0a4d69469bf7e77f26f3036fbb183ecf73368a5d (diff)
prog: export deserialization test helper for sys/{linux,openbsd}
sys/{linux,openbsd} duplicate deserialization test logic as well. Export and reuse the existing helper function.
Diffstat (limited to 'sys/linux/init_test.go')
-rw-r--r--sys/linux/init_test.go122
1 files changed, 51 insertions, 71 deletions
diff --git a/sys/linux/init_test.go b/sys/linux/init_test.go
index 89a31e289..ae1a49698 100644
--- a/sys/linux/init_test.go
+++ b/sys/linux/init_test.go
@@ -4,8 +4,6 @@
package linux_test
import (
- "fmt"
- "strings"
"testing"
"github.com/google/syzkaller/prog"
@@ -13,100 +11,94 @@ import (
)
func TestSanitize(t *testing.T) {
- target, err := prog.GetTarget("linux", "amd64")
- if err != nil {
- t.Fatal(err)
- }
- tests := []struct {
- input string
- output string
- }{
+ prog.TestDeserializeHelper(t, "linux", "amd64", nil, []prog.DeserializeTest{
{
- `syslog(0x10000000006, 0x0, 0x0)`,
- `syslog(0x9, 0x0, 0x0)`,
+ In: `syslog(0x10000000006, 0x0, 0x0)`,
+ Out: `syslog(0x9, 0x0, 0x0)`,
},
{
- `syslog(0x10000000007, 0x0, 0x0)`,
- `syslog(0x9, 0x0, 0x0)`,
+ In: `syslog(0x10000000007, 0x0, 0x0)`,
+ Out: `syslog(0x9, 0x0, 0x0)`,
},
{
- `syslog(0x1, 0x0, 0x0)`,
- `syslog(0x1, 0x0, 0x0)`,
+ In: `syslog(0x1, 0x0, 0x0)`,
+ Out: `syslog(0x1, 0x0, 0x0)`,
},
{
- `ptrace(0xf000000000, 0x0)`,
- `ptrace(0xffffffffffffffff, 0x0)`,
+ In: `ptrace(0xf000000000, 0x0)`,
+ Out: `ptrace(0xffffffffffffffff, 0x0)`,
},
{
- `ptrace$peek(0x0, 0x0, &(0x7f0000000000))`,
- `ptrace$peek(0xffffffffffffffff, 0x0, &(0x7f0000000000))`,
+ In: `ptrace$peek(0x0, 0x0, &(0x7f0000000000))`,
+ Out: `ptrace$peek(0xffffffffffffffff, 0x0, &(0x7f0000000000))`,
},
{
- `ptrace(0x1, 0x0)`,
- `ptrace(0x1, 0x0)`,
+ In: `ptrace(0x1, 0x0)`,
+ Out: `ptrace(0x1, 0x0)`,
},
{
- `arch_prctl$ARCH_SET_GS(0xf00000001002, 0x0)`,
- `arch_prctl$ARCH_SET_GS(0x1001, 0x0)`,
+ In: `arch_prctl$ARCH_SET_GS(0xf00000001002, 0x0)`,
+ Out: `arch_prctl$ARCH_SET_GS(0x1001, 0x0)`,
},
{
- `arch_prctl$ARCH_SET_GS(0x1003, 0x0)`,
- `arch_prctl$ARCH_SET_GS(0x1003, 0x0)`,
+ In: `arch_prctl$ARCH_SET_GS(0x1003, 0x0)`,
+ Out: `arch_prctl$ARCH_SET_GS(0x1003, 0x0)`,
},
{
- `ioctl(0x0, 0x200000c0045877, 0x0)`,
- `ioctl(0x0, 0xc0045878, 0x0)`,
+ In: `ioctl(0x0, 0x200000c0045877, 0x0)`,
+ Out: `ioctl(0x0, 0xc0045878, 0x0)`,
},
{
- `ioctl$int_in(0x0, 0x2000008004587d, 0x0)`,
- `ioctl$int_in(0x0, 0x6609, 0x0)`,
+ In: `ioctl$int_in(0x0, 0x2000008004587d, 0x0)`,
+ Out: `ioctl$int_in(0x0, 0x6609, 0x0)`,
},
{
- `fanotify_mark(0x1, 0x2, 0x407fe029, 0x3, 0x0)`,
- `fanotify_mark(0x1, 0x2, 0x4078e029, 0x3, 0x0)`,
+ In: `fanotify_mark(0x1, 0x2, 0x407fe029, 0x3, 0x0)`,
+ Out: `fanotify_mark(0x1, 0x2, 0x4078e029, 0x3, 0x0)`,
},
{
- `fanotify_mark(0xffffffffffffffff, 0xffffffffffffffff, 0xfffffffffff8ffff, 0xffffffffffffffff, 0x0)`,
- `fanotify_mark(0xffffffffffffffff, 0xffffffffffffffff, 0xfffffffffff8ffff, 0xffffffffffffffff, 0x0)`,
+ In: `fanotify_mark(0xffffffffffffffff, 0xffffffffffffffff, 0xfffffffffff8ffff, 0xffffffffffffffff, 0x0)`,
+ Out: `fanotify_mark(0xffffffffffffffff, 0xffffffffffffffff, 0xfffffffffff8ffff, 0xffffffffffffffff, 0x0)`,
},
{
- `syz_init_net_socket$bt_hci(0x1, 0x0, 0x0)`,
- `syz_init_net_socket$bt_hci(0xffffffffffffffff, 0x0, 0x0)`,
+ In: `syz_init_net_socket$bt_hci(0x1, 0x0, 0x0)`,
+ Out: `syz_init_net_socket$bt_hci(0xffffffffffffffff, 0x0, 0x0)`,
},
{
- `syz_init_net_socket$bt_hci(0x27, 0x0, 0x0)`,
- `syz_init_net_socket$bt_hci(0x27, 0x0, 0x0)`,
+ In: `syz_init_net_socket$bt_hci(0x27, 0x0, 0x0)`,
+ Out: `syz_init_net_socket$bt_hci(0x27, 0x0, 0x0)`,
},
{
- `syz_init_net_socket$bt_hci(0x1a, 0x0, 0x0)`,
- `syz_init_net_socket$bt_hci(0x1a, 0x0, 0x0)`,
+ In: `syz_init_net_socket$bt_hci(0x1a, 0x0, 0x0)`,
+ Out: `syz_init_net_socket$bt_hci(0x1a, 0x0, 0x0)`,
},
{
- `syz_init_net_socket$bt_hci(0x1f, 0x0, 0x0)`,
- `syz_init_net_socket$bt_hci(0x1f, 0x0, 0x0)`,
+ In: `syz_init_net_socket$bt_hci(0x1f, 0x0, 0x0)`,
+ Out: `syz_init_net_socket$bt_hci(0x1f, 0x0, 0x0)`,
},
{
- `mmap(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)`,
- `mmap(0x0, 0x0, 0x0, 0x10, 0x0, 0x0)`,
+ In: `mmap(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)`,
+ Out: `mmap(0x0, 0x0, 0x0, 0x10, 0x0, 0x0)`,
},
{
- `mremap(0x0, 0x0, 0x0, 0xcc, 0x0)`,
- `mremap(0x0, 0x0, 0x0, 0xcc, 0x0)`,
+ In: `mremap(0x0, 0x0, 0x0, 0xcc, 0x0)`,
+ Out: `mremap(0x0, 0x0, 0x0, 0xcc, 0x0)`,
},
{
- `mremap(0x0, 0x0, 0x0, 0xcd, 0x0)`,
- `mremap(0x0, 0x0, 0x0, 0xcf, 0x0)`,
+ In: `mremap(0x0, 0x0, 0x0, 0xcd, 0x0)`,
+ Out: `mremap(0x0, 0x0, 0x0, 0xcf, 0x0)`,
},
{
- `
+ In: `
mknod(0x0, 0x1000, 0x0)
mknod(0x0, 0x8000, 0x0)
mknod(0x0, 0xc000, 0x0)
mknod(0x0, 0x2000, 0x0)
mknod(0x0, 0x6000, 0x0)
mknod(0x0, 0x6000, 0x700)
-`, `
+`,
+ Out: `
mknod(0x0, 0x1000, 0x0)
mknod(0x0, 0x8000, 0x0)
mknod(0x0, 0xc000, 0x0)
@@ -116,7 +108,7 @@ mknod(0x0, 0x6000, 0x700)
`,
},
{
- `
+ In: `
exit(0x3)
exit(0x43)
exit(0xc3)
@@ -124,7 +116,8 @@ exit(0xc3)
exit_group(0x5a)
exit_group(0x43)
exit_group(0x443)
-`, `
+`,
+ Out: `
exit(0x3)
exit(0x1)
exit(0x1)
@@ -135,33 +128,20 @@ exit_group(0x1)
`,
},
{
- `
+ In: `
syz_open_dev$tty1(0xc, 0x4, 0x4)
syz_open_dev$tty1(0xb, 0x2, 0x4)
syz_open_dev$tty1(0xc, 0x4, 0x5)
`,
- `
+ Out: `
syz_open_dev$tty1(0xc, 0x4, 0x4)
syz_open_dev$tty1(0xc, 0x4, 0x4)
syz_open_dev$tty1(0xc, 0x4, 0x1)
`,
},
{
- `ioctl$TIOCSSERIAL(0x0, 0x541f, 0x0)`,
- `ioctl$TIOCSSERIAL(0x0, 0x541e, 0x0)`,
- },
- }
- for i, test := range tests {
- t.Run(fmt.Sprint(i), func(t *testing.T) {
- p, err := target.Deserialize([]byte(test.input), prog.Strict)
- if err != nil {
- t.Fatal(err)
- }
- got := strings.TrimSpace(string(p.Serialize()))
- want := strings.TrimSpace(test.output)
- if got != want {
- t.Fatalf("input:\n%v\ngot:\n%v\nwant:\n%s", test.input, got, want)
- }
- })
- }
+ In: `ioctl$TIOCSSERIAL(0x0, 0x541f, 0x0)`,
+ Out: `ioctl$TIOCSSERIAL(0x0, 0x541e, 0x0)`,
+ },
+ })
}