libgo: update to go1.9
[official-gcc.git] / libgo / go / runtime / memmove_linux_amd64_test.go
blobd0e8b42a5a708da2f0add38609e4150a36c18b22
1 // Copyright 2013 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 "io/ioutil"
9 "os"
10 "reflect"
11 "syscall"
12 "testing"
13 "unsafe"
16 // TestMemmoveOverflow maps 3GB of memory and calls memmove on
17 // the corresponding slice.
18 func TestMemmoveOverflow(t *testing.T) {
19 t.Parallel()
20 // Create a temporary file.
21 tmp, err := ioutil.TempFile("", "go-memmovetest")
22 if err != nil {
23 t.Fatal(err)
25 _, err = tmp.Write(make([]byte, 65536))
26 if err != nil {
27 t.Fatal(err)
29 defer os.Remove(tmp.Name())
30 defer tmp.Close()
32 // Set up mappings.
33 base, _, errno := syscall.Syscall6(syscall.SYS_MMAP,
34 0xa0<<32, 3<<30, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUS, ^uintptr(0), 0)
35 if errno != 0 {
36 t.Skipf("could not create memory mapping: %s", errno)
38 syscall.Syscall(syscall.SYS_MUNMAP, base, 3<<30, 0)
40 for off := uintptr(0); off < 3<<30; off += 65536 {
41 _, _, errno := syscall.Syscall6(syscall.SYS_MMAP,
42 base+off, 65536, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED|syscall.MAP_FIXED, tmp.Fd(), 0)
43 if errno != 0 {
44 t.Skipf("could not map a page at requested 0x%x: %s", base+off, errno)
46 defer syscall.Syscall(syscall.SYS_MUNMAP, base+off, 65536, 0)
49 var s []byte
50 sp := (*reflect.SliceHeader)(unsafe.Pointer(&s))
51 sp.Data = base
52 sp.Len, sp.Cap = 3<<30, 3<<30
54 n := copy(s[1:], s)
55 if n != 3<<30-1 {
56 t.Fatalf("copied %d bytes, expected %d", n, 3<<30-1)
58 n = copy(s, s[1:])
59 if n != 3<<30-1 {
60 t.Fatalf("copied %d bytes, expected %d", n, 3<<30-1)