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
e3937d32
Commit
e3937d32
authored
Oct 25, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X tracing: Test for start/stop the world.
parent
cf299b65
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
1 deletion
+73
-1
go/xcommon/tracing/internal/xruntime/runtime_test.go
go/xcommon/tracing/internal/xruntime/runtime_test.go
+73
-1
No files found.
go/xcommon/tracing/internal/xruntime/runtime_test.go
View file @
e3937d32
package
xruntime
// TODO tests for stop/start the world.
import
(
"runtime"
"sync/atomic"
"testing"
"time"
)
func
TestStartStopTheWorld
(
t
*
testing
.
T
)
{
var
x
,
stop
int32
ready
:=
make
(
chan
int
)
go
func
()
{
// make sure the thread running this goroutine is different from thread for main g.
// this way we can be sure there are 2 OS threads in action and communicating via busywait should work.
runtime
.
LockOSThread
()
ready
<-
0
for
atomic
.
LoadInt32
(
&
stop
)
==
0
{
atomic
.
AddInt32
(
&
x
,
1
)
// XXX as of go19 tight loops are not preemptible (golang.org/issues/10958)
// -> explicitly make sure we do not miss STW request.
runtime
.
Gosched
()
}
}()
// wait for spawned goroutine to jump into its own thread
<-
ready
// verify g and g2 are indeed running in parallel
xprev
:=
atomic
.
LoadInt32
(
&
x
)
xnext
:=
xprev
nδ
:=
0
tstart
:=
time
.
Now
()
for
nδ
<
100
&&
time
.
Now
()
.
Sub
(
tstart
)
<
time
.
Second
{
xnext
=
atomic
.
LoadInt32
(
&
x
)
if
xnext
!=
xprev
{
nδ
+=
1
xprev
=
xnext
}
}
if
nδ
==
0
{
t
.
Fatal
(
"g and g2 are not running in parallel"
)
}
// now stop the world and for 1s make sure g2 is not running in parallel with us
StopTheWorld
(
"just for my reason"
)
xprev
=
atomic
.
LoadInt32
(
&
x
)
xnext
=
xprev
nδ
=
0
tstart
=
time
.
Now
()
for
time
.
Now
()
.
Sub
(
tstart
)
<
time
.
Second
{
for
i
:=
0
;
i
<
100
;
i
++
{
xnext
=
atomic
.
LoadInt32
(
&
x
)
if
xnext
!=
xprev
{
nδ
+=
1
xprev
=
xnext
}
}
}
StartTheWorld
()
if
nδ
!=
0
{
t
.
Fatalf
(
"g2 modified x at least %d times while the world was stopped"
,
nδ
)
}
atomic
.
StoreInt32
(
&
stop
,
1
)
}
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