diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2015-12-23 13:38:31 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2015-12-23 13:38:31 +0100 |
| commit | e253cbc79fc20b65ce9dd965c6fe3adddac817ca (patch) | |
| tree | 3a64c5a18d8b0a020c3cee24abbfe32fc468fc86 /csource/csource_test.go | |
| parent | 071ad4e91f95f115236a639e934181c7e596f337 (diff) | |
csource: new package
Move C source generation into a separate package.
Prog is too bloated already.
Diffstat (limited to 'csource/csource_test.go')
| -rw-r--r-- | csource/csource_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/csource/csource_test.go b/csource/csource_test.go new file mode 100644 index 000000000..b2fbda6dc --- /dev/null +++ b/csource/csource_test.go @@ -0,0 +1,53 @@ +// Copyright 2015 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. + +package csource + +import ( + "math/rand" + "os" + "testing" + "time" + + "github.com/google/syzkaller/prog" +) + +func initTest(t *testing.T) (rand.Source, int) { + iters := 1000 + if testing.Short() { + iters = 10 + } + seed := int64(time.Now().UnixNano()) + rs := rand.NewSource(seed) + t.Logf("seed=%v", seed) + return rs, iters +} + +func Test(t *testing.T) { + rs, iters := initTest(t) + options := []Options{ + Options{}, + Options{Threaded: true}, + Options{Threaded: true, Collide: true}, + } + for i := 0; i < iters; i++ { + p := prog.Generate(rs, 10, nil) + for _, opts := range options { + testOne(t, p, opts) + } + } +} + +func testOne(t *testing.T, p *prog.Prog, opts Options) { + src := Write(p, opts) + srcf, err := WriteTempFile(src) + if err != nil { + t.Fatalf("%v", err) + } + defer os.Remove(srcf) + bin, err := Build(srcf) + if err != nil { + t.Fatalf("%v", err) + } + defer os.Remove(bin) +} |
