1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Cleanup Frame tests and rename Frame.IsValid to Frame.Valid

This commit is contained in:
Achilleas Anagnostopoulos 2017-05-31 17:00:24 +01:00
parent ff8aabe51f
commit 1a6ade8ced
3 changed files with 16 additions and 13 deletions

View File

@ -49,7 +49,7 @@ func TestBootMemoryAllocator(t *testing.T) {
t.Errorf("[frame %d] expected frame address to be 0x%x; got 0x%x", allocFrameCount, expAddress, got) t.Errorf("[frame %d] expected frame address to be 0x%x; got 0x%x", allocFrameCount, expAddress, got)
} }
if !frame.IsValid() { if !frame.Valid() {
t.Errorf("[frame %d] expected IsValid() to return true", allocFrameCount) t.Errorf("[frame %d] expected IsValid() to return true", allocFrameCount)
} }
} }
@ -59,7 +59,7 @@ func TestBootMemoryAllocator(t *testing.T) {
} }
// This allocator only works with order(0) blocks // This allocator only works with order(0) blocks
if frame, err := alloc.AllocFrame(mem.PageOrder(1)); err != errBootAllocUnsupportedPageSize || frame.IsValid() { if frame, err := alloc.AllocFrame(mem.PageOrder(1)); err != errBootAllocUnsupportedPageSize || frame.Valid() {
t.Fatalf("expected allocator to return errBootAllocUnsupportedPageSize and an invalid frame when requested to allocate a block with order > 0; got %v, %v", err, frame) t.Fatalf("expected allocator to return errBootAllocUnsupportedPageSize and an invalid frame when requested to allocate a block with order > 0; got %v, %v", err, frame)
} }
} }

View File

@ -16,8 +16,8 @@ const (
InvalidFrame = Frame(math.MaxUint64) InvalidFrame = Frame(math.MaxUint64)
) )
// IsValid returns true if this is a valid frame. // Valid returns true if this is a valid frame.
func (f Frame) IsValid() bool { func (f Frame) Valid() bool {
return f != InvalidFrame return f != InvalidFrame
} }

View File

@ -7,17 +7,20 @@ import (
) )
func TestFrameMethods(t *testing.T) { func TestFrameMethods(t *testing.T) {
for order := mem.PageOrder(0); order < mem.PageOrder(10); order++ { for frameIndex := uint64(0); frameIndex < 128; frameIndex++ {
for frameIndex := uint64(0); frameIndex < 128; frameIndex++ { frame := Frame(frameIndex)
frame := Frame(frameIndex | (uint64(order) << 56))
if !frame.IsValid() { if !frame.Valid() {
t.Errorf("[order %d] expected frame %d to be valid", order, frameIndex) t.Errorf("expected frame %d to be valid", frameIndex)
} }
if exp, got := uintptr(frameIndex<<mem.PageShift), frame.Address(); got != exp { if exp, got := uintptr(frameIndex<<mem.PageShift), frame.Address(); got != exp {
t.Errorf("[order %d] expected frame (%d, index: %d) call to Address() to return %x; got %x", order, frame, frameIndex, exp, got) t.Errorf("expected frame (%d, index: %d) call to Address() to return %x; got %x", frame, frameIndex, exp, got)
}
} }
} }
invalidFrame := InvalidFrame
if invalidFrame.Valid() {
t.Error("expected InvalidFrame.Valid() to return false")
}
} }