Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
2ec2288e
Commit
2ec2288e
authored
Dec 22, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
454b6576
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
441 additions
and
20 deletions
+441
-20
go/internal/xtracing/tracetest/example_test.go
go/internal/xtracing/tracetest/example_test.go
+101
-3
go/internal/xtracing/tracetest/tracetest.go
go/internal/xtracing/tracetest/tracetest.go
+274
-17
go/internal/xtracing/tracetest/ztrace_x_test.go
go/internal/xtracing/tracetest/ztrace_x_test.go
+66
-0
No files found.
go/internal/xtracing/tracetest/example_test.go
View file @
2ec2288e
// Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Copyright (C) 2018
-2020
Nexedi SA and Contributors.
//
Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
...
...
@@ -17,6 +17,104 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// XXX explain
package
tracetest_test
// TODO example for tracetest usage
//go:generate gotrace gen .
import
(
"fmt"
"strings"
"sync"
"testing"
"lab.nexedi.com/kirr/go123/tracing"
"lab.nexedi.com/kirr/neo/go/internal/xtracing/tracetest"
)
// hi and hello are functions that emit "(Hi|Hello), <who>" and can be traced.
//trace:event traceHi(who string)
//trace:event traceHello(who string)
func
hi
(
who
string
)
{
traceHi
(
who
)
fmt
.
Println
(
"Hi,"
,
who
)
}
func
hello
(
who
string
)
{
traceHello
(
who
)
fmt
.
Println
(
"Hello,"
,
who
)
}
// TestTracetestExample demonstrates how to use tracetest to verify concurrent system with 2 threads.
func
TestTracetestExample
(
t
*
testing
.
T
)
{
type
eventHi
string
type
eventHello
string
testf
:=
func
(
t
*
tracetest
.
T
)
{
// setup tracing to deliver trace events to t XXX not to t, but to something dedicated?
pg
:=
&
tracing
.
ProbeGroup
{}
tracing
.
Lock
()
traceHi_Attach
(
pg
,
func
(
who
string
)
{
// XXX NewEvent? IncomingEvent?
t
.
RxEvent
(
eventHi
(
who
))
// XXX -> t.OnEvent? not via t?
})
traceHello_Attach
(
pg
,
func
(
who
string
)
{
t
.
RxEvent
(
eventHello
(
who
))
})
tracing
.
Unlock
()
defer
pg
.
Done
()
// tell tracetest to which stream an event should go.
t
.
SetEventRouter
(
func
(
event
interface
{})
(
stream
string
)
{
// it can be only eventHi and eventHello.
// in this test the convention is that who comes as <threadID>·...
// we used threadID as stream.
who
:=
""
switch
ev
:=
event
.
(
type
)
{
default
:
panic
(
fmt
.
Sprintf
(
"unexpected event type %T"
,
event
))
case
eventHi
:
who
=
string
(
ev
)
case
eventHello
:
who
=
string
(
ev
)
}
i
:=
strings
.
Index
(
who
,
"·"
)
if
i
==
-
1
{
panic
(
fmt
.
Sprintf
(
"who does not have threadID: %q"
,
who
))
}
return
strings
.
ToLower
(
who
[
:
i
])
})
// run the workload
var
wg
sync
.
WaitGroup
defer
wg
.
Wait
()
wg
.
Add
(
2
)
go
func
()
{
// thread1
defer
wg
.
Done
()
hi
(
"T1·A"
)
hello
(
"T1·B"
)
}()
go
func
()
{
// thread2
defer
wg
.
Done
()
hi
(
"T2·C"
)
}()
// assert that events come as expected
t
.
Expect
(
"t3"
,
eventHi
(
"T1·C"
))
t
.
Expect
(
"t1"
,
eventHi
(
"T1·A"
))
t
.
Expect
(
"t1"
,
eventHello
(
"T1·B"
))
// XXX also t.Recv, t.ExpectNoAck ?
//t1 := t.OnStream("t1")
//t1.Expect(eventHi("X·A"))
}
tracetest
.
Verify
(
t
,
testf
)
}
go/internal/xtracing/tracetest/tracetest.go
View file @
2ec2288e
This diff is collapsed.
Click to expand it.
go/internal/xtracing/tracetest/ztrace_x_test.go
0 → 100644
View file @
2ec2288e
// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.
package
tracetest_test
// code generated for tracepoints
import
(
"lab.nexedi.com/kirr/go123/tracing"
"unsafe"
)
// traceevent: traceHello(who string)
type
_t_traceHello
struct
{
tracing
.
Probe
probefunc
func
(
who
string
)
}
var
_traceHello
*
_t_traceHello
func
traceHello
(
who
string
)
{
if
_traceHello
!=
nil
{
_traceHello_run
(
who
)
}
}
func
_traceHello_run
(
who
string
)
{
for
p
:=
_traceHello
;
p
!=
nil
;
p
=
(
*
_t_traceHello
)(
unsafe
.
Pointer
(
p
.
Next
()))
{
p
.
probefunc
(
who
)
}
}
func
traceHello_Attach
(
pg
*
tracing
.
ProbeGroup
,
probe
func
(
who
string
))
*
tracing
.
Probe
{
p
:=
_t_traceHello
{
probefunc
:
probe
}
tracing
.
AttachProbe
(
pg
,
(
**
tracing
.
Probe
)(
unsafe
.
Pointer
(
&
_traceHello
)),
&
p
.
Probe
)
return
&
p
.
Probe
}
// traceevent: traceHi(who string)
type
_t_traceHi
struct
{
tracing
.
Probe
probefunc
func
(
who
string
)
}
var
_traceHi
*
_t_traceHi
func
traceHi
(
who
string
)
{
if
_traceHi
!=
nil
{
_traceHi_run
(
who
)
}
}
func
_traceHi_run
(
who
string
)
{
for
p
:=
_traceHi
;
p
!=
nil
;
p
=
(
*
_t_traceHi
)(
unsafe
.
Pointer
(
p
.
Next
()))
{
p
.
probefunc
(
who
)
}
}
func
traceHi_Attach
(
pg
*
tracing
.
ProbeGroup
,
probe
func
(
who
string
))
*
tracing
.
Probe
{
p
:=
_t_traceHi
{
probefunc
:
probe
}
tracing
.
AttachProbe
(
pg
,
(
**
tracing
.
Probe
)(
unsafe
.
Pointer
(
&
_traceHi
)),
&
p
.
Probe
)
return
&
p
.
Probe
}
// trace export signature
func
_trace_exporthash_51bb0086e9435e499919853bae2dbb429f70d833
()
{}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment