| 1 | package sysenc_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "unsafe" |
| 6 | |
| 7 | "github.com/go-quicktest/qt" |
| 8 | |
| 9 | "github.com/cilium/ebpf/internal/sys" |
| 10 | "github.com/cilium/ebpf/internal/sysenc" |
| 11 | ) |
| 12 | |
| 13 | func TestZeroBuffer(t *testing.T) { |
| 14 | var zero sysenc.Buffer |
| 15 | |
| 16 | qt.Assert(t, qt.Equals(zero.CopyTo(make([]byte, 1)), 0)) |
| 17 | qt.Assert(t, qt.Equals(zero.Pointer(), sys.Pointer{})) |
| 18 | qt.Assert(t, qt.IsNotNil(zero.Unmarshal(new(uint16)))) |
| 19 | } |
| 20 | |
| 21 | func TestUnsafeBuffer(t *testing.T) { |
| 22 | ptr := unsafe.Pointer(new(uint16)) |
| 23 | buf := sysenc.UnsafeBuffer(ptr) |
| 24 | |
| 25 | qt.Assert(t, qt.Equals(buf.CopyTo(make([]byte, 1)), 0)) |
| 26 | qt.Assert(t, qt.Equals(buf.Pointer(), sys.UnsafePointer(ptr))) |
| 27 | qt.Assert(t, qt.IsNil(buf.Unmarshal(new(uint16)))) |
| 28 | } |