aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2021-12-21 14:23:50 +0100
committerDmitry Vyukov <dvyukov@google.com>2021-12-21 18:52:46 +0100
commitad097c94a04025c865b3956566ea5da7670ed437 (patch)
tree12a7efa8c65fa8fef91f33fb12d34d8f8f2023d7
parentc6f13480f3e562921f700b3e4f878ca5d54d958f (diff)
pkg/testutil: add package
Add package with RaceEnabled const that can be used in test to skip long tests in race mode. Switch existing tests to use the new package. Update #2886
-rw-r--r--pkg/csource/csource_test.go14
-rw-r--r--pkg/csource/race_test.go24
-rw-r--r--pkg/testutil/norace.go (renamed from prog/norace_test.go)4
-rw-r--r--pkg/testutil/race.go (renamed from prog/race_test.go)4
-rw-r--r--prog/decl_test.go4
-rw-r--r--prog/export_test.go6
-rw-r--r--prog/mutation_test.go6
-rw-r--r--prog/prio_test.go4
-rw-r--r--prog/prog_test.go4
9 files changed, 35 insertions, 35 deletions
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go
index fc3b21573..91bd2cccf 100644
--- a/pkg/csource/csource_test.go
+++ b/pkg/csource/csource_test.go
@@ -14,11 +14,25 @@ import (
"testing"
"time"
+ "github.com/google/syzkaller/pkg/testutil"
"github.com/google/syzkaller/prog"
_ "github.com/google/syzkaller/sys"
"github.com/google/syzkaller/sys/targets"
)
+func init() {
+ // csource tests consume too much memory under race detector (>1GB),
+ // and periodically timeout on Travis. So we skip them.
+ if testutil.RaceEnabled {
+ for _, arg := range os.Args[1:] {
+ if strings.Contains(arg, "-test.short") {
+ fmt.Printf("skipping race testing in short mode\n")
+ os.Exit(0)
+ }
+ }
+ }
+}
+
func TestGenerate(t *testing.T) {
t.Parallel()
checked := make(map[string]bool)
diff --git a/pkg/csource/race_test.go b/pkg/csource/race_test.go
deleted file mode 100644
index c41cef5d3..000000000
--- a/pkg/csource/race_test.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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.
-
-//go:build race
-// +build race
-
-package csource
-
-import (
- "fmt"
- "os"
- "strings"
-)
-
-func init() {
- // csource tests consume too much memory under race detector (>1GB),
- // and periodically timeout on Travis. So we skip them.
- for _, arg := range os.Args[1:] {
- if strings.Contains(arg, "-test.short") {
- fmt.Printf("skipping race testing in short mode\n")
- os.Exit(0)
- }
- }
-}
diff --git a/prog/norace_test.go b/pkg/testutil/norace.go
index 02b461925..ceb03928f 100644
--- a/prog/norace_test.go
+++ b/pkg/testutil/norace.go
@@ -4,6 +4,6 @@
//go:build !race
// +build !race
-package prog
+package testutil
-const raceEnabled = false
+const RaceEnabled = false
diff --git a/prog/race_test.go b/pkg/testutil/race.go
index 0c41a94f2..96a9043bb 100644
--- a/prog/race_test.go
+++ b/pkg/testutil/race.go
@@ -4,6 +4,6 @@
//go:build race
// +build race
-package prog
+package testutil
-const raceEnabled = true
+const RaceEnabled = true
diff --git a/prog/decl_test.go b/prog/decl_test.go
index 6cec10e27..b041bf8e9 100644
--- a/prog/decl_test.go
+++ b/prog/decl_test.go
@@ -6,10 +6,12 @@ package prog
import (
"strings"
"testing"
+
+ "github.com/google/syzkaller/pkg/testutil"
)
func TestResourceCtors(t *testing.T) {
- if testing.Short() && raceEnabled {
+ if testing.Short() && testutil.RaceEnabled {
t.Skip("too slow")
}
testEachTarget(t, func(t *testing.T, target *Target) {
diff --git a/prog/export_test.go b/prog/export_test.go
index a007ed3ce..415b03047 100644
--- a/prog/export_test.go
+++ b/prog/export_test.go
@@ -9,6 +9,8 @@ import (
"os"
"testing"
"time"
+
+ "github.com/google/syzkaller/pkg/testutil"
)
// Export guts for testing.
@@ -37,7 +39,7 @@ func iterCount() int {
if testing.Short() {
iters /= 10
}
- if raceEnabled {
+ if testutil.RaceEnabled {
iters /= 10
}
return iters
@@ -88,7 +90,7 @@ func skipTargetRace(t *testing.T, target *Target) {
// Race execution is slow and we are getting timeouts on CI.
// For tests that run for all targets, leave only 2 targets,
// this should be enough to detect some races.
- if raceEnabled && (target.OS != "test" || target.Arch != "64" && target.Arch != "32") {
+ if testutil.RaceEnabled && (target.OS != "test" || target.Arch != "64" && target.Arch != "32") {
t.Skip("skipping all but test/64 targets in race mode")
}
}
diff --git a/prog/mutation_test.go b/prog/mutation_test.go
index 6dfa15d63..a14719065 100644
--- a/prog/mutation_test.go
+++ b/prog/mutation_test.go
@@ -8,6 +8,8 @@ import (
"fmt"
"math/rand"
"testing"
+
+ "github.com/google/syzkaller/pkg/testutil"
)
func TestMutationFlags(t *testing.T) {
@@ -81,7 +83,7 @@ mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)`,
}
func TestMutateArgument(t *testing.T) {
- if raceEnabled {
+ if testutil.RaceEnabled {
t.Skip("skipping in race mode, too slow")
}
tests := [][2]string{
@@ -391,7 +393,7 @@ func BenchmarkGenerate(b *testing.B) {
}
func runMutationTests(t *testing.T, tests [][2]string, valid bool) {
- if raceEnabled {
+ if testutil.RaceEnabled {
t.Skip("skipping in race mode, too slow")
}
target := initTargetTest(t, "test", "64")
diff --git a/prog/prio_test.go b/prog/prio_test.go
index 21eb7f147..3f2fbc2ce 100644
--- a/prog/prio_test.go
+++ b/prog/prio_test.go
@@ -7,6 +7,8 @@ import (
"math/rand"
"reflect"
"testing"
+
+ "github.com/google/syzkaller/pkg/testutil"
)
func TestNormalizePrio(t *testing.T) {
@@ -69,7 +71,7 @@ func TestStaticPriorities(t *testing.T) {
}
func TestPrioDeterminism(t *testing.T) {
- if raceEnabled {
+ if testutil.RaceEnabled {
t.Skip("skipping in race mode, too slow")
}
target, rs, iters := initTest(t)
diff --git a/prog/prog_test.go b/prog/prog_test.go
index 6586d1a1d..a21c464a0 100644
--- a/prog/prog_test.go
+++ b/prog/prog_test.go
@@ -9,6 +9,8 @@ import (
"math/rand"
"strings"
"testing"
+
+ "github.com/google/syzkaller/pkg/testutil"
)
func TestGeneration(t *testing.T) {
@@ -142,7 +144,7 @@ func TestVmaType(t *testing.T) {
// deserialized for another arch. This happens when managers exchange
// programs via hub.
func TestCrossTarget(t *testing.T) {
- if raceEnabled {
+ if testutil.RaceEnabled {
t.Skip("skipping in race mode, too slow")
}
t.Parallel()