runtime: sleep in TestSegv program to let signal be delivered

Since we're sleeping rather than waiting for the goroutines,
let the goroutines run forever.

Fixes #38595

Change-Id: I4cd611fd7565f6e8d91e50c9273d91c514825314
Reviewed-on: https://go-review.googlesource.com/c/go/+/229484
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Ian Lance Taylor 2020-04-22 16:03:30 -07:00
parent c53d1236df
commit 1cc46d3a25
1 changed files with 7 additions and 11 deletions

View File

@ -10,8 +10,8 @@ package main
import "C"
import (
"sync"
"syscall"
"time"
)
func init() {
@ -23,12 +23,9 @@ var Sum int
func Segv() {
c := make(chan bool)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
close(c)
for i := 0; i < 10000; i++ {
for i := 0; ; i++ {
Sum += i
}
}()
@ -37,17 +34,15 @@ func Segv() {
syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
wg.Wait()
// Give the OS time to deliver the signal.
time.Sleep(time.Second)
}
func SegvInCgo() {
c := make(chan bool)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
close(c)
for i := 0; i < 10000; i++ {
for {
C.nop()
}
}()
@ -56,5 +51,6 @@ func SegvInCgo() {
syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
wg.Wait()
// Give the OS time to deliver the signal.
time.Sleep(time.Second)
}