runtime: scan register backing store on ia64
[official-gcc.git] / libgo / go / runtime / runtime_mmap_test.go
blobc0040414d46f6cb76ca960db74bd57f667e2590b
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package runtime_test
7 import (
8 "runtime"
9 "testing"
10 "unsafe"
13 // Test that the error value returned by mmap is positive, as that is
14 // what the code in mem_bsd.go, mem_darwin.go, and mem_linux.go expects.
15 // See the uses of ENOMEM in sysMap in those files.
16 func TestMmapErrorSign(t *testing.T) {
17 p, err := runtime.Mmap(nil, ^uintptr(0)&^(runtime.GetPhysPageSize()-1), 0, runtime.MAP_ANON|runtime.MAP_PRIVATE, -1, 0)
19 if p != nil || err != runtime.ENOMEM {
20 t.Errorf("mmap = %v, %v, want nil, %v", p, err, runtime.ENOMEM)
24 func TestPhysPageSize(t *testing.T) {
25 // Mmap fails if the address is not page aligned, so we can
26 // use this to test if the page size is the true page size.
27 ps := runtime.GetPhysPageSize()
29 // Get a region of memory to play with. This should be page-aligned.
30 b, err := runtime.Mmap(nil, 2*ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE, -1, 0)
31 if err != 0 {
32 t.Fatalf("Mmap: %v", err)
35 // Mmap should fail at a half page into the buffer.
36 _, err = runtime.Mmap(unsafe.Pointer(uintptr(b)+ps/2), ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE|runtime.MAP_FIXED, -1, 0)
37 if err == 0 {
38 t.Errorf("Mmap should have failed with half-page alignment %d, but succeeded: %v", ps/2, err)
41 // Mmap should succeed at a full page into the buffer.
42 _, err = runtime.Mmap(unsafe.Pointer(uintptr(b)+ps), ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE|runtime.MAP_FIXED, -1, 0)
43 if err != 0 {
44 t.Errorf("Mmap at full-page alignment %d failed: %v", ps, err)