aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encoding_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-08-30 14:17:47 -0700
committerDmitry Vyukov <dvyukov@google.com>2018-08-30 21:45:03 -0700
commite8dd2c6713522707b3b89884eb95601cdf9bc9be (patch)
tree9df12a938af90c06794ec9f60920d59330766ed1 /prog/encoding_test.go
parent6ba5fe3e62880ddf8aeec68ab44eabaa8bc148b8 (diff)
prog: add concept of "special pointers"
Currently we only generate either valid user-space pointers or NULL. Extend NULL to a set of special pointers that we will use in programs. All targets now contain 3 special values: - NULL - 0xfffffffffffffff (invalid kernel pointer) - 0x999999999999999 (non-canonical address) Each target can add additional special pointers on top of this. Also generate NULL/special pointers for non-opt ptr's. This restriction was always too restrictive. We may want to generate them with very low probability, but we do want to generate them. Also change pointers to NULL/special during mutation (but still not in the opposite direction).
Diffstat (limited to 'prog/encoding_test.go')
-rw-r--r--prog/encoding_test.go36
1 files changed, 34 insertions, 2 deletions
diff --git a/prog/encoding_test.go b/prog/encoding_test.go
index 0b3364e63..1bb22228f 100644
--- a/prog/encoding_test.go
+++ b/prog/encoding_test.go
@@ -12,6 +12,8 @@ import (
"sort"
"strings"
"testing"
+
+ "github.com/google/go-cmp/cmp"
)
func setToArray(s map[string]struct{}) []string {
@@ -160,7 +162,7 @@ func TestDeserialize(t *testing.T) {
},
{
input: `test$excessive_fields1(0x0)`,
- output: `test$excessive_fields1(&(0x7f0000000000))`,
+ output: `test$excessive_fields1(0x0)`,
},
{
input: `test$excessive_fields1(r0)`,
@@ -206,6 +208,26 @@ func TestDeserialize(t *testing.T) {
input: `test$excessive_fields1(&(0x7f0000000000)=0x0)`,
output: `test$excessive_fields1(&(0x7f0000000000))`,
},
+ {
+ input: `test$excessive_fields1(0x0)`,
+ output: `test$excessive_fields1(0x0)`,
+ },
+ {
+ input: `test$excessive_fields1(0xffffffffffffffff)`,
+ output: `test$excessive_fields1(0xffffffffffffffff)`,
+ },
+ {
+ input: `test$excessive_fields1(0xfffffffffffffffe)`,
+ output: `test$excessive_fields1(0xfffffffffffffffe)`,
+ },
+ {
+ input: `test$excessive_fields1(0xfffffffffffffffd)`,
+ output: `test$excessive_fields1(0x0)`,
+ },
+ {
+ input: `test$excessive_fields1(0xfffffffffffffffc)`,
+ output: `test$excessive_fields1(0xffffffffffffffff)`,
+ },
}
buf := make([]byte, ExecBufferSize)
for _, test := range tests {
@@ -276,8 +298,18 @@ func TestSerializeDeserializeRandom(t *testing.T) {
})
ok, n0, n1 := testSerializeDeserialize(t, p0, data0, data1)
if ok {
- t.Fatal("flaky?")
+ t.Log("flaky?")
+ }
+ decoded0, err := target.DeserializeExec(data0[:n0])
+ if err != nil {
+ t.Fatal(err)
+ }
+ decoded1, err := target.DeserializeExec(data1[:n1])
+ if err != nil {
+ t.Fatal(err)
}
+ diff := cmp.Diff(decoded0, decoded1)
+ t.Logf("decoded diff: %v", diff)
t.Fatalf("was: %q\ngot: %q\nprogram:\n%s",
data0[:n0], data1[:n1], p0.Serialize())
}