aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--prog/any_test.go6
-rw-r--r--prog/decl_test.go3
-rw-r--r--prog/encoding_test.go1
-rw-r--r--prog/export_test.go23
-rw-r--r--prog/hints_test.go3
-rw-r--r--prog/mutation_test.go21
-rw-r--r--prog/norace_test.go8
-rw-r--r--prog/parse_test.go3
-rw-r--r--prog/prog_test.go1
-rw-r--r--prog/race_test.go8
10 files changed, 65 insertions, 12 deletions
diff --git a/prog/any_test.go b/prog/any_test.go
index 43100cde2..3294e4aeb 100644
--- a/prog/any_test.go
+++ b/prog/any_test.go
@@ -12,10 +12,14 @@ import (
func TestIsComplexPtr(t *testing.T) {
target, rs, _ := initRandomTargetTest(t, "linux", "amd64")
+ iters := 10
+ if testing.Short() {
+ iters = 1
+ }
r := newRand(target, rs)
compl := make(map[string]bool)
for _, meta := range target.Syscalls {
- for i := 0; i < 10; i++ {
+ for i := 0; i < iters; i++ {
s := newState(target, nil)
calls := r.generateParticularCall(s, meta)
p := &Prog{Target: target, Calls: calls}
diff --git a/prog/decl_test.go b/prog/decl_test.go
index d05289655..0f727aa7f 100644
--- a/prog/decl_test.go
+++ b/prog/decl_test.go
@@ -9,6 +9,9 @@ import (
)
func TestResourceCtors(t *testing.T) {
+ if testing.Short() && raceEnabled {
+ t.Skip("too slow")
+ }
testEachTarget(t, func(t *testing.T, target *Target) {
for _, c := range target.Syscalls {
for _, res := range c.inputResources() {
diff --git a/prog/encoding_test.go b/prog/encoding_test.go
index 10b4bb9c1..9870b91f6 100644
--- a/prog/encoding_test.go
+++ b/prog/encoding_test.go
@@ -48,6 +48,7 @@ func TestSerializeData(t *testing.T) {
}
func TestCallSet(t *testing.T) {
+ t.Parallel()
tests := []struct {
prog string
ok bool
diff --git a/prog/export_test.go b/prog/export_test.go
index 015d4f319..b6247c850 100644
--- a/prog/export_test.go
+++ b/prog/export_test.go
@@ -36,13 +36,20 @@ func randSource(t *testing.T) rand.Source {
return rand.NewSource(seed)
}
-func initRandomTargetTest(t *testing.T, os, arch string) (*Target, rand.Source, int) {
- target := initTargetTest(t, os, arch)
+func iterCount() int {
iters := 10000
if testing.Short() {
iters = 100
}
- return target, randSource(t), iters
+ if raceEnabled {
+ iters /= 10
+ }
+ return iters
+}
+
+func initRandomTargetTest(t *testing.T, os, arch string) (*Target, rand.Source, int) {
+ target := initTargetTest(t, os, arch)
+ return target, randSource(t), iterCount()
}
func initTest(t *testing.T) (*Target, rand.Source, int) {
@@ -50,6 +57,7 @@ func initTest(t *testing.T) (*Target, rand.Source, int) {
}
func testEachTarget(t *testing.T, fn func(t *testing.T, target *Target)) {
+ t.Parallel()
for _, target := range AllTargets() {
target := target
t.Run(fmt.Sprintf("%v/%v", target.OS, target.Arch), func(t *testing.T) {
@@ -60,12 +68,13 @@ func testEachTarget(t *testing.T, fn func(t *testing.T, target *Target)) {
}
func testEachTargetRandom(t *testing.T, fn func(t *testing.T, target *Target, rs rand.Source, iters int)) {
- iters := 10000
- if testing.Short() {
- iters = 100
- }
+ t.Parallel()
targets := AllTargets()
+ iters := iterCount()
iters /= len(targets)
+ if iters < 3 {
+ iters = 3
+ }
rs0 := randSource(t)
for _, target := range targets {
target := target
diff --git a/prog/hints_test.go b/prog/hints_test.go
index 58519a6ff..e861b45bd 100644
--- a/prog/hints_test.go
+++ b/prog/hints_test.go
@@ -55,6 +55,7 @@ func TestHintsCheckConstArg(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
+ t.Parallel()
res := uint64Set{}
constArg := &ConstArg{ArgCommon{nil}, test.in}
checkConstArg(constArg, test.comps, func() {
@@ -187,6 +188,7 @@ func TestHintsCheckDataArg(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
+ t.Parallel()
res := make(map[string]bool)
// Whatever type here. It's just needed to pass the
// dataArg.Type().Dir() == DirIn check.
@@ -363,6 +365,7 @@ func TestHintsShrinkExpand(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
+ t.Parallel()
res := shrinkExpand(test.in, test.comps)
if !reflect.DeepEqual(res, test.res) {
t.Fatalf("\ngot : %v\nwant: %v", res, test.res)
diff --git a/prog/mutation_test.go b/prog/mutation_test.go
index 2267dd254..23f994c84 100644
--- a/prog/mutation_test.go
+++ b/prog/mutation_test.go
@@ -7,6 +7,7 @@ import (
"bytes"
"fmt"
"math/rand"
+ "sync"
"testing"
)
@@ -194,10 +195,10 @@ func BenchmarkMutate(b *testing.B) {
if err != nil {
b.Fatal(err)
}
- prios := target.CalculatePriorities(nil)
- ct := target.BuildChoiceTable(prios, nil)
+ ct := linuxAmd64ChoiceTable(target)
const progLen = 30
p := target.Generate(rand.NewSource(0), progLen, nil)
+ b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
rs := rand.NewSource(0)
for pb.Next() {
@@ -214,9 +215,9 @@ func BenchmarkGenerate(b *testing.B) {
if err != nil {
b.Fatal(err)
}
- prios := target.CalculatePriorities(nil)
- ct := target.BuildChoiceTable(prios, nil)
+ ct := linuxAmd64ChoiceTable(target)
const progLen = 30
+ b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
rs := rand.NewSource(0)
for pb.Next() {
@@ -224,3 +225,15 @@ func BenchmarkGenerate(b *testing.B) {
}
})
}
+
+var (
+ linuxCTOnce sync.Once
+ linuxCT *ChoiceTable
+)
+
+func linuxAmd64ChoiceTable(target *Target) *ChoiceTable {
+ linuxCTOnce.Do(func() {
+ linuxCT = target.BuildChoiceTable(target.CalculatePriorities(nil), nil)
+ })
+ return linuxCT
+}
diff --git a/prog/norace_test.go b/prog/norace_test.go
new file mode 100644
index 000000000..528d64877
--- /dev/null
+++ b/prog/norace_test.go
@@ -0,0 +1,8 @@
+// Copyright 2018 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+// +build !race
+
+package prog
+
+const raceEnabled = false
diff --git a/prog/parse_test.go b/prog/parse_test.go
index c6ecf565c..48e3cd203 100644
--- a/prog/parse_test.go
+++ b/prog/parse_test.go
@@ -8,6 +8,7 @@ import (
)
func TestParseSingle(t *testing.T) {
+ t.Parallel()
target, err := GetTarget("linux", "amd64")
if err != nil {
t.Fatal(err)
@@ -40,6 +41,7 @@ gettid()
}
func TestParseMulti(t *testing.T) {
+ t.Parallel()
target, err := GetTarget("linux", "amd64")
if err != nil {
t.Fatal(err)
@@ -107,6 +109,7 @@ munlockall()
`
func TestParseFault(t *testing.T) {
+ t.Parallel()
target, err := GetTarget("linux", "amd64")
if err != nil {
t.Fatal(err)
diff --git a/prog/prog_test.go b/prog/prog_test.go
index 2dc4f6bbd..504b2c923 100644
--- a/prog/prog_test.go
+++ b/prog/prog_test.go
@@ -114,6 +114,7 @@ func TestVmaType(t *testing.T) {
// deserialized for another arch. This happens when managers exchange
// programs via hub.
func TestCrossTarget(t *testing.T) {
+ t.Parallel()
for os, archs := range targetsPkg.List {
if len(archs) == 1 {
continue
diff --git a/prog/race_test.go b/prog/race_test.go
new file mode 100644
index 000000000..5d4787717
--- /dev/null
+++ b/prog/race_test.go
@@ -0,0 +1,8 @@
+// Copyright 2018 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+// +build race
+
+package prog
+
+const raceEnabled = true