2012-05-29 23:10:54 -06:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build cgo
|
|
|
|
|
|
|
|
package runtime_test
|
|
|
|
|
|
|
|
import (
|
2013-08-07 14:04:28 -06:00
|
|
|
"runtime"
|
2012-05-29 23:10:54 -06:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCgoCrashHandler(t *testing.T) {
|
2013-02-20 01:15:02 -07:00
|
|
|
testCrashHandler(t, true)
|
2012-05-29 23:10:54 -06:00
|
|
|
}
|
2013-02-28 01:07:26 -07:00
|
|
|
|
|
|
|
func TestCgoSignalDeadlock(t *testing.T) {
|
2013-08-07 14:04:28 -06:00
|
|
|
if testing.Short() && runtime.GOOS == "windows" {
|
|
|
|
t.Skip("Skipping in short mode") // takes up to 64 seconds
|
|
|
|
}
|
2013-02-28 01:07:26 -07:00
|
|
|
got := executeTest(t, cgoSignalDeadlockSource, nil)
|
|
|
|
want := "OK\n"
|
|
|
|
if got != want {
|
|
|
|
t.Fatalf("expected %q, but got %q", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const cgoSignalDeadlockSource = `
|
|
|
|
package main
|
|
|
|
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
runtime.GOMAXPROCS(100)
|
|
|
|
ping := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
runtime.Gosched()
|
|
|
|
select {
|
|
|
|
case done := <-ping:
|
|
|
|
if done {
|
|
|
|
ping <- true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ping <- true
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
func() {
|
|
|
|
defer func() {
|
|
|
|
recover()
|
|
|
|
}()
|
|
|
|
var s *string
|
|
|
|
*s = ""
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
time.Sleep(time.Millisecond)
|
|
|
|
for i := 0; i < 64; i++ {
|
|
|
|
go func() {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
select {}
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
select {}
|
|
|
|
}()
|
|
|
|
time.Sleep(time.Millisecond)
|
|
|
|
ping <- false
|
|
|
|
select {
|
|
|
|
case <-ping:
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
fmt.Printf("HANG\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ping <- true
|
|
|
|
select {
|
|
|
|
case <-ping:
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
fmt.Printf("HANG\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Printf("OK\n")
|
|
|
|
}
|
|
|
|
`
|