aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encodingexec_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-12-22 11:47:04 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-12-22 11:59:46 +0100
commit3645389673af4c62a636cfe36f258ae770e8fb6b (patch)
tree356f9337e5ca323babef0e43fc345b0017dda798 /prog/encodingexec_test.go
parent6f298a18e582be006780954d6b0c30cbe2f568f4 (diff)
pkg/csource: fix handling of proc types
Generated program always uses pid=0 even when there are multiple processes. Make each process use own pid. Unfortunately required to do quite significant changes to prog, because the current format only supported fixed pid. Fixes #490
Diffstat (limited to 'prog/encodingexec_test.go')
-rw-r--r--prog/encodingexec_test.go255
1 files changed, 170 insertions, 85 deletions
diff --git a/prog/encodingexec_test.go b/prog/encodingexec_test.go
index 15d58d873..5c2c18534 100644
--- a/prog/encodingexec_test.go
+++ b/prog/encodingexec_test.go
@@ -16,7 +16,7 @@ func TestSerializeForExecRandom(t *testing.T) {
buf := make([]byte, ExecBufferSize)
for i := 0; i < iters; i++ {
p := target.Generate(rs, 10, nil)
- n, err := p.SerializeForExec(buf, i%16)
+ n, err := p.SerializeForExec(buf)
if err != nil {
t.Fatalf("failed to serialize: %v", err)
}
@@ -65,11 +65,11 @@ func TestSerializeForExec(t *testing.T) {
"syz_test$int(0x1, 0x2, 0x3, 0x4, 0x5)",
[]uint64{
callID("syz_test$int"), ExecNoCopyout, 5,
- execArgConst, 8, 1, 0, 0,
- execArgConst, 1, 2, 0, 0,
- execArgConst, 2, 3, 0, 0,
- execArgConst, 4, 4, 0, 0,
- execArgConst, 8, 5, 0, 0,
+ execArgConst, 8, 1,
+ execArgConst, 1, 2,
+ execArgConst, 2, 3,
+ execArgConst, 4, 4,
+ execArgConst, 8, 5,
execInstrEOF,
},
nil,
@@ -77,12 +77,12 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$align0(&(0x7f0000000000)={0x1, 0x2, 0x3, 0x4, 0x5})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 2, 1, 0, 0,
- execInstrCopyin, dataOffset + 4, execArgConst, 4, 2, 0, 0,
- execInstrCopyin, dataOffset + 8, execArgConst, 1, 3, 0, 0,
- execInstrCopyin, dataOffset + 10, execArgConst, 2, 4, 0, 0,
- execInstrCopyin, dataOffset + 16, execArgConst, 8, 5, 0, 0,
- callID("syz_test$align0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 2, 1,
+ execInstrCopyin, dataOffset + 4, execArgConst, 4, 2,
+ execInstrCopyin, dataOffset + 8, execArgConst, 1, 3,
+ execInstrCopyin, dataOffset + 10, execArgConst, 2, 4,
+ execInstrCopyin, dataOffset + 16, execArgConst, 8, 5,
+ callID("syz_test$align0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -90,12 +90,12 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$align1(&(0x7f0000000000)={0x1, 0x2, 0x3, 0x4, 0x5})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 2, 1, 0, 0,
- execInstrCopyin, dataOffset + 2, execArgConst, 4, 2, 0, 0,
- execInstrCopyin, dataOffset + 6, execArgConst, 1, 3, 0, 0,
- execInstrCopyin, dataOffset + 7, execArgConst, 2, 4, 0, 0,
- execInstrCopyin, dataOffset + 9, execArgConst, 8, 5, 0, 0,
- callID("syz_test$align1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 2, 1,
+ execInstrCopyin, dataOffset + 2, execArgConst, 4, 2,
+ execInstrCopyin, dataOffset + 6, execArgConst, 1, 3,
+ execInstrCopyin, dataOffset + 7, execArgConst, 2, 4,
+ execInstrCopyin, dataOffset + 9, execArgConst, 8, 5,
+ callID("syz_test$align1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -103,10 +103,10 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$align2(&(0x7f0000000000)={0x42, {[0x43]}, {[0x44]}})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 1, execArgConst, 2, 0x43, 0, 0,
- execInstrCopyin, dataOffset + 4, execArgConst, 2, 0x44, 0, 0,
- callID("syz_test$align2"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42,
+ execInstrCopyin, dataOffset + 1, execArgConst, 2, 0x43,
+ execInstrCopyin, dataOffset + 4, execArgConst, 2, 0x44,
+ callID("syz_test$align2"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -114,10 +114,10 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$align3(&(0x7f0000000000)={0x42, {0x43}, {0x44}})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 1, execArgConst, 1, 0x43, 0, 0,
- execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x44, 0, 0,
- callID("syz_test$align3"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42,
+ execInstrCopyin, dataOffset + 1, execArgConst, 1, 0x43,
+ execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x44,
+ callID("syz_test$align3"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -125,10 +125,10 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$align4(&(0x7f0000000000)={{0x42, 0x43}, 0x44})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 1, execArgConst, 2, 0x43, 0, 0,
- execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x44, 0, 0,
- callID("syz_test$align4"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42,
+ execInstrCopyin, dataOffset + 1, execArgConst, 2, 0x43,
+ execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x44,
+ callID("syz_test$align4"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -136,13 +136,13 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$align5(&(0x7f0000000000)={{0x42, []}, {0x43, [0x44, 0x45, 0x46]}, 0x47})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 8, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 8, execArgConst, 8, 0x43, 0, 0,
- execInstrCopyin, dataOffset + 16, execArgConst, 2, 0x44, 0, 0,
- execInstrCopyin, dataOffset + 18, execArgConst, 2, 0x45, 0, 0,
- execInstrCopyin, dataOffset + 20, execArgConst, 2, 0x46, 0, 0,
- execInstrCopyin, dataOffset + 22, execArgConst, 1, 0x47, 0, 0,
- callID("syz_test$align5"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 8, 0x42,
+ execInstrCopyin, dataOffset + 8, execArgConst, 8, 0x43,
+ execInstrCopyin, dataOffset + 16, execArgConst, 2, 0x44,
+ execInstrCopyin, dataOffset + 18, execArgConst, 2, 0x45,
+ execInstrCopyin, dataOffset + 20, execArgConst, 2, 0x46,
+ execInstrCopyin, dataOffset + 22, execArgConst, 1, 0x47,
+ callID("syz_test$align5"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -150,9 +150,9 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$align6(&(0x7f0000000000)={0x42, [0x43]})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 4, execArgConst, 4, 0x43, 0, 0,
- callID("syz_test$align6"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42,
+ execInstrCopyin, dataOffset + 4, execArgConst, 4, 0x43,
+ callID("syz_test$align6"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -160,9 +160,9 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$union0(&(0x7f0000000000)={0x1, @f2=0x2})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 8, 1, 0, 0,
- execInstrCopyin, dataOffset + 8, execArgConst, 1, 2, 0, 0,
- callID("syz_test$union0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 8, 1,
+ execInstrCopyin, dataOffset + 8, execArgConst, 1, 2,
+ callID("syz_test$union0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -170,9 +170,9 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$union1(&(0x7f0000000000)={@f1=0x42, 0x43})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 4, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 8, execArgConst, 1, 0x43, 0, 0,
- callID("syz_test$union1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 4, 0x42,
+ execInstrCopyin, dataOffset + 8, execArgConst, 1, 0x43,
+ callID("syz_test$union1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -180,9 +180,9 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$union2(&(0x7f0000000000)={@f1=0x42, 0x43})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 4, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x43, 0, 0,
- callID("syz_test$union2"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 4, 0x42,
+ execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x43,
+ callID("syz_test$union2"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -190,11 +190,11 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$array0(&(0x7f0000000000)={0x1, [@f0=0x2, @f1=0x3], 0x4})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 1, 1, 0, 0,
- execInstrCopyin, dataOffset + 1, execArgConst, 2, 2, 0, 0,
- execInstrCopyin, dataOffset + 3, execArgConst, 8, 3, 0, 0,
- execInstrCopyin, dataOffset + 11, execArgConst, 8, 4, 0, 0,
- callID("syz_test$array0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 1, 1,
+ execInstrCopyin, dataOffset + 1, execArgConst, 2, 2,
+ execInstrCopyin, dataOffset + 3, execArgConst, 8, 3,
+ execInstrCopyin, dataOffset + 11, execArgConst, 8, 4,
+ callID("syz_test$array0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -202,9 +202,9 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$array1(&(0x7f0000000000)={0x42, \"0102030405\"})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42,
execInstrCopyin, dataOffset + 1, execArgData, 5, 0x0504030201,
- callID("syz_test$array1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ callID("syz_test$array1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -212,10 +212,10 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$array2(&(0x7f0000000000)={0x42, \"aaaaaaaabbbbbbbbccccccccdddddddd\", 0x43})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 2, 0x42, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 2, 0x42,
execInstrCopyin, dataOffset + 2, execArgData, 16, 0xbbbbbbbbaaaaaaaa, 0xddddddddcccccccc,
- execInstrCopyin, dataOffset + 18, execArgConst, 2, 0x43, 0, 0,
- callID("syz_test$array2"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 18, execArgConst, 2, 0x43,
+ callID("syz_test$array2"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -223,11 +223,11 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$end0(&(0x7f0000000000)={0x42, 0x42, 0x42, 0x42})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 1, execArgConst, 2, 0x4200, 0, 0,
- execInstrCopyin, dataOffset + 3, execArgConst, 4, 0x42000000, 0, 0,
- execInstrCopyin, dataOffset + 7, execArgConst, 8, 0x4200000000000000, 0, 0,
- callID("syz_test$end0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 1, 0x42,
+ execInstrCopyin, dataOffset + 1, execArgConst, 2 | 1<<8, 0x42,
+ execInstrCopyin, dataOffset + 3, execArgConst, 4 | 1<<8, 0x42,
+ execInstrCopyin, dataOffset + 7, execArgConst, 8 | 1<<8, 0x42,
+ callID("syz_test$end0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -235,10 +235,10 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$end1(&(0x7f0000000000)={0xe, 0x42, 0x1})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 2, 0x0e00, 0, 0,
- execInstrCopyin, dataOffset + 2, execArgConst, 4, 0x42000000, 0, 0,
- execInstrCopyin, dataOffset + 6, execArgConst, 8, 0x0100000000000000, 0, 0,
- callID("syz_test$end1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 2 | 1<<8, 0xe,
+ execInstrCopyin, dataOffset + 2, execArgConst, 4 | 1<<8, 0x42,
+ execInstrCopyin, dataOffset + 6, execArgConst, 8 | 1<<8, 0x1,
+ callID("syz_test$end1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -246,27 +246,112 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$bf0(&(0x7f0000000000)={0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 2, 0x42, 0, 10,
- execInstrCopyin, dataOffset + 8, execArgConst, 8, 0x42, 0, 0,
- execInstrCopyin, dataOffset + 16, execArgConst, 2, 0x42, 0, 5,
- execInstrCopyin, dataOffset + 16, execArgConst, 2, 0x42, 5, 6,
- execInstrCopyin, dataOffset + 20, execArgConst, 4, 0x42, 0, 15,
- execInstrCopyin, dataOffset + 24, execArgConst, 2, 0x42, 0, 11,
- execInstrCopyin, dataOffset + 26, execArgConst, 2, 0x4200, 0, 11,
- execInstrCopyin, dataOffset + 28, execArgConst, 1, 0x42, 0, 0,
- callID("syz_test$bf0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 2 | 0<<16 | 10<<24, 0x42,
+ execInstrCopyin, dataOffset + 8, execArgConst, 8, 0x42,
+ execInstrCopyin, dataOffset + 16, execArgConst, 2 | 0<<16 | 5<<24, 0x42,
+ execInstrCopyin, dataOffset + 16, execArgConst, 2 | 5<<16 | 6<<24, 0x42,
+ execInstrCopyin, dataOffset + 20, execArgConst, 4 | 0<<16 | 15<<24, 0x42,
+ execInstrCopyin, dataOffset + 24, execArgConst, 2 | 0<<16 | 11<<24, 0x42,
+ execInstrCopyin, dataOffset + 26, execArgConst, 2 | 1<<8 | 0<<16 | 11<<24, 0x42,
+ execInstrCopyin, dataOffset + 28, execArgConst, 1, 0x42,
+ callID("syz_test$bf0"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
- nil,
+ &ExecProg{
+ Calls: []ExecCall{
+ {
+ Meta: target.SyscallMap["syz_test$bf0"],
+ Index: ExecNoCopyout,
+ Args: []ExecArg{
+ ExecArgConst{
+ Size: ptrSize,
+ Value: dataOffset,
+ },
+ },
+ Copyin: []ExecCopyin{
+ {
+ Addr: dataOffset + 0,
+ Arg: ExecArgConst{
+ Size: 2,
+ Value: 0x42,
+ BitfieldOffset: 0,
+ BitfieldLength: 10,
+ },
+ },
+ {
+ Addr: dataOffset + 8,
+ Arg: ExecArgConst{
+ Size: 8,
+ Value: 0x42,
+ },
+ },
+ {
+ Addr: dataOffset + 16,
+ Arg: ExecArgConst{
+ Size: 2,
+ Value: 0x42,
+ BitfieldOffset: 0,
+ BitfieldLength: 5,
+ },
+ },
+ {
+ Addr: dataOffset + 16,
+ Arg: ExecArgConst{
+ Size: 2,
+ Value: 0x42,
+ BitfieldOffset: 5,
+ BitfieldLength: 6,
+ },
+ },
+ {
+ Addr: dataOffset + 20,
+ Arg: ExecArgConst{
+ Size: 4,
+ Value: 0x42,
+ BitfieldOffset: 0,
+ BitfieldLength: 15,
+ },
+ },
+ {
+ Addr: dataOffset + 24,
+ Arg: ExecArgConst{
+ Size: 2,
+ Value: 0x42,
+ BitfieldOffset: 0,
+ BitfieldLength: 11,
+ },
+ },
+ {
+ Addr: dataOffset + 26,
+ Arg: ExecArgConst{
+ Size: 2,
+ Value: 0x42,
+ BitfieldOffset: 0,
+ BitfieldLength: 11,
+ BigEndian: true,
+ },
+ },
+ {
+ Addr: dataOffset + 28,
+ Arg: ExecArgConst{
+ Size: 1,
+ Value: 0x42,
+ },
+ },
+ },
+ },
+ },
+ NumVars: 0,
+ },
},
{
"syz_test$bf1(&(0x7f0000000000)={{0x42, 0x42, 0x42}, 0x42})",
[]uint64{
- execInstrCopyin, dataOffset + 0, execArgConst, 4, 0x42, 0, 10,
- execInstrCopyin, dataOffset + 0, execArgConst, 4, 0x42, 10, 10,
- execInstrCopyin, dataOffset + 0, execArgConst, 4, 0x42, 20, 10,
- execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x42, 0, 0,
- callID("syz_test$bf1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset, 0, 0,
+ execInstrCopyin, dataOffset + 0, execArgConst, 4 | 0<<16 | 10<<24, 0x42,
+ execInstrCopyin, dataOffset + 0, execArgConst, 4 | 10<<16 | 10<<24, 0x42,
+ execInstrCopyin, dataOffset + 0, execArgConst, 4 | 20<<16 | 10<<24, 0x42,
+ execInstrCopyin, dataOffset + 4, execArgConst, 1, 0x42,
+ callID("syz_test$bf1"), ExecNoCopyout, 1, execArgConst, ptrSize, dataOffset,
execInstrEOF,
},
nil,
@@ -274,7 +359,7 @@ func TestSerializeForExec(t *testing.T) {
{
"syz_test$res1(0xffff)",
[]uint64{
- callID("syz_test$res1"), ExecNoCopyout, 1, execArgConst, 4, 0xffff, 0, 0,
+ callID("syz_test$res1"), ExecNoCopyout, 1, execArgConst, 4, 0xffff,
execInstrEOF,
},
nil,
@@ -289,7 +374,7 @@ func TestSerializeForExec(t *testing.T) {
if err != nil {
t.Fatalf("failed to deserialize prog %v: %v", i, err)
}
- n, err := p.SerializeForExec(buf, i%16)
+ n, err := p.SerializeForExec(buf)
if err != nil {
t.Fatalf("failed to serialize: %v", err)
}