]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix TestSehUnwind
authorqmuntal <quimmuntal@gmail.com>
Mon, 15 Sep 2025 14:02:22 +0000 (16:02 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 16 Sep 2025 00:36:12 +0000 (17:36 -0700)
The various TestSehUnwind tests recently started to fail due an
unrelated refactor (in CL 698098) that made the stack frames to
not match the expected pattern. This CL updates the tests to
be more robust to such changes.

Fixes #75467

Change-Id: I7950332bb6ca54e4bf693d13e2490b3d9d901dde
Reviewed-on: https://go-review.googlesource.com/c/go/+/703779
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/runtime-seh_windows_test.go

index 8503a0550c4b25e6d6fd8561d54605107b5eba34..e1cd0601bbd3f2af8c97b0916eb26faac5ae54b6 100644 (file)
@@ -65,14 +65,20 @@ func TestSehLookupFunctionEntry(t *testing.T) {
        }
 }
 
-func sehCallers() []uintptr {
-       // We don't need a real context,
-       // RtlVirtualUnwind just needs a context with
-       // valid a pc, sp and fp (aka bp).
+//go:noinline
+func newCtx() *windows.Context {
        var ctx windows.Context
        ctx.SetPC(sys.GetCallerPC())
        ctx.SetSP(sys.GetCallerSP())
        ctx.SetFP(runtime.GetCallerFp())
+       return &ctx
+}
+
+func sehCallers() []uintptr {
+       // We don't need a real context,
+       // RtlVirtualUnwind just needs a context with
+       // valid a pc, sp and fp (aka bp).
+       ctx := newCtx()
 
        pcs := make([]uintptr, 15)
        var base, frame uintptr
@@ -84,7 +90,7 @@ func sehCallers() []uintptr {
                }
                pcs[i] = ctx.PC()
                n++
-               windows.RtlVirtualUnwind(0, base, ctx.PC(), fn, unsafe.Pointer(&ctx), nil, &frame, nil)
+               windows.RtlVirtualUnwind(0, base, ctx.PC(), fn, unsafe.Pointer(ctx), nil, &frame, nil)
        }
        return pcs[:n]
 }
@@ -120,6 +126,9 @@ func testSehCallersEqual(t *testing.T, pcs []uintptr, want []string) {
                        // These functions are skipped as they appear inconsistently depending
                        // whether inlining is on or off.
                        continue
+               case "runtime_test.sehCallers":
+                       // This is an artifact of the implementation of sehCallers.
+                       continue
                }
                got = append(got, name)
        }