mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-15 09:07:43 +00:00
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.
This commit is contained in:
parent
d8b4c311be
commit
e530ec1bef
@ -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)
|
||||
getpid()
|
||||
|
Loading…
x
Reference in New Issue
Block a user