1
0
mirror of https://github.com/golang/go synced 2024-11-23 04:10:04 -07:00

cmd/cgo/internal/test: only test specific frames in testCallbackCallersSEH

testCallbackCallersSEH will break if anything in this call chain is
refactored to have a different number of function calls.

This change makes the test more robust by only testing the frames
that are actually relevant to the test.

Change-Id: Idb51514d7079f55da6e6ddc52ad43b1ffe32c8c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/545755
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
qmuntal 2023-11-29 11:15:54 +01:00 committed by Gopher Robot
parent 1908d4354b
commit b9a4eaa62b

View File

@ -29,7 +29,7 @@ USHORT backtrace(ULONG FramesToCapture, PVOID *BackTrace) {
} }
ControlPc = context.Rip; ControlPc = context.Rip;
// Check if we left the user range. // Check if we left the user range.
if (ControlPc < 0x10000) { if (ControlPc < 0x10000) {
break; break;
} }
@ -65,32 +65,17 @@ func testCallbackCallersSEH(t *testing.T) {
// TODO: support SEH on other architectures. // TODO: support SEH on other architectures.
t.Skip("skipping on non-amd64") t.Skip("skipping on non-amd64")
} }
const cgoexpPrefix = "_cgoexp_" // Only frames in the test package are checked.
want := []string{ want := []string{
"runtime.asmcgocall_landingpad",
"runtime.asmcgocall",
"runtime.cgocall",
"test._Cfunc_backtrace", "test._Cfunc_backtrace",
"test.testCallbackCallersSEH.func1.1", "test.testCallbackCallersSEH.func1.1",
"test.testCallbackCallersSEH.func1", "test.testCallbackCallersSEH.func1",
"test.goCallback", "test.goCallback",
cgoexpPrefix + "goCallback",
"runtime.cgocallbackg1",
"runtime.cgocallbackg",
"runtime.cgocallbackg",
"runtime.cgocallback",
"crosscall2",
"runtime.asmcgocall_landingpad",
"runtime.asmcgocall",
"runtime.cgocall",
"test._Cfunc_callback", "test._Cfunc_callback",
"test.nestedCall.func1", "test.nestedCall.func1",
"test.nestedCall", "test.nestedCall",
"test.testCallbackCallersSEH", "test.testCallbackCallersSEH",
"test.TestCallbackCallersSEH", "test.TestCallbackCallersSEH",
"testing.tRunner",
"testing.(*T).Run.gowrap1",
"runtime.goexit",
} }
pc := make([]uintptr, 100) pc := make([]uintptr, 100)
n := 0 n := 0
@ -105,26 +90,17 @@ func testCallbackCallersSEH(t *testing.T) {
} }
fname := f.Name() fname := f.Name()
switch fname { switch fname {
case "goCallback", "callback": case "goCallback":
// TODO(qmuntal): investigate why these functions don't appear // TODO(qmuntal): investigate why this function doesn't appear
// when using the external linker. // when using the external linker.
continue continue
} }
// Skip cgo-generated functions, the runtime might not know about them,
// depending on the link mode.
if strings.HasPrefix(fname, "_cgo_") {
continue
}
// Remove the cgo-generated random prefix.
if strings.HasPrefix(fname, cgoexpPrefix) {
idx := strings.Index(fname[len(cgoexpPrefix):], "_")
if idx >= 0 {
fname = cgoexpPrefix + fname[len(cgoexpPrefix)+idx+1:]
}
}
// In module mode, this package has a fully-qualified import path. // In module mode, this package has a fully-qualified import path.
// Remove it if present. // Remove it if present.
fname = strings.TrimPrefix(fname, "cmd/cgo/internal/") fname = strings.TrimPrefix(fname, "cmd/cgo/internal/")
if !strings.HasPrefix(fname, "test.") {
continue
}
got = append(got, fname) got = append(got, fname)
} }
if !reflect.DeepEqual(want, got) { if !reflect.DeepEqual(want, got) {