mirror of
https://github.com/reactos/syzkaller.git
synced 2024-11-27 13:20:34 +00:00
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
// 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 prog
|
|
|
|
import (
|
|
"bytes"
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func initTest(t *testing.T) (rand.Source, int) {
|
|
iters := 10000
|
|
if testing.Short() {
|
|
iters = 100
|
|
}
|
|
seed := int64(time.Now().UnixNano())
|
|
rs := rand.NewSource(seed)
|
|
t.Logf("seed=%v", seed)
|
|
return rs, iters
|
|
}
|
|
|
|
func TestGeneration(t *testing.T) {
|
|
rs, iters := initTest(t)
|
|
for i := 0; i < iters; i++ {
|
|
Generate(rs, 20, nil)
|
|
}
|
|
}
|
|
|
|
func TestSerialize(t *testing.T) {
|
|
rs, iters := initTest(t)
|
|
for i := 0; i < iters; i++ {
|
|
p := Generate(rs, 10, nil)
|
|
data := p.Serialize()
|
|
p1, err := Deserialize(data)
|
|
if err != nil {
|
|
t.Fatalf("failed to deserialize program: %v\n%s", err, data)
|
|
}
|
|
data1 := p1.Serialize()
|
|
if len(p.Calls) != len(p1.Calls) {
|
|
t.Fatalf("different number of calls")
|
|
}
|
|
if !bytes.Equal(data, data1) {
|
|
t.Fatalf("program changed after serialize/deserialize\noriginal:\n%s\n\nnew:\n%s\n", data, data1)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSerializeForExec(t *testing.T) {
|
|
rs, iters := initTest(t)
|
|
for i := 0; i < iters; i++ {
|
|
p := Generate(rs, 10, nil)
|
|
p.SerializeForExec()
|
|
}
|
|
}
|
|
|
|
func TestSerializeC(t *testing.T) {
|
|
rs, iters := initTest(t)
|
|
for i := 0; i < iters; i++ {
|
|
p := Generate(rs, 10, nil)
|
|
p.WriteCSource()
|
|
}
|
|
}
|