reflect: canonicalize types returned by StructOf() and friends
[official-gcc.git] / gcc / testsuite / go.test / test / init1.go
blobf6eda6edfea011941eb5f38d53c5d6d394a0eadb
1 // run
3 // Copyright 2011 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test that goroutines and garbage collection run during init.
9 package main
11 import "runtime"
13 var x []byte
15 func init() {
16 c := make(chan int)
17 go send(c)
18 <-c
20 const chunk = 1 << 20
21 memstats := new(runtime.MemStats)
22 runtime.ReadMemStats(memstats)
23 sys := memstats.Sys
24 b := make([]byte, chunk)
25 for i := range b {
26 b[i] = byte(i%10 + '0')
28 s := string(b)
29 for i := 0; i < 1000; i++ {
30 x = []byte(s)
32 runtime.ReadMemStats(memstats)
33 sys1 := memstats.Sys
34 if sys1-sys > chunk*50 {
35 println("allocated 1000 chunks of", chunk, "and used ", sys1-sys, "memory")
36 panic("init1")
40 func send(c chan int) {
41 c <- 1
44 func main() {