Skip to content
Snippets Groups Projects
Commit 5ca57518 authored by eric fang's avatar eric fang Committed by Ian Lance Taylor
Browse files

runtime: fix TestCallersNilPointerPanic

The expected result of TestCallersNilPointerPanic has changed in
GoLLVM.  This CL makes some elements of the expected result optional
so that this test passes in both gccgo and GoLLVM.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/230138
parent 4f157ed7
No related branches found
No related tags found
No related merge requests found
8645632618262d1661ece0c9e6fe9e04c6e3a878 876bdf3df3bb33dbf1414237d84be5da32a48082
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -67,7 +67,7 @@ func testCallers(t *testing.T, pcs []uintptr, pan bool) { ...@@ -67,7 +67,7 @@ func testCallers(t *testing.T, pcs []uintptr, pan bool) {
} }
} }
func testCallersEqual(t *testing.T, pcs []uintptr, want []string) { func testCallersEqual(t *testing.T, pcs []uintptr, want []string, ignore map[string]struct{}) {
got := make([]string, 0, len(want)) got := make([]string, 0, len(want))
frames := runtime.CallersFrames(pcs) frames := runtime.CallersFrames(pcs)
...@@ -76,7 +76,9 @@ func testCallersEqual(t *testing.T, pcs []uintptr, want []string) { ...@@ -76,7 +76,9 @@ func testCallersEqual(t *testing.T, pcs []uintptr, want []string) {
if !more || len(got) >= len(want) { if !more || len(got) >= len(want) {
break break
} }
got = append(got, frame.Function) if _, ok := ignore[frame.Function]; !ok {
got = append(got, frame.Function)
}
} }
if !reflect.DeepEqual(want, got) { if !reflect.DeepEqual(want, got) {
t.Fatalf("wanted %v, got %v", want, got) t.Fatalf("wanted %v, got %v", want, got)
...@@ -106,7 +108,7 @@ func TestCallersPanic(t *testing.T) { ...@@ -106,7 +108,7 @@ func TestCallersPanic(t *testing.T) {
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallers(t, pcs, true) testCallers(t, pcs, true)
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
}() }()
f1(true) f1(true)
} }
...@@ -128,7 +130,7 @@ func TestCallersDoublePanic(t *testing.T) { ...@@ -128,7 +130,7 @@ func TestCallersDoublePanic(t *testing.T) {
if recover() == nil { if recover() == nil {
t.Fatal("did not panic") t.Fatal("did not panic")
} }
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
}() }()
if recover() == nil { if recover() == nil {
t.Fatal("did not panic") t.Fatal("did not panic")
...@@ -149,7 +151,7 @@ func TestCallersAfterRecovery(t *testing.T) { ...@@ -149,7 +151,7 @@ func TestCallersAfterRecovery(t *testing.T) {
defer func() { defer func() {
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
}() }()
defer func() { defer func() {
if recover() == nil { if recover() == nil {
...@@ -177,7 +179,7 @@ func TestCallersAbortedPanic(t *testing.T) { ...@@ -177,7 +179,7 @@ func TestCallersAbortedPanic(t *testing.T) {
// recovered, there is no remaining panic on the stack. // recovered, there is no remaining panic on the stack.
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
}() }()
defer func() { defer func() {
r := recover() r := recover()
...@@ -208,7 +210,7 @@ func TestCallersAbortedPanic2(t *testing.T) { ...@@ -208,7 +210,7 @@ func TestCallersAbortedPanic2(t *testing.T) {
defer func() { defer func() {
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
}() }()
func() { func() {
defer func() { defer func() {
...@@ -233,10 +235,16 @@ func TestCallersNilPointerPanic(t *testing.T) { ...@@ -233,10 +235,16 @@ func TestCallersNilPointerPanic(t *testing.T) {
want := []string{"runtime.Callers", "runtime_test.TestCallersNilPointerPanic.func1", want := []string{"runtime.Callers", "runtime_test.TestCallersNilPointerPanic.func1",
"runtime.gopanic", "runtime.panicmem", "runtime.sigpanic", "runtime.gopanic", "runtime.panicmem", "runtime.sigpanic",
"runtime_test.TestCallersNilPointerPanic"} "runtime_test.TestCallersNilPointerPanic"}
ign := make(map[string]struct{})
if runtime.Compiler == "gccgo" { if runtime.Compiler == "gccgo" {
// The expected results of gollvm and gccgo are slightly different, the result
// of gccgo does not contain tRunner, and the result of gollvm does not contain
// sigpanic. Make these two elementes optional to pass both of gollvm and gccgo.
want = []string{"runtime.Callers", "runtime_test.TestCallersNilPointerPanic..func1", want = []string{"runtime.Callers", "runtime_test.TestCallersNilPointerPanic..func1",
"runtime.gopanic", "runtime.panicmem", "runtime.sigpanic", "runtime.gopanic", "runtime.panicmem",
"runtime_test.TestCallersNilPointerPanic"} "runtime_test.TestCallersNilPointerPanic"}
ign["runtime.sigpanic"] = struct{}{}
ign["testing.tRunner"] = struct{}{}
} }
defer func() { defer func() {
...@@ -245,7 +253,7 @@ func TestCallersNilPointerPanic(t *testing.T) { ...@@ -245,7 +253,7 @@ func TestCallersNilPointerPanic(t *testing.T) {
} }
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, ign)
}() }()
var p *int var p *int
if *p == 3 { if *p == 3 {
...@@ -271,7 +279,7 @@ func TestCallersDivZeroPanic(t *testing.T) { ...@@ -271,7 +279,7 @@ func TestCallersDivZeroPanic(t *testing.T) {
} }
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
}() }()
var n int var n int
if 5/n == 1 { if 5/n == 1 {
...@@ -298,7 +306,7 @@ func TestCallersDeferNilFuncPanic(t *testing.T) { ...@@ -298,7 +306,7 @@ func TestCallersDeferNilFuncPanic(t *testing.T) {
} }
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
if state == 1 { if state == 1 {
t.Fatal("nil defer func panicked at defer time rather than function exit time") t.Fatal("nil defer func panicked at defer time rather than function exit time")
} }
...@@ -328,7 +336,7 @@ func TestCallersDeferNilFuncPanicWithLoop(t *testing.T) { ...@@ -328,7 +336,7 @@ func TestCallersDeferNilFuncPanicWithLoop(t *testing.T) {
} }
pcs := make([]uintptr, 20) pcs := make([]uintptr, 20)
pcs = pcs[:runtime.Callers(0, pcs)] pcs = pcs[:runtime.Callers(0, pcs)]
testCallersEqual(t, pcs, want) testCallersEqual(t, pcs, want, nil)
if state == 1 { if state == 1 {
t.Fatal("nil defer func panicked at defer time rather than function exit time") t.Fatal("nil defer func panicked at defer time rather than function exit time")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment