Skip to content

Commit

Permalink
pkg/csource: reduce short tests
Browse files Browse the repository at this point in the history
pkg/csource test gets OOM-killed on travis:
https://travis-ci.org/google/syzkaller/jobs/461827347
https://travis-ci.org/google/syzkaller/jobs/460226110

Add several measures:
 - set GOMAXPROCS=1 to restrict parallel processes
 - remove -g from compiler invocation
 - reduce set of tests run in short mode to compensate for GOMAXPROCS=1
 - also reduce set of tests in full mode as they timeout now
  • Loading branch information
dvyukov committed Dec 3, 2018
1 parent c3ff181 commit 2192790
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pkg/csource/build.go
Expand Up @@ -39,7 +39,7 @@ func build(target *prog.Target, src []byte, file string) (string, error) {
}

flags := []string{
"-Wall", "-Werror", "-O1", "-g", "-o", bin, "-pthread",
"-Wall", "-Werror", "-O1", "-o", bin, "-pthread",
"-DGOOS_" + target.OS + "=1",
"-DGOARCH_" + target.Arch + "=1",
}
Expand Down
81 changes: 42 additions & 39 deletions pkg/csource/csource_test.go
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"
"math/rand"
"os"
"os/exec"
"runtime"
"strings"
"testing"
"time"

Expand All @@ -17,11 +17,20 @@ import (
"github.com/google/syzkaller/sys/targets"
)

func init() {
if os.Getenv("TRAVIS") != "" {
// Otherwise tests OOM on travis.
runtime.GOMAXPROCS(1)
}
}

func TestGenerate(t *testing.T) {
t.Parallel()
checked := make(map[string]bool)
for _, target := range prog.AllTargets() {
target := target
if runtime.GOOS != targets.Get(target.OS, target.Arch).BuildOS {
sysTarget := targets.Get(target.OS, target.Arch)
if runtime.GOOS != sysTarget.BuildOS {
continue
}
t.Run(target.OS+"/"+target.Arch, func(t *testing.T) {
Expand All @@ -40,50 +49,47 @@ func TestGenerate(t *testing.T) {
// The same reason as linux/32.
t.Skip("broken")
}
if _, err := exec.LookPath(sysTarget.CCompiler); err != nil {
t.Skipf("no target compiler %v", sysTarget.CCompiler)
}
full := !checked[target.OS]
checked[target.OS] = true
t.Parallel()
testTarget(t, target)
testTarget(t, target, full)
})

}
}

func testTarget(t *testing.T, target *prog.Target) {
func testTarget(t *testing.T, target *prog.Target, full bool) {
seed := int64(time.Now().UnixNano())
rs := rand.NewSource(seed)
t.Logf("seed=%v", seed)
r := rand.New(rs)
progs := []*prog.Prog{target.GenerateSimpleProg()}
if p := target.GenerateAllSyzProg(rs); len(p.Calls) != 0 {
progs = append(progs, p)
}
if !testing.Short() {
progs = append(progs, target.Generate(rs, 10, nil))
}
opts := allOptionsSingle(target.OS)
opts = append(opts, Options{
Threaded: true,
Collide: true,
Repeat: true,
Procs: 2,
Sandbox: "none",
Repro: true,
UseTmpDir: true,
})
allPermutations := allOptionsPermutations(target.OS)
if testing.Short() {
for i := 0; i < 16; i++ {
opts = append(opts, allPermutations[r.Intn(len(allPermutations))])
}
p := target.Generate(rs, 10, nil)
p.Calls = append(p.Calls, target.GenerateAllSyzProg(rs).Calls...)
var opts []Options
if !full || testing.Short() {
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,
})
} else {
opts = allPermutations
opts = allOptionsPermutations(target.OS)
}
for pi, p := range progs {
for opti, opts := range opts {
p, opts := p, opts
t.Run(fmt.Sprintf("%v/%v", pi, opti), func(t *testing.T) {
t.Parallel()
testOne(t, p, opts)
})
}
for opti, opts := range opts {
opts := opts
t.Run(fmt.Sprintf("%v", opti), func(t *testing.T) {
t.Parallel()
testOne(t, p, opts)
})
}
}

Expand All @@ -95,9 +101,6 @@ func testOne(t *testing.T, p *prog.Prog, opts Options) {
}
bin, err := Build(p.Target, src)
if err != nil {
if strings.Contains(err.Error(), "no target compiler") {
t.Skip(err)
}
t.Logf("opts: %+v\nprogram:\n%s\n", opts, p.Serialize())
t.Fatalf("%v", err)
}
Expand Down

0 comments on commit 2192790

Please sign in to comment.