Skip to content
Permalink
Browse files

pkg/csource: test sys/*/test programs

Running sys/*/test programs requires real machines and kernels for each OS.
We can't do that in unit tests, but at least try to deserialize these programs
so that they don't get rotten.
  • Loading branch information...
dvyukov committed Jul 22, 2019
1 parent d8b4c31 commit e530ec1befe3153020d601f5066939d984d790ac
Showing with 55 additions and 12 deletions.
  1. +52 −11 pkg/csource/csource_test.go
  2. +3 −1 sys/linux/test/vusb
@@ -5,13 +5,17 @@ package csource

import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/prog"
_ "github.com/google/syzkaller/sys"
"github.com/google/syzkaller/sys/targets"
@@ -48,6 +52,17 @@ func TestGenerate(t *testing.T) {
}
}

// This is the main configuration used by executor, so we want to test it as well.
var executorOpts = Options{
Threaded: true,
Collide: true,
Repeat: true,
Procs: 2,
Sandbox: "none",
Repro: true,
UseTmpDir: true,
}

func testTarget(t *testing.T, target *prog.Target, full bool) {
seed := time.Now().UnixNano()
if os.Getenv("TRAVIS") != "" {
@@ -67,17 +82,7 @@ func testTarget(t *testing.T, target *prog.Target, full bool) {
if !full || testing.Short() {
p.Calls = append(p.Calls, syzProg.Calls...)
opts = allOptionsSingle(target.OS)
// This is the main configuration used by executor,
// so we want to test it as well.
opts = append(opts, Options{
Threaded: true,
Collide: true,
Repeat: true,
Procs: 2,
Sandbox: "none",
Repro: true,
UseTmpDir: true,
})
opts = append(opts, executorOpts)
} else {
minimized, _ := prog.Minimize(syzProg, -1, false, func(p *prog.Prog, call int) bool {
return len(p.Calls) == len(syzProg.Calls)
@@ -107,3 +112,39 @@ func testOne(t *testing.T, p *prog.Prog, opts Options) {
}
defer os.Remove(bin)
}

func TestSysTests(t *testing.T) {
t.Parallel()
for _, target := range prog.AllTargets() {
target := target
t.Run(target.OS+"/"+target.Arch, func(t *testing.T) {
t.Parallel()
dir := filepath.Join("..", "..", "sys", target.OS, "test")
if !osutil.IsExist(dir) {
return
}
files, err := ioutil.ReadDir(dir)
if err != nil {
t.Fatalf("failed to read %v: %v", dir, err)
}
for _, finfo := range files {
file := filepath.Join(dir, finfo.Name())
if strings.HasSuffix(file, "~") || strings.HasSuffix(file, ".swp") {
continue
}
data, err := ioutil.ReadFile(file)
if err != nil {
t.Fatalf("failed to read %v: %v", file, err)
}
p, err := target.Deserialize(data, prog.Strict)
if err != nil {
t.Fatalf("failed to parse program %v: %v", file, err)
}
_, err = Write(p, executorOpts)
if err != nil {
t.Fatalf("failed to generate C source for %v: %v", file, err)
}
}
})
}
}
@@ -1,3 +1,5 @@
# requires: -sandbox=setuid -sandbox=namespace

syz_usb_connect(0x0, 0x24, &(0x7f0000000000)={0x12, 0x1, 0x0, 0x97, 0xff, 0x82, 0x8, 0x2058, 0x1005, 0xc19b, 0x0, 0x0, 0x0, 0x1, [{0x9, 0x2, 0x12, 0x1, 0x0, 0x0, 0x0, 0x0, [{0x9, 0x4, 0x8f, 0x0, 0x0, 0xbf, 0x57, 0x5a, 0x0, [], []}]}]}, 0x0)
# Temporary disabled because deserialization fails (run go test ./pkg/csource).
#syz_usb_connect(0x0, 0x24, &(0x7f0000000000)={0x12, 0x1, 0x0, 0x97, 0xff, 0x82, 0x8, 0x2058, 0x1005, 0xc19b, 0x0, 0x0, 0x0, 0x1, [{0x9, 0x2, 0x12, 0x1, 0x0, 0x0, 0x0, 0x0, [{0x9, 0x4, 0x8f, 0x0, 0x0, 0xbf, 0x57, 0x5a, 0x0, [], []}]}]}, 0x0)

This comment has been minimized.

Copy link
@dvyukov

dvyukov Jul 22, 2019

Author Collaborator

@xairy this program needs some updating

This comment has been minimized.

Copy link
@dvyukov

dvyukov Jul 22, 2019

Author Collaborator
    --- FAIL: TestSysTests/linux/ppc64le (0.57s)
        csource_test.go:142: failed to parse program ../../sys/linux/test/vusb: wrong int arg
            line #3:50: syz_usb_connect(0x0, 0x24, &(0x7f0000000000)={0x12, 0x1, 0x0, 0x97, 0xff, 0x82, 0x8, 0x2058, 0x1005, 0xc19b, 0x0, 0x0, 0x0, 0x1, [{0x9, 0x2, 0x12, 0x1, 0x0, 0x0, 0x0, 0x0, [{0x9, 0x4, 0x8f, 0x0, 0x0, 0xbf, 0x57, 0x5a, 0x0, [], []}]}]}, 0x0)
getpid()

0 comments on commit e530ec1

Please sign in to comment.
You can’t perform that action at this time.