Skip to content

wip: test: added cgo trace parse test, should be passed on all platforms. #54491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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* callbackTraceParser(void*);
typedef void* (*cbTraceParser)(void*);

static void testCallbackTraceParser(cbTraceParser cb) {
cb(NULL);
}
*/
import "C"

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

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

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

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

trace.Start(buf)
C.testCallbackTraceParser(C.cbTraceParser(C.callbackTraceParser))
trace.Stop()

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