blob: 7124c54c25bf3b7d540af16323e172bcbebdf8b4 [file] [log] [blame]
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zx_test
import (
"syscall/zx"
"testing"
"unsafe"
)
func TestVmoInfo(t *testing.T) {
const vmoSize uint64 = 4096
const vmoName = "test-vmo"
vmo, err := zx.NewVMO(vmoSize, 0)
if err != nil {
t.Fatalf("zx.NewVMO(%d, 0) = %s", vmoSize, err)
}
defer func() {
if err := vmo.Close(); err != nil {
t.Errorf("vmo.Close() = %s", err)
}
}()
if err := vmo.Handle().SetProperty(zx.PropName, []byte(vmoName)); err != nil {
t.Fatalf("vmo.Handle().SetProperty(%d, %s) = %s", zx.PropName, vmoName, err)
}
var info zx.InfoVmo
if err := vmo.Handle().GetInfo(zx.ObjectInfoVMO, unsafe.Pointer(&info), uint(unsafe.Sizeof(info))); err != nil {
t.Fatalf("vmo.Handle().GetInfo(%d, _, %d) = %s", zx.ObjectInfoVMO, unsafe.Sizeof(info), err)
}
if info.Koid == 0 {
t.Errorf("info.Koid == 0, expected nonzero")
}
if got, want := string(info.Name[:len(vmoName)]), vmoName; got != want {
t.Errorf("got info.Name = %s, want = %s", got, want)
}
if got, want := info.SizeBytes, vmoSize; got != want {
t.Errorf("got info.SizeBytes = %d, want = %d", got, want)
}
if got, want := info.ParentKoid, uint64(0); got != want {
t.Errorf("got info.ParentKoid = %d, want = %d", got, want)
}
if got, want := info.NumChildren, uint(0); got != want {
t.Errorf("got info.NumChildren = %d, want = %d", got, want)
}
if got, want := info.NumMappings, uint(0); got != want {
t.Errorf("got info.NumMappings = %d, want = %d", got, want)
}
if got, want := info.ShareCount, uint(1); got != want {
t.Errorf("got info.ShareCount = %d, want = %d", got, want)
}
if got, want := info.Flags, uint32(zx.ZX_INFO_VMO_TYPE_PAGED|zx.ZX_INFO_VMO_VIA_HANDLE); got != want {
t.Errorf("got info.Flags = %d, want = %d", got, want)
}
if got, want := info.CommittedBytes, uint64(0); got != want {
t.Errorf("got info.CommittedBytes = %d, want = %d", got, want)
}
if got, want := info.CachePolicy, uint32(zx.ZX_CACHE_POLICY_CACHED); got != want {
t.Errorf("got info.CachePolicy = %d, want = %d", got, want)
}
if got, want := info.MetadataBytes, uint64(0); got != want {
t.Errorf("got info.MetadataBytes = %d, want = %d", got, want)
}
if got, want := info.CommittedChangeEvents, uint64(0); got != want {
t.Errorf("got info.CommittedChangeEvents = %d, want = %d", got, want)
}
}