aboutsummaryrefslogtreecommitdiffstats
path: root/sys
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
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')
-rw-r--r--sys/linux/init_test.go122
-rw-r--r--sys/openbsd/init_test.go82
2 files changed, 81 insertions, 123 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)`,
+ },
+ })
}
diff --git a/sys/openbsd/init_test.go b/sys/openbsd/init_test.go
index 39e93a688..6895ce3c9 100644
--- a/sys/openbsd/init_test.go
+++ b/sys/openbsd/init_test.go
@@ -4,8 +4,6 @@
package openbsd_test
import (
- "fmt"
- "strings"
"testing"
"github.com/google/syzkaller/prog"
@@ -13,93 +11,73 @@ import (
)
func TestSanitizeCall(t *testing.T) {
- target, err := prog.GetTarget("openbsd", "amd64")
- if err != nil {
- t.Fatal(err)
- }
- tests := []struct {
- input string
- output string
- }{
+ prog.TestDeserializeHelper(t, "openbsd", "amd64", nil, []prog.DeserializeTest{
{
- `chflagsat(0x0, 0x0, 0x60004, 0x0)`,
- `chflagsat(0x0, 0x0, 0x0, 0x0)`,
+ In: `chflagsat(0x0, 0x0, 0x60004, 0x0)`,
+ Out: `chflagsat(0x0, 0x0, 0x0, 0x0)`,
},
{
- `fchflags(0x0, 0x60004)`,
- `fchflags(0x0, 0x0)`,
+ In: `fchflags(0x0, 0x60004)`,
+ Out: `fchflags(0x0, 0x0)`,
},
{
- `ioctl$BIOCSDIRFILT(0x0, 0xc0e04429, 0x0)`,
- `ioctl$BIOCSDIRFILT(0x0, 0x0, 0x0)`,
+ In: `ioctl$BIOCSDIRFILT(0x0, 0xc0e04429, 0x0)`,
+ Out: `ioctl$BIOCSDIRFILT(0x0, 0x0, 0x0)`,
},
{
// major=22, minor=232
- `mknodat(0x0, 0x0, 0x0, 0x16e8)`,
- `mknodat(0x0, 0x0, 0x0, 0x202)`,
+ In: `mknodat(0x0, 0x0, 0x0, 0x16e8)`,
+ Out: `mknodat(0x0, 0x0, 0x0, 0x202)`,
},
{
// major=22, minor=232
- `mknod(0x0, 0x0, 0x16e8)`,
- `mknod(0x0, 0x0, 0x202)`,
+ In: `mknod(0x0, 0x0, 0x16e8)`,
+ Out: `mknod(0x0, 0x0, 0x202)`,
},
{
// major=22, minor=0
- `mknod(0x0, 0x0, 0x1600)`,
- `mknod(0x0, 0x0, 0x1600)`,
+ In: `mknod(0x0, 0x0, 0x1600)`,
+ Out: `mknod(0x0, 0x0, 0x1600)`,
},
{
// major=4, minor=0
- `mknod(0x0, 0x0, 0x400)`,
- `mknod(0x0, 0x0, 0x400)`,
+ In: `mknod(0x0, 0x0, 0x400)`,
+ Out: `mknod(0x0, 0x0, 0x400)`,
},
{
// major=4, minor=1
- `mknod(0x0, 0x0, 0x401)`,
- `mknod(0x0, 0x0, 0x202)`,
+ In: `mknod(0x0, 0x0, 0x401)`,
+ Out: `mknod(0x0, 0x0, 0x202)`,
},
{
// major=4, minor=2
- `mknod(0x0, 0x0, 0x402)`,
- `mknod(0x0, 0x0, 0x202)`,
+ In: `mknod(0x0, 0x0, 0x402)`,
+ Out: `mknod(0x0, 0x0, 0x202)`,
},
{
// MCL_CURRENT | MCL_FUTURE
- `mlockall(0x3)`,
- `mlockall(0x1)`,
+ In: `mlockall(0x3)`,
+ Out: `mlockall(0x1)`,
},
{
// RLIMIT_DATA
- `setrlimit(0x2, &(0x7f0000cc0ff0)={0x0, 0x80000000})`,
- `setrlimit(0x2, &(0x7f0000cc0ff0)={0x60000000, 0x80000000})`,
+ In: `setrlimit(0x2, &(0x7f0000cc0ff0)={0x0, 0x80000000})`,
+ Out: `setrlimit(0x2, &(0x7f0000cc0ff0)={0x60000000, 0x80000000})`,
},
{
// RLIMIT_DATA
- `setrlimit(0x10000000000002, &(0x7f0000cc0ff0)={0x0, 0x80000000})`,
- `setrlimit(0x10000000000002, &(0x7f0000cc0ff0)={0x60000000, 0x80000000})`,
+ In: `setrlimit(0x10000000000002, &(0x7f0000cc0ff0)={0x0, 0x80000000})`,
+ Out: `setrlimit(0x10000000000002, &(0x7f0000cc0ff0)={0x60000000, 0x80000000})`,
},
{
// RLIMIT_STACK
- `setrlimit(0x3, &(0x7f0000cc0ff0)={0x1000000000, 0x1000000000})`,
- `setrlimit(0x3, &(0x7f0000cc0ff0)={0x100000, 0x100000})`,
+ In: `setrlimit(0x3, &(0x7f0000cc0ff0)={0x1000000000, 0x1000000000})`,
+ Out: `setrlimit(0x3, &(0x7f0000cc0ff0)={0x100000, 0x100000})`,
},
{
// RLIMIT_CPU
- `setrlimit(0x0, &(0x7f0000cc0ff0)={0x1, 0x1})`,
- `setrlimit(0x0, &(0x7f0000cc0ff0)={0x1, 0x1})`,
+ In: `setrlimit(0x0, &(0x7f0000cc0ff0)={0x1, 0x1})`,
+ Out: `setrlimit(0x0, &(0x7f0000cc0ff0)={0x1, 0x1})`,
},
- }
- 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)
- }
- })
- }
+ })
}