aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/csource/csource_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-07-22 10:20:51 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-07-22 10:20:51 +0200
commite530ec1befe3153020d601f5066939d984d790ac (patch)
tree673a30e4c485b3a4f617deb7f1b2bd306d1420f5 /pkg/csource/csource_test.go
parentd8b4c311beb922f45e67ca405cff2b84157b3380 (diff)
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.
Diffstat (limited to 'pkg/csource/csource_test.go')
-rw-r--r--pkg/csource/csource_test.go63
1 files changed, 52 insertions, 11 deletions
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go
index 592f4fe19..e31347357 100644
--- a/pkg/csource/csource_test.go
+++ b/pkg/csource/csource_test.go
@@ -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)
+ }
+ }
+ })
+ }
+}