Skip to content

Commit

Permalink
runtime: fix TestDeferWithRepeatedRepanics and TestIssue37688 to be l…
Browse files Browse the repository at this point in the history
…ess chatty

Converted some Println() statements (used to make sure that certain variables were
kept alive and not optimized out) to assignments into global variables, so the
tests don't produce extraneous output when there is a failure.

Fixes golang#38594

Change-Id: I7eb41bb02b2b1e78afd7849676b5c85bc11c759c
Reviewed-on: https://go-review.googlesource.com/c/go/+/229538
Run-TryBot: Dan Scales <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
danscales committed Apr 23, 2020
1 parent 681ba43 commit 939379f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/runtime/defer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package runtime_test

import (
"fmt"
"os"
"reflect"
"runtime"
"testing"
Expand Down Expand Up @@ -325,11 +324,13 @@ func recurseFnPanicRec(level int, maxlevel int) {
recurseFn(level, maxlevel)
}

var saveInt uint32

func recurseFn(level int, maxlevel int) {
a := [40]uint32{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}
if level+1 < maxlevel {
// Need this print statement to keep a around. '_ = a[4]' doesn't do it.
fmt.Fprintln(os.Stderr, "recurseFn", level, a[4])
// Make sure a array is referenced, so it is not optimized away
saveInt = a[4]
recurseFn(level+1, maxlevel)
} else {
panic("recurseFn panic")
Expand All @@ -350,12 +351,12 @@ func TestIssue37688(t *testing.T) {
type foo struct {
}

//go:noinline
func (f *foo) method1() {
fmt.Fprintln(os.Stderr, "method1")
}

//go:noinline
func (f *foo) method2() {
fmt.Fprintln(os.Stderr, "method2")
}

func g2() {
Expand All @@ -379,6 +380,10 @@ func g3() {
g2()
}

var globstruct struct {
a, b, c, d, e, f, g, h, i int
}

func ff1(ap *foo, a, b, c, d, e, f, g, h, i int) {
defer ap.method1()

Expand All @@ -387,17 +392,21 @@ func ff1(ap *foo, a, b, c, d, e, f, g, h, i int) {
// defer pool)
defer func(ap *foo, a, b, c, d, e, f, g, h, i int) {
if v := recover(); v != nil {
fmt.Fprintln(os.Stderr, "did recover")
}
fmt.Fprintln(os.Stderr, "debug", ap, a, b, c, d, e, f, g, h)
globstruct.a = a
globstruct.b = b
globstruct.c = c
globstruct.d = d
globstruct.e = e
globstruct.f = f
globstruct.g = g
globstruct.h = h
}(ap, a, b, c, d, e, f, g, h, i)
panic("ff1 panic")
}

func rec1(max int) {
if max > 0 {
rec1(max - 1)
} else {
fmt.Fprintln(os.Stderr, "finished recursion", max)
}
}

0 comments on commit 939379f

Please sign in to comment.