From 09f84a75bc63a6316d575f531489d69ec8ade2e8 Mon Sep 17 00:00:00 2001 From: Ingo Oeser Date: Fri, 14 Jun 2013 23:22:50 +0200 Subject: Imported Upstream version 1.1.1 --- src/pkg/runtime/gc_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/pkg/runtime/gc_test.go') diff --git a/src/pkg/runtime/gc_test.go b/src/pkg/runtime/gc_test.go index 26fc77de1..a3c731ccb 100644 --- a/src/pkg/runtime/gc_test.go +++ b/src/pkg/runtime/gc_test.go @@ -97,3 +97,55 @@ func TestGcHashmapIndirection(t *testing.T) { m[a] = T{} } } + +func TestGcArraySlice(t *testing.T) { + type X struct { + buf [1]byte + nextbuf []byte + next *X + } + var head *X + for i := 0; i < 10; i++ { + p := &X{} + p.buf[0] = 42 + p.next = head + if head != nil { + p.nextbuf = head.buf[:] + } + head = p + runtime.GC() + } + for p := head; p != nil; p = p.next { + if p.buf[0] != 42 { + t.Fatal("corrupted heap") + } + } +} + +func TestGcRescan(t *testing.T) { + type X struct { + c chan error + nextx *X + } + type Y struct { + X + nexty *Y + p *int + } + var head *Y + for i := 0; i < 10; i++ { + p := &Y{} + p.c = make(chan error) + p.nextx = &head.X + p.nexty = head + p.p = new(int) + *p.p = 42 + head = p + runtime.GC() + } + for p := head; p != nil; p = p.nexty { + if *p.p != 42 { + t.Fatal("corrupted heap") + } + } +} -- cgit v1.2.3