From a2f9a446496d23c4bf6db95e0d4337583595c78c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 17 Mar 2020 10:44:38 +0100 Subject: 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. --- sys/openbsd/init_test.go | 82 ++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 52 deletions(-) (limited to 'sys/openbsd') 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) - } - }) - } + }) } -- cgit mrf-deployment