1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
21
type NamedPoint struct {
26
type DummyWriter struct {
29
type Writer interface {
30
Write(p []byte) (n int)
33
func (d DummyWriter) Write(p []byte) (n int) {
37
var GlobalX, GlobalY int = 0, 0
38
var GlobalCh chan int = make(chan int, 2)
50
func TestRaceIntRWGlobalFuncs(t *testing.T) {
57
func TestRaceIntRWClosures(t *testing.T) {
59
ch := make(chan int, 2)
73
func TestNoRaceIntRWClosures(t *testing.T) {
75
ch := make(chan int, 1)
90
func TestRaceInt32RWClosures(t *testing.T) {
92
ch := make(chan bool, 2)
106
func TestNoRaceCase(t *testing.T) {
108
for x := -1; x <= 1; x++ {
121
func TestRaceCaseCondition(t *testing.T) {
123
ch := make(chan int, 2)
142
func TestRaceCaseCondition2(t *testing.T) {
143
// switch body is rearranged by the compiler so the tests
144
// passes even if we don't instrument '<'
146
ch := make(chan int, 2)
165
func TestRaceCaseBody(t *testing.T) {
167
ch := make(chan int, 2)
186
func TestNoRaceCaseFallthrough(t *testing.T) {
188
ch := make(chan int, 2)
207
func TestRaceCaseFallthrough(t *testing.T) {
209
ch := make(chan int, 2)
230
func TestRaceCaseType(t *testing.T) {
232
var i interface{} = x
233
c := make(chan int, 1)
245
func TestRaceCaseTypeBody(t *testing.T) {
247
var i interface{} = &x
248
c := make(chan int, 1)
250
switch i := i.(type) {
261
func TestNoRaceRange(t *testing.T) {
262
ch := make(chan int, 3)
263
a := [...]int{1, 2, 3}
264
for _, v := range a {
270
func TestRaceRange(t *testing.T) {
274
done := make(chan bool, N)
275
for i, v := range a {
277
// we don't want a write-vs-write race
278
// so there is no array b here
287
for i := 0; i < N; i++ {
292
func TestRacePlus(t *testing.T) {
294
ch := make(chan int, 2)
308
func TestRacePlus2(t *testing.T) {
310
ch := make(chan int, 2)
324
func TestNoRacePlus(t *testing.T) {
326
ch := make(chan int, 2)
340
func TestRaceComplement(t *testing.T) {
342
ch := make(chan int, 2)
356
func TestRaceDiv(t *testing.T) {
358
ch := make(chan int, 2)
372
func TestRaceDivConst(t *testing.T) {
374
ch := make(chan int, 2)
377
x = y / 3 // involves only a HMUL node
388
func TestRaceMod(t *testing.T) {
390
ch := make(chan int, 2)
404
func TestRaceModConst(t *testing.T) {
406
ch := make(chan int, 2)
420
func TestRaceRotate(t *testing.T) {
422
ch := make(chan int, 2)
436
// May crash if the instrumentation is reckless.
437
func TestNoRaceEnoughRegisters(t *testing.T) {
451
S = 1 + s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(sa5+s*(sa6+s*(sa7+s*sa8)))))))
455
// emptyFunc should not be inlined.
456
func emptyFunc(x int) {
462
func TestRaceFuncArgument(t *testing.T) {
464
ch := make(chan bool, 1)
473
func TestRaceFuncArgument2(t *testing.T) {
475
ch := make(chan bool, 2)
487
func TestRaceSprint(t *testing.T) {
489
ch := make(chan bool, 1)
499
func TestRaceFailingArrayCopy(t *testing.T) {
500
ch := make(chan bool, 1)
506
a = [5]int{1, 2, 3, 4, 5}
510
func TestRaceStructRW(t *testing.T) {
512
ch := make(chan bool, 1)
522
func TestRaceStructFieldRW1(t *testing.T) {
524
ch := make(chan bool, 1)
533
func TestNoRaceStructFieldRW1(t *testing.T) {
534
// Same struct, different variables, no
535
// pointers. The layout is known (at compile time?) ->
539
ch := make(chan bool, 1)
549
func TestNoRaceStructFieldRW2(t *testing.T) {
550
// Same as NoRaceStructFieldRW1
551
// but p is a pointer, so there is a read on p
553
ch := make(chan bool, 1)
563
func TestRaceStructFieldRW2(t *testing.T) {
565
ch := make(chan bool, 1)
574
func TestRaceStructFieldRW3(t *testing.T) {
575
p := NamedPoint{name: "a", p: Point{0, 0}}
576
ch := make(chan bool, 1)
585
func TestRaceEfaceWW(t *testing.T) {
587
ch := make(chan bool, 1)
597
func TestRaceIfaceWW(t *testing.T) {
599
ch := make(chan bool, 1)
610
func TestRaceIfaceCmp(t *testing.T) {
613
ch := make(chan bool, 1)
622
func TestRaceIfaceCmpNil(t *testing.T) {
625
ch := make(chan bool, 1)
634
func TestRaceEfaceConv(t *testing.T) {
638
go func(x interface{}) {
648
func (*OsFile) Read() {
651
type IoReader interface {
655
func TestRaceIfaceConv(t *testing.T) {
659
go func(x IoReader) {
667
func TestRaceError(t *testing.T) {
668
ch := make(chan bool, 1)
678
func TestRaceIntptrRW(t *testing.T) {
681
ch := make(chan bool, 1)
691
func TestRaceStringRW(t *testing.T) {
692
ch := make(chan bool, 1)
702
func TestRaceStringPtrRW(t *testing.T) {
703
ch := make(chan bool, 1)
714
func TestRaceFloat64WW(t *testing.T) {
716
ch := make(chan bool, 1)
728
func TestRaceComplex128WW(t *testing.T) {
730
ch := make(chan bool, 1)
742
func TestRaceUnsafePtrRW(t *testing.T) {
745
var p unsafe.Pointer = unsafe.Pointer(&x)
746
ch := make(chan bool, 1)
748
p = (unsafe.Pointer)(&z)
756
func TestRaceFuncVariableRW(t *testing.T) {
757
var f func(x int) int
758
f = func(x int) int {
761
ch := make(chan bool, 1)
763
f = func(x int) int {
774
func TestRaceFuncVariableWW(t *testing.T) {
775
var f func(x int) int
776
ch := make(chan bool, 1)
778
f = func(x int) int {
783
f = func(x int) int {
789
// This one should not belong to mop_test
790
func TestRacePanic(t *testing.T) {
793
ch := make(chan bool, 2)
798
panic("should be panicking")
810
panic("should be panicking")
822
panic("zero has changed")
826
func TestNoRaceBlank(t *testing.T) {
828
ch := make(chan bool, 1)
838
func TestRaceAppendRW(t *testing.T) {
840
ch := make(chan bool)
849
func TestRaceAppendLenRW(t *testing.T) {
851
ch := make(chan bool)
860
func TestRaceAppendCapRW(t *testing.T) {
862
ch := make(chan string)
871
func TestNoRaceFuncArgsRW(t *testing.T) {
872
ch := make(chan byte, 1)
882
func TestRaceFuncArgsRW(t *testing.T) {
883
ch := make(chan byte, 1)
893
// from the mailing list, slightly modified
894
// unprotected concurrent access to seen[]
895
func TestRaceCrawl(t *testing.T) {
898
seen := make(map[string]bool)
899
ch := make(chan int, 100)
900
var wg sync.WaitGroup
901
var crawl func(string, int)
902
crawl = func(u string, d int) {
911
urls := [...]string{"a", "b", "c"}
912
for _, uu := range urls {
913
if _, ok := seen[uu]; !ok {
926
func TestRaceIndirection(t *testing.T) {
927
ch := make(chan struct{}, 1)
939
func TestRaceRune(t *testing.T) {
950
func TestRaceEmptyInterface1(t *testing.T) {
961
func TestRaceEmptyInterface2(t *testing.T) {
972
func TestRaceTLS(t *testing.T) {
973
comm := make(chan *int)
974
done := make(chan bool, 2)
992
func TestNoRaceHeapReallocation(t *testing.T) {
993
// It is possible that a future implementation
994
// of memory allocation will ruin this test.
995
// Increasing n might help in this case, so
996
// this test is a bit more generic than most of the
999
done := make(chan bool, n)
1000
empty := func(p *int) {}
1001
for i := 0; i < n; i++ {
1004
<-time.After(time.Duration(ms) * time.Millisecond)
1007
empty(&x) // x goes to the heap
1011
for i := 0; i < n; i++ {
1016
func TestRaceAnd(t *testing.T) {
1017
c := make(chan bool)
1023
if x == 1 && y == 1 {
1028
func TestRaceAnd2(t *testing.T) {
1029
c := make(chan bool)
1035
if y == 0 && x == 1 {
1040
func TestNoRaceAnd(t *testing.T) {
1041
c := make(chan bool)
1047
if y == 1 && x == 1 {
1052
func TestRaceOr(t *testing.T) {
1053
c := make(chan bool)
1059
if x == 1 || y == 1 {
1064
func TestRaceOr2(t *testing.T) {
1065
c := make(chan bool)
1071
if y == 1 || x == 1 {
1076
func TestNoRaceOr(t *testing.T) {
1077
c := make(chan bool)
1083
if y == 0 || x == 1 {
1088
func TestNoRaceShortCalc(t *testing.T) {
1089
c := make(chan bool)
1095
if x == 0 || y == 0 {
1100
func TestNoRaceShortCalc2(t *testing.T) {
1101
c := make(chan bool)
1107
if x == 1 && y == 0 {
1112
func TestRaceFuncItself(t *testing.T) {
1113
c := make(chan bool)
1123
func TestNoRaceFuncUnlock(t *testing.T) {
1124
ch := make(chan bool, 1)
1133
x = func(mu *sync.Mutex) int {
1141
func TestRaceStructInit(t *testing.T) {
1145
c := make(chan bool, 1)
1156
func TestRaceArrayInit(t *testing.T) {
1157
c := make(chan bool, 1)
1163
x := []int{0, y, 42}
1168
func TestRaceMapInit(t *testing.T) {
1169
c := make(chan bool, 1)
1175
x := map[int]int{0: 42, y: 42}
1180
func TestRaceMapInit2(t *testing.T) {
1181
c := make(chan bool, 1)
1187
x := map[int]int{0: 42, 42: y}
1192
type Inter interface {
1195
type InterImpl struct {
1199
func (p InterImpl) Foo(x int) {
1209
type InterImpl2 InterImpl
1211
func (p *InterImpl2) Foo(x int) {
1215
InterImpl(*p).Foo(x)
1218
func TestRaceInterCall(t *testing.T) {
1219
c := make(chan bool, 1)
1231
func TestRaceInterCall2(t *testing.T) {
1232
c := make(chan bool, 1)
1244
func TestRaceFuncCall(t *testing.T) {
1245
c := make(chan bool, 1)
1246
f := func(x, y int) {}
1256
func TestRaceMethodCall(t *testing.T) {
1257
c := make(chan bool, 1)
1268
func TestRaceMethodCall2(t *testing.T) {
1269
c := make(chan bool, 1)
1279
// Method value with concrete value receiver.
1280
func TestRaceMethodValue(t *testing.T) {
1281
c := make(chan bool, 1)
1291
// Method value with interface receiver.
1292
func TestRaceMethodValue2(t *testing.T) {
1293
c := make(chan bool, 1)
1294
var i Inter = InterImpl{}
1303
// Method value with implicit dereference.
1304
func TestRaceMethodValue3(t *testing.T) {
1305
c := make(chan bool, 1)
1311
_ = i.Foo // dereferences i.
1315
// Method value implicitly taking receiver address.
1316
func TestNoRaceMethodValue(t *testing.T) {
1317
c := make(chan bool, 1)
1323
_ = i.Foo // takes the address of i only.
1327
func TestRacePanicArg(t *testing.T) {
1328
c := make(chan bool, 1)
1329
err := errors.New("err")
1331
err = errors.New("err2")
1341
func TestRaceDeferArg(t *testing.T) {
1342
c := make(chan bool, 1)
1357
func (d DeferT) Foo() {
1360
func TestRaceDeferArg2(t *testing.T) {
1361
c := make(chan bool, 1)
1374
func TestNoRaceAddrExpr(t *testing.T) {
1375
c := make(chan bool, 1)
1390
type AddrT2 struct {
1395
func TestRaceAddrExpr(t *testing.T) {
1396
c := make(chan bool, 1)
1397
a := AddrT2{p: &AddrT{x: 42}}
1406
func TestRaceTypeAssert(t *testing.T) {
1407
c := make(chan bool, 1)
1409
var i interface{} = x
1419
func TestRaceBlockAs(t *testing.T) {
1420
c := make(chan bool, 1)
1430
func TestRaceSliceSlice(t *testing.T) {
1431
c := make(chan bool, 1)
1432
x := make([]int, 10)
1441
func TestRaceSliceSlice2(t *testing.T) {
1442
c := make(chan bool, 1)
1443
x := make([]int, 10)
1453
func TestRaceSliceString(t *testing.T) {
1454
c := make(chan bool, 1)
1464
// http://golang.org/issue/4453
1465
func TestRaceFailingSliceStruct(t *testing.T) {
1469
c := make(chan bool, 1)
1480
func TestRaceFailingAppendSliceStruct(t *testing.T) {
1484
c := make(chan bool, 1)
1487
y := make([]X, 0, 10)
1495
func TestRaceStructInd(t *testing.T) {
1496
c := make(chan bool, 1)
1509
func TestRaceAsFunc1(t *testing.T) {
1511
c := make(chan bool, 1)
1514
s, err = func() ([]byte, error) {
1515
t := []byte("hello world")
1525
func TestRaceAsFunc2(t *testing.T) {
1526
c := make(chan bool, 1)
1537
func TestRaceAsFunc3(t *testing.T) {
1538
c := make(chan bool, 1)
1544
}(x) // Read of x must be outside of the mutex.
1554
func TestNoRaceAsFunc4(t *testing.T) {
1555
c := make(chan bool, 1)
1559
x = func() int { // Write of x must be under the mutex.
1572
func TestRaceHeapParam(t *testing.T) {
1573
x := func() (x int) {
1582
func TestNoRaceEmptyStruct(t *testing.T) {
1602
func TestRaceNestedStruct(t *testing.T) {