Skip to content

Commit dc032ab

Browse files
committed
wip: test: added cgo trace parse test, should be passed in on platforms.
just a test for golang#54458
1 parent e49e876 commit dc032ab

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/runtime/crash_cgo_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,15 @@ func TestCgoTracebackGoroutineProfile(t *testing.T) {
710710
t.Fatalf("want %s, got %s\n", want, output)
711711
}
712712
}
713+
714+
func TestCgoTraceParser(t *testing.T) {
715+
switch runtime.GOOS {
716+
case "windows", "plan9":
717+
t.Skipf("skipping cgo trace parser test on %s", runtime.GOOS)
718+
}
719+
output := runTestProg(t, "testprogcgo", "CgoTraceParser")
720+
want := "OK\n"
721+
if output != want {
722+
t.Fatalf("want %s, got %s\n", want, output)
723+
}
724+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2011 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.
4+
5+
// This is for issue #29707
6+
7+
package main
8+
9+
/*
10+
#include <pthread.h>
11+
12+
extern void* callback(void*);
13+
typedef void* (*cb)(void*);
14+
15+
static void testCallback(cb cb) {
16+
cb(NULL);
17+
}
18+
*/
19+
import "C"
20+
21+
import (
22+
"bytes"
23+
"fmt"
24+
traceparser "internal/trace"
25+
"runtime/trace"
26+
"time"
27+
"unsafe"
28+
)
29+
30+
func init() {
31+
register("CgoTraceParser", CgoTraceParser)
32+
}
33+
34+
//export callback
35+
func callback(unsafe.Pointer) unsafe.Pointer {
36+
time.Sleep(time.Millisecond)
37+
return nil
38+
}
39+
40+
func CgoTraceParser() {
41+
buf := new(bytes.Buffer)
42+
43+
trace.Start(buf)
44+
C.testCallback(C.cb(C.callback))
45+
trace.Stop()
46+
47+
_, err := traceparser.Parse(buf, "")
48+
if err != nil {
49+
fmt.Println("Parse error: ", err)
50+
} else {
51+
fmt.Println("OK")
52+
}
53+
}

0 commit comments

Comments
 (0)