summaryrefslogtreecommitdiffhomepage
path: root/tools/go_marshal/test
diff options
context:
space:
mode:
Diffstat (limited to 'tools/go_marshal/test')
-rw-r--r--tools/go_marshal/test/escape/escape.go26
-rw-r--r--tools/go_marshal/test/marshal_test.go114
2 files changed, 70 insertions, 70 deletions
diff --git a/tools/go_marshal/test/escape/escape.go b/tools/go_marshal/test/escape/escape.go
index ff23d87d1..7f62b0a2b 100644
--- a/tools/go_marshal/test/escape/escape.go
+++ b/tools/go_marshal/test/escape/escape.go
@@ -20,29 +20,29 @@ import (
"gvisor.dev/gvisor/tools/go_marshal/test"
)
-// dummyTask implements marshal.Task.
-type dummyTask struct {
+// dummyCopyContext implements marshal.CopyContext.
+type dummyCopyContext struct {
}
-func (*dummyTask) CopyScratchBuffer(size int) []byte {
+func (*dummyCopyContext) CopyScratchBuffer(size int) []byte {
return make([]byte, size)
}
-func (*dummyTask) CopyOutBytes(addr usermem.Addr, b []byte) (int, error) {
+func (*dummyCopyContext) CopyOutBytes(addr usermem.Addr, b []byte) (int, error) {
return len(b), nil
}
-func (*dummyTask) CopyInBytes(addr usermem.Addr, b []byte) (int, error) {
+func (*dummyCopyContext) CopyInBytes(addr usermem.Addr, b []byte) (int, error) {
return len(b), nil
}
-func (t *dummyTask) MarshalBytes(addr usermem.Addr, marshallable marshal.Marshallable) {
+func (t *dummyCopyContext) MarshalBytes(addr usermem.Addr, marshallable marshal.Marshallable) {
buf := t.CopyScratchBuffer(marshallable.SizeBytes())
marshallable.MarshalBytes(buf)
t.CopyOutBytes(addr, buf)
}
-func (t *dummyTask) MarshalUnsafe(addr usermem.Addr, marshallable marshal.Marshallable) {
+func (t *dummyCopyContext) MarshalUnsafe(addr usermem.Addr, marshallable marshal.Marshallable) {
buf := t.CopyScratchBuffer(marshallable.SizeBytes())
marshallable.MarshalUnsafe(buf)
t.CopyOutBytes(addr, buf)
@@ -50,14 +50,14 @@ func (t *dummyTask) MarshalUnsafe(addr usermem.Addr, marshallable marshal.Marsha
// +checkescape:all
//go:nosplit
-func doCopyIn(t *dummyTask) {
+func doCopyIn(t *dummyCopyContext) {
var stat test.Stat
stat.CopyIn(t, usermem.Addr(0xf000ba12))
}
// +checkescape:all
//go:nosplit
-func doCopyOut(t *dummyTask) {
+func doCopyOut(t *dummyCopyContext) {
var stat test.Stat
stat.CopyOut(t, usermem.Addr(0xf000ba12))
}
@@ -65,7 +65,7 @@ func doCopyOut(t *dummyTask) {
// +mustescape:builtin
// +mustescape:stack
//go:nosplit
-func doMarshalBytesDirect(t *dummyTask) {
+func doMarshalBytesDirect(t *dummyCopyContext) {
var stat test.Stat
buf := t.CopyScratchBuffer(stat.SizeBytes())
stat.MarshalBytes(buf)
@@ -75,7 +75,7 @@ func doMarshalBytesDirect(t *dummyTask) {
// +mustescape:builtin
// +mustescape:stack
//go:nosplit
-func doMarshalUnsafeDirect(t *dummyTask) {
+func doMarshalUnsafeDirect(t *dummyCopyContext) {
var stat test.Stat
buf := t.CopyScratchBuffer(stat.SizeBytes())
stat.MarshalUnsafe(buf)
@@ -85,7 +85,7 @@ func doMarshalUnsafeDirect(t *dummyTask) {
// +mustescape:local,heap
// +mustescape:stack
//go:nosplit
-func doMarshalBytesViaMarshallable(t *dummyTask) {
+func doMarshalBytesViaMarshallable(t *dummyCopyContext) {
var stat test.Stat
t.MarshalBytes(usermem.Addr(0xf000ba12), &stat)
}
@@ -93,7 +93,7 @@ func doMarshalBytesViaMarshallable(t *dummyTask) {
// +mustescape:local,heap
// +mustescape:stack
//go:nosplit
-func doMarshalUnsafeViaMarshallable(t *dummyTask) {
+func doMarshalUnsafeViaMarshallable(t *dummyCopyContext) {
var stat test.Stat
t.MarshalUnsafe(usermem.Addr(0xf000ba12), &stat)
}
diff --git a/tools/go_marshal/test/marshal_test.go b/tools/go_marshal/test/marshal_test.go
index 7c3481ac8..a00f9a684 100644
--- a/tools/go_marshal/test/marshal_test.go
+++ b/tools/go_marshal/test/marshal_test.go
@@ -36,13 +36,13 @@ import (
var simulatedErr error = syserror.EFAULT
-// mockTask implements marshal.Task.
-type mockTask struct {
+// mockCopyContext implements marshal.CopyContext.
+type mockCopyContext struct {
taskMem usermem.BytesIO
}
// populate fills the task memory with the contents of val.
-func (t *mockTask) populate(val interface{}) {
+func (t *mockCopyContext) populate(val interface{}) {
var buf bytes.Buffer
// Use binary.Write so we aren't testing go-marshal against its own
// potentially buggy implementation.
@@ -52,7 +52,7 @@ func (t *mockTask) populate(val interface{}) {
t.taskMem.Bytes = buf.Bytes()
}
-func (t *mockTask) setLimit(n int) {
+func (t *mockCopyContext) setLimit(n int) {
if len(t.taskMem.Bytes) < n {
grown := make([]byte, n)
copy(grown, t.taskMem.Bytes)
@@ -62,22 +62,22 @@ func (t *mockTask) setLimit(n int) {
t.taskMem.Bytes = t.taskMem.Bytes[:n]
}
-// CopyScratchBuffer implements marshal.Task.CopyScratchBuffer.
-func (t *mockTask) CopyScratchBuffer(size int) []byte {
+// CopyScratchBuffer implements marshal.CopyContext.CopyScratchBuffer.
+func (t *mockCopyContext) CopyScratchBuffer(size int) []byte {
return make([]byte, size)
}
-// CopyOutBytes implements marshal.Task.CopyOutBytes. The implementation
+// CopyOutBytes implements marshal.CopyContext.CopyOutBytes. The implementation
// completely ignores the target address and stores a copy of b in its
// internally buffer, overriding any previous contents.
-func (t *mockTask) CopyOutBytes(_ usermem.Addr, b []byte) (int, error) {
+func (t *mockCopyContext) CopyOutBytes(_ usermem.Addr, b []byte) (int, error) {
return t.taskMem.CopyOut(nil, 0, b, usermem.IOOpts{})
}
-// CopyInBytes implements marshal.Task.CopyInBytes. The implementation
+// CopyInBytes implements marshal.CopyContext.CopyInBytes. The implementation
// completely ignores the source address and always fills b from the begining of
// its internal buffer.
-func (t *mockTask) CopyInBytes(_ usermem.Addr, b []byte) (int, error) {
+func (t *mockCopyContext) CopyInBytes(_ usermem.Addr, b []byte) (int, error) {
return t.taskMem.CopyIn(nil, 0, b, usermem.IOOpts{})
}
@@ -171,11 +171,11 @@ func compareMemory(t *testing.T, expected, actual []byte, n int) {
// dst. The task signals an error at limit bytes during copy-in, which should
// result in a truncated unmarshalling.
func limitedCopyIn(t *testing.T, src, dst marshal.Marshallable, limit int) {
- var task mockTask
- task.populate(src)
- task.setLimit(limit)
+ var cc mockCopyContext
+ cc.populate(src)
+ cc.setLimit(limit)
- n, err := dst.CopyIn(&task, usermem.Addr(0))
+ n, err := dst.CopyIn(&cc, usermem.Addr(0))
if n != limit {
t.Errorf("CopyIn copied unexpected number of bytes, expected %d, got %d", limit, n)
}
@@ -202,10 +202,10 @@ func limitedCopyIn(t *testing.T, src, dst marshal.Marshallable, limit int) {
// limitedCopyOut marshals src to task memory. The task signals an error at
// limit bytes during copy-out, which should result in a truncated marshalling.
func limitedCopyOut(t *testing.T, src marshal.Marshallable, limit int) {
- var task mockTask
- task.setLimit(limit)
+ var cc mockCopyContext
+ cc.setLimit(limit)
- n, err := src.CopyOut(&task, usermem.Addr(0))
+ n, err := src.CopyOut(&cc, usermem.Addr(0))
if n != limit {
t.Errorf("CopyOut copied unexpected number of bytes, expected %d, got %d", limit, n)
}
@@ -215,7 +215,7 @@ func limitedCopyOut(t *testing.T, src marshal.Marshallable, limit int) {
expectedMem := unsafeMemory(src)
defer runtime.KeepAlive(src)
- actualMem := task.taskMem.Bytes
+ actualMem := cc.taskMem.Bytes
compareMemory(t, expectedMem, actualMem, n)
}
@@ -223,10 +223,10 @@ func limitedCopyOut(t *testing.T, src marshal.Marshallable, limit int) {
// copyOutN marshals src to task memory, requesting the marshalling to be
// limited to limit bytes.
func copyOutN(t *testing.T, src marshal.Marshallable, limit int) {
- var task mockTask
- task.setLimit(limit)
+ var cc mockCopyContext
+ cc.setLimit(limit)
- n, err := src.CopyOutN(&task, usermem.Addr(0), limit)
+ n, err := src.CopyOutN(&cc, usermem.Addr(0), limit)
if err != nil {
t.Errorf("CopyOut returned unexpected error: %v", err)
}
@@ -236,7 +236,7 @@ func copyOutN(t *testing.T, src marshal.Marshallable, limit int) {
expectedMem := unsafeMemory(src)
defer runtime.KeepAlive(src)
- actualMem := task.taskMem.Bytes
+ actualMem := cc.taskMem.Bytes
t.Logf("Expected: %v + %v\n", expectedMem[:n], expectedMem[n:])
t.Logf("Actual : %v + %v\n", actualMem[:n], actualMem[n:])
@@ -303,20 +303,20 @@ func TestLimitedMarshalling(t *testing.T) {
func TestLimitedSliceMarshalling(t *testing.T) {
types := []struct {
arrayPtrType reflect.Type
- copySliceIn func(task marshal.Task, addr usermem.Addr, dstSlice interface{}) (int, error)
- copySliceOut func(task marshal.Task, addr usermem.Addr, srcSlice interface{}) (int, error)
+ copySliceIn func(cc marshal.CopyContext, addr usermem.Addr, dstSlice interface{}) (int, error)
+ copySliceOut func(cc marshal.CopyContext, addr usermem.Addr, srcSlice interface{}) (int, error)
unsafeMemory func(arrPtr interface{}) []byte
}{
// Packed types.
{
reflect.TypeOf((*[20]test.Stat)(nil)),
- func(task marshal.Task, addr usermem.Addr, dst interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, dst interface{}) (int, error) {
slice := dst.(*[20]test.Stat)[:]
- return test.CopyStatSliceIn(task, addr, slice)
+ return test.CopyStatSliceIn(cc, addr, slice)
},
- func(task marshal.Task, addr usermem.Addr, src interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, src interface{}) (int, error) {
slice := src.(*[20]test.Stat)[:]
- return test.CopyStatSliceOut(task, addr, slice)
+ return test.CopyStatSliceOut(cc, addr, slice)
},
func(a interface{}) []byte {
slice := a.(*[20]test.Stat)[:]
@@ -325,13 +325,13 @@ func TestLimitedSliceMarshalling(t *testing.T) {
},
{
reflect.TypeOf((*[1]test.Stat)(nil)),
- func(task marshal.Task, addr usermem.Addr, dst interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, dst interface{}) (int, error) {
slice := dst.(*[1]test.Stat)[:]
- return test.CopyStatSliceIn(task, addr, slice)
+ return test.CopyStatSliceIn(cc, addr, slice)
},
- func(task marshal.Task, addr usermem.Addr, src interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, src interface{}) (int, error) {
slice := src.(*[1]test.Stat)[:]
- return test.CopyStatSliceOut(task, addr, slice)
+ return test.CopyStatSliceOut(cc, addr, slice)
},
func(a interface{}) []byte {
slice := a.(*[1]test.Stat)[:]
@@ -340,13 +340,13 @@ func TestLimitedSliceMarshalling(t *testing.T) {
},
{
reflect.TypeOf((*[5]test.SignalSetAlias)(nil)),
- func(task marshal.Task, addr usermem.Addr, dst interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, dst interface{}) (int, error) {
slice := dst.(*[5]test.SignalSetAlias)[:]
- return test.CopySignalSetAliasSliceIn(task, addr, slice)
+ return test.CopySignalSetAliasSliceIn(cc, addr, slice)
},
- func(task marshal.Task, addr usermem.Addr, src interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, src interface{}) (int, error) {
slice := src.(*[5]test.SignalSetAlias)[:]
- return test.CopySignalSetAliasSliceOut(task, addr, slice)
+ return test.CopySignalSetAliasSliceOut(cc, addr, slice)
},
func(a interface{}) []byte {
slice := a.(*[5]test.SignalSetAlias)[:]
@@ -356,13 +356,13 @@ func TestLimitedSliceMarshalling(t *testing.T) {
// Non-packed types.
{
reflect.TypeOf((*[20]test.Type1)(nil)),
- func(task marshal.Task, addr usermem.Addr, dst interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, dst interface{}) (int, error) {
slice := dst.(*[20]test.Type1)[:]
- return test.CopyType1SliceIn(task, addr, slice)
+ return test.CopyType1SliceIn(cc, addr, slice)
},
- func(task marshal.Task, addr usermem.Addr, src interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, src interface{}) (int, error) {
slice := src.(*[20]test.Type1)[:]
- return test.CopyType1SliceOut(task, addr, slice)
+ return test.CopyType1SliceOut(cc, addr, slice)
},
func(a interface{}) []byte {
slice := a.(*[20]test.Type1)[:]
@@ -371,13 +371,13 @@ func TestLimitedSliceMarshalling(t *testing.T) {
},
{
reflect.TypeOf((*[1]test.Type1)(nil)),
- func(task marshal.Task, addr usermem.Addr, dst interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, dst interface{}) (int, error) {
slice := dst.(*[1]test.Type1)[:]
- return test.CopyType1SliceIn(task, addr, slice)
+ return test.CopyType1SliceIn(cc, addr, slice)
},
- func(task marshal.Task, addr usermem.Addr, src interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, src interface{}) (int, error) {
slice := src.(*[1]test.Type1)[:]
- return test.CopyType1SliceOut(task, addr, slice)
+ return test.CopyType1SliceOut(cc, addr, slice)
},
func(a interface{}) []byte {
slice := a.(*[1]test.Type1)[:]
@@ -386,13 +386,13 @@ func TestLimitedSliceMarshalling(t *testing.T) {
},
{
reflect.TypeOf((*[7]test.Type8)(nil)),
- func(task marshal.Task, addr usermem.Addr, dst interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, dst interface{}) (int, error) {
slice := dst.(*[7]test.Type8)[:]
- return test.CopyType8SliceIn(task, addr, slice)
+ return test.CopyType8SliceIn(cc, addr, slice)
},
- func(task marshal.Task, addr usermem.Addr, src interface{}) (int, error) {
+ func(cc marshal.CopyContext, addr usermem.Addr, src interface{}) (int, error) {
slice := src.(*[7]test.Type8)[:]
- return test.CopyType8SliceOut(task, addr, slice)
+ return test.CopyType8SliceOut(cc, addr, slice)
},
func(a interface{}) []byte {
slice := a.(*[7]test.Type8)[:]
@@ -439,11 +439,11 @@ func TestLimitedSliceMarshalling(t *testing.T) {
limit += elem.SizeBytes() / 2
analysis.RandomizeValue(expected)
- var task mockTask
- task.populate(expected)
- task.setLimit(limit)
+ var cc mockCopyContext
+ cc.populate(expected)
+ cc.setLimit(limit)
- n, err := tt.copySliceIn(&task, usermem.Addr(0), actual)
+ n, err := tt.copySliceIn(&cc, usermem.Addr(0), actual)
if n != limit {
t.Errorf("CopyIn copied unexpected number of bytes, expected %d, got %d", limit, n)
}
@@ -493,11 +493,11 @@ func TestLimitedSliceMarshalling(t *testing.T) {
limit += elem.SizeBytes() / 2
analysis.RandomizeValue(expected)
- var task mockTask
- task.populate(expected)
- task.setLimit(limit)
+ var cc mockCopyContext
+ cc.populate(expected)
+ cc.setLimit(limit)
- n, err := tt.copySliceOut(&task, usermem.Addr(0), expected)
+ n, err := tt.copySliceOut(&cc, usermem.Addr(0), expected)
if n != limit {
t.Errorf("CopyIn copied unexpected number of bytes, expected %d, got %d", limit, n)
}
@@ -507,7 +507,7 @@ func TestLimitedSliceMarshalling(t *testing.T) {
expectedMem := tt.unsafeMemory(expected)
defer runtime.KeepAlive(expected)
- actualMem := task.taskMem.Bytes
+ actualMem := cc.taskMem.Bytes
compareMemory(t, expectedMem, actualMem, n)
})