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) }