File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -710,3 +710,15 @@ func TestCgoTracebackGoroutineProfile(t *testing.T) {
710
710
t .Fatalf ("want %s, got %s\n " , want , output )
711
711
}
712
712
}
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments