1 // Copyright 2011 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.
14 func TestGcSys(t
*testing
.T
) {
15 /* gccgo does not have a go command
16 if os.Getenv("GOGC") == "off" {
17 t.Skip("skipping test; GOGC=off in environment")
19 data := struct{ Short bool }{testing.Short()}
20 got := executeTest(t, testGCSysSource, &data)
23 t.Fatalf("expected %q, but got %q", want, got)
28 const testGCSysSource
= `
38 memstats := new(runtime.MemStats)
40 runtime.ReadMemStats(memstats)
43 runtime.MemProfileRate = 0 // disable profiler
49 for i := 0; i < itercount; i++ {
53 // Should only be using a few MB.
54 // We allocated 100 MB or (if not short) 1 GB.
55 runtime.ReadMemStats(memstats)
56 if sys > memstats.Sys {
59 sys = memstats.Sys - sys
62 fmt.Printf("using too much memory: %d bytes\n", sys)
68 func workthegc() []byte {
69 return make([]byte, 1029)
73 func TestGcDeepNesting(t
*testing
.T
) {
74 type T
[2][2][2][2][2][2][2][2][2][2]*int
77 // Prevent the compiler from applying escape analysis.
78 // This makes sure new(T) is allocated on heap, not on the stack.
81 a
[0][0][0][0][0][0][0][0][0][0] = new(int)
82 *a
[0][0][0][0][0][0][0][0][0][0] = 13
84 if *a
[0][0][0][0][0][0][0][0][0][0] != 13 {
89 func TestGcHashmapIndirection(t
*testing
.T
) {
90 defer debug
.SetGCPercent(debug
.SetGCPercent(1))
96 for i
:= 0; i
< 2000; i
++ {
103 func TestGcArraySlice(t
*testing
.T
) {
110 for i
:= 0; i
< 10; i
++ {
115 p
.nextbuf
= head
.buf
[:]
120 for p
:= head
; p
!= nil; p
= p
.next
{
122 t
.Fatal("corrupted heap")
127 func TestGcRescan(t
*testing
.T
) {
138 for i
:= 0; i
< 10; i
++ {
140 p
.c
= make(chan error
)
148 for p
:= head
; p
!= nil; p
= p
.nexty
{
150 t
.Fatal("corrupted heap")