1
0
mirror of https://github.com/golang/go synced 2024-11-14 08:10:22 -07:00
go/test/gc2.go
Richard Musiol e3c684777a all: skip unsupported tests for js/wasm
The general policy for the current state of js/wasm is that it only
has to support tests that are also supported by nacl.

The test nilptr3.go makes assumptions about which nil checks can be
removed. Since WebAssembly does not signal on reading a null pointer,
all nil checks have to be explicit.

Updates #18892

Change-Id: I06a687860b8d22ae26b1c391499c0f5183e4c485
Reviewed-on: https://go-review.googlesource.com/110096
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-30 19:39:18 +00:00

46 lines
972 B
Go

// +build !nacl,!js
// run
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that buffered channels are garbage collected properly.
// An interesting case because they have finalizers and used to
// have self loops that kept them from being collected.
// (Cyclic data with finalizers is never finalized, nor collected.)
package main
import (
"fmt"
"os"
"runtime"
)
func main() {
const N = 10000
st := new(runtime.MemStats)
memstats := new(runtime.MemStats)
runtime.ReadMemStats(st)
for i := 0; i < N; i++ {
c := make(chan int, 10)
_ = c
if i%100 == 0 {
for j := 0; j < 4; j++ {
runtime.GC()
runtime.Gosched()
runtime.GC()
runtime.Gosched()
}
}
}
runtime.ReadMemStats(memstats)
obj := int64(memstats.HeapObjects - st.HeapObjects)
if obj > N/5 {
fmt.Println("too many objects left:", obj)
os.Exit(1)
}
}