aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/runtime/malloc_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-09-24 21:46:21 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-09-24 21:46:21 +0000
commitdd931d9b48647e898dc80927c532ae93cc09e192 (patch)
tree71be2295cd79b8a182f6130611658db8628772d5 /libgo/go/runtime/malloc_test.go
parent779d8a5ad09b01428726ea5a0e6c87bd9ac3c0e4 (diff)
downloadgcc-dd931d9b48647e898dc80927c532ae93cc09e192.zip
gcc-dd931d9b48647e898dc80927c532ae93cc09e192.tar.gz
gcc-dd931d9b48647e898dc80927c532ae93cc09e192.tar.bz2
libgo: update to Go 1.11
Reviewed-on: https://go-review.googlesource.com/136435 gotools/: * Makefile.am (mostlyclean-local): Run chmod on check-go-dir to make sure it is writable. (check-go-tools): Likewise. (check-vet): Copy internal/objabi to check-vet-dir. * Makefile.in: Rebuild. From-SVN: r264546
Diffstat (limited to 'libgo/go/runtime/malloc_test.go')
-rw-r--r--libgo/go/runtime/malloc_test.go76
1 files changed, 75 insertions, 1 deletions
diff --git a/libgo/go/runtime/malloc_test.go b/libgo/go/runtime/malloc_test.go
index ab580f8..30a7d84 100644
--- a/libgo/go/runtime/malloc_test.go
+++ b/libgo/go/runtime/malloc_test.go
@@ -7,16 +7,25 @@ package runtime_test
import (
"flag"
"fmt"
+ "internal/race"
+ "internal/testenv"
+ "os"
+ "os/exec"
"reflect"
. "runtime"
+ "strings"
"testing"
"time"
"unsafe"
)
+var testMemStatsCount int
+
func TestMemStats(t *testing.T) {
t.Skip("skipping test with gccgo")
+ testMemStatsCount++
+
// Make sure there's at least one forced GC.
GC()
@@ -32,6 +41,13 @@ func TestMemStats(t *testing.T) {
}
le := func(thresh float64) func(interface{}) error {
return func(x interface{}) error {
+ // These sanity tests aren't necessarily valid
+ // with high -test.count values, so only run
+ // them once.
+ if testMemStatsCount > 1 {
+ return nil
+ }
+
if reflect.ValueOf(x).Convert(reflect.TypeOf(thresh)).Float() < thresh {
return nil
}
@@ -50,7 +66,7 @@ func TestMemStats(t *testing.T) {
// PauseTotalNs can be 0 if timer resolution is poor.
fields := map[string][]func(interface{}) error{
"Alloc": {nz, le(1e10)}, "TotalAlloc": {nz, le(1e11)}, "Sys": {nz, le(1e10)},
- "Lookups": {nz, le(1e10)}, "Mallocs": {nz, le(1e10)}, "Frees": {nz, le(1e10)},
+ "Lookups": {eq(uint64(0))}, "Mallocs": {nz, le(1e10)}, "Frees": {nz, le(1e10)},
"HeapAlloc": {nz, le(1e10)}, "HeapSys": {nz, le(1e10)}, "HeapIdle": {le(1e10)},
"HeapInuse": {nz, le(1e10)}, "HeapReleased": {le(1e10)}, "HeapObjects": {nz, le(1e10)},
"StackInuse": {nz, le(1e10)}, "StackSys": {nz, le(1e10)},
@@ -154,6 +170,64 @@ func TestTinyAlloc(t *testing.T) {
}
}
+type acLink struct {
+ x [1 << 20]byte
+}
+
+var arenaCollisionSink []*acLink
+
+func TestArenaCollision(t *testing.T) {
+ testenv.MustHaveExec(t)
+
+ // Test that mheap.sysAlloc handles collisions with other
+ // memory mappings.
+ if os.Getenv("TEST_ARENA_COLLISION") != "1" {
+ cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestArenaCollision", "-test.v"))
+ cmd.Env = append(cmd.Env, "TEST_ARENA_COLLISION=1")
+ out, err := cmd.CombinedOutput()
+ if race.Enabled {
+ // This test runs the runtime out of hint
+ // addresses, so it will start mapping the
+ // heap wherever it can. The race detector
+ // doesn't support this, so look for the
+ // expected failure.
+ if want := "too many address space collisions"; !strings.Contains(string(out), want) {
+ t.Fatalf("want %q, got:\n%s", want, string(out))
+ }
+ } else if !strings.Contains(string(out), "PASS\n") || err != nil {
+ t.Fatalf("%s\n(exit status %v)", string(out), err)
+ }
+ return
+ }
+ disallowed := [][2]uintptr{}
+ // Drop all but the next 3 hints. 64-bit has a lot of hints,
+ // so it would take a lot of memory to go through all of them.
+ KeepNArenaHints(3)
+ // Consume these 3 hints and force the runtime to find some
+ // fallback hints.
+ for i := 0; i < 5; i++ {
+ // Reserve memory at the next hint so it can't be used
+ // for the heap.
+ start, end := MapNextArenaHint()
+ disallowed = append(disallowed, [2]uintptr{start, end})
+ // Allocate until the runtime tries to use the hint we
+ // just mapped over.
+ hint := GetNextArenaHint()
+ for GetNextArenaHint() == hint {
+ ac := new(acLink)
+ arenaCollisionSink = append(arenaCollisionSink, ac)
+ // The allocation must not have fallen into
+ // one of the reserved regions.
+ p := uintptr(unsafe.Pointer(ac))
+ for _, d := range disallowed {
+ if d[0] <= p && p < d[1] {
+ t.Fatalf("allocation %#x in reserved region [%#x, %#x)", p, d[0], d[1])
+ }
+ }
+ }
+ }
+}
+
var mallocSink uintptr
func BenchmarkMalloc8(b *testing.B) {