Daily bump.
[official-gcc.git] / libgo / go / runtime / crash_cgo_test.go
blobb534b89e5596265b1d0b5f108fbecbf935b171dc
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build cgo
7 package runtime_test
9 import (
10 "runtime"
11 "testing"
14 func TestCgoCrashHandler(t *testing.T) {
15 testCrashHandler(t, true)
18 func TestCgoSignalDeadlock(t *testing.T) {
19 if testing.Short() && runtime.GOOS == "windows" {
20 t.Skip("Skipping in short mode") // takes up to 64 seconds
22 t.Skip("gccgo does not have a go command")
23 got := executeTest(t, cgoSignalDeadlockSource, nil)
24 want := "OK\n"
25 if got != want {
26 t.Fatalf("expected %q, but got %q", want, got)
30 func TestCgoTraceback(t *testing.T) {
31 got := executeTest(t, cgoTracebackSource, nil)
32 want := "OK\n"
33 if got != want {
34 t.Fatalf("expected %q, but got %q", want, got)
38 const cgoSignalDeadlockSource = `
39 package main
41 import "C"
43 import (
44 "fmt"
45 "runtime"
46 "time"
49 func main() {
50 runtime.GOMAXPROCS(100)
51 ping := make(chan bool)
52 go func() {
53 for i := 0; ; i++ {
54 runtime.Gosched()
55 select {
56 case done := <-ping:
57 if done {
58 ping <- true
59 return
61 ping <- true
62 default:
64 func() {
65 defer func() {
66 recover()
67 }()
68 var s *string
69 *s = ""
70 }()
72 }()
73 time.Sleep(time.Millisecond)
74 for i := 0; i < 64; i++ {
75 go func() {
76 runtime.LockOSThread()
77 select {}
78 }()
79 go func() {
80 runtime.LockOSThread()
81 select {}
82 }()
83 time.Sleep(time.Millisecond)
84 ping <- false
85 select {
86 case <-ping:
87 case <-time.After(time.Second):
88 fmt.Printf("HANG\n")
89 return
92 ping <- true
93 select {
94 case <-ping:
95 case <-time.After(time.Second):
96 fmt.Printf("HANG\n")
97 return
99 fmt.Printf("OK\n")
103 const cgoTracebackSource = `
104 package main
106 /* void foo(void) {} */
107 import "C"
109 import (
110 "fmt"
111 "runtime"
114 func main() {
115 C.foo()
116 buf := make([]byte, 1)
117 runtime.Stack(buf, true)
118 fmt.Printf("OK\n")