1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00
gopher-os/src/gopheros/kernel/mem_util_test.go
Achilleas Anagnostopoulos e67e2644e2 mm: refactor package layout for the memory management code
Summary of changes:
- kernel/mem renamed to kernel/mm
- consolidated page/frame defs into one file which now lives in the
kernel/mm package and is referenced by both pmm and vmm pkgs
- consolidated parts of the vmm code (e.g. PDT+PTE)
- memcopy/memset helpers moved to the kernel package
- physical allocators moved to the kernel/mm/pmm package
- break vmm -> pmm pkg dependency by moving AllocFrame() into the mm
package.
2018-05-28 08:16:26 +01:00

55 lines
1.1 KiB
Go

package kernel
import (
"testing"
"unsafe"
)
const pageSize = 4096
func TestMemset(t *testing.T) {
// memset with a 0 size should be a no-op
Memset(uintptr(0), 0x00, 0)
for pageCount := uint32(1); pageCount <= 10; pageCount++ {
buf := make([]byte, pageSize<<pageCount)
for i := 0; i < len(buf); i++ {
buf[i] = 0xFE
}
addr := uintptr(unsafe.Pointer(&buf[0]))
Memset(addr, 0x00, uintptr(len(buf)))
for i := 0; i < len(buf); i++ {
if got := buf[i]; got != 0x00 {
t.Errorf("[block with %d pages] expected byte: %d to be 0x00; got 0x%x", pageCount, i, got)
}
}
}
}
func TestMemcopy(t *testing.T) {
// memcopy with a 0 size should be a no-op
Memcopy(uintptr(0), uintptr(0), 0)
var (
src = make([]byte, pageSize)
dst = make([]byte, pageSize)
)
for i := 0; i < len(src); i++ {
src[i] = byte(i % 256)
}
Memcopy(
uintptr(unsafe.Pointer(&src[0])),
uintptr(unsafe.Pointer(&dst[0])),
pageSize,
)
for i := 0; i < len(src); i++ {
if got := dst[i]; got != src[i] {
t.Errorf("value mismatch between src and dst at index %d", i)
}
}
}