aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encodingexec_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-09-24 11:46:43 +0200
committerDmitry Vyukov <dvyukov@google.com>2016-09-24 11:46:43 +0200
commit8904ff96b59a4f9433eae0897cce551fb0f1613d (patch)
treee7285032e703eec55bece91596e9bc597c728923 /prog/encodingexec_test.go
parent8f1cbd29ba7ce8fdfaf096663308c4be19074a82 (diff)
prog: add a simple test for exec encoding
Diffstat (limited to 'prog/encodingexec_test.go')
-rw-r--r--prog/encodingexec_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/prog/encodingexec_test.go b/prog/encodingexec_test.go
new file mode 100644
index 000000000..8c64581f9
--- /dev/null
+++ b/prog/encodingexec_test.go
@@ -0,0 +1,48 @@
+// Copyright 2016 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"
+ "encoding/binary"
+ "fmt"
+ "testing"
+
+ "github.com/google/syzkaller/sys"
+)
+
+func TestSerializeForExecRandom(t *testing.T) {
+ rs, iters := initTest(t)
+ for i := 0; i < iters; i++ {
+ p := Generate(rs, 10, nil)
+ p.SerializeForExec()
+ }
+}
+
+func TestSerializeForExec(t *testing.T) {
+ tests := []struct {
+ prog string
+ serialized []uint64
+ }{
+ {
+ "getpid()",
+ []uint64{uint64(sys.CallMap["getpid"].ID), 0, uint64(ExecInstrEOF)},
+ },
+ }
+ for i, test := range tests {
+ p, err := Deserialize([]byte(test.prog))
+ if err != nil {
+ t.Fatalf("failed to deserialize prog %v: %v", i, err)
+ }
+ t.Run(fmt.Sprintf("%v:%v", i, p.String()), func(t *testing.T) {
+ data := p.SerializeForExec()
+ w := new(bytes.Buffer)
+ binary.Write(w, binary.LittleEndian, test.serialized)
+ if !bytes.Equal(data, w.Bytes()) {
+ t.Fatalf("want %+q, got %+q", w.Bytes(), data)
+ }
+
+ })
+ }
+}