Skip to content

Commit

Permalink
wip: test: added cgo trace parse test, should be passed in on platforms.
Browse files Browse the repository at this point in the history
just a test for golang#54458
  • Loading branch information
doujiang24 committed Aug 17, 2022
1 parent e49e876 commit dc032ab
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/runtime/crash_cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,15 @@ func TestCgoTracebackGoroutineProfile(t *testing.T) {
t.Fatalf("want %s, got %s\n", want, output)
}
}

func TestCgoTraceParser(t *testing.T) {
switch runtime.GOOS {
case "windows", "plan9":
t.Skipf("skipping cgo trace parser test on %s", runtime.GOOS)
}
output := runTestProg(t, "testprogcgo", "CgoTraceParser")
want := "OK\n"
if output != want {
t.Fatalf("want %s, got %s\n", want, output)
}
}
53 changes: 53 additions & 0 deletions src/runtime/testdata/testprogcgo/cgotrace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2011 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.

// This is for issue #29707

package main

/*
#include <pthread.h>
extern void* callback(void*);
typedef void* (*cb)(void*);
static void testCallback(cb cb) {
cb(NULL);
}
*/
import "C"

import (
"bytes"
"fmt"
traceparser "internal/trace"
"runtime/trace"
"time"
"unsafe"
)

func init() {
register("CgoTraceParser", CgoTraceParser)
}

//export callback
func callback(unsafe.Pointer) unsafe.Pointer {
time.Sleep(time.Millisecond)
return nil
}

func CgoTraceParser() {
buf := new(bytes.Buffer)

trace.Start(buf)
C.testCallback(C.cb(C.callback))
trace.Stop()

_, err := traceparser.Parse(buf, "")
if err != nil {
fmt.Println("Parse error: ", err)
} else {
fmt.Println("OK")
}
}

0 comments on commit dc032ab

Please sign in to comment.