mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-22 16:34:25 +01:00
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package vhost
|
|
|
|
import (
|
|
"testing"
|
|
"unsafe"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMemoryRegion_Size(t *testing.T) {
|
|
assert.EqualValues(t, 32, unsafe.Sizeof(MemoryRegion{}))
|
|
}
|
|
|
|
func TestMemoryLayout_SerializePayload(t *testing.T) {
|
|
layout := MemoryLayout([]MemoryRegion{
|
|
{
|
|
GuestPhysicalAddress: 42,
|
|
Size: 100,
|
|
UserspaceAddress: 142,
|
|
}, {
|
|
GuestPhysicalAddress: 99,
|
|
Size: 100,
|
|
UserspaceAddress: 99,
|
|
},
|
|
})
|
|
payload := layout.serializePayload()
|
|
|
|
assert.Equal(t, []byte{
|
|
0x02, 0x00, 0x00, 0x00, // nregions
|
|
0x00, 0x00, 0x00, 0x00, // padding
|
|
// region 0
|
|
0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // guest_phys_addr
|
|
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // memory_size
|
|
0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // userspace_addr
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // flags_padding
|
|
// region 1
|
|
0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // guest_phys_addr
|
|
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // memory_size
|
|
0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // userspace_addr
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // flags_padding
|
|
}, payload)
|
|
}
|