Commit b7e99d87 authored by Kirill Smelkov's avatar Kirill Smelkov

tracing/gotrace: Fix tests for Go1.10 where CGo is now supported

Go1.10 now modifies CGo sources as text, not AST, and this way comments
are not removed and gotrace can see its '//trace:event ' comments in a
CGo *.go files: https://github.com/golang/go/commit/85c3ebf4.

This way with Go1.10 tests were failing because `//trace:event
traceHello()` in a/pkg1/pkg1c.go was now noticed by gotrace and more
then expected trace events produces.

I have not noticed this in 65c399f0 (tracing/runtime: Add support for
Go1.10 (preliminary)) probably because at that time above Go commit was
not in my local Go1.10 tree.

For the reference: tracing/runtime support regenerated for Go1.10.2
stays exactly the same as in 65c399f0 and so does not need updating.
parent e58c6ea2
// Copyright (C) 2017 Nexedi SA and Contributors. // Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -281,10 +281,9 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err ...@@ -281,10 +281,9 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err
// go through files of the original package and process //trace: directives // go through files of the original package and process //trace: directives
// //
// FIXME we currently don't process cgo files as go/loader passes to us // NOTE before go1.10 we don't process cgo files as there go/loader passes to us
// already preprocessed results with comments stripped, not original source. // already preprocessed results with comments stripped, not original source.
// Maybe in some time it will be possible to have AST of original source: // This problem was fixed for go1.10 in https://github.com/golang/go/commit/85c3ebf4.
// https://golang.org/issues/16623
for _, file := range pkgi.Files { // ast.File for _, file := range pkgi.Files { // ast.File
for _, commgroup := range file.Comments { // ast.CommentGroup for _, commgroup := range file.Comments { // ast.CommentGroup
for _, comment := range commgroup.List { // ast.Comment for _, comment := range commgroup.List { // ast.Comment
......
...@@ -134,6 +134,16 @@ func diffR(patha, pathb string) (diff string, err error) { ...@@ -134,6 +134,16 @@ func diffR(patha, pathb string) (diff string, err error) {
return string(out), err return string(out), err
} }
// haveReleaseTag returns whether current compiler has specified tag in its default build environment.
func haveReleaseTag(tag string) bool {
for _, rtag := range build.Default.ReleaseTags {
if tag == rtag {
return true
}
}
return false
}
func TestGoTrace(t *testing.T) { func TestGoTrace(t *testing.T) {
tmp, err := ioutil.TempDir("", "t-gotrace") tmp, err := ioutil.TempDir("", "t-gotrace")
if err != nil { if err != nil {
...@@ -159,6 +169,10 @@ func TestGoTrace(t *testing.T) { ...@@ -159,6 +169,10 @@ func TestGoTrace(t *testing.T) {
// XXX autodetect (go list ?) // XXX autodetect (go list ?)
testv := []string{"a/pkg1", "b/pkg2", "c/pkg3", "d/pkg4"} testv := []string{"a/pkg1", "b/pkg2", "c/pkg3", "d/pkg4"}
// cgo parsing works starting with Go 1.10
if haveReleaseTag("go1.10") {
testv = append(testv, "a/pkg1_cgo")
}
for _, tpkg := range testv { for _, tpkg := range testv {
// verify `gotrace gen` // verify `gotrace gen`
......
...@@ -9,13 +9,10 @@ void hello() { ...@@ -9,13 +9,10 @@ void hello() {
*/ */
import "C" import "C"
// FIXME vvv does not currently work because go/loader gives us already
// preprocessed result without original comments.
//
// trace event defined in a cgo file // trace event defined in a cgo file
//trace:event traceHello() //trace:event traceCHello()
func Hello() { func Hello() {
//traceHello() traceCHello()
C.hello() C.hello()
} }
// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.
package pkg1
// code generated for tracepoints
import (
"lab.nexedi.com/kirr/go123/tracing"
"unsafe"
)
// traceevent: traceCHello()
type _t_traceCHello struct {
tracing.Probe
probefunc func()
}
var _traceCHello *_t_traceCHello
func traceCHello() {
if _traceCHello != nil {
_traceCHello_run()
}
}
func _traceCHello_run() {
for p := _traceCHello; p != nil; p = (*_t_traceCHello)(unsafe.Pointer(p.Next())) {
p.probefunc()
}
}
func traceCHello_Attach(pg *tracing.ProbeGroup, probe func()) *tracing.Probe {
p := _t_traceCHello{probefunc: probe}
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceCHello)), &p.Probe)
return &p.Probe
}
// trace export signature
func _trace_exporthash_6c1e623c8877bd3e4d9efc72e73ac2bdbf56462b() {}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment