Skip to content

Commit

Permalink
runtime: crash asap and extend total sleep time for slow machine in test
Browse files Browse the repository at this point in the history
  • Loading branch information
zzkcode committed Jan 8, 2024
1 parent 8db1310 commit 2eb8fef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/runtime/runtime-gdb_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"runtime"
"syscall"
"testing"
_ "unsafe" // for go:linkname
)

func canGenerateCore(t *testing.T) bool {
Expand Down Expand Up @@ -282,6 +283,9 @@ func main() {
}
`

//go:linkname totalSleepTimeUs runtime.totalSleepTimeUs
var totalSleepTimeUs int

// TestGdbCoreCrashThreadBacktrace tests that runtime could let the fault thread to crash process
// and make fault thread as number one thread while gdb in a core file
func TestGdbCoreCrashThreadBacktrace(t *testing.T) {
Expand All @@ -303,6 +307,7 @@ func TestGdbCoreCrashThreadBacktrace(t *testing.T) {

coreUsesPID := canGenerateCore(t)

totalSleepTimeUs = 60 * 1000 * 1000
// Build the source code.
dir := t.TempDir()
src := filepath.Join(dir, "main.go")
Expand Down
14 changes: 9 additions & 5 deletions src/runtime/signal_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ func adjustSignalStack(sig uint32, mp *m, gsigStack *gsignalStack) bool {
// GOTRACEBACK=crash when a signal is received.
var crashing atomic.Int32

// declared as global for dynamic change in TestGdbCoreCrashThreadBacktrace, see issue 64752.
var totalSleepTimeUs = 5 * 1000 * 1000

// testSigtrap and testSigusr1 are used by the runtime tests. If
// non-nil, it is called on SIGTRAP/SIGUSR1. If it returns true, the
// normal behavior on this signal is suppressed.
Expand Down Expand Up @@ -775,13 +778,14 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
raiseproc(_SIGQUIT)
}
if isCrashThread {
i := 0
for (crashing.Load() < mcount()-int32(extraMLength.Load())) && i < 10 {
i++
usleep(500 * 1000)
perLoopSleepTimeUs := 5000
i := totalSleepTimeUs / perLoopSleepTimeUs
for (crashing.Load() < mcount()-int32(extraMLength.Load())) && i > 0 {
i--
usleep(uint32(perLoopSleepTimeUs))
}
} else {
usleep(5 * 1000 * 1000)
usleep(uint32(totalSleepTimeUs))
}
printDebugLog()
crash()
Expand Down

0 comments on commit 2eb8fef

Please sign in to comment.